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
Logger.cpp@192:54b758a8eaaa, 2014-09-26 (annotated)
- Committer:
- ansond
- Date:
- Fri Sep 26 05:16:07 2014 +0000
- Revision:
- 192:54b758a8eaaa
- Parent:
- ErrorHandler.cpp@180:eb43d5cd0ed7
updates to new logger name
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 | 192:54b758a8eaaa | 19 | #include "Logger.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 | 192:54b758a8eaaa | 62 | #define LOGGER_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 | 192:54b758a8eaaa | 75 | Logger::Logger(RawSerial *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 | 192:54b758a8eaaa | 95 | Logger::~Logger() { |
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 | 192:54b758a8eaaa | 106 | void Logger::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 | 192:54b758a8eaaa | 110 | void Logger::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 | 192:54b758a8eaaa | 119 | void Logger::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 | 192:54b758a8eaaa | 131 | LOGGER_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 | 192:54b758a8eaaa | 168 | // log ( to serial console only )information |
ansond | 192:54b758a8eaaa | 169 | void Logger::logConsole(const char *format, ...) { |
ansond | 192:54b758a8eaaa | 170 | memset(this->m_message,0,MAX_LOG_MESSAGE+1); |
ansond | 192:54b758a8eaaa | 171 | va_list args; |
ansond | 192:54b758a8eaaa | 172 | va_start(args, format); |
ansond | 192:54b758a8eaaa | 173 | vsprintf(this->m_message, format, args); |
ansond | 192:54b758a8eaaa | 174 | va_end(args); |
ansond | 192:54b758a8eaaa | 175 | |
ansond | 192:54b758a8eaaa | 176 | #ifdef EH_USE_MUTEXES |
ansond | 192:54b758a8eaaa | 177 | if (this->m_mutex != NULL) this->m_mutex->lock(); |
ansond | 192:54b758a8eaaa | 178 | #endif |
ansond | 192:54b758a8eaaa | 179 | if (this->m_pc != NULL) this->m_pc->printf(this->m_message); |
ansond | 192:54b758a8eaaa | 180 | #ifdef ENABLE_MEMORY_DEBUG |
ansond | 192:54b758a8eaaa | 181 | LOGGER_MEM_STATS(0); |
ansond | 192:54b758a8eaaa | 182 | #endif |
ansond | 192:54b758a8eaaa | 183 | if (this->m_pc != NULL) this->m_pc->printf("\r\n"); |
ansond | 192:54b758a8eaaa | 184 | #ifdef EH_USE_MUTEXES |
ansond | 192:54b758a8eaaa | 185 | if (this->m_mutex != NULL) this->m_mutex->unlock(); |
ansond | 192:54b758a8eaaa | 186 | #endif |
ansond | 192:54b758a8eaaa | 187 | } |
ansond | 192:54b758a8eaaa | 188 | |
ansond | 74:b60149dd669e | 189 | // log information |
ansond | 192:54b758a8eaaa | 190 | void Logger::log_memory(const char *format, ...) { |
ansond | 82:24af66daaf17 | 191 | #ifndef HUSH_LOG |
ansond | 74:b60149dd669e | 192 | #ifdef MEMORY_LOGGING |
ansond | 74:b60149dd669e | 193 | memset(this->m_message,0,MAX_LOG_MESSAGE+1); |
ansond | 74:b60149dd669e | 194 | va_list args; |
ansond | 74:b60149dd669e | 195 | va_start(args, format); |
ansond | 74:b60149dd669e | 196 | vsprintf(this->m_message, format, args); |
ansond | 74:b60149dd669e | 197 | va_end(args); |
ansond | 160:24337c83dd1d | 198 | #ifdef EH_USE_MUTEXES |
ansond | 84:4a993dd7c38b | 199 | if (this->m_mutex != NULL) this->m_mutex->lock(); |
ansond | 160:24337c83dd1d | 200 | #endif |
ansond | 149:7fde829ed672 | 201 | if (this->m_pc != NULL) this->m_pc->printf(this->m_message); |
ansond | 192:54b758a8eaaa | 202 | LOGGER_MEM_STATS(0); |
ansond | 160:24337c83dd1d | 203 | #ifdef EH_USE_MUTEXES |
ansond | 74:b60149dd669e | 204 | if (this->m_mutex != NULL) this->m_mutex->unlock(); |
ansond | 74:b60149dd669e | 205 | #endif |
ansond | 82:24af66daaf17 | 206 | #endif |
ansond | 160:24337c83dd1d | 207 | #endif |
ansond | 74:b60149dd669e | 208 | } |
ansond | 74:b60149dd669e | 209 | |
ansond | 15:386dccd0000a | 210 | // pause |
ansond | 192:54b758a8eaaa | 211 | void Logger::pause(const char *format, ...) { |
ansond | 82:24af66daaf17 | 212 | #ifndef HUSH_LOG |
ansond | 26:791d22d43cb4 | 213 | memset(this->m_message,0,MAX_LOG_MESSAGE+1); |
ansond | 15:386dccd0000a | 214 | va_list args; |
ansond | 15:386dccd0000a | 215 | va_start(args, format); |
ansond | 15:386dccd0000a | 216 | vsprintf(this->m_message, format, args); |
ansond | 15:386dccd0000a | 217 | va_end(args); |
ansond | 160:24337c83dd1d | 218 | #ifdef EH_USE_MUTEXES |
ansond | 84:4a993dd7c38b | 219 | if (this->m_mutex != NULL) this->m_mutex->lock(); |
ansond | 160:24337c83dd1d | 220 | #endif |
ansond | 149:7fde829ed672 | 221 | if (this->m_pc != NULL) this->m_pc->printf(this->m_message); |
ansond | 149:7fde829ed672 | 222 | if (this->m_pc != NULL) this->m_pc->printf("\r\n"); |
ansond | 15:386dccd0000a | 223 | this->m_lcd->cls(); |
ansond | 15:386dccd0000a | 224 | this->m_lcd->locate(0,0); |
ansond | 15:386dccd0000a | 225 | this->m_lcd->printf(this->m_message); |
ansond | 149:7fde829ed672 | 226 | if (this->m_pc != NULL) { |
ansond | 149:7fde829ed672 | 227 | this->m_pc->printf("Press any key to continue...ctrl-c to stop\r\n"); |
ansond | 149:7fde829ed672 | 228 | char c = this->m_pc->getc(); |
ansond | 149:7fde829ed672 | 229 | if (c == 0x03) { // CTRL-C ASCII |
ansond | 16:fda7dbb8b47a | 230 | this->m_pc->printf("ctrl-c: closing down...\r\n"); |
ansond | 160:24337c83dd1d | 231 | #ifdef EH_USE_MUTEXES |
ansond | 84:4a993dd7c38b | 232 | if (this->m_mutex != NULL) this->m_mutex->unlock(); |
ansond | 160:24337c83dd1d | 233 | #endif |
ansond | 149:7fde829ed672 | 234 | closedown(1); |
ansond | 149:7fde829ed672 | 235 | } |
ansond | 16:fda7dbb8b47a | 236 | } |
ansond | 160:24337c83dd1d | 237 | #ifdef EH_USE_MUTEXES |
ansond | 70:055ebf51f6ad | 238 | if (this->m_mutex != NULL) this->m_mutex->unlock(); |
ansond | 82:24af66daaf17 | 239 | #endif |
ansond | 160:24337c83dd1d | 240 | #endif |
ansond | 15:386dccd0000a | 241 | } |
ansond | 15:386dccd0000a | 242 | |
ansond | 0:4c9bfcb3e759 | 243 | // check for exit |
ansond | 192:54b758a8eaaa | 244 | void Logger::checkForExit() { |
ansond | 160:24337c83dd1d | 245 | #ifdef EH_USE_MUTEXES |
ansond | 70:055ebf51f6ad | 246 | if (this->m_close_mutex != NULL) this->m_close_mutex->lock(); |
ansond | 160:24337c83dd1d | 247 | #endif |
ansond | 149:7fde829ed672 | 248 | if (this->m_pc != NULL && this->m_pc->readable()) { |
ansond | 0:4c9bfcb3e759 | 249 | char c = this->m_pc->getc(); |
ansond | 0:4c9bfcb3e759 | 250 | if (c == 0x03) { // CTRL-C ASCII |
ansond | 0:4c9bfcb3e759 | 251 | this->m_pc->printf("ctrl-c: closing down...\r\n"); |
ansond | 20:f2dbbd852e08 | 252 | closedown(1); |
ansond | 0:4c9bfcb3e759 | 253 | } |
ansond | 0:4c9bfcb3e759 | 254 | } |
ansond | 160:24337c83dd1d | 255 | #ifdef EH_USE_MUTEXES |
ansond | 70:055ebf51f6ad | 256 | if (this->m_close_mutex != NULL) this->m_close_mutex->unlock(); |
ansond | 160:24337c83dd1d | 257 | #endif |
ansond | 0:4c9bfcb3e759 | 258 | } |
ansond | 0:4c9bfcb3e759 | 259 | |
ansond | 0:4c9bfcb3e759 | 260 | // set the color LED |
ansond | 192:54b758a8eaaa | 261 | void Logger::setRGBLED(float H, float S, float V) { |
ansond | 82:24af66daaf17 | 262 | #ifndef HUSH_LEDS |
ansond | 160:24337c83dd1d | 263 | #ifdef EH_USE_MUTEXES |
ansond | 83:2f49051d6acf | 264 | if (this->m_rgb_mutex != NULL) this->m_rgb_mutex->lock(); |
ansond | 160:24337c83dd1d | 265 | #endif |
ansond | 0:4c9bfcb3e759 | 266 | float f,h,p,q,t; |
ansond | 0:4c9bfcb3e759 | 267 | int i; |
ansond | 0:4c9bfcb3e759 | 268 | if( S == 0.0) { |
ansond | 0:4c9bfcb3e759 | 269 | r = 1.0 - V; // invert pwm ! |
ansond | 0:4c9bfcb3e759 | 270 | g = 1.0 - V; |
ansond | 0:4c9bfcb3e759 | 271 | b = 1.0 - V; |
ansond | 0:4c9bfcb3e759 | 272 | return; |
ansond | 0:4c9bfcb3e759 | 273 | } |
ansond | 0:4c9bfcb3e759 | 274 | if(H > 360.0) H = 0.0; // check values |
ansond | 0:4c9bfcb3e759 | 275 | if(S > 1.0) S = 1.0; |
ansond | 0:4c9bfcb3e759 | 276 | if(S < 0.0) S = 0.0; |
ansond | 0:4c9bfcb3e759 | 277 | if(V > 1.0) V = 1.0; |
ansond | 0:4c9bfcb3e759 | 278 | if(V < 0.0) V = 0.0; |
ansond | 0:4c9bfcb3e759 | 279 | h = H / 60.0; |
ansond | 0:4c9bfcb3e759 | 280 | i = (int) h; |
ansond | 0:4c9bfcb3e759 | 281 | f = h - i; |
ansond | 0:4c9bfcb3e759 | 282 | p = V * (1.0 - S); |
ansond | 0:4c9bfcb3e759 | 283 | q = V * (1.0 - (S * f)); |
ansond | 0:4c9bfcb3e759 | 284 | t = V * (1.0 - (S * (1.0 - f))); |
ansond | 0:4c9bfcb3e759 | 285 | |
ansond | 0:4c9bfcb3e759 | 286 | switch(i) { |
ansond | 0:4c9bfcb3e759 | 287 | case 0: |
ansond | 0:4c9bfcb3e759 | 288 | r = 1.0 - V; // invert pwm ! |
ansond | 0:4c9bfcb3e759 | 289 | g = 1.0 - t; |
ansond | 0:4c9bfcb3e759 | 290 | b = 1.0 - p; |
ansond | 0:4c9bfcb3e759 | 291 | break; |
ansond | 0:4c9bfcb3e759 | 292 | case 1: |
ansond | 0:4c9bfcb3e759 | 293 | r = 1.0 - q; |
ansond | 0:4c9bfcb3e759 | 294 | g = 1.0 - V; |
ansond | 0:4c9bfcb3e759 | 295 | b = 1.0 - p; |
ansond | 0:4c9bfcb3e759 | 296 | break; |
ansond | 0:4c9bfcb3e759 | 297 | case 2: |
ansond | 0:4c9bfcb3e759 | 298 | r = 1.0 - p; |
ansond | 0:4c9bfcb3e759 | 299 | g = 1.0 - V; |
ansond | 0:4c9bfcb3e759 | 300 | b = 1.0 - t; |
ansond | 0:4c9bfcb3e759 | 301 | break; |
ansond | 0:4c9bfcb3e759 | 302 | case 3: |
ansond | 0:4c9bfcb3e759 | 303 | r = 1.0 - p; |
ansond | 0:4c9bfcb3e759 | 304 | g = 1.0 - q; |
ansond | 0:4c9bfcb3e759 | 305 | b = 1.0 - V; |
ansond | 0:4c9bfcb3e759 | 306 | break; |
ansond | 0:4c9bfcb3e759 | 307 | case 4: |
ansond | 0:4c9bfcb3e759 | 308 | r = 1.0 - t; |
ansond | 0:4c9bfcb3e759 | 309 | g = 1.0 - p; |
ansond | 0:4c9bfcb3e759 | 310 | b = 1.0 - V; |
ansond | 0:4c9bfcb3e759 | 311 | break; |
ansond | 0:4c9bfcb3e759 | 312 | case 5: |
ansond | 0:4c9bfcb3e759 | 313 | default: |
ansond | 0:4c9bfcb3e759 | 314 | r = 1.0 - V; |
ansond | 0:4c9bfcb3e759 | 315 | g = 1.0 - p; |
ansond | 0:4c9bfcb3e759 | 316 | b = 1.0 - q; |
ansond | 0:4c9bfcb3e759 | 317 | break; |
ansond | 0:4c9bfcb3e759 | 318 | } |
ansond | 160:24337c83dd1d | 319 | #ifdef EH_USE_MUTEXES |
ansond | 83:2f49051d6acf | 320 | if (this->m_rgb_mutex != NULL) this->m_rgb_mutex->unlock(); |
ansond | 82:24af66daaf17 | 321 | #endif |
ansond | 160:24337c83dd1d | 322 | #endif |
ansond | 0:4c9bfcb3e759 | 323 | } |
ansond | 0:4c9bfcb3e759 | 324 | |
ansond | 0:4c9bfcb3e759 | 325 | // turn the RGB LED specific colors |
ansond | 192:54b758a8eaaa | 326 | void Logger::turnLEDRed() { this->setRGBLED(0.0,1.0,0.2); } |
ansond | 192:54b758a8eaaa | 327 | void Logger::turnLEDGreen() { this->setRGBLED(120.0,1.0,0.2); } |
ansond | 192:54b758a8eaaa | 328 | void Logger::turnLEDBlue() { this->setRGBLED(200.0,1.0,0.2); } |
ansond | 192:54b758a8eaaa | 329 | void Logger::turnLEDPurple() { this->setRGBLED(261.9,1.0,0.2); } |
ansond | 192:54b758a8eaaa | 330 | void Logger::turnLEDOrange() { this->setRGBLED(51.0,1.0,0.2); } |
ansond | 192:54b758a8eaaa | 331 | void Logger::turnLEDBlack() { this->setRGBLED(0,0,0); } |
ansond | 192:54b758a8eaaa | 332 | void Logger::turnLEDYellow() { this->setRGBLED(60.0,1.0,0.133); } |
ansond | 0:4c9bfcb3e759 | 333 | |
ansond | 0:4c9bfcb3e759 | 334 | // reset LEDs |
ansond | 192:54b758a8eaaa | 335 | void Logger::resetLEDs() { |
ansond | 82:24af66daaf17 | 336 | #ifndef HUSH_LEDS |
ansond | 0:4c9bfcb3e759 | 337 | // turn off all LEDs |
ansond | 0:4c9bfcb3e759 | 338 | led1 = 0; led2 = 0; led3 = 0; led4 = 0; |
ansond | 82:24af66daaf17 | 339 | #endif |
ansond | 0:4c9bfcb3e759 | 340 | } |
ansond | 0:4c9bfcb3e759 | 341 | |
ansond | 0:4c9bfcb3e759 | 342 | // blink an LED |
ansond | 192:54b758a8eaaa | 343 | void Logger::blinkLED(DigitalOut led) { |
ansond | 82:24af66daaf17 | 344 | #ifndef HUSH_LEDS |
ansond | 160:24337c83dd1d | 345 | #ifdef EH_USE_MUTEXES |
ansond | 84:4a993dd7c38b | 346 | if (this->m_led_mutex != NULL) this->m_led_mutex->lock(); |
ansond | 160:24337c83dd1d | 347 | #endif |
ansond | 0:4c9bfcb3e759 | 348 | led = 1; |
ansond | 160:24337c83dd1d | 349 | #ifdef EH_USE_MUTEXES |
ansond | 84:4a993dd7c38b | 350 | if (this->m_led_mutex != NULL) this->m_led_mutex->unlock(); |
ansond | 160:24337c83dd1d | 351 | #endif |
ansond | 180:eb43d5cd0ed7 | 352 | Thread::wait(BLINK_TIME); |
ansond | 160:24337c83dd1d | 353 | #ifdef EH_USE_MUTEXES |
ansond | 84:4a993dd7c38b | 354 | if (this->m_led_mutex != NULL) this->m_led_mutex->lock(); |
ansond | 160:24337c83dd1d | 355 | #endif |
ansond | 0:4c9bfcb3e759 | 356 | led = 0; |
ansond | 160:24337c83dd1d | 357 | #ifdef EH_USE_MUTEXES |
ansond | 84:4a993dd7c38b | 358 | if (this->m_led_mutex != NULL) this->m_led_mutex->unlock(); |
ansond | 82:24af66daaf17 | 359 | #endif |
ansond | 160:24337c83dd1d | 360 | #endif |
ansond | 0:4c9bfcb3e759 | 361 | } |
ansond | 0:4c9bfcb3e759 | 362 | |
ansond | 192:54b758a8eaaa | 363 | void Logger::changeLED(DigitalOut led,bool onoff) { |
ansond | 160:24337c83dd1d | 364 | #ifdef EH_USE_MUTEXES |
ansond | 84:4a993dd7c38b | 365 | if (this->m_led_mutex != NULL) this->m_led_mutex->lock(); |
ansond | 160:24337c83dd1d | 366 | #endif |
ansond | 84:4a993dd7c38b | 367 | if (onoff) led = 1; |
ansond | 84:4a993dd7c38b | 368 | else led = 0; |
ansond | 160:24337c83dd1d | 369 | #ifdef EH_USE_MUTEXES |
ansond | 84:4a993dd7c38b | 370 | if (this->m_led_mutex != NULL) this->m_led_mutex->unlock(); |
ansond | 160:24337c83dd1d | 371 | #endif |
ansond | 84:4a993dd7c38b | 372 | } |
ansond | 84:4a993dd7c38b | 373 | |
ansond | 192:54b758a8eaaa | 374 | void Logger::led2On() { this->changeLED(led2,true); } |
ansond | 192:54b758a8eaaa | 375 | void Logger::led2Off() { this->changeLED(led2,false); } |
ansond | 192:54b758a8eaaa | 376 | void Logger::led3On() { this->changeLED(led3,true); } |
ansond | 192:54b758a8eaaa | 377 | void Logger::led3Off() { this->changeLED(led3,false); } |
ansond | 84:4a993dd7c38b | 378 | |
ansond | 192:54b758a8eaaa | 379 | void Logger::setEndpoint(void *endpoint) { this->m_endpoint = endpoint; } |
ansond | 192:54b758a8eaaa | 380 | void *Logger::getEndpoint() { return this->m_endpoint; } |
ansond | 112:1fb53d4729af | 381 | |
ansond | 36:73e343ddca7f | 382 | // blink the Transport TX LED |
ansond | 192:54b758a8eaaa | 383 | void Logger::blinkTransportTxLED() { this->blinkLED(led4); } |
ansond | 0:4c9bfcb3e759 | 384 | |
ansond | 36:73e343ddca7f | 385 | // blink the Transport RX LED |
ansond | 192:54b758a8eaaa | 386 | void Logger::blinkTransportRxLED() { this->blinkLED(led1); } |