Michael Kuchnik / Mbed 2 deprecated uLCD_Multiscreen

Dependencies:   4DGL-uLCD-SE mbed-rtos mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ScreenUpdater.cpp Source File

ScreenUpdater.cpp

00001 #include "ScreenUpdater.h"
00002 #include "uLCD_4DGL.h"
00003 #include "mbed.h"
00004 static void uLCD_thread_func(void const *args) {
00005     //printf("Thread alive.");
00006     uLCD_4DGL *lcd = ((uLCD_Thread_Args*)args)->uLCD;
00007     std::queue<Command*> *commands = ((uLCD_Thread_Args*)args)->commands;
00008     Mutex *commands_mutex = ((uLCD_Thread_Args*)args)->commands_mutex;
00009     while (true) {
00010         if (!commands->empty()) {
00011             commands_mutex->lock();
00012             Command *command = commands->front();
00013             commands->pop();
00014             command->execute(lcd);
00015             delete command;
00016             commands_mutex->unlock();
00017         } else {
00018             //printf("empty.");
00019             Thread::signal_wait(0x1);
00020         }
00021     }
00022 }
00023 ScreenUpdater::ScreenUpdater(uLCD_4DGL *uLCD) {
00024     //printf("ScreenUpdater booting.");
00025     uLCD_Thread_Args args = {uLCD, &commands, &commands_mutex};
00026     Thread *_thread = new Thread(uLCD_thread_func, &(args), osPriorityHigh);
00027     uLCD_thread = _thread;
00028     //printf("Thread creation complete\n");
00029     this->uLCD = uLCD;
00030 }
00031 void ScreenUpdater::addCommand(Command* _command) {
00032     //printf("I'm here!");
00033     commands_mutex.lock();
00034     commands.push(_command);    
00035     //printf("Adding command %d. State %d\n", commands.size(), uLCD_thread->get_state());
00036     commands_mutex.unlock();
00037     uLCD_thread->signal_set(0x1);
00038 }
00039 ScreenUpdater::~ScreenUpdater() {
00040     //printf("KILLING THREAD!!!!!!!!!!!!!!\n");
00041     uLCD_thread->terminate();
00042 }