From 665e50f45626232b5a6a5e9a4dff22865c0cdab7 Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Thu, 7 Mar 2024 15:15:20 +0100 Subject: [PATCH] first std::function test --- src/raspikeyer.cpp | 8 ++++++++ src/winkeyer.cpp | 6 ++++++ src/winkeyer.h | 5 +++++ 3 files changed, 19 insertions(+) diff --git a/src/raspikeyer.cpp b/src/raspikeyer.cpp index f0d620e..18c9ea4 100644 --- a/src/raspikeyer.cpp +++ b/src/raspikeyer.cpp @@ -2,6 +2,7 @@ #include #include +#include #include "bsp/board.h" #include "hardware/adc.h" @@ -101,6 +102,10 @@ void core1_main() } } +void test() { + printf("Test\n"); +} + int main() { 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}; queue_add_blocking(&keyerQueue, &keyerQueueData); + std::function f_observer = test; + WinKeyer winKeyer; + winKeyer.addObserver(f_observer); pio_hw_t *pio = pio0; TM1637 display {DISPLAY_DIO_PIN, DISPLAY_CLK_PIN, pio}; diff --git a/src/winkeyer.cpp b/src/winkeyer.cpp index c0c53fb..3a35ba3 100644 --- a/src/winkeyer.cpp +++ b/src/winkeyer.cpp @@ -103,4 +103,10 @@ void WinKeyer::run(queue_t &queue) m_commandState = CommandState::None; } } +} + +void WinKeyer::addObserver(std::function obs) { + m_observers.push_back(obs); + + obs(); } \ No newline at end of file diff --git a/src/winkeyer.h b/src/winkeyer.h index e0aabee..19e02c5 100644 --- a/src/winkeyer.h +++ b/src/winkeyer.h @@ -1,11 +1,15 @@ #pragma once +#include +#include + #include "pico/util/queue.h" class WinKeyer final { public: void run(queue_t &queue); + void addObserver(std::function obs); private: enum class CommandState { @@ -24,4 +28,5 @@ class WinKeyer final CommandState m_commandState {CommandState::None}; WkMode m_wkMode {WkMode::WK1}; bool m_hostOpen {false}; + std::vector> m_observers; }; \ No newline at end of file