Allows users to seamlessly write to 2 or 3 uLCD screens as if they were one large screen.
Dependencies: 4DGL-uLCD-SE mbed-rtos mbed
Diff: ScreenUpdater.cpp
- Revision:
- 0:15002a72309b
diff -r 000000000000 -r 15002a72309b ScreenUpdater.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ScreenUpdater.cpp Wed Mar 11 21:33:18 2015 +0000 @@ -0,0 +1,42 @@ +#include "ScreenUpdater.h" +#include "uLCD_4DGL.h" +#include "mbed.h" +static void uLCD_thread_func(void const *args) { + //printf("Thread alive."); + uLCD_4DGL *lcd = ((uLCD_Thread_Args*)args)->uLCD; + std::queue<Command*> *commands = ((uLCD_Thread_Args*)args)->commands; + Mutex *commands_mutex = ((uLCD_Thread_Args*)args)->commands_mutex; + while (true) { + if (!commands->empty()) { + commands_mutex->lock(); + Command *command = commands->front(); + commands->pop(); + command->execute(lcd); + delete command; + commands_mutex->unlock(); + } else { + //printf("empty."); + Thread::signal_wait(0x1); + } + } +} +ScreenUpdater::ScreenUpdater(uLCD_4DGL *uLCD) { + //printf("ScreenUpdater booting."); + uLCD_Thread_Args args = {uLCD, &commands, &commands_mutex}; + Thread *_thread = new Thread(uLCD_thread_func, &(args), osPriorityHigh); + uLCD_thread = _thread; + //printf("Thread creation complete\n"); + this->uLCD = uLCD; +} +void ScreenUpdater::addCommand(Command* _command) { + //printf("I'm here!"); + commands_mutex.lock(); + commands.push(_command); + //printf("Adding command %d. State %d\n", commands.size(), uLCD_thread->get_state()); + commands_mutex.unlock(); + uLCD_thread->signal_set(0x1); +} +ScreenUpdater::~ScreenUpdater() { + //printf("KILLING THREAD!!!!!!!!!!!!!!\n"); + uLCD_thread->terminate(); +}