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

Committer:
ansond
Date:
Fri Sep 12 20:36:09 2014 +0000
Revision:
180:eb43d5cd0ed7
Parent:
179:35e88daf2d75
updated with thread-safe wait()

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ansond 0:4c9bfcb3e759 1 /* Copyright C2013 Doug Anson, MIT License
ansond 0:4c9bfcb3e759 2 *
ansond 0:4c9bfcb3e759 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
ansond 0:4c9bfcb3e759 4 * and associated documentation files the "Software", to deal in the Software without restriction,
ansond 0:4c9bfcb3e759 5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
ansond 0:4c9bfcb3e759 6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
ansond 0:4c9bfcb3e759 7 * furnished to do so, subject to the following conditions:
ansond 0:4c9bfcb3e759 8 *
ansond 0:4c9bfcb3e759 9 * The above copyright notice and this permission notice shall be included in all copies or
ansond 0:4c9bfcb3e759 10 * substantial portions of the Software.
ansond 0:4c9bfcb3e759 11 *
ansond 0:4c9bfcb3e759 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
ansond 0:4c9bfcb3e759 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
ansond 0:4c9bfcb3e759 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
ansond 0:4c9bfcb3e759 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
ansond 0:4c9bfcb3e759 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
ansond 0:4c9bfcb3e759 17 */
ansond 0:4c9bfcb3e759 18
ansond 0:4c9bfcb3e759 19 #include "ErrorHandler.h"
ansond 114:bd38ad417d6a 20 #include "MBEDEndpoint.h"
ansond 0:4c9bfcb3e759 21
ansond 130:630d05daed77 22 #ifdef _ENDPOINT_UBLOX_PLATFORM
ansond 130:630d05daed77 23 // Annunciations
ansond 130:630d05daed77 24 DigitalOut led1(P3_25);
ansond 130:630d05daed77 25 DigitalOut led2(P3_25);
ansond 130:630d05daed77 26 DigitalOut led3(P3_25);
ansond 130:630d05daed77 27 DigitalOut led4(P3_25);
ansond 130:630d05daed77 28
ansond 130:630d05daed77 29 // Multi-color LED support
ansond 130:630d05daed77 30 PwmOut r(D5);
ansond 130:630d05daed77 31 PwmOut g(D9);
ansond 130:630d05daed77 32 PwmOut b(D8);
ansond 130:630d05daed77 33 #endif
ansond 0:4c9bfcb3e759 34
ansond 130:630d05daed77 35 #ifdef _ENDPOINT_NXP_PLATFORM
ansond 130:630d05daed77 36 // Annunciations
ansond 130:630d05daed77 37 DigitalOut led1(LED1);
ansond 130:630d05daed77 38 DigitalOut led2(LED2);
ansond 130:630d05daed77 39 DigitalOut led3(LED3);
ansond 130:630d05daed77 40 DigitalOut led4(LED4);
ansond 130:630d05daed77 41
ansond 130:630d05daed77 42 // Multi-color LED support
ansond 130:630d05daed77 43 PwmOut r(p23);
ansond 130:630d05daed77 44 PwmOut g(p24);
ansond 130:630d05daed77 45 PwmOut b(p25);
ansond 130:630d05daed77 46 #endif
ansond 130:630d05daed77 47
ansond 130:630d05daed77 48 #ifdef _ENDPOINT_FREEDOM_PLATFORM
ansond 130:630d05daed77 49 // Annunciations
ansond 130:630d05daed77 50 DigitalOut led1(LED1);
ansond 130:630d05daed77 51 DigitalOut led2(LED2);
ansond 130:630d05daed77 52 DigitalOut led3(LED3);
ansond 130:630d05daed77 53 DigitalOut led4(LED4);
ansond 130:630d05daed77 54
ansond 130:630d05daed77 55 // Multi-color LED support
ansond 130:630d05daed77 56 PwmOut r(p23);
ansond 130:630d05daed77 57 PwmOut g(p24);
ansond 130:630d05daed77 58 PwmOut b(p25);
ansond 130:630d05daed77 59 #endif
ansond 0:4c9bfcb3e759 60
ansond 71:90bf61bc3727 61 // Memory statistics macro
ansond 114:bd38ad417d6a 62 #define ERROR_HANDLER_MEM_STATS(x) \
ansond 71:90bf61bc3727 63 int s##x=0;\
ansond 71:90bf61bc3727 64 int *h##x = new int [1];\
ansond 149:7fde829ed672 65 if (this->m_pc != NULL) 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);\
ansond 71:90bf61bc3727 66 if (h##x > &s##x)\
ansond 71:90bf61bc3727 67 error("collision\n");\
ansond 71:90bf61bc3727 68 delete [] h##x;\
ansond 71:90bf61bc3727 69 __nop();
ansond 71:90bf61bc3727 70
ansond 71:90bf61bc3727 71 // close down connections
ansond 20:f2dbbd852e08 72 extern void closedown(int code);
ansond 0:4c9bfcb3e759 73
ansond 0:4c9bfcb3e759 74 // default constructor
ansond 179:35e88daf2d75 75 ErrorHandler::ErrorHandler(BufferedSerial *pc,LCDCLASS *lcd) {
ansond 0:4c9bfcb3e759 76 this->m_pc = pc;
ansond 0:4c9bfcb3e759 77 this->m_lcd = lcd;
ansond 114:bd38ad417d6a 78 this->m_status_lcd = false;
ansond 160:24337c83dd1d 79 memset(this->m_message,0,MAX_LOG_MESSAGE+1);
ansond 160:24337c83dd1d 80 #ifdef EH_USE_MUTEXES
ansond 70:055ebf51f6ad 81 this->m_mutex = NULL;
ansond 70:055ebf51f6ad 82 this->m_close_mutex = NULL;
ansond 70:055ebf51f6ad 83 this->m_led_mutex = NULL;
ansond 83:2f49051d6acf 84 this->m_rgb_mutex = NULL;
ansond 61:6012d61573ea 85 this->m_mutex = new Mutex();
ansond 70:055ebf51f6ad 86 this->m_close_mutex = new Mutex();
ansond 61:6012d61573ea 87 this->m_led_mutex = new Mutex();
ansond 83:2f49051d6acf 88 this->m_rgb_mutex = new Mutex();
ansond 160:24337c83dd1d 89 this->releaseMutexes();
ansond 70:055ebf51f6ad 90 #endif
ansond 84:4a993dd7c38b 91 this->resetLEDs();
ansond 0:4c9bfcb3e759 92 }
ansond 0:4c9bfcb3e759 93
ansond 0:4c9bfcb3e759 94 // default destructor
ansond 0:4c9bfcb3e759 95 ErrorHandler::~ErrorHandler() {
ansond 160:24337c83dd1d 96 #ifdef EH_USE_MUTEXES
ansond 70:055ebf51f6ad 97 this->releaseMutexes();
ansond 70:055ebf51f6ad 98 if (this->m_mutex != NULL) delete this->m_mutex;
ansond 70:055ebf51f6ad 99 if (this->m_close_mutex != NULL) delete this->m_close_mutex;
ansond 70:055ebf51f6ad 100 if (this->m_led_mutex != NULL) delete this->m_led_mutex;
ansond 83:2f49051d6acf 101 if (this->m_rgb_mutex != NULL) delete this->m_rgb_mutex;
ansond 160:24337c83dd1d 102 #endif
ansond 70:055ebf51f6ad 103 }
ansond 70:055ebf51f6ad 104
ansond 114:bd38ad417d6a 105 // enable LCD to only show summary status
ansond 114:bd38ad417d6a 106 void ErrorHandler::lcdStatusOnly(bool status_lcd) { this->m_status_lcd = status_lcd; }
ansond 114:bd38ad417d6a 107
ansond 160:24337c83dd1d 108 #ifdef EH_USE_MUTEXES
ansond 70:055ebf51f6ad 109 // release all mutexes
ansond 70:055ebf51f6ad 110 void ErrorHandler::releaseMutexes() {
ansond 70:055ebf51f6ad 111 if (this->m_mutex != NULL) this->m_mutex->unlock();
ansond 70:055ebf51f6ad 112 if (this->m_close_mutex != NULL) this->m_close_mutex->unlock();
ansond 70:055ebf51f6ad 113 if (this->m_led_mutex != NULL) this->m_led_mutex->unlock();
ansond 83:2f49051d6acf 114 if (this->m_rgb_mutex != NULL) this->m_rgb_mutex->unlock();
ansond 0:4c9bfcb3e759 115 }
ansond 160:24337c83dd1d 116 #endif
ansond 0:4c9bfcb3e759 117
ansond 0:4c9bfcb3e759 118 // log information
ansond 0:4c9bfcb3e759 119 void ErrorHandler::log(const char *format, ...) {
ansond 82:24af66daaf17 120 #ifndef HUSH_LOG
ansond 26:791d22d43cb4 121 memset(this->m_message,0,MAX_LOG_MESSAGE+1);
ansond 0:4c9bfcb3e759 122 va_list args;
ansond 0:4c9bfcb3e759 123 va_start(args, format);
ansond 0:4c9bfcb3e759 124 vsprintf(this->m_message, format, args);
ansond 0:4c9bfcb3e759 125 va_end(args);
ansond 160:24337c83dd1d 126 #ifdef EH_USE_MUTEXES
ansond 84:4a993dd7c38b 127 if (this->m_mutex != NULL) this->m_mutex->lock();
ansond 160:24337c83dd1d 128 #endif
ansond 149:7fde829ed672 129 if (this->m_pc != NULL) this->m_pc->printf(this->m_message);
ansond 64:7e494186e2ec 130 #ifdef ENABLE_MEMORY_DEBUG
ansond 114:bd38ad417d6a 131 ERROR_HANDLER_MEM_STATS(0);
ansond 64:7e494186e2ec 132 #endif
ansond 149:7fde829ed672 133 if (this->m_pc != NULL) this->m_pc->printf("\r\n");
ansond 114:bd38ad417d6a 134 if (this->m_status_lcd) {
ansond 114:bd38ad417d6a 135 MBEDEndpoint *endpoint = (MBEDEndpoint *)this->m_endpoint;
ansond 114:bd38ad417d6a 136 if (endpoint != NULL) {
ansond 114:bd38ad417d6a 137 this->m_lcd->cls();
ansond 114:bd38ad417d6a 138 this->m_lcd->locate(0,0);
ansond 114:bd38ad417d6a 139 this->m_lcd->printf(endpoint->getLCDStatus());
ansond 114:bd38ad417d6a 140 }
ansond 114:bd38ad417d6a 141 }
ansond 114:bd38ad417d6a 142 else {
ansond 114:bd38ad417d6a 143 this->m_lcd->cls();
ansond 114:bd38ad417d6a 144 this->m_lcd->locate(0,0);
ansond 114:bd38ad417d6a 145 this->m_lcd->printf(this->m_message);
ansond 114:bd38ad417d6a 146 }
ansond 160:24337c83dd1d 147 #ifdef EH_USE_MUTEXES
ansond 114:bd38ad417d6a 148 if (this->m_mutex != NULL) this->m_mutex->unlock();
ansond 160:24337c83dd1d 149 #endif
ansond 114:bd38ad417d6a 150 #else
ansond 160:24337c83dd1d 151 #ifdef EH_USE_MUTEXES
ansond 114:bd38ad417d6a 152 if (this->m_mutex != NULL) this->m_mutex->lock();
ansond 160:24337c83dd1d 153 #endif
ansond 114:bd38ad417d6a 154 if (this->m_status_lcd) {
ansond 114:bd38ad417d6a 155 MBEDEndpoint *endpoint = (MBEDEndpoint *)this->m_endpoint;
ansond 114:bd38ad417d6a 156 if (endpoint != NULL) {
ansond 114:bd38ad417d6a 157 this->m_lcd->cls();
ansond 114:bd38ad417d6a 158 this->m_lcd->locate(0,0);
ansond 114:bd38ad417d6a 159 this->m_lcd->printf(endpoint->getLCDStatus());
ansond 114:bd38ad417d6a 160 }
ansond 114:bd38ad417d6a 161 }
ansond 160:24337c83dd1d 162 #ifdef EH_USE_MUTEXES
ansond 70:055ebf51f6ad 163 if (this->m_mutex != NULL) this->m_mutex->unlock();
ansond 82:24af66daaf17 164 #endif
ansond 160:24337c83dd1d 165 #endif
ansond 0:4c9bfcb3e759 166 }
ansond 0:4c9bfcb3e759 167
ansond 74:b60149dd669e 168 // log information
ansond 74:b60149dd669e 169 void ErrorHandler::log_memory(const char *format, ...) {
ansond 82:24af66daaf17 170 #ifndef HUSH_LOG
ansond 74:b60149dd669e 171 #ifdef MEMORY_LOGGING
ansond 74:b60149dd669e 172 memset(this->m_message,0,MAX_LOG_MESSAGE+1);
ansond 74:b60149dd669e 173 va_list args;
ansond 74:b60149dd669e 174 va_start(args, format);
ansond 74:b60149dd669e 175 vsprintf(this->m_message, format, args);
ansond 74:b60149dd669e 176 va_end(args);
ansond 160:24337c83dd1d 177 #ifdef EH_USE_MUTEXES
ansond 84:4a993dd7c38b 178 if (this->m_mutex != NULL) this->m_mutex->lock();
ansond 160:24337c83dd1d 179 #endif
ansond 149:7fde829ed672 180 if (this->m_pc != NULL) this->m_pc->printf(this->m_message);
ansond 114:bd38ad417d6a 181 ERROR_HANDLER_MEM_STATS(0);
ansond 160:24337c83dd1d 182 #ifdef EH_USE_MUTEXES
ansond 74:b60149dd669e 183 if (this->m_mutex != NULL) this->m_mutex->unlock();
ansond 74:b60149dd669e 184 #endif
ansond 82:24af66daaf17 185 #endif
ansond 160:24337c83dd1d 186 #endif
ansond 74:b60149dd669e 187 }
ansond 74:b60149dd669e 188
ansond 15:386dccd0000a 189 // pause
ansond 15:386dccd0000a 190 void ErrorHandler::pause(const char *format, ...) {
ansond 82:24af66daaf17 191 #ifndef HUSH_LOG
ansond 26:791d22d43cb4 192 memset(this->m_message,0,MAX_LOG_MESSAGE+1);
ansond 15:386dccd0000a 193 va_list args;
ansond 15:386dccd0000a 194 va_start(args, format);
ansond 15:386dccd0000a 195 vsprintf(this->m_message, format, args);
ansond 15:386dccd0000a 196 va_end(args);
ansond 160:24337c83dd1d 197 #ifdef EH_USE_MUTEXES
ansond 84:4a993dd7c38b 198 if (this->m_mutex != NULL) this->m_mutex->lock();
ansond 160:24337c83dd1d 199 #endif
ansond 149:7fde829ed672 200 if (this->m_pc != NULL) this->m_pc->printf(this->m_message);
ansond 149:7fde829ed672 201 if (this->m_pc != NULL) this->m_pc->printf("\r\n");
ansond 15:386dccd0000a 202 this->m_lcd->cls();
ansond 15:386dccd0000a 203 this->m_lcd->locate(0,0);
ansond 15:386dccd0000a 204 this->m_lcd->printf(this->m_message);
ansond 149:7fde829ed672 205 if (this->m_pc != NULL) {
ansond 149:7fde829ed672 206 this->m_pc->printf("Press any key to continue...ctrl-c to stop\r\n");
ansond 149:7fde829ed672 207 char c = this->m_pc->getc();
ansond 149:7fde829ed672 208 if (c == 0x03) { // CTRL-C ASCII
ansond 16:fda7dbb8b47a 209 this->m_pc->printf("ctrl-c: closing down...\r\n");
ansond 160:24337c83dd1d 210 #ifdef EH_USE_MUTEXES
ansond 84:4a993dd7c38b 211 if (this->m_mutex != NULL) this->m_mutex->unlock();
ansond 160:24337c83dd1d 212 #endif
ansond 149:7fde829ed672 213 closedown(1);
ansond 149:7fde829ed672 214 }
ansond 16:fda7dbb8b47a 215 }
ansond 160:24337c83dd1d 216 #ifdef EH_USE_MUTEXES
ansond 70:055ebf51f6ad 217 if (this->m_mutex != NULL) this->m_mutex->unlock();
ansond 82:24af66daaf17 218 #endif
ansond 160:24337c83dd1d 219 #endif
ansond 15:386dccd0000a 220 }
ansond 15:386dccd0000a 221
ansond 0:4c9bfcb3e759 222 // check for exit
ansond 15:386dccd0000a 223 void ErrorHandler::checkForExit() {
ansond 160:24337c83dd1d 224 #ifdef EH_USE_MUTEXES
ansond 70:055ebf51f6ad 225 if (this->m_close_mutex != NULL) this->m_close_mutex->lock();
ansond 160:24337c83dd1d 226 #endif
ansond 149:7fde829ed672 227 if (this->m_pc != NULL && this->m_pc->readable()) {
ansond 0:4c9bfcb3e759 228 char c = this->m_pc->getc();
ansond 0:4c9bfcb3e759 229 if (c == 0x03) { // CTRL-C ASCII
ansond 0:4c9bfcb3e759 230 this->m_pc->printf("ctrl-c: closing down...\r\n");
ansond 20:f2dbbd852e08 231 closedown(1);
ansond 0:4c9bfcb3e759 232 }
ansond 0:4c9bfcb3e759 233 }
ansond 160:24337c83dd1d 234 #ifdef EH_USE_MUTEXES
ansond 70:055ebf51f6ad 235 if (this->m_close_mutex != NULL) this->m_close_mutex->unlock();
ansond 160:24337c83dd1d 236 #endif
ansond 0:4c9bfcb3e759 237 }
ansond 0:4c9bfcb3e759 238
ansond 0:4c9bfcb3e759 239 // set the color LED
ansond 0:4c9bfcb3e759 240 void ErrorHandler::setRGBLED(float H, float S, float V) {
ansond 82:24af66daaf17 241 #ifndef HUSH_LEDS
ansond 160:24337c83dd1d 242 #ifdef EH_USE_MUTEXES
ansond 83:2f49051d6acf 243 if (this->m_rgb_mutex != NULL) this->m_rgb_mutex->lock();
ansond 160:24337c83dd1d 244 #endif
ansond 0:4c9bfcb3e759 245 float f,h,p,q,t;
ansond 0:4c9bfcb3e759 246 int i;
ansond 0:4c9bfcb3e759 247 if( S == 0.0) {
ansond 0:4c9bfcb3e759 248 r = 1.0 - V; // invert pwm !
ansond 0:4c9bfcb3e759 249 g = 1.0 - V;
ansond 0:4c9bfcb3e759 250 b = 1.0 - V;
ansond 0:4c9bfcb3e759 251 return;
ansond 0:4c9bfcb3e759 252 }
ansond 0:4c9bfcb3e759 253 if(H > 360.0) H = 0.0; // check values
ansond 0:4c9bfcb3e759 254 if(S > 1.0) S = 1.0;
ansond 0:4c9bfcb3e759 255 if(S < 0.0) S = 0.0;
ansond 0:4c9bfcb3e759 256 if(V > 1.0) V = 1.0;
ansond 0:4c9bfcb3e759 257 if(V < 0.0) V = 0.0;
ansond 0:4c9bfcb3e759 258 h = H / 60.0;
ansond 0:4c9bfcb3e759 259 i = (int) h;
ansond 0:4c9bfcb3e759 260 f = h - i;
ansond 0:4c9bfcb3e759 261 p = V * (1.0 - S);
ansond 0:4c9bfcb3e759 262 q = V * (1.0 - (S * f));
ansond 0:4c9bfcb3e759 263 t = V * (1.0 - (S * (1.0 - f)));
ansond 0:4c9bfcb3e759 264
ansond 0:4c9bfcb3e759 265 switch(i) {
ansond 0:4c9bfcb3e759 266 case 0:
ansond 0:4c9bfcb3e759 267 r = 1.0 - V; // invert pwm !
ansond 0:4c9bfcb3e759 268 g = 1.0 - t;
ansond 0:4c9bfcb3e759 269 b = 1.0 - p;
ansond 0:4c9bfcb3e759 270 break;
ansond 0:4c9bfcb3e759 271 case 1:
ansond 0:4c9bfcb3e759 272 r = 1.0 - q;
ansond 0:4c9bfcb3e759 273 g = 1.0 - V;
ansond 0:4c9bfcb3e759 274 b = 1.0 - p;
ansond 0:4c9bfcb3e759 275 break;
ansond 0:4c9bfcb3e759 276 case 2:
ansond 0:4c9bfcb3e759 277 r = 1.0 - p;
ansond 0:4c9bfcb3e759 278 g = 1.0 - V;
ansond 0:4c9bfcb3e759 279 b = 1.0 - t;
ansond 0:4c9bfcb3e759 280 break;
ansond 0:4c9bfcb3e759 281 case 3:
ansond 0:4c9bfcb3e759 282 r = 1.0 - p;
ansond 0:4c9bfcb3e759 283 g = 1.0 - q;
ansond 0:4c9bfcb3e759 284 b = 1.0 - V;
ansond 0:4c9bfcb3e759 285 break;
ansond 0:4c9bfcb3e759 286 case 4:
ansond 0:4c9bfcb3e759 287 r = 1.0 - t;
ansond 0:4c9bfcb3e759 288 g = 1.0 - p;
ansond 0:4c9bfcb3e759 289 b = 1.0 - V;
ansond 0:4c9bfcb3e759 290 break;
ansond 0:4c9bfcb3e759 291 case 5:
ansond 0:4c9bfcb3e759 292 default:
ansond 0:4c9bfcb3e759 293 r = 1.0 - V;
ansond 0:4c9bfcb3e759 294 g = 1.0 - p;
ansond 0:4c9bfcb3e759 295 b = 1.0 - q;
ansond 0:4c9bfcb3e759 296 break;
ansond 0:4c9bfcb3e759 297 }
ansond 160:24337c83dd1d 298 #ifdef EH_USE_MUTEXES
ansond 83:2f49051d6acf 299 if (this->m_rgb_mutex != NULL) this->m_rgb_mutex->unlock();
ansond 82:24af66daaf17 300 #endif
ansond 160:24337c83dd1d 301 #endif
ansond 0:4c9bfcb3e759 302 }
ansond 0:4c9bfcb3e759 303
ansond 0:4c9bfcb3e759 304 // turn the RGB LED specific colors
ansond 0:4c9bfcb3e759 305 void ErrorHandler::turnLEDRed() { this->setRGBLED(0.0,1.0,0.2); }
ansond 0:4c9bfcb3e759 306 void ErrorHandler::turnLEDGreen() { this->setRGBLED(120.0,1.0,0.2); }
ansond 0:4c9bfcb3e759 307 void ErrorHandler::turnLEDBlue() { this->setRGBLED(200.0,1.0,0.2); }
ansond 114:bd38ad417d6a 308 void ErrorHandler::turnLEDPurple() { this->setRGBLED(261.9,1.0,0.2); }
ansond 114:bd38ad417d6a 309 void ErrorHandler::turnLEDOrange() { this->setRGBLED(51.0,1.0,0.2); }
ansond 0:4c9bfcb3e759 310 void ErrorHandler::turnLEDBlack() { this->setRGBLED(0,0,0); }
ansond 0:4c9bfcb3e759 311 void ErrorHandler::turnLEDYellow() { this->setRGBLED(60.0,1.0,0.133); }
ansond 0:4c9bfcb3e759 312
ansond 0:4c9bfcb3e759 313 // reset LEDs
ansond 0:4c9bfcb3e759 314 void ErrorHandler::resetLEDs() {
ansond 82:24af66daaf17 315 #ifndef HUSH_LEDS
ansond 0:4c9bfcb3e759 316 // turn off all LEDs
ansond 0:4c9bfcb3e759 317 led1 = 0; led2 = 0; led3 = 0; led4 = 0;
ansond 82:24af66daaf17 318 #endif
ansond 0:4c9bfcb3e759 319 }
ansond 0:4c9bfcb3e759 320
ansond 0:4c9bfcb3e759 321 // blink an LED
ansond 0:4c9bfcb3e759 322 void ErrorHandler::blinkLED(DigitalOut led) {
ansond 82:24af66daaf17 323 #ifndef HUSH_LEDS
ansond 160:24337c83dd1d 324 #ifdef EH_USE_MUTEXES
ansond 84:4a993dd7c38b 325 if (this->m_led_mutex != NULL) this->m_led_mutex->lock();
ansond 160:24337c83dd1d 326 #endif
ansond 0:4c9bfcb3e759 327 led = 1;
ansond 160:24337c83dd1d 328 #ifdef EH_USE_MUTEXES
ansond 84:4a993dd7c38b 329 if (this->m_led_mutex != NULL) this->m_led_mutex->unlock();
ansond 160:24337c83dd1d 330 #endif
ansond 180:eb43d5cd0ed7 331 Thread::wait(BLINK_TIME);
ansond 160:24337c83dd1d 332 #ifdef EH_USE_MUTEXES
ansond 84:4a993dd7c38b 333 if (this->m_led_mutex != NULL) this->m_led_mutex->lock();
ansond 160:24337c83dd1d 334 #endif
ansond 0:4c9bfcb3e759 335 led = 0;
ansond 160:24337c83dd1d 336 #ifdef EH_USE_MUTEXES
ansond 84:4a993dd7c38b 337 if (this->m_led_mutex != NULL) this->m_led_mutex->unlock();
ansond 82:24af66daaf17 338 #endif
ansond 160:24337c83dd1d 339 #endif
ansond 0:4c9bfcb3e759 340 }
ansond 0:4c9bfcb3e759 341
ansond 84:4a993dd7c38b 342 void ErrorHandler::changeLED(DigitalOut led,bool onoff) {
ansond 160:24337c83dd1d 343 #ifdef EH_USE_MUTEXES
ansond 84:4a993dd7c38b 344 if (this->m_led_mutex != NULL) this->m_led_mutex->lock();
ansond 160:24337c83dd1d 345 #endif
ansond 84:4a993dd7c38b 346 if (onoff) led = 1;
ansond 84:4a993dd7c38b 347 else led = 0;
ansond 160:24337c83dd1d 348 #ifdef EH_USE_MUTEXES
ansond 84:4a993dd7c38b 349 if (this->m_led_mutex != NULL) this->m_led_mutex->unlock();
ansond 160:24337c83dd1d 350 #endif
ansond 84:4a993dd7c38b 351 }
ansond 84:4a993dd7c38b 352
ansond 84:4a993dd7c38b 353 void ErrorHandler::led2On() { this->changeLED(led2,true); }
ansond 84:4a993dd7c38b 354 void ErrorHandler::led2Off() { this->changeLED(led2,false); }
ansond 84:4a993dd7c38b 355 void ErrorHandler::led3On() { this->changeLED(led3,true); }
ansond 84:4a993dd7c38b 356 void ErrorHandler::led3Off() { this->changeLED(led3,false); }
ansond 84:4a993dd7c38b 357
ansond 112:1fb53d4729af 358 void ErrorHandler::setEndpoint(void *endpoint) { this->m_endpoint = endpoint; }
ansond 112:1fb53d4729af 359 void *ErrorHandler::getEndpoint() { return this->m_endpoint; }
ansond 112:1fb53d4729af 360
ansond 36:73e343ddca7f 361 // blink the Transport TX LED
ansond 36:73e343ddca7f 362 void ErrorHandler::blinkTransportTxLED() { this->blinkLED(led4); }
ansond 0:4c9bfcb3e759 363
ansond 36:73e343ddca7f 364 // blink the Transport RX LED
ansond 36:73e343ddca7f 365 void ErrorHandler::blinkTransportRxLED() { this->blinkLED(led1); }