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
ErrorHandler.cpp@114:bd38ad417d6a, 2014-03-19 (annotated)
- Committer:
- ansond
- Date:
- Wed Mar 19 03:30:37 2014 +0000
- Revision:
- 114:bd38ad417d6a
- Parent:
- 112:1fb53d4729af
- Child:
- 130:630d05daed77
updates
Who changed what in which revision?
User | Revision | Line number | New 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 | 18:bc165829bb88 | 22 | // Annunciations |
ansond | 0:4c9bfcb3e759 | 23 | DigitalOut led1(LED1); |
ansond | 73:3e6478c7649f | 24 | DigitalOut led2(LED2); |
ansond | 73:3e6478c7649f | 25 | DigitalOut led3(LED3); |
ansond | 0:4c9bfcb3e759 | 26 | DigitalOut led4(LED4); |
ansond | 0:4c9bfcb3e759 | 27 | |
ansond | 0:4c9bfcb3e759 | 28 | // Multi-color LED support |
ansond | 72:46c94966311b | 29 | PwmOut r(p23); |
ansond | 72:46c94966311b | 30 | PwmOut g(p24); |
ansond | 72:46c94966311b | 31 | PwmOut b(p25); |
ansond | 0:4c9bfcb3e759 | 32 | |
ansond | 71:90bf61bc3727 | 33 | // Memory statistics macro |
ansond | 114:bd38ad417d6a | 34 | #define ERROR_HANDLER_MEM_STATS(x) \ |
ansond | 71:90bf61bc3727 | 35 | int s##x=0;\ |
ansond | 71:90bf61bc3727 | 36 | int *h##x = new int [1];\ |
ansond | 71:90bf61bc3727 | 37 | 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 | 38 | if (h##x > &s##x)\ |
ansond | 71:90bf61bc3727 | 39 | error("collision\n");\ |
ansond | 71:90bf61bc3727 | 40 | delete [] h##x;\ |
ansond | 71:90bf61bc3727 | 41 | __nop(); |
ansond | 71:90bf61bc3727 | 42 | |
ansond | 71:90bf61bc3727 | 43 | // close down connections |
ansond | 20:f2dbbd852e08 | 44 | extern void closedown(int code); |
ansond | 0:4c9bfcb3e759 | 45 | |
ansond | 0:4c9bfcb3e759 | 46 | // default constructor |
ansond | 68:e6431dfe2f30 | 47 | ErrorHandler::ErrorHandler(Serial *pc,C12832_LCD *lcd) { |
ansond | 0:4c9bfcb3e759 | 48 | this->m_pc = pc; |
ansond | 0:4c9bfcb3e759 | 49 | this->m_lcd = lcd; |
ansond | 114:bd38ad417d6a | 50 | this->m_status_lcd = false; |
ansond | 26:791d22d43cb4 | 51 | memset(this->m_message,0,MAX_LOG_MESSAGE+1); |
ansond | 70:055ebf51f6ad | 52 | this->m_mutex = NULL; |
ansond | 70:055ebf51f6ad | 53 | this->m_close_mutex = NULL; |
ansond | 70:055ebf51f6ad | 54 | this->m_led_mutex = NULL; |
ansond | 83:2f49051d6acf | 55 | this->m_rgb_mutex = NULL; |
ansond | 70:055ebf51f6ad | 56 | #ifdef EH_USE_MUTEXES |
ansond | 61:6012d61573ea | 57 | this->m_mutex = new Mutex(); |
ansond | 70:055ebf51f6ad | 58 | this->m_close_mutex = new Mutex(); |
ansond | 61:6012d61573ea | 59 | this->m_led_mutex = new Mutex(); |
ansond | 83:2f49051d6acf | 60 | this->m_rgb_mutex = new Mutex(); |
ansond | 70:055ebf51f6ad | 61 | #endif |
ansond | 70:055ebf51f6ad | 62 | this->releaseMutexes(); |
ansond | 84:4a993dd7c38b | 63 | this->resetLEDs(); |
ansond | 0:4c9bfcb3e759 | 64 | } |
ansond | 0:4c9bfcb3e759 | 65 | |
ansond | 0:4c9bfcb3e759 | 66 | // default destructor |
ansond | 0:4c9bfcb3e759 | 67 | ErrorHandler::~ErrorHandler() { |
ansond | 70:055ebf51f6ad | 68 | this->releaseMutexes(); |
ansond | 70:055ebf51f6ad | 69 | if (this->m_mutex != NULL) delete this->m_mutex; |
ansond | 70:055ebf51f6ad | 70 | if (this->m_close_mutex != NULL) delete this->m_close_mutex; |
ansond | 70:055ebf51f6ad | 71 | if (this->m_led_mutex != NULL) delete this->m_led_mutex; |
ansond | 83:2f49051d6acf | 72 | if (this->m_rgb_mutex != NULL) delete this->m_rgb_mutex; |
ansond | 70:055ebf51f6ad | 73 | } |
ansond | 70:055ebf51f6ad | 74 | |
ansond | 114:bd38ad417d6a | 75 | // enable LCD to only show summary status |
ansond | 114:bd38ad417d6a | 76 | void ErrorHandler::lcdStatusOnly(bool status_lcd) { this->m_status_lcd = status_lcd; } |
ansond | 114:bd38ad417d6a | 77 | |
ansond | 70:055ebf51f6ad | 78 | // release all mutexes |
ansond | 70:055ebf51f6ad | 79 | void ErrorHandler::releaseMutexes() { |
ansond | 70:055ebf51f6ad | 80 | if (this->m_mutex != NULL) this->m_mutex->unlock(); |
ansond | 70:055ebf51f6ad | 81 | if (this->m_close_mutex != NULL) this->m_close_mutex->unlock(); |
ansond | 70:055ebf51f6ad | 82 | if (this->m_led_mutex != NULL) this->m_led_mutex->unlock(); |
ansond | 83:2f49051d6acf | 83 | if (this->m_rgb_mutex != NULL) this->m_rgb_mutex->unlock(); |
ansond | 0:4c9bfcb3e759 | 84 | } |
ansond | 0:4c9bfcb3e759 | 85 | |
ansond | 0:4c9bfcb3e759 | 86 | // log information |
ansond | 0:4c9bfcb3e759 | 87 | void ErrorHandler::log(const char *format, ...) { |
ansond | 82:24af66daaf17 | 88 | #ifndef HUSH_LOG |
ansond | 26:791d22d43cb4 | 89 | memset(this->m_message,0,MAX_LOG_MESSAGE+1); |
ansond | 0:4c9bfcb3e759 | 90 | va_list args; |
ansond | 0:4c9bfcb3e759 | 91 | va_start(args, format); |
ansond | 0:4c9bfcb3e759 | 92 | vsprintf(this->m_message, format, args); |
ansond | 0:4c9bfcb3e759 | 93 | va_end(args); |
ansond | 84:4a993dd7c38b | 94 | if (this->m_mutex != NULL) this->m_mutex->lock(); |
ansond | 0:4c9bfcb3e759 | 95 | this->m_pc->printf(this->m_message); |
ansond | 64:7e494186e2ec | 96 | #ifdef ENABLE_MEMORY_DEBUG |
ansond | 114:bd38ad417d6a | 97 | ERROR_HANDLER_MEM_STATS(0); |
ansond | 64:7e494186e2ec | 98 | #endif |
ansond | 0:4c9bfcb3e759 | 99 | this->m_pc->printf("\r\n"); |
ansond | 114:bd38ad417d6a | 100 | if (this->m_status_lcd) { |
ansond | 114:bd38ad417d6a | 101 | MBEDEndpoint *endpoint = (MBEDEndpoint *)this->m_endpoint; |
ansond | 114:bd38ad417d6a | 102 | if (endpoint != NULL) { |
ansond | 114:bd38ad417d6a | 103 | this->m_lcd->cls(); |
ansond | 114:bd38ad417d6a | 104 | this->m_lcd->locate(0,0); |
ansond | 114:bd38ad417d6a | 105 | this->m_lcd->printf(endpoint->getLCDStatus()); |
ansond | 114:bd38ad417d6a | 106 | } |
ansond | 114:bd38ad417d6a | 107 | } |
ansond | 114:bd38ad417d6a | 108 | else { |
ansond | 114:bd38ad417d6a | 109 | this->m_lcd->cls(); |
ansond | 114:bd38ad417d6a | 110 | this->m_lcd->locate(0,0); |
ansond | 114:bd38ad417d6a | 111 | this->m_lcd->printf(this->m_message); |
ansond | 114:bd38ad417d6a | 112 | } |
ansond | 114:bd38ad417d6a | 113 | if (this->m_mutex != NULL) this->m_mutex->unlock(); |
ansond | 114:bd38ad417d6a | 114 | #else |
ansond | 114:bd38ad417d6a | 115 | if (this->m_mutex != NULL) this->m_mutex->lock(); |
ansond | 114:bd38ad417d6a | 116 | if (this->m_status_lcd) { |
ansond | 114:bd38ad417d6a | 117 | MBEDEndpoint *endpoint = (MBEDEndpoint *)this->m_endpoint; |
ansond | 114:bd38ad417d6a | 118 | if (endpoint != NULL) { |
ansond | 114:bd38ad417d6a | 119 | this->m_lcd->cls(); |
ansond | 114:bd38ad417d6a | 120 | this->m_lcd->locate(0,0); |
ansond | 114:bd38ad417d6a | 121 | this->m_lcd->printf(endpoint->getLCDStatus()); |
ansond | 114:bd38ad417d6a | 122 | } |
ansond | 114:bd38ad417d6a | 123 | } |
ansond | 70:055ebf51f6ad | 124 | if (this->m_mutex != NULL) this->m_mutex->unlock(); |
ansond | 82:24af66daaf17 | 125 | #endif |
ansond | 0:4c9bfcb3e759 | 126 | } |
ansond | 0:4c9bfcb3e759 | 127 | |
ansond | 74:b60149dd669e | 128 | // log information |
ansond | 74:b60149dd669e | 129 | void ErrorHandler::log_memory(const char *format, ...) { |
ansond | 82:24af66daaf17 | 130 | #ifndef HUSH_LOG |
ansond | 74:b60149dd669e | 131 | #ifdef MEMORY_LOGGING |
ansond | 74:b60149dd669e | 132 | memset(this->m_message,0,MAX_LOG_MESSAGE+1); |
ansond | 74:b60149dd669e | 133 | va_list args; |
ansond | 74:b60149dd669e | 134 | va_start(args, format); |
ansond | 74:b60149dd669e | 135 | vsprintf(this->m_message, format, args); |
ansond | 74:b60149dd669e | 136 | va_end(args); |
ansond | 84:4a993dd7c38b | 137 | if (this->m_mutex != NULL) this->m_mutex->lock(); |
ansond | 74:b60149dd669e | 138 | this->m_pc->printf(this->m_message); |
ansond | 114:bd38ad417d6a | 139 | ERROR_HANDLER_MEM_STATS(0); |
ansond | 74:b60149dd669e | 140 | if (this->m_mutex != NULL) this->m_mutex->unlock(); |
ansond | 74:b60149dd669e | 141 | #endif |
ansond | 82:24af66daaf17 | 142 | #endif |
ansond | 74:b60149dd669e | 143 | } |
ansond | 74:b60149dd669e | 144 | |
ansond | 15:386dccd0000a | 145 | // pause |
ansond | 15:386dccd0000a | 146 | void ErrorHandler::pause(const char *format, ...) { |
ansond | 82:24af66daaf17 | 147 | #ifndef HUSH_LOG |
ansond | 26:791d22d43cb4 | 148 | memset(this->m_message,0,MAX_LOG_MESSAGE+1); |
ansond | 15:386dccd0000a | 149 | va_list args; |
ansond | 15:386dccd0000a | 150 | va_start(args, format); |
ansond | 15:386dccd0000a | 151 | vsprintf(this->m_message, format, args); |
ansond | 15:386dccd0000a | 152 | va_end(args); |
ansond | 84:4a993dd7c38b | 153 | if (this->m_mutex != NULL) this->m_mutex->lock(); |
ansond | 15:386dccd0000a | 154 | this->m_pc->printf(this->m_message); |
ansond | 15:386dccd0000a | 155 | this->m_pc->printf("\r\n"); |
ansond | 15:386dccd0000a | 156 | this->m_lcd->cls(); |
ansond | 15:386dccd0000a | 157 | this->m_lcd->locate(0,0); |
ansond | 15:386dccd0000a | 158 | this->m_lcd->printf(this->m_message); |
ansond | 18:bc165829bb88 | 159 | this->m_pc->printf("Press any key to continue...ctrl-c to stop\r\n"); |
ansond | 16:fda7dbb8b47a | 160 | char c = this->m_pc->getc(); |
ansond | 16:fda7dbb8b47a | 161 | if (c == 0x03) { // CTRL-C ASCII |
ansond | 16:fda7dbb8b47a | 162 | this->m_pc->printf("ctrl-c: closing down...\r\n"); |
ansond | 84:4a993dd7c38b | 163 | if (this->m_mutex != NULL) this->m_mutex->unlock(); |
ansond | 20:f2dbbd852e08 | 164 | closedown(1); |
ansond | 16:fda7dbb8b47a | 165 | } |
ansond | 70:055ebf51f6ad | 166 | if (this->m_mutex != NULL) this->m_mutex->unlock(); |
ansond | 82:24af66daaf17 | 167 | #endif |
ansond | 15:386dccd0000a | 168 | } |
ansond | 15:386dccd0000a | 169 | |
ansond | 0:4c9bfcb3e759 | 170 | // check for exit |
ansond | 15:386dccd0000a | 171 | void ErrorHandler::checkForExit() { |
ansond | 70:055ebf51f6ad | 172 | if (this->m_close_mutex != NULL) this->m_close_mutex->lock(); |
ansond | 0:4c9bfcb3e759 | 173 | if (this->m_pc->readable()) { |
ansond | 0:4c9bfcb3e759 | 174 | char c = this->m_pc->getc(); |
ansond | 0:4c9bfcb3e759 | 175 | if (c == 0x03) { // CTRL-C ASCII |
ansond | 0:4c9bfcb3e759 | 176 | this->m_pc->printf("ctrl-c: closing down...\r\n"); |
ansond | 20:f2dbbd852e08 | 177 | closedown(1); |
ansond | 0:4c9bfcb3e759 | 178 | } |
ansond | 0:4c9bfcb3e759 | 179 | } |
ansond | 70:055ebf51f6ad | 180 | if (this->m_close_mutex != NULL) this->m_close_mutex->unlock(); |
ansond | 0:4c9bfcb3e759 | 181 | } |
ansond | 0:4c9bfcb3e759 | 182 | |
ansond | 0:4c9bfcb3e759 | 183 | // set the color LED |
ansond | 0:4c9bfcb3e759 | 184 | void ErrorHandler::setRGBLED(float H, float S, float V) { |
ansond | 82:24af66daaf17 | 185 | #ifndef HUSH_LEDS |
ansond | 83:2f49051d6acf | 186 | if (this->m_rgb_mutex != NULL) this->m_rgb_mutex->lock(); |
ansond | 0:4c9bfcb3e759 | 187 | float f,h,p,q,t; |
ansond | 0:4c9bfcb3e759 | 188 | int i; |
ansond | 0:4c9bfcb3e759 | 189 | if( S == 0.0) { |
ansond | 0:4c9bfcb3e759 | 190 | r = 1.0 - V; // invert pwm ! |
ansond | 0:4c9bfcb3e759 | 191 | g = 1.0 - V; |
ansond | 0:4c9bfcb3e759 | 192 | b = 1.0 - V; |
ansond | 0:4c9bfcb3e759 | 193 | return; |
ansond | 0:4c9bfcb3e759 | 194 | } |
ansond | 0:4c9bfcb3e759 | 195 | if(H > 360.0) H = 0.0; // check values |
ansond | 0:4c9bfcb3e759 | 196 | if(S > 1.0) S = 1.0; |
ansond | 0:4c9bfcb3e759 | 197 | if(S < 0.0) S = 0.0; |
ansond | 0:4c9bfcb3e759 | 198 | if(V > 1.0) V = 1.0; |
ansond | 0:4c9bfcb3e759 | 199 | if(V < 0.0) V = 0.0; |
ansond | 0:4c9bfcb3e759 | 200 | h = H / 60.0; |
ansond | 0:4c9bfcb3e759 | 201 | i = (int) h; |
ansond | 0:4c9bfcb3e759 | 202 | f = h - i; |
ansond | 0:4c9bfcb3e759 | 203 | p = V * (1.0 - S); |
ansond | 0:4c9bfcb3e759 | 204 | q = V * (1.0 - (S * f)); |
ansond | 0:4c9bfcb3e759 | 205 | t = V * (1.0 - (S * (1.0 - f))); |
ansond | 0:4c9bfcb3e759 | 206 | |
ansond | 0:4c9bfcb3e759 | 207 | switch(i) { |
ansond | 0:4c9bfcb3e759 | 208 | case 0: |
ansond | 0:4c9bfcb3e759 | 209 | r = 1.0 - V; // invert pwm ! |
ansond | 0:4c9bfcb3e759 | 210 | g = 1.0 - t; |
ansond | 0:4c9bfcb3e759 | 211 | b = 1.0 - p; |
ansond | 0:4c9bfcb3e759 | 212 | break; |
ansond | 0:4c9bfcb3e759 | 213 | case 1: |
ansond | 0:4c9bfcb3e759 | 214 | r = 1.0 - q; |
ansond | 0:4c9bfcb3e759 | 215 | g = 1.0 - V; |
ansond | 0:4c9bfcb3e759 | 216 | b = 1.0 - p; |
ansond | 0:4c9bfcb3e759 | 217 | break; |
ansond | 0:4c9bfcb3e759 | 218 | case 2: |
ansond | 0:4c9bfcb3e759 | 219 | r = 1.0 - p; |
ansond | 0:4c9bfcb3e759 | 220 | g = 1.0 - V; |
ansond | 0:4c9bfcb3e759 | 221 | b = 1.0 - t; |
ansond | 0:4c9bfcb3e759 | 222 | break; |
ansond | 0:4c9bfcb3e759 | 223 | case 3: |
ansond | 0:4c9bfcb3e759 | 224 | r = 1.0 - p; |
ansond | 0:4c9bfcb3e759 | 225 | g = 1.0 - q; |
ansond | 0:4c9bfcb3e759 | 226 | b = 1.0 - V; |
ansond | 0:4c9bfcb3e759 | 227 | break; |
ansond | 0:4c9bfcb3e759 | 228 | case 4: |
ansond | 0:4c9bfcb3e759 | 229 | r = 1.0 - t; |
ansond | 0:4c9bfcb3e759 | 230 | g = 1.0 - p; |
ansond | 0:4c9bfcb3e759 | 231 | b = 1.0 - V; |
ansond | 0:4c9bfcb3e759 | 232 | break; |
ansond | 0:4c9bfcb3e759 | 233 | case 5: |
ansond | 0:4c9bfcb3e759 | 234 | default: |
ansond | 0:4c9bfcb3e759 | 235 | r = 1.0 - V; |
ansond | 0:4c9bfcb3e759 | 236 | g = 1.0 - p; |
ansond | 0:4c9bfcb3e759 | 237 | b = 1.0 - q; |
ansond | 0:4c9bfcb3e759 | 238 | break; |
ansond | 0:4c9bfcb3e759 | 239 | } |
ansond | 83:2f49051d6acf | 240 | if (this->m_rgb_mutex != NULL) this->m_rgb_mutex->unlock(); |
ansond | 82:24af66daaf17 | 241 | #endif |
ansond | 0:4c9bfcb3e759 | 242 | } |
ansond | 0:4c9bfcb3e759 | 243 | |
ansond | 0:4c9bfcb3e759 | 244 | // turn the RGB LED specific colors |
ansond | 0:4c9bfcb3e759 | 245 | void ErrorHandler::turnLEDRed() { this->setRGBLED(0.0,1.0,0.2); } |
ansond | 0:4c9bfcb3e759 | 246 | void ErrorHandler::turnLEDGreen() { this->setRGBLED(120.0,1.0,0.2); } |
ansond | 0:4c9bfcb3e759 | 247 | void ErrorHandler::turnLEDBlue() { this->setRGBLED(200.0,1.0,0.2); } |
ansond | 114:bd38ad417d6a | 248 | void ErrorHandler::turnLEDPurple() { this->setRGBLED(261.9,1.0,0.2); } |
ansond | 114:bd38ad417d6a | 249 | void ErrorHandler::turnLEDOrange() { this->setRGBLED(51.0,1.0,0.2); } |
ansond | 0:4c9bfcb3e759 | 250 | void ErrorHandler::turnLEDBlack() { this->setRGBLED(0,0,0); } |
ansond | 0:4c9bfcb3e759 | 251 | void ErrorHandler::turnLEDYellow() { this->setRGBLED(60.0,1.0,0.133); } |
ansond | 0:4c9bfcb3e759 | 252 | |
ansond | 0:4c9bfcb3e759 | 253 | // reset LEDs |
ansond | 0:4c9bfcb3e759 | 254 | void ErrorHandler::resetLEDs() { |
ansond | 82:24af66daaf17 | 255 | #ifndef HUSH_LEDS |
ansond | 0:4c9bfcb3e759 | 256 | // turn off all LEDs |
ansond | 0:4c9bfcb3e759 | 257 | led1 = 0; led2 = 0; led3 = 0; led4 = 0; |
ansond | 82:24af66daaf17 | 258 | #endif |
ansond | 0:4c9bfcb3e759 | 259 | } |
ansond | 0:4c9bfcb3e759 | 260 | |
ansond | 0:4c9bfcb3e759 | 261 | // blink an LED |
ansond | 0:4c9bfcb3e759 | 262 | void ErrorHandler::blinkLED(DigitalOut led) { |
ansond | 82:24af66daaf17 | 263 | #ifndef HUSH_LEDS |
ansond | 84:4a993dd7c38b | 264 | if (this->m_led_mutex != NULL) this->m_led_mutex->lock(); |
ansond | 0:4c9bfcb3e759 | 265 | led = 1; |
ansond | 84:4a993dd7c38b | 266 | if (this->m_led_mutex != NULL) this->m_led_mutex->unlock(); |
ansond | 0:4c9bfcb3e759 | 267 | wait_ms(BLINK_TIME); |
ansond | 84:4a993dd7c38b | 268 | if (this->m_led_mutex != NULL) this->m_led_mutex->lock(); |
ansond | 0:4c9bfcb3e759 | 269 | led = 0; |
ansond | 84:4a993dd7c38b | 270 | if (this->m_led_mutex != NULL) this->m_led_mutex->unlock(); |
ansond | 82:24af66daaf17 | 271 | #endif |
ansond | 0:4c9bfcb3e759 | 272 | } |
ansond | 0:4c9bfcb3e759 | 273 | |
ansond | 84:4a993dd7c38b | 274 | void ErrorHandler::changeLED(DigitalOut led,bool onoff) { |
ansond | 84:4a993dd7c38b | 275 | if (this->m_led_mutex != NULL) this->m_led_mutex->lock(); |
ansond | 84:4a993dd7c38b | 276 | if (onoff) led = 1; |
ansond | 84:4a993dd7c38b | 277 | else led = 0; |
ansond | 84:4a993dd7c38b | 278 | if (this->m_led_mutex != NULL) this->m_led_mutex->unlock(); |
ansond | 84:4a993dd7c38b | 279 | } |
ansond | 84:4a993dd7c38b | 280 | |
ansond | 84:4a993dd7c38b | 281 | void ErrorHandler::led2On() { this->changeLED(led2,true); } |
ansond | 84:4a993dd7c38b | 282 | void ErrorHandler::led2Off() { this->changeLED(led2,false); } |
ansond | 84:4a993dd7c38b | 283 | void ErrorHandler::led3On() { this->changeLED(led3,true); } |
ansond | 84:4a993dd7c38b | 284 | void ErrorHandler::led3Off() { this->changeLED(led3,false); } |
ansond | 84:4a993dd7c38b | 285 | |
ansond | 112:1fb53d4729af | 286 | void ErrorHandler::setEndpoint(void *endpoint) { this->m_endpoint = endpoint; } |
ansond | 112:1fb53d4729af | 287 | void *ErrorHandler::getEndpoint() { return this->m_endpoint; } |
ansond | 112:1fb53d4729af | 288 | |
ansond | 36:73e343ddca7f | 289 | // blink the Transport TX LED |
ansond | 36:73e343ddca7f | 290 | void ErrorHandler::blinkTransportTxLED() { this->blinkLED(led4); } |
ansond | 0:4c9bfcb3e759 | 291 | |
ansond | 36:73e343ddca7f | 292 | // blink the Transport RX LED |
ansond | 36:73e343ddca7f | 293 | void ErrorHandler::blinkTransportRxLED() { this->blinkLED(led1); } |