Core Base Classes for the Light Endpoints

Dependencies:   BufferedSerial

Dependents:   mbed_mqtt_endpoint_ublox_ethernet mbed_mqtt_endpoint_ublox_cellular mbed_nsp_endpoint_ublox_cellular mbed_nsp_endpoint_ublox_ethernet ... more

Revision:
68:e6431dfe2f30
Parent:
66:3361be4bfd38
Child:
70:055ebf51f6ad
diff -r 08e0f3f46aa0 -r e6431dfe2f30 ErrorHandler.cpp
--- a/ErrorHandler.cpp	Mon Mar 03 19:27:54 2014 +0000
+++ b/ErrorHandler.cpp	Mon Mar 03 21:57:58 2014 +0000
@@ -43,13 +43,15 @@
  extern void closedown(int code);
  
  // default constructor
- ErrorHandler::ErrorHandler(MODSERIAL *pc,C12832_LCD *lcd) {
+ ErrorHandler::ErrorHandler(Serial *pc,C12832_LCD *lcd) {
      this->m_pc = pc;
      this->m_lcd = lcd;
      memset(this->m_message,0,MAX_LOG_MESSAGE+1);
      this->resetLEDs();
      this->m_mutex = new Mutex();
      this->m_led_mutex = new Mutex();
+     if (this->m_mutex != NULL) this->m_mutex->unlock();
+     if (this->m_led_mutex != NULL) this->m_led_mutex->unlock();
  }
  
  // default destructor
@@ -108,6 +110,7 @@
  
  // check for exit
  void ErrorHandler::checkForExit() {
+    this->m_mutex->lock();
     if (this->m_pc->readable()) {
         char c = this->m_pc->getc();
         if (c == 0x03) {    // CTRL-C ASCII
@@ -116,6 +119,7 @@
             closedown(1);
         }
     }
+    this->m_mutex->unlock();
 }
 
 // set the color LED 
@@ -184,8 +188,10 @@
 
 // reset LEDs
 void ErrorHandler::resetLEDs() {
+    this->m_led_mutex->lock();
     // turn off all LEDs
     led1 = 0; led2 = 0; led3 = 0; led4 = 0;
+    this->m_led_mutex->unlock();
 }
 
 // blink an LED