first std::function test

This commit is contained in:
Martin Brodbeck 2024-03-07 15:15:20 +01:00
parent 87ea5f663f
commit 665e50f456
3 changed files with 19 additions and 0 deletions

View file

@ -2,6 +2,7 @@
#include <stdio.h> #include <stdio.h>
#include <utility> #include <utility>
#include <functional>
#include "bsp/board.h" #include "bsp/board.h"
#include "hardware/adc.h" #include "hardware/adc.h"
@ -101,6 +102,10 @@ void core1_main()
} }
} }
void test() {
printf("Test\n");
}
int main() int main()
{ {
timer_hw->dbgpause = 0; // workaround for problem with debug and sleep_ms timer_hw->dbgpause = 0; // workaround for problem with debug and sleep_ms
@ -130,7 +135,10 @@ int main()
KeyerQueueData keyerQueueData {KeyerQueueCommand::Run, currentWpm, settings.mode, 0}; KeyerQueueData keyerQueueData {KeyerQueueCommand::Run, currentWpm, settings.mode, 0};
queue_add_blocking(&keyerQueue, &keyerQueueData); queue_add_blocking(&keyerQueue, &keyerQueueData);
std::function<void()> f_observer = test;
WinKeyer winKeyer; WinKeyer winKeyer;
winKeyer.addObserver(f_observer);
pio_hw_t *pio = pio0; pio_hw_t *pio = pio0;
TM1637 display {DISPLAY_DIO_PIN, DISPLAY_CLK_PIN, pio}; TM1637 display {DISPLAY_DIO_PIN, DISPLAY_CLK_PIN, pio};

View file

@ -104,3 +104,9 @@ void WinKeyer::run(queue_t &queue)
} }
} }
} }
void WinKeyer::addObserver(std::function<void()> obs) {
m_observers.push_back(obs);
obs();
}

View file

@ -1,11 +1,15 @@
#pragma once #pragma once
#include <vector>
#include <functional>
#include "pico/util/queue.h" #include "pico/util/queue.h"
class WinKeyer final class WinKeyer final
{ {
public: public:
void run(queue_t &queue); void run(queue_t &queue);
void addObserver(std::function<void()> obs);
private: private:
enum class CommandState { enum class CommandState {
@ -24,4 +28,5 @@ class WinKeyer final
CommandState m_commandState {CommandState::None}; CommandState m_commandState {CommandState::None};
WkMode m_wkMode {WkMode::WK1}; WkMode m_wkMode {WkMode::WK1};
bool m_hostOpen {false}; bool m_hostOpen {false};
std::vector<std::function<void()>> m_observers;
}; };