Skip to content

Commit

Permalink
Proxy PinPatternManager::RunPattern
Browse files Browse the repository at this point in the history
  • Loading branch information
hhvrc committed Oct 23, 2024
1 parent 6fc14f4 commit f85a991
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
5 changes: 3 additions & 2 deletions include/PinPatternManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ namespace OpenShock {

void SetPattern(const State* pattern, std::size_t patternLength);
template<std::size_t N>
inline void SetPattern(const State (&pattern)[N]) {
inline void SetPattern(const State (&pattern)[N])
{
SetPattern(pattern, N);
}
void ClearPattern();

private:
void ClearPatternInternal();
static void RunPattern(void* arg);
void RunPattern();

gpio_num_t m_gpioPin;
std::vector<State> m_pattern;
Expand Down
15 changes: 6 additions & 9 deletions src/PinPatternManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const char* const TAG = "PinPatternManager";

#include "Chipset.h"
#include "Logging.h"
#include "util/FnProxy.h"
#include "util/TaskUtils.h"

using namespace OpenShock;

Expand Down Expand Up @@ -62,7 +64,7 @@ void PinPatternManager::SetPattern(const State* pattern, std::size_t patternLeng
snprintf(name, sizeof(name), "PinPatternManager-%hhi", m_gpioPin);

// Start the task
BaseType_t result = xTaskCreate(RunPattern, name, 1024, this, 1, &m_taskHandle); // PROFILED: 0.5KB stack usage
BaseType_t result = TaskUtils::TaskCreateUniversal(&Util::FnProxy<&PinPatternManager::RunPattern>, name, 1024, this, 1, &m_taskHandle, 1); // PROFILED: 0.5KB stack usage
if (result != pdPASS) {
OS_LOGE(TAG, "[pin-%hhi] Failed to create task: %d", m_gpioPin, result);

Expand Down Expand Up @@ -92,16 +94,11 @@ void PinPatternManager::ClearPatternInternal()
m_pattern.clear();
}

void PinPatternManager::RunPattern(void* arg)
void PinPatternManager::RunPattern()
{
PinPatternManager* thisPtr = reinterpret_cast<PinPatternManager*>(arg);

gpio_num_t pin = thisPtr->m_gpioPin;
std::vector<State>& pattern = thisPtr->m_pattern;

while (true) {
for (const auto& state : pattern) {
gpio_set_level(pin, state.level);
for (const auto& state : m_pattern) {
gpio_set_level(m_gpioPin, state.level);
vTaskDelay(pdMS_TO_TICKS(state.duration));
}
}
Expand Down

0 comments on commit f85a991

Please sign in to comment.