From 2240d6ce09ac11e5f3f582af1df4466b5894d870 Mon Sep 17 00:00:00 2001 From: Vasily Davydov Date: Thu, 11 May 2023 01:22:05 +0300 Subject: [PATCH] master: [#9] parse event in master to route it fwd --- source/shoh/src/threads/master/Master.cpp | 58 +++++++++++++++++++---- source/shoh/src/threads/master/Master.h | 2 + 2 files changed, 50 insertions(+), 10 deletions(-) diff --git a/source/shoh/src/threads/master/Master.cpp b/source/shoh/src/threads/master/Master.cpp index aaf4588..96efbbf 100644 --- a/source/shoh/src/threads/master/Master.cpp +++ b/source/shoh/src/threads/master/Master.cpp @@ -12,36 +12,74 @@ Master::Master(ThreadCommon::QueueManager* qm) : _qm(qm) } -void Master::taskFunction() { - Event data(Event::Null, 0); +void Master::HandleEventType(Event* e, Event::EventType type) +{ + switch (type) + { + case Event::Null: + break; + case Event::Rotary: + _qm->send(ThreadCommon::QueueManager::manager_event_master, e, 0); + DebugRotaryEvent(e->getDataOf(Event::Rotary)); + break; + case Event::InternalTemp: + // TODO remove (deprecated) + break; + case Event::ExternalTemp: + //TODO comes from sensors, goes to relay & manager + break; + case Event::SetPoint: + //TODO comes from manager, goes to relay + break; + default: + assert(0); + break; + } +} + +void Master::DebugRotaryEvent(EventRawData e_data) +{ bool LedState = true; - for (;;) { - if(!_qm->receive(ThreadCommon::QueueManager::master_event_all, &data, 10000)) - data.setDataOf(Event::Rotary, ThreadCommon::RotaryAction::Idle); - switch(data.getDataOf(Event::Rotary)) + switch(e_data) { case ThreadCommon::RotaryAction::Right: Board_LED_Set(ThreadCommon::RotaryAction::Right, LedState); printf("Right\r\n"); - _qm->send(ThreadCommon::QueueManager::manager_event_master, &data, 0); break; case ThreadCommon::RotaryAction::Left: Board_LED_Set(ThreadCommon::RotaryAction::Left, LedState); printf("Left\r\n"); - _qm->send(ThreadCommon::QueueManager::manager_event_master, &data, 0); break; case ThreadCommon::RotaryAction::Press: Board_LED_Set(ThreadCommon::RotaryAction::Press, LedState); printf("Press\r\n"); - _qm->send(ThreadCommon::QueueManager::manager_event_master, &data, 0); break; case ThreadCommon::RotaryAction::Idle: //Board_LED_Set(ThreadCommon::RotaryAction::Right, LedState); printf("Idle\r\n"); - _qm->send(ThreadCommon::QueueManager::manager_event_master, &data, 0); break; } LedState = !LedState; +} + +void Master::taskFunction() { + Event data(Event::Null, 0); + for (;;) { + if(!_qm->receive(ThreadCommon::QueueManager::master_event_all, &data, 10000)) + data.setDataOf(Event::Rotary, ThreadCommon::RotaryAction::Idle); + + for(Event::EventType i : + {Event::Null, + Event::Rotary, + Event::InternalTemp, + Event::ExternalTemp, + Event::SetPoint}) + { + if (data.getDataOf(i) != ERROR_RETURN) + { + HandleEventType(&data, i); + } + } } } diff --git a/source/shoh/src/threads/master/Master.h b/source/shoh/src/threads/master/Master.h index 3a5e790..690385c 100644 --- a/source/shoh/src/threads/master/Master.h +++ b/source/shoh/src/threads/master/Master.h @@ -24,6 +24,8 @@ public: private: Event* message; ThreadCommon::QueueManager* _qm; + void HandleEventType(Event* e, Event::EventType type); + void DebugRotaryEvent(EventRawData data); }; void thread_master(void* pvParams);