From 2240d6ce09ac11e5f3f582af1df4466b5894d870 Mon Sep 17 00:00:00 2001 From: Vasily Davydov Date: Thu, 11 May 2023 01:22:05 +0300 Subject: [PATCH 1/4] 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); From 4853e4993c3415b9e5ee6d5a1cbfaa9932e3d832 Mon Sep 17 00:00:00 2001 From: Vasily Davydov Date: Thu, 11 May 2023 16:11:14 +0300 Subject: [PATCH 2/4] master: [#9] forward temp event to manager and relay --- source/shoh/src/threads/master/Master.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/source/shoh/src/threads/master/Master.cpp b/source/shoh/src/threads/master/Master.cpp index 96efbbf..b48e7b4 100644 --- a/source/shoh/src/threads/master/Master.cpp +++ b/source/shoh/src/threads/master/Master.cpp @@ -19,6 +19,7 @@ void Master::HandleEventType(Event* e, Event::EventType type) case Event::Null: break; case Event::Rotary: + //Comes from rotary, goes to manager _qm->send(ThreadCommon::QueueManager::manager_event_master, e, 0); DebugRotaryEvent(e->getDataOf(Event::Rotary)); break; @@ -26,7 +27,9 @@ void Master::HandleEventType(Event* e, Event::EventType type) // TODO remove (deprecated) break; case Event::ExternalTemp: - //TODO comes from sensors, goes to relay & manager + //Comes from sensors, goes to relay & manager + _qm->send(ThreadCommon::QueueManager::relay_event_master, e, 0); + _qm->send(ThreadCommon::QueueManager::manager_event_master, e, 0); break; case Event::SetPoint: //TODO comes from manager, goes to relay From 7f2945efc9f8fbedee977b8c602880ae7908c58a Mon Sep 17 00:00:00 2001 From: Vasily Davydov Date: Thu, 11 May 2023 16:12:10 +0300 Subject: [PATCH 3/4] master: [#9] route setpoint to relay --- source/shoh/src/threads/master/Master.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/shoh/src/threads/master/Master.cpp b/source/shoh/src/threads/master/Master.cpp index b48e7b4..f6c8e69 100644 --- a/source/shoh/src/threads/master/Master.cpp +++ b/source/shoh/src/threads/master/Master.cpp @@ -32,7 +32,8 @@ void Master::HandleEventType(Event* e, Event::EventType type) _qm->send(ThreadCommon::QueueManager::manager_event_master, e, 0); break; case Event::SetPoint: - //TODO comes from manager, goes to relay + //Comes from manager, goes to relay + _qm->send(ThreadCommon::QueueManager::relay_event_master, e, 0); break; default: assert(0); From 366010ed028bf35f00c84a357f5a1245d317b4df Mon Sep 17 00:00:00 2001 From: Vasily Davydov Date: Thu, 11 May 2023 16:45:50 +0300 Subject: [PATCH 4/4] master: [#9] remove redundant code --- source/shoh/src/threads/master/Master.cpp | 34 ++++++----------------- source/shoh/src/threads/master/Master.h | 1 - 2 files changed, 8 insertions(+), 27 deletions(-) diff --git a/source/shoh/src/threads/master/Master.cpp b/source/shoh/src/threads/master/Master.cpp index f6c8e69..775771b 100644 --- a/source/shoh/src/threads/master/Master.cpp +++ b/source/shoh/src/threads/master/Master.cpp @@ -7,6 +7,14 @@ #include "Master.h" +static const char* rotary_direction[] = +{ + "Right", + "Left", + "Press", + "Idle" +}; + Master::Master(ThreadCommon::QueueManager* qm) : _qm(qm) { @@ -21,7 +29,6 @@ void Master::HandleEventType(Event* e, Event::EventType type) case Event::Rotary: //Comes from rotary, goes to manager _qm->send(ThreadCommon::QueueManager::manager_event_master, e, 0); - DebugRotaryEvent(e->getDataOf(Event::Rotary)); break; case Event::InternalTemp: // TODO remove (deprecated) @@ -41,31 +48,6 @@ void Master::HandleEventType(Event* e, Event::EventType type) } } -void Master::DebugRotaryEvent(EventRawData e_data) -{ - bool LedState = true; - switch(e_data) - { - case ThreadCommon::RotaryAction::Right: - Board_LED_Set(ThreadCommon::RotaryAction::Right, LedState); - printf("Right\r\n"); - break; - case ThreadCommon::RotaryAction::Left: - Board_LED_Set(ThreadCommon::RotaryAction::Left, LedState); - printf("Left\r\n"); - break; - case ThreadCommon::RotaryAction::Press: - Board_LED_Set(ThreadCommon::RotaryAction::Press, LedState); - printf("Press\r\n"); - break; - case ThreadCommon::RotaryAction::Idle: - //Board_LED_Set(ThreadCommon::RotaryAction::Right, LedState); - printf("Idle\r\n"); - break; - } - LedState = !LedState; -} - void Master::taskFunction() { Event data(Event::Null, 0); for (;;) { diff --git a/source/shoh/src/threads/master/Master.h b/source/shoh/src/threads/master/Master.h index 690385c..b0ae831 100644 --- a/source/shoh/src/threads/master/Master.h +++ b/source/shoh/src/threads/master/Master.h @@ -25,7 +25,6 @@ private: Event* message; ThreadCommon::QueueManager* _qm; void HandleEventType(Event* e, Event::EventType type); - void DebugRotaryEvent(EventRawData data); }; void thread_master(void* pvParams);