event: separate event
Give container-type implementation
This commit is contained in:
parent
d909fdb609
commit
daec484c01
@ -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
|
||||
@ -25,9 +25,9 @@ int main(void)
|
||||
|
||||
//<Queue_test>
|
||||
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::Event>(ThreadCommon::QueueManager::master_event_all, e, 1000);
|
||||
qmanager->send<Event>(ThreadCommon::QueueManager::master_event_all, e, 1000);
|
||||
//</Queue_test>
|
||||
|
||||
// Start the real time kernel with preemption.
|
||||
|
||||
55
source/shoh/src/threads/common/Event.h
Normal file
55
source/shoh/src/threads/common/Event.h
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Event.h
|
||||
*
|
||||
* Created on: 26 Apr 2023
|
||||
* Author: tylen
|
||||
*/
|
||||
|
||||
#ifndef THREADS_COMMON_EVENT_H_
|
||||
#define THREADS_COMMON_EVENT_H_
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
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 <Event::EventType, EventRawData> events;
|
||||
};
|
||||
|
||||
|
||||
#endif /* THREADS_COMMON_EVENT_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:
|
||||
|
||||
@ -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::Event>(ThreadCommon::QueueManager::master_event_all, &data, portMAX_DELAY);
|
||||
if(data.getData() == 1 && data.getType() == ThreadCommon::EventType::Rotary){
|
||||
_qm->receive<Event>(ThreadCommon::QueueManager::master_event_all, &data, portMAX_DELAY);
|
||||
if(data.getDataOf(Event::Rotary) == 1){
|
||||
Board_LED_Set(led, LedState);
|
||||
}
|
||||
}
|
||||
|
||||
@ -11,6 +11,7 @@
|
||||
#include "chip.h"
|
||||
#include "board.h"
|
||||
#include "threads/common/ThreadCommon.h"
|
||||
#include "threads/common/Event.h"
|
||||
#include "task.h"
|
||||
#include <string>
|
||||
|
||||
@ -23,7 +24,7 @@ public:
|
||||
//Master(Master&&) noexcept = default;
|
||||
//Master& operator=(Master&&) noexcept = default;
|
||||
private:
|
||||
ThreadCommon::Event* message;
|
||||
Event* message;
|
||||
ThreadCommon::QueueManager* _qm;
|
||||
};
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user