diff --git a/source/shoh/.cproject b/source/shoh/.cproject index 12a087c..aa180f6 100644 --- a/source/shoh/.cproject +++ b/source/shoh/.cproject @@ -48,9 +48,9 @@ + - @@ -197,6 +197,7 @@ + @@ -225,6 +226,7 @@ + @@ -331,7 +334,14 @@ LPCXpresso11U68 - + + + + + + + + diff --git a/source/shoh/src/main.cpp b/source/shoh/src/main.cpp index 7558463..bf1f949 100644 --- a/source/shoh/src/main.cpp +++ b/source/shoh/src/main.cpp @@ -3,7 +3,7 @@ #include "FreeRTOS.h" #include "task.h" #include -#include "common/ThreadCommon.h" +#include "ThreadCommon.h" #include "Master.h" @@ -15,7 +15,7 @@ int main(void) ThreadCommon::QueueManager* qmanager = new ThreadCommon::QueueManager; //Creating queues qmanager->createQueue(100, - sizeof(ThreadCommon::Event), + sizeof(Event), ThreadCommon::QueueManager::master_event_all); //Creating tasks @@ -24,10 +24,9 @@ int main(void) static_cast(qmanager)); // - QueueHandle_t master_event_all_q = qmanager->getQueue(ThreadCommon::QueueManager::master_event_all); - ThreadCommon::Event* e = new ThreadCommon::Event(ThreadCommon::Rotary, 1); + Event* e = new Event(Event::Rotary, 1); - qmanager->send(ThreadCommon::QueueManager::master_event_all, e, 1000); + qmanager->send(ThreadCommon::QueueManager::master_event_all, e, 1000); // // Start the real time kernel with preemption. diff --git a/source/shoh/src/threads/common/Event.h b/source/shoh/src/threads/common/Event.h new file mode 100644 index 0000000..30c9dea --- /dev/null +++ b/source/shoh/src/threads/common/Event.h @@ -0,0 +1,55 @@ +/* + * Event.h + * + * Created on: 26 Apr 2023 + * Author: tylen + */ + +#ifndef THREADS_COMMON_EVENT_H_ +#define THREADS_COMMON_EVENT_H_ + +#include +#include + +typedef short int EventRawData; +const EventRawData ERROR_RETURN = -999; + +class Event +{ +public: + enum EventType + { + Null, + Rotary, + InternalTemp, + ExternalTemp, + SetPoint + }; + + Event(Event::EventType type, EventRawData data) + { + events.insert({type, data}); + } + + void inline addData(Event::EventType type, EventRawData data) + { + const auto pos = events.find(type); + // No duplicates + if (pos == events.end()) + events.insert({type, data}); + } + + EventRawData getDataOf(Event::EventType e) const + { + const auto pos = events.find(e); + if (pos == events.end()) + return ERROR_RETURN; + return pos->second; + } + +private: + std::map events; +}; + + +#endif /* THREADS_COMMON_EVENT_H_ */ diff --git a/source/shoh/src/threads/common/ThreadCommon.h b/source/shoh/src/threads/common/ThreadCommon.h index be6b149..73a5b72 100644 --- a/source/shoh/src/threads/common/ThreadCommon.h +++ b/source/shoh/src/threads/common/ThreadCommon.h @@ -18,38 +18,6 @@ namespace ThreadCommon { - typedef enum EventType - { - Null, - Rotary, - Temperature, - Manager - }; - - class Event - { - public: - Event(ThreadCommon::EventType type, uint8_t data) - { - _type = type; - _data = data; - } - - ThreadCommon::EventType getType() const - { - return _type; - } - - uint8_t getData() const - { - return _data; - } - - private: - ThreadCommon::EventType _type; - uint8_t _data; - }; - class ThreadManager { public: diff --git a/source/shoh/src/threads/master/Master.cpp b/source/shoh/src/threads/master/Master.cpp index e986e74..34f86d9 100644 --- a/source/shoh/src/threads/master/Master.cpp +++ b/source/shoh/src/threads/master/Master.cpp @@ -13,12 +13,12 @@ Master::Master(ThreadCommon::QueueManager* qm) : _qm(qm) } void Master::taskFunction() { - ThreadCommon::Event data(ThreadCommon::Null, 0); + Event data(Event::Null, 0); int led = 0; bool LedState = true; for (;;) { - _qm->receive(ThreadCommon::QueueManager::master_event_all, &data, portMAX_DELAY); - if(data.getData() == 1 && data.getType() == ThreadCommon::EventType::Rotary){ + _qm->receive(ThreadCommon::QueueManager::master_event_all, &data, portMAX_DELAY); + if(data.getDataOf(Event::Rotary) == 1){ Board_LED_Set(led, LedState); } } diff --git a/source/shoh/src/threads/master/Master.h b/source/shoh/src/threads/master/Master.h index 303cf59..aa59969 100644 --- a/source/shoh/src/threads/master/Master.h +++ b/source/shoh/src/threads/master/Master.h @@ -10,7 +10,8 @@ #include "chip.h" #include "board.h" -#include "threads/common/ThreadCommon.h" +#include "ThreadCommon.h" +#include "Event.h" #include "task.h" #include @@ -23,7 +24,7 @@ public: //Master(Master&&) noexcept = default; //Master& operator=(Master&&) noexcept = default; private: - ThreadCommon::Event* message; + Event* message; ThreadCommon::QueueManager* _qm; };