Core Base Classes for the Light Endpoints
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:
- 61:6012d61573ea
- Parent:
- 36:73e343ddca7f
- Child:
- 64:7e494186e2ec
diff -r 76728655fa12 -r 6012d61573ea ErrorHandler.cpp --- a/ErrorHandler.cpp Mon Mar 03 03:32:42 2014 +0000 +++ b/ErrorHandler.cpp Mon Mar 03 05:07:19 2014 +0000 @@ -38,14 +38,25 @@ 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(); } // default destructor ErrorHandler::~ErrorHandler() { + if (this->m_mutex != NULL) { + this->m_mutex->unlock(); + delete this->m_mutex; + } + if (this->m_led_mutex != NULL) { + this->m_led_mutex->unlock(); + delete this->m_led_mutex; + } } // log information void ErrorHandler::log(const char *format, ...) { + this->m_mutex->lock(); memset(this->m_message,0,MAX_LOG_MESSAGE+1); va_list args; va_start(args, format); @@ -56,10 +67,12 @@ this->m_lcd->cls(); this->m_lcd->locate(0,0); this->m_lcd->printf(this->m_message); + this->m_mutex->unlock(); } // pause void ErrorHandler::pause(const char *format, ...) { + this->m_mutex->lock(); memset(this->m_message,0,MAX_LOG_MESSAGE+1); va_list args; va_start(args, format); @@ -74,8 +87,10 @@ char c = this->m_pc->getc(); if (c == 0x03) { // CTRL-C ASCII this->m_pc->printf("ctrl-c: closing down...\r\n"); + this->m_mutex->unlock(); closedown(1); } + this->m_mutex->unlock(); } // check for exit @@ -84,6 +99,7 @@ char c = this->m_pc->getc(); if (c == 0x03) { // CTRL-C ASCII this->m_pc->printf("ctrl-c: closing down...\r\n"); + this->m_mutex->unlock(); closedown(1); } } @@ -161,9 +177,11 @@ // blink an LED void ErrorHandler::blinkLED(DigitalOut led) { + this->m_led_mutex->lock(); led = 1; wait_ms(BLINK_TIME); led = 0; + this->m_led_mutex->unlock(); } // blink the Transport TX LED