UI: [#35] Fixing issues.
*Send UserInterface::InterfaceWithData in the queue instead of Event. *Remove pointer madness for LCD. *Timeout for Idle Event from Master thread.
This commit is contained in:
parent
f0bbfb22ab
commit
ea1139567a
@ -30,7 +30,7 @@ int main(void)
|
||||
sizeof(Event),
|
||||
ThreadCommon::QueueManager::manager_event_master);
|
||||
qmanager->createQueue(20,
|
||||
sizeof(Event),
|
||||
sizeof(UserInterface::InterfaceWithData),
|
||||
ThreadCommon::QueueManager::ui_event_manager);
|
||||
|
||||
//Creating tasks
|
||||
|
||||
@ -82,6 +82,7 @@ void Menu::sInitView(const MenuObjEvent &e)
|
||||
case MenuObjEvent::eClick:
|
||||
break;
|
||||
case MenuObjEvent::eRefresh:
|
||||
printf("NOTE: sInitView handled eRefresh.\n");
|
||||
this->SetState(&Menu::sMainView);
|
||||
break;
|
||||
default:
|
||||
@ -166,7 +167,7 @@ void Menu::HandleObj (const MenuObjEvent &event)
|
||||
void Menu::NotifyAndRefreshUI (const char *str)
|
||||
{
|
||||
//Send string on a queue to UI task.
|
||||
UserInterface::InterfaceWithData ud = {UserInterface::LCD1, *str};
|
||||
Event * p_e = new Event(Event::EventType::NotifyUI, *(reinterpret_cast<EventRawData*>(&ud)));
|
||||
this->_qm->send<Event>(ThreadCommon::QueueManager::ui_event_manager, p_e, portMAX_DELAY);
|
||||
UserInterface::InterfaceWithData ud = {UserInterface::LCD1, str};
|
||||
//Event * p_e = new Event(Event::EventType::NotifyUI, *(reinterpret_cast<EventRawData*>(&ud)));
|
||||
this->_qm->send<UserInterface::InterfaceWithData>(ThreadCommon::QueueManager::ui_event_manager, &ud, portMAX_DELAY);
|
||||
}
|
||||
@ -27,7 +27,7 @@ private:
|
||||
/* Variables and objects */
|
||||
ThreadCommon::QueueManager* _qm;
|
||||
p_state current;
|
||||
int ext_temp;
|
||||
short ext_temp;
|
||||
Counter<EventRawData> set_point;
|
||||
const char main_text[64];
|
||||
const char set_point_text[64];
|
||||
|
||||
@ -16,24 +16,29 @@ void Master::taskFunction() {
|
||||
Event data(Event::Null, 0);
|
||||
bool LedState = true;
|
||||
for (;;) {
|
||||
_qm->receive<Event>(ThreadCommon::QueueManager::master_event_all, &data, portMAX_DELAY);
|
||||
if(!_qm->receive<Event>(ThreadCommon::QueueManager::master_event_all, &data, 10000))
|
||||
data.setDataOf(Event::Rotary, ThreadCommon::RotaryAction::Idle);
|
||||
switch(data.getDataOf(Event::Rotary))
|
||||
{
|
||||
case ThreadCommon::RotaryAction::Right:
|
||||
Board_LED_Set(ThreadCommon::RotaryAction::Right, LedState);
|
||||
printf("Right\r\n");
|
||||
_qm->send<Event>(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<Event>(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<Event>(ThreadCommon::QueueManager::manager_event_master, &data, 0);
|
||||
break;
|
||||
case ThreadCommon::RotaryAction::Idle:
|
||||
Board_LED_Set(ThreadCommon::RotaryAction::Right, LedState);
|
||||
//Board_LED_Set(ThreadCommon::RotaryAction::Right, LedState);
|
||||
printf("Idle\r\n");
|
||||
_qm->send<Event>(ThreadCommon::QueueManager::manager_event_master, &data, 0);
|
||||
break;
|
||||
}
|
||||
LedState = !LedState;
|
||||
|
||||
@ -10,6 +10,7 @@
|
||||
UserInterface::UserInterface(ThreadCommon::QueueManager* qm) :
|
||||
_qm(qm), lcd1(nullptr)
|
||||
{
|
||||
this->initLCD1();
|
||||
}
|
||||
|
||||
UserInterface::~UserInterface()
|
||||
@ -26,19 +27,15 @@ UserInterface::~UserInterface()
|
||||
void UserInterface::taskFunction()
|
||||
{
|
||||
Event data(Event::Null, 0);
|
||||
//LCD1 init.
|
||||
this->initLCD(this->lcd1, this->lcd1_rs, this->lcd1_en, this->lcd1_d4,
|
||||
this->lcd1_d5, this->lcd1_d6, this->lcd1_d7);
|
||||
InterfaceWithData ui_with_data;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
this->_qm->receive<Event>(ThreadCommon::QueueManager::ui_event_manager, &data, portMAX_DELAY);
|
||||
this->_qm->receive<UserInterface::InterfaceWithData>(ThreadCommon::QueueManager::ui_event_manager, &ui_with_data, portMAX_DELAY);
|
||||
//Don't mind the type, we care only about the raw_data.
|
||||
EventRawData ed = data.getDataOf(Event::NotifyUI);
|
||||
if(ed != ERROR_RETURN)
|
||||
this->handleEvent(reinterpret_cast<UserInterface::InterfaceWithData*>(&ed));
|
||||
else
|
||||
printf("ERROR: [UserInterface::taskFunction] Event gave ERROR_RETURN data.");
|
||||
//EventRawData ed = data.getDataOf(Event::NotifyUI);
|
||||
//if(ed != ERROR_RETURN)
|
||||
this->handleEvent(&ui_with_data);
|
||||
}
|
||||
|
||||
}
|
||||
@ -52,7 +49,7 @@ void UserInterface::handleEvent(InterfaceWithData* ui_data)
|
||||
break;
|
||||
default:
|
||||
//Should never happen.
|
||||
printf("WARNING: [UserInterface::handleEvent] executed default case.");
|
||||
printf("WARNING: [UserInterface::handleEvent] executed default case.\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -74,17 +71,14 @@ void UserInterface::handleLCD(LiquidCrystal *lcd, const char *str)
|
||||
}
|
||||
}
|
||||
|
||||
void UserInterface::initLCD(LiquidCrystal *lcd,
|
||||
DigitalIoPin *rs, DigitalIoPin *en,
|
||||
DigitalIoPin *d4, DigitalIoPin *d5,
|
||||
DigitalIoPin *d6, DigitalIoPin *d7)
|
||||
void UserInterface::initLCD1()
|
||||
{
|
||||
rs = new DigitalIoPin(1, 9, false);
|
||||
en = new DigitalIoPin(0, 14, false);
|
||||
d4 = new DigitalIoPin(0, 13, false);
|
||||
d5 = new DigitalIoPin(0, 12, false);
|
||||
d6 = new DigitalIoPin(0, 23, false);
|
||||
d7 = new DigitalIoPin(0, 11, false);
|
||||
this->lcd1_rs = new DigitalIoPin(1, 9, false);
|
||||
this->lcd1_en = new DigitalIoPin(0, 14, false);
|
||||
this->lcd1_d4 = new DigitalIoPin(0, 13, false);
|
||||
this->lcd1_d5 = new DigitalIoPin(0, 12, false);
|
||||
this->lcd1_d6 = new DigitalIoPin(0, 23, false);
|
||||
this->lcd1_d7 = new DigitalIoPin(0, 11, false);
|
||||
|
||||
//Fix Pin Muxing.
|
||||
Chip_IOCON_PinMuxSet (LPC_IOCON, 1, 9, (IOCON_FUNC0 | IOCON_MODE_INACT | IOCON_DIGMODE_EN));
|
||||
@ -94,17 +88,18 @@ void UserInterface::initLCD(LiquidCrystal *lcd,
|
||||
Chip_IOCON_PinMuxSet (LPC_IOCON, 0, 23, (IOCON_FUNC0 | IOCON_MODE_INACT | IOCON_DIGMODE_EN));
|
||||
Chip_IOCON_PinMuxSet (LPC_IOCON, 0, 11, (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_DIGMODE_EN));
|
||||
|
||||
rs->write(false);
|
||||
en->write(false);
|
||||
d4->write(false);
|
||||
d5->write(false);
|
||||
d6->write(false);
|
||||
d7->write(false);
|
||||
this->lcd1_rs->write(false);
|
||||
this->lcd1_en->write(false);
|
||||
this->lcd1_d4->write(false);
|
||||
this->lcd1_d5->write(false);
|
||||
this->lcd1_d6->write(false);
|
||||
this->lcd1_d7->write(false);
|
||||
// LCD init.
|
||||
lcd = new LiquidCrystal(rs, en, d4, d5, d6, d7);
|
||||
this->lcd1 = new LiquidCrystal(this->lcd1_rs, this->lcd1_en, this->lcd1_d4,
|
||||
this->lcd1_d5, this->lcd1_d6, this->lcd1_d7);
|
||||
// LCD configure display geometry.
|
||||
lcd->begin(16, 2);
|
||||
lcd->setCursor (0, 0);
|
||||
this->lcd1->begin(16, 2);
|
||||
this->lcd1->setCursor (0, 0);
|
||||
}
|
||||
|
||||
void thread_user_interface(void* pvParams)
|
||||
|
||||
@ -23,7 +23,7 @@ public:
|
||||
|
||||
union InterfaceData
|
||||
{
|
||||
const char str[64];
|
||||
const char* str;
|
||||
};
|
||||
|
||||
struct InterfaceWithData
|
||||
@ -44,10 +44,7 @@ private:
|
||||
|
||||
//UIs
|
||||
void handleLCD(LiquidCrystal *lcd, const char *str);
|
||||
void initLCD(LiquidCrystal *lcd,
|
||||
DigitalIoPin *rs, DigitalIoPin *en,
|
||||
DigitalIoPin *d4, DigitalIoPin *d5,
|
||||
DigitalIoPin *d6, DigitalIoPin *d7);
|
||||
void initLCD1();
|
||||
};
|
||||
|
||||
void thread_user_interface(void* pvParams);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user