Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: mbed_mqtt_endpoint_ublox_ethernet mbed_mqtt_endpoint_ublox_cellular mbed_nsp_endpoint_ublox_cellular mbed_nsp_endpoint_ublox_ethernet ... more
Diff: ErrorHandler.cpp
- Revision:
- 160:24337c83dd1d
- Parent:
- 149:7fde829ed672
- Child:
- 179:35e88daf2d75
--- a/ErrorHandler.cpp Mon Jun 30 22:17:32 2014 +0000
+++ b/ErrorHandler.cpp Tue Jul 01 17:12:18 2014 +0000
@@ -76,33 +76,36 @@
this->m_pc = pc;
this->m_lcd = lcd;
this->m_status_lcd = false;
- memset(this->m_message,0,MAX_LOG_MESSAGE+1);
+ memset(this->m_message,0,MAX_LOG_MESSAGE+1);
+#ifdef EH_USE_MUTEXES
this->m_mutex = NULL;
this->m_close_mutex = NULL;
this->m_led_mutex = NULL;
this->m_rgb_mutex = NULL;
-#ifdef EH_USE_MUTEXES
this->m_mutex = new Mutex();
this->m_close_mutex = new Mutex();
this->m_led_mutex = new Mutex();
this->m_rgb_mutex = new Mutex();
+ this->releaseMutexes();
#endif
- this->releaseMutexes();
this->resetLEDs();
}
// default destructor
ErrorHandler::~ErrorHandler() {
+#ifdef EH_USE_MUTEXES
this->releaseMutexes();
if (this->m_mutex != NULL) delete this->m_mutex;
if (this->m_close_mutex != NULL) delete this->m_close_mutex;
if (this->m_led_mutex != NULL) delete this->m_led_mutex;
if (this->m_rgb_mutex != NULL) delete this->m_rgb_mutex;
+#endif
}
// enable LCD to only show summary status
void ErrorHandler::lcdStatusOnly(bool status_lcd) { this->m_status_lcd = status_lcd; }
+ #ifdef EH_USE_MUTEXES
// release all mutexes
void ErrorHandler::releaseMutexes() {
if (this->m_mutex != NULL) this->m_mutex->unlock();
@@ -110,6 +113,7 @@
if (this->m_led_mutex != NULL) this->m_led_mutex->unlock();
if (this->m_rgb_mutex != NULL) this->m_rgb_mutex->unlock();
}
+ #endif
// log information
void ErrorHandler::log(const char *format, ...) {
@@ -119,7 +123,9 @@
va_start(args, format);
vsprintf(this->m_message, format, args);
va_end(args);
+#ifdef EH_USE_MUTEXES
if (this->m_mutex != NULL) this->m_mutex->lock();
+#endif
if (this->m_pc != NULL) this->m_pc->printf(this->m_message);
#ifdef ENABLE_MEMORY_DEBUG
ERROR_HANDLER_MEM_STATS(0);
@@ -138,9 +144,13 @@
this->m_lcd->locate(0,0);
this->m_lcd->printf(this->m_message);
}
+#ifdef EH_USE_MUTEXES
if (this->m_mutex != NULL) this->m_mutex->unlock();
+#endif
#else
+#ifdef EH_USE_MUTEXES
if (this->m_mutex != NULL) this->m_mutex->lock();
+#endif
if (this->m_status_lcd) {
MBEDEndpoint *endpoint = (MBEDEndpoint *)this->m_endpoint;
if (endpoint != NULL) {
@@ -149,8 +159,10 @@
this->m_lcd->printf(endpoint->getLCDStatus());
}
}
+#ifdef EH_USE_MUTEXES
if (this->m_mutex != NULL) this->m_mutex->unlock();
#endif
+#endif
}
// log information
@@ -162,12 +174,16 @@
va_start(args, format);
vsprintf(this->m_message, format, args);
va_end(args);
+ #ifdef EH_USE_MUTEXES
if (this->m_mutex != NULL) this->m_mutex->lock();
+ #endif
if (this->m_pc != NULL) this->m_pc->printf(this->m_message);
ERROR_HANDLER_MEM_STATS(0);
+ #ifdef EH_USE_MUTEXES
if (this->m_mutex != NULL) this->m_mutex->unlock();
#endif
#endif
+ #endif
}
// pause
@@ -178,7 +194,9 @@
va_start(args, format);
vsprintf(this->m_message, format, args);
va_end(args);
+ #ifdef EH_USE_MUTEXES
if (this->m_mutex != NULL) this->m_mutex->lock();
+ #endif
if (this->m_pc != NULL) this->m_pc->printf(this->m_message);
if (this->m_pc != NULL) this->m_pc->printf("\r\n");
this->m_lcd->cls();
@@ -189,17 +207,23 @@
char c = this->m_pc->getc();
if (c == 0x03) { // CTRL-C ASCII
this->m_pc->printf("ctrl-c: closing down...\r\n");
+ #ifdef EH_USE_MUTEXES
if (this->m_mutex != NULL) this->m_mutex->unlock();
+ #endif
closedown(1);
}
}
+ #ifdef EH_USE_MUTEXES
if (this->m_mutex != NULL) this->m_mutex->unlock();
#endif
+ #endif
}
// check for exit
void ErrorHandler::checkForExit() {
+ #ifdef EH_USE_MUTEXES
if (this->m_close_mutex != NULL) this->m_close_mutex->lock();
+ #endif
if (this->m_pc != NULL && this->m_pc->readable()) {
char c = this->m_pc->getc();
if (c == 0x03) { // CTRL-C ASCII
@@ -207,13 +231,17 @@
closedown(1);
}
}
+ #ifdef EH_USE_MUTEXES
if (this->m_close_mutex != NULL) this->m_close_mutex->unlock();
+ #endif
}
// set the color LED
void ErrorHandler::setRGBLED(float H, float S, float V) {
#ifndef HUSH_LEDS
+#ifdef EH_USE_MUTEXES
if (this->m_rgb_mutex != NULL) this->m_rgb_mutex->lock();
+#endif
float f,h,p,q,t;
int i;
if( S == 0.0) {
@@ -267,8 +295,10 @@
b = 1.0 - q;
break;
}
+ #ifdef EH_USE_MUTEXES
if (this->m_rgb_mutex != NULL) this->m_rgb_mutex->unlock();
#endif
+ #endif
}
// turn the RGB LED specific colors
@@ -291,21 +321,33 @@
// blink an LED
void ErrorHandler::blinkLED(DigitalOut led) {
#ifndef HUSH_LEDS
+#ifdef EH_USE_MUTEXES
if (this->m_led_mutex != NULL) this->m_led_mutex->lock();
+#endif
led = 1;
+#ifdef EH_USE_MUTEXES
if (this->m_led_mutex != NULL) this->m_led_mutex->unlock();
+#endif
wait_ms(BLINK_TIME);
+#ifdef EH_USE_MUTEXES
if (this->m_led_mutex != NULL) this->m_led_mutex->lock();
+#endif
led = 0;
+#ifdef EH_USE_MUTEXES
if (this->m_led_mutex != NULL) this->m_led_mutex->unlock();
#endif
+#endif
}
void ErrorHandler::changeLED(DigitalOut led,bool onoff) {
+#ifdef EH_USE_MUTEXES
if (this->m_led_mutex != NULL) this->m_led_mutex->lock();
+#endif
if (onoff) led = 1;
else led = 0;
+#ifdef EH_USE_MUTEXES
if (this->m_led_mutex != NULL) this->m_led_mutex->unlock();
+#endif
}
void ErrorHandler::led2On() { this->changeLED(led2,true); }