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:
114:bd38ad417d6a
Parent:
112:1fb53d4729af
Child:
130:630d05daed77
--- a/ErrorHandler.cpp	Tue Mar 18 21:50:19 2014 +0000
+++ b/ErrorHandler.cpp	Wed Mar 19 03:30:37 2014 +0000
@@ -17,6 +17,7 @@
  */
  
  #include "ErrorHandler.h"
+ #include "MBEDEndpoint.h"
  
 // Annunciations
 DigitalOut led1(LED1);
@@ -30,7 +31,7 @@
 PwmOut b(p25);
 
 // Memory statistics macro
-#define MEM_STATS(x) \
+#define ERROR_HANDLER_MEM_STATS(x) \
     int s##x=0;\
     int *h##x = new int [1];\
     this->m_pc->printf("\r\nMEMORY: stack: 0x%08x  heap: 0x%08x  avail: %d bytes\r\n", &s##x, h##x, &s##x-h##x);\
@@ -46,6 +47,7 @@
  ErrorHandler::ErrorHandler(Serial *pc,C12832_LCD *lcd) {
      this->m_pc = pc;
      this->m_lcd = lcd;
+     this->m_status_lcd = false;
      memset(this->m_message,0,MAX_LOG_MESSAGE+1);
      this->m_mutex = NULL;
      this->m_close_mutex = NULL;
@@ -70,6 +72,9 @@
      if (this->m_rgb_mutex != NULL) delete this->m_rgb_mutex;
  }
  
+ // enable LCD to only show summary status
+ void ErrorHandler::lcdStatusOnly(bool status_lcd) { this->m_status_lcd = status_lcd; }
+ 
  // release all mutexes
  void ErrorHandler::releaseMutexes() {
      if (this->m_mutex != NULL) this->m_mutex->unlock();
@@ -89,12 +94,33 @@
     if (this->m_mutex != NULL) this->m_mutex->lock();
     this->m_pc->printf(this->m_message);
     #ifdef ENABLE_MEMORY_DEBUG
-    MEM_STATS(0);
+    ERROR_HANDLER_MEM_STATS(0);
     #endif
     this->m_pc->printf("\r\n");
-    this->m_lcd->cls();
-    this->m_lcd->locate(0,0);
-    this->m_lcd->printf(this->m_message);
+    if (this->m_status_lcd) {
+        MBEDEndpoint *endpoint = (MBEDEndpoint *)this->m_endpoint;
+        if (endpoint != NULL) {
+            this->m_lcd->cls();
+            this->m_lcd->locate(0,0);
+            this->m_lcd->printf(endpoint->getLCDStatus());
+        }
+    }
+    else {
+        this->m_lcd->cls();
+        this->m_lcd->locate(0,0);
+        this->m_lcd->printf(this->m_message);
+    }
+    if (this->m_mutex != NULL) this->m_mutex->unlock();
+#else
+    if (this->m_mutex != NULL) this->m_mutex->lock();
+    if (this->m_status_lcd) {
+        MBEDEndpoint *endpoint = (MBEDEndpoint *)this->m_endpoint;
+        if (endpoint != NULL) {
+            this->m_lcd->cls();
+            this->m_lcd->locate(0,0);
+            this->m_lcd->printf(endpoint->getLCDStatus());
+        }
+    }
     if (this->m_mutex != NULL) this->m_mutex->unlock();
 #endif
  }
@@ -110,7 +136,7 @@
     va_end(args);
     if (this->m_mutex != NULL) this->m_mutex->lock();
     this->m_pc->printf(this->m_message);
-    MEM_STATS(0);
+    ERROR_HANDLER_MEM_STATS(0);
     if (this->m_mutex != NULL) this->m_mutex->unlock();
  #endif
  #endif
@@ -219,17 +245,10 @@
 void ErrorHandler::turnLEDRed() { this->setRGBLED(0.0,1.0,0.2); }
 void ErrorHandler::turnLEDGreen() { this->setRGBLED(120.0,1.0,0.2); }
 void ErrorHandler::turnLEDBlue() { this->setRGBLED(200.0,1.0,0.2); }
+void ErrorHandler::turnLEDPurple() { this->setRGBLED(261.9,1.0,0.2); }
+void ErrorHandler::turnLEDOrange() { this->setRGBLED(51.0,1.0,0.2); }
 void ErrorHandler::turnLEDBlack() { this->setRGBLED(0,0,0); }
 void ErrorHandler::turnLEDYellow() { this->setRGBLED(60.0,1.0,0.133); }
-void ErrorHandler::dimRGB(float value) {
-#ifndef HUSH_LEDS
-    float H, S, V;
-    H = 120.0 - (120.0*(1.0 - value));
-    S = 1.0 - (1.0*(1.0 - value));
-    V = 0.2 - (0.2*(1.0 - value));
-    this->setRGBLED(H,S,V);
-#endif
-}
 
 // reset LEDs
 void ErrorHandler::resetLEDs() {