Compare commits
No commits in common. "c5f3220569de6bd2a9eec418aa404ecd4cb37f92" and "10e937b0dd10ee6fcf3574c1a2dc206c971f33ea" have entirely different histories.
c5f3220569
...
10e937b0dd
5 changed files with 15 additions and 109 deletions
|
@ -15,7 +15,4 @@ framework = arduino
|
|||
board_build.partitions = huge_app.csv
|
||||
lib_deps = etlcpp/Embedded Template Library@^20.35.12
|
||||
monitor_speed=115200
|
||||
build_flags=-Wall
|
||||
check_tool = clangtidy
|
||||
check_flags =
|
||||
clangtidy: --checks=-*,clang-diagnostic-*,-clang-diagnostic-unused-value,clang-analyzer-*,-*,bugprone-*,performance-*,readability-*,-readability-magic-numbers,-readability-braces-around-statements,-readability-inconsistent-declaration-parameter-name,-readability-named-parameter --fix
|
||||
upload_port=/dev/ttyUSB1
|
||||
|
|
|
@ -8,7 +8,7 @@ freertos::Task::Task(TaskFunction_t taskFunction, const etl::string_view name,
|
|||
params, priority, &handle, coreID);
|
||||
}
|
||||
|
||||
freertos::Task::Task(Task &&other) noexcept
|
||||
freertos::Task::Task(Task &&other)
|
||||
: name{etl::move(other.name)}, handle{etl::move(other.handle)},
|
||||
stackDepth{etl::move(other.stackDepth)},
|
||||
priority{etl::move(other.priority)}, coreID{etl::move(other.coreID)} {}
|
||||
|
@ -19,7 +19,7 @@ freertos::Task::~Task() {
|
|||
}
|
||||
}
|
||||
|
||||
auto freertos::Task::operator=(const Task &&other) noexcept -> Task & {
|
||||
auto freertos::Task::operator=(const Task &&other) -> Task & {
|
||||
name = etl::move(other.name);
|
||||
handle = etl::move(other.handle);
|
||||
stackDepth = etl::move(other.stackDepth);
|
||||
|
@ -28,16 +28,16 @@ auto freertos::Task::operator=(const Task &&other) noexcept -> Task & {
|
|||
return *this;
|
||||
}
|
||||
|
||||
auto freertos::Task::getName() const -> etl::string_view { return name; }
|
||||
auto freertos::Task::getName() -> etl::string_view { return name; }
|
||||
|
||||
auto freertos::Task::getStackDepth() const -> uint32_t { return stackDepth; }
|
||||
auto freertos::Task::getStackDepth() -> uint32_t { return stackDepth; }
|
||||
|
||||
auto freertos::Task::getPriority() const -> UBaseType_t { return priority; }
|
||||
auto freertos::Task::getPriority() -> UBaseType_t { return priority; }
|
||||
|
||||
auto freertos::Task::setPriority(const UBaseType_t newPriority) -> void {
|
||||
vTaskPrioritySet(handle, newPriority);
|
||||
}
|
||||
|
||||
auto freertos::Task::getCoreID() const -> BaseType_t { return coreID; }
|
||||
auto freertos::Task::getCoreID() -> BaseType_t { return coreID; }
|
||||
|
||||
auto freertos::Task::isValid() const -> bool { return status == pdPASS; }
|
||||
auto freertos::Task::isValid() -> bool { return status == pdPASS; }
|
|
@ -9,17 +9,17 @@ public:
|
|||
const uint32_t stackDepth, void *const params, UBaseType_t priority,
|
||||
const BaseType_t coreID);
|
||||
Task(const Task &other) = delete;
|
||||
Task(Task &&other) noexcept;
|
||||
Task(Task &&other);
|
||||
~Task();
|
||||
Task &operator=(const Task &other) = delete;
|
||||
Task &operator=(const Task &&other) noexcept;
|
||||
Task &operator=(const Task &&other);
|
||||
|
||||
etl::string_view getName() const;
|
||||
uint32_t getStackDepth() const;
|
||||
UBaseType_t getPriority() const;
|
||||
etl::string_view getName();
|
||||
uint32_t getStackDepth();
|
||||
UBaseType_t getPriority();
|
||||
void setPriority(const UBaseType_t newPriority);
|
||||
BaseType_t getCoreID() const;
|
||||
bool isValid() const;
|
||||
BaseType_t getCoreID();
|
||||
bool isValid();
|
||||
|
||||
private:
|
||||
etl::string_view name;
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
#pragma once
|
||||
#include <Arduino.h>
|
||||
|
||||
namespace freertos {
|
||||
/// @brief Blocks the task for the specified amount of time
|
||||
/// @param time in milliseconds
|
||||
void sleep(int time) { vTaskDelay(time * portTICK_PERIOD_MS); }
|
||||
} // namespace freertos
|
|
@ -1,83 +0,0 @@
|
|||
#pragma once
|
||||
#include <Arduino.h>
|
||||
#include <FreeRTOS/Queue.h>
|
||||
#include <FreeRTOS/Task.h>
|
||||
#include <etl/optional.h>
|
||||
#include <etl/span.h>
|
||||
|
||||
namespace LightController {
|
||||
enum class LightActionType { INCREASE, DECREASE, TOGGLE, ON, OFF };
|
||||
using LightAction = etl::pair<LightActionType, etl::optional<uint8_t>>;
|
||||
|
||||
template <int... PIN> class Controller {
|
||||
public:
|
||||
Controller(size_t actionQueueSize, UBaseType_t priority, BaseType_t coreID)
|
||||
: lightPins{PIN...}, lightActions{actionQueueSize},
|
||||
lightControllerTask{exec, "control lights", stackDepth,
|
||||
this, priority, coreID} {
|
||||
for (int pin : lightPins) {
|
||||
pinMode(pin, OUTPUT);
|
||||
}
|
||||
}
|
||||
|
||||
freertos::Queue<LightAction> &getActionQueue() { return lightActions; }
|
||||
constexpr size_t lightCount() { return lightPins.size(); }
|
||||
const etl::span<int> getPins() { return lightPins; }
|
||||
|
||||
private:
|
||||
static void exec(void *controllerPtr) {
|
||||
Controller<PIN...> *controller{
|
||||
static_cast<Controller<PIN...> *>(controllerPtr)};
|
||||
etl::array<uint8_t, sizeof...(PIN)> lightStates;
|
||||
const uint8_t step = 5;
|
||||
|
||||
while (true) {
|
||||
auto action{controller->getActionQueue().pop()};
|
||||
if (action.has_value()) {
|
||||
LightActionType type{action.value().first};
|
||||
etl::optional<uint8_t> index{action.value().second};
|
||||
|
||||
switch (type) {
|
||||
case LightActionType::INCREASE:
|
||||
if (index.has_value() && index.value() < lightStates.size() &&
|
||||
lightStates[index.value()] <= 255 - step) {
|
||||
lightStates[index.value()] += step;
|
||||
}
|
||||
break;
|
||||
case LightActionType::DECREASE:
|
||||
if (index.has_value() && index.value() < lightStates.size() &&
|
||||
lightStates[index.value()] >= 0) {
|
||||
lightStates[index.value()] -= step;
|
||||
}
|
||||
break;
|
||||
case LightActionType::TOGGLE:
|
||||
if (index.has_value() && index.value() < lightStates.size()) {
|
||||
lightStates[index.value()] =
|
||||
lightStates[index.value()] == 0 ? 255 : 0;
|
||||
}
|
||||
break;
|
||||
case LightActionType::ON:
|
||||
lightStates.fill(255);
|
||||
break;
|
||||
case LightActionType::OFF:
|
||||
lightStates.fill(0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
for (size_t lightIndex = 0; lightIndex < lightStates.size();
|
||||
++lightIndex) {
|
||||
analogWrite(controller->getPins()[lightIndex],
|
||||
lightStates[lightIndex]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static const uint32_t stackDepth = 2048;
|
||||
etl::array<int, sizeof...(PIN)> lightPins;
|
||||
freertos::Queue<LightAction> lightActions;
|
||||
freertos::Task lightControllerTask;
|
||||
};
|
||||
} // namespace LightController
|
Reference in a new issue