light sensor
Dependencies: X_NUCLEO_IKS01A1 LoRaWAN-lib SX1276Lib mbed
Fork of LoRaWAN-SX1276-Application-Demo by
app/LoRaApp.cpp@6:25f847c99aa2, 2017-09-09 (annotated)
- Committer:
- ubhat
- Date:
- Sat Sep 09 00:26:19 2017 +0000
- Revision:
- 6:25f847c99aa2
- Parent:
- 5:f04a6f68e159
Changed packet format to Senet Packet Format for numeric stream on M2X
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ubhat | 0:42863a11464a | 1 | /* |
ubhat | 0:42863a11464a | 2 | / _____) _ | | |
ubhat | 0:42863a11464a | 3 | ( (____ _____ ____ _| |_ _____ ____| |__ |
ubhat | 0:42863a11464a | 4 | \____ \| ___ | (_ _) ___ |/ ___) _ \ |
ubhat | 0:42863a11464a | 5 | _____) ) ____| | | || |_| ____( (___| | | | |
ubhat | 0:42863a11464a | 6 | (______/|_____)_|_|_| \__)_____)\____)_| |_| |
ubhat | 0:42863a11464a | 7 | (C)2015 Semtech |
ubhat | 0:42863a11464a | 8 | |
ubhat | 0:42863a11464a | 9 | Description: User-defined applications such as GPS, Temp, Accelerometer, LED indications etc. |
ubhat | 0:42863a11464a | 10 | Event based actions such as LED blink on Tx, LED toggle on downlink etc |
ubhat | 0:42863a11464a | 11 | |
ubhat | 0:42863a11464a | 12 | License: Revised BSD License, see LICENSE.TXT file include in the project |
ubhat | 0:42863a11464a | 13 | |
ubhat | 0:42863a11464a | 14 | Maintainer: Uttam Bhat |
ubhat | 0:42863a11464a | 15 | */ |
ubhat | 0:42863a11464a | 16 | |
ubhat | 0:42863a11464a | 17 | #include "LoRaApp.h" |
ubhat | 0:42863a11464a | 18 | |
ubhat | 2:78df92a365c2 | 19 | #ifdef USE_IKS01A1_SENSOR |
ubhat | 2:78df92a365c2 | 20 | float iks01a1_data; |
ubhat | 2:78df92a365c2 | 21 | int32_t Accl_Value[3] = {0}; |
ubhat | 2:78df92a365c2 | 22 | #endif |
ubhat | 2:78df92a365c2 | 23 | |
ubhat | 3:4bca7f8f731a | 24 | #ifdef USE_CAYENNE_LPP |
ubhat | 3:4bca7f8f731a | 25 | /* |
ubhat | 3:4bca7f8f731a | 26 | .... Pressure |
ubhat | 3:4bca7f8f731a | 27 | .... Temperature |
ubhat | 3:4bca7f8f731a | 28 | .... Humidity |
ubhat | 3:4bca7f8f731a | 29 | .... Accelerometer |
ubhat | 3:4bca7f8f731a | 30 | */ |
ubhat | 3:4bca7f8f731a | 31 | uint8_t maxLPPsize[4] = {4, 4, 3, 8}; |
ubhat | 3:4bca7f8f731a | 32 | #endif |
ubhat | 3:4bca7f8f731a | 33 | |
ubhat | 0:42863a11464a | 34 | bool VerticalStatus = false; |
ubhat | 0:42863a11464a | 35 | |
ubhat | 0:42863a11464a | 36 | |
ubhat | 0:42863a11464a | 37 | Application::Application( uint8_t * memptr ) |
ubhat | 0:42863a11464a | 38 | { |
ubhat | 0:42863a11464a | 39 | BuffAddr = memptr; |
ubhat | 0:42863a11464a | 40 | memset( BuffAddr, 0, LORAWAN_APP_DATA_MAX_SIZE ); |
ubhat | 0:42863a11464a | 41 | BuffPtr = 0; |
ubhat | 0:42863a11464a | 42 | } |
ubhat | 0:42863a11464a | 43 | |
ubhat | 0:42863a11464a | 44 | Application::~Application( ) |
ubhat | 0:42863a11464a | 45 | { |
ubhat | 0:42863a11464a | 46 | } |
ubhat | 0:42863a11464a | 47 | |
ubhat | 0:42863a11464a | 48 | void Application::ApplicationAppendData( uint8_t *pData, uint8_t len ) |
ubhat | 0:42863a11464a | 49 | { |
ubhat | 0:42863a11464a | 50 | memcpy( BuffAddr + BuffPtr, pData, len ); |
ubhat | 0:42863a11464a | 51 | BuffPtr += len; |
ubhat | 0:42863a11464a | 52 | } |
ubhat | 0:42863a11464a | 53 | |
ubhat | 0:42863a11464a | 54 | void Application::ApplicationPtrPos( uint8_t ptrPos ) |
ubhat | 0:42863a11464a | 55 | { |
ubhat | 0:42863a11464a | 56 | BuffPtr = ptrPos; |
ubhat | 0:42863a11464a | 57 | } |
ubhat | 0:42863a11464a | 58 | |
ubhat | 0:42863a11464a | 59 | void Application::ApplicationCall( eAppType App ) |
ubhat | 0:42863a11464a | 60 | { |
ubhat | 0:42863a11464a | 61 | switch( App ) |
ubhat | 2:78df92a365c2 | 62 | { |
ubhat | 0:42863a11464a | 63 | // Appends 1 Byte to TX buffer |
ubhat | 0:42863a11464a | 64 | case AppTemp: |
ubhat | 0:42863a11464a | 65 | { |
ubhat | 2:78df92a365c2 | 66 | #ifdef USE_IKS01A1_SENSOR |
ubhat | 2:78df92a365c2 | 67 | |
ubhat | 3:4bca7f8f731a | 68 | temp_sensor2->GetTemperature(&iks01a1_data); |
ubhat | 2:78df92a365c2 | 69 | |
ubhat | 2:78df92a365c2 | 70 | printf("Temp = %f, %d\r\n", iks01a1_data, (int8_t) iks01a1_data); |
ubhat | 2:78df92a365c2 | 71 | |
ubhat | 0:42863a11464a | 72 | if( ( BuffPtr + 1 ) <= LORAWAN_APP_DATA_SIZE ) |
ubhat | 0:42863a11464a | 73 | { |
ubhat | 3:4bca7f8f731a | 74 | #ifdef USE_CAYENNE_LPP |
ubhat | 3:4bca7f8f731a | 75 | BuffAddr[BuffPtr++] = 0; |
ubhat | 3:4bca7f8f731a | 76 | BuffAddr[BuffPtr++] = (int8_t) ( iks01a1_data * 10 ); |
ubhat | 3:4bca7f8f731a | 77 | #else |
ubhat | 3:4bca7f8f731a | 78 | BuffAddr[BuffPtr++] = (int8_t) iks01a1_data; |
ubhat | 3:4bca7f8f731a | 79 | #endif |
ubhat | 2:78df92a365c2 | 80 | } |
ubhat | 2:78df92a365c2 | 81 | |
ubhat | 2:78df92a365c2 | 82 | #endif |
ubhat | 2:78df92a365c2 | 83 | break; |
ubhat | 2:78df92a365c2 | 84 | } |
ubhat | 2:78df92a365c2 | 85 | |
ubhat | 2:78df92a365c2 | 86 | // Appends 2 Bytes to TX buffer |
ubhat | 2:78df92a365c2 | 87 | case AppPressr: |
ubhat | 2:78df92a365c2 | 88 | { |
ubhat | 2:78df92a365c2 | 89 | #ifdef USE_IKS01A1_SENSOR |
ubhat | 2:78df92a365c2 | 90 | |
ubhat | 2:78df92a365c2 | 91 | pressure_sensor->GetPressure(&iks01a1_data); |
ubhat | 2:78df92a365c2 | 92 | |
ubhat | 2:78df92a365c2 | 93 | printf("Pressure = %f, %d\r\n", iks01a1_data, (uint16_t) iks01a1_data); |
ubhat | 2:78df92a365c2 | 94 | |
ubhat | 2:78df92a365c2 | 95 | if( ( BuffPtr + 2 ) <= LORAWAN_APP_DATA_SIZE ) |
ubhat | 2:78df92a365c2 | 96 | { |
ubhat | 3:4bca7f8f731a | 97 | #ifdef USE_CAYENNE_LPP |
ubhat | 3:4bca7f8f731a | 98 | int16_t tmp; |
ubhat | 3:4bca7f8f731a | 99 | |
ubhat | 3:4bca7f8f731a | 100 | tmp = (int16_t) ( iks01a1_data * 10 ); |
ubhat | 3:4bca7f8f731a | 101 | BuffAddr[BuffPtr++] = ( tmp >> 8 ) & 0xFF; |
ubhat | 3:4bca7f8f731a | 102 | BuffAddr[BuffPtr++] = ( tmp ) & 0xFF; |
ubhat | 3:4bca7f8f731a | 103 | #else |
ubhat | 2:78df92a365c2 | 104 | BuffAddr[BuffPtr++] = ( (int16_t) iks01a1_data >> 8 ) & 0xFF; |
ubhat | 3:4bca7f8f731a | 105 | BuffAddr[BuffPtr++] = ( (int16_t) iks01a1_data ) & 0xFF; |
ubhat | 3:4bca7f8f731a | 106 | #endif |
ubhat | 0:42863a11464a | 107 | } |
ubhat | 2:78df92a365c2 | 108 | |
ubhat | 2:78df92a365c2 | 109 | #endif |
ubhat | 2:78df92a365c2 | 110 | break; |
ubhat | 2:78df92a365c2 | 111 | } |
ubhat | 2:78df92a365c2 | 112 | |
ubhat | 2:78df92a365c2 | 113 | // Appends 2 Bytes to TX buffer |
ubhat | 2:78df92a365c2 | 114 | case AppHumid: |
ubhat | 2:78df92a365c2 | 115 | { |
ubhat | 2:78df92a365c2 | 116 | #ifdef USE_IKS01A1_SENSOR |
ubhat | 2:78df92a365c2 | 117 | |
ubhat | 2:78df92a365c2 | 118 | humidity_sensor->GetHumidity(&iks01a1_data); |
ubhat | 2:78df92a365c2 | 119 | |
ubhat | 2:78df92a365c2 | 120 | printf("Humidity = %f, %d\r\n", iks01a1_data, (uint8_t) iks01a1_data); |
ubhat | 2:78df92a365c2 | 121 | |
ubhat | 2:78df92a365c2 | 122 | if( ( BuffPtr + 1 ) <= LORAWAN_APP_DATA_SIZE ) |
ubhat | 2:78df92a365c2 | 123 | { |
ubhat | 3:4bca7f8f731a | 124 | #ifdef USE_CAYENNE_LPP |
ubhat | 3:4bca7f8f731a | 125 | BuffAddr[BuffPtr++] = (uint8_t) ( iks01a1_data * 2 ); |
ubhat | 3:4bca7f8f731a | 126 | #else |
ubhat | 2:78df92a365c2 | 127 | BuffAddr[BuffPtr++] = (int8_t) iks01a1_data; |
ubhat | 3:4bca7f8f731a | 128 | #endif |
ubhat | 2:78df92a365c2 | 129 | } |
ubhat | 2:78df92a365c2 | 130 | |
ubhat | 2:78df92a365c2 | 131 | #endif |
ubhat | 0:42863a11464a | 132 | break; |
ubhat | 0:42863a11464a | 133 | } |
ubhat | 0:42863a11464a | 134 | |
ubhat | 0:42863a11464a | 135 | // Appends 1 Byte to TX buffer |
ubhat | 0:42863a11464a | 136 | case AppBat: |
ubhat | 0:42863a11464a | 137 | { |
ubhat | 0:42863a11464a | 138 | if( ( BuffPtr + 1 ) <= LORAWAN_APP_DATA_SIZE ) |
ubhat | 0:42863a11464a | 139 | { |
ubhat | 0:42863a11464a | 140 | BuffAddr[BuffPtr++] = BoardGetBatteryLevel( ); // Per LoRaWAN spec; 0 = Charging; 1...254 = level, 255 = N/A |
ubhat | 0:42863a11464a | 141 | } |
ubhat | 0:42863a11464a | 142 | break; |
ubhat | 0:42863a11464a | 143 | } |
ubhat | 0:42863a11464a | 144 | |
ubhat | 0:42863a11464a | 145 | // Appends incremental values of 1 Byte each to TX buffer until Full |
ubhat | 0:42863a11464a | 146 | case AppRamp: |
ubhat | 0:42863a11464a | 147 | { |
ubhat | 0:42863a11464a | 148 | int32_t i, j; |
ubhat | 0:42863a11464a | 149 | |
ubhat | 0:42863a11464a | 150 | // Populate Tx Buffer with increasing byte values starting from 0x00, 0x01, 0x02 ... |
ubhat | 0:42863a11464a | 151 | for( i = BuffPtr, j = 0; i < LORAWAN_APP_DATA_SIZE; i++ ) |
ubhat | 0:42863a11464a | 152 | { |
ubhat | 0:42863a11464a | 153 | BuffAddr[i] = j++; |
ubhat | 0:42863a11464a | 154 | } |
ubhat | 0:42863a11464a | 155 | BuffPtr = LORAWAN_APP_DATA_SIZE; |
ubhat | 0:42863a11464a | 156 | break; |
ubhat | 0:42863a11464a | 157 | } |
ubhat | 0:42863a11464a | 158 | |
ubhat | 0:42863a11464a | 159 | // Appends 2 Bytes to TX buffer |
ubhat | 0:42863a11464a | 160 | case AppAccl: |
ubhat | 0:42863a11464a | 161 | { |
ubhat | 2:78df92a365c2 | 162 | #ifdef USE_IKS01A1_SENSOR |
ubhat | 2:78df92a365c2 | 163 | |
ubhat | 2:78df92a365c2 | 164 | accelerometer->Get_X_Axes(Accl_Value); |
ubhat | 2:78df92a365c2 | 165 | |
ubhat | 2:78df92a365c2 | 166 | printf("X/Y/Z = %d/%d/%d\r\n", Accl_Value[0], Accl_Value[1], Accl_Value[2]); |
ubhat | 2:78df92a365c2 | 167 | |
ubhat | 2:78df92a365c2 | 168 | if( ( BuffPtr + 6 ) <= LORAWAN_APP_DATA_SIZE ) |
ubhat | 0:42863a11464a | 169 | { |
ubhat | 2:78df92a365c2 | 170 | BuffAddr[BuffPtr++] = ( (int16_t) Accl_Value[0] >> 8 ) & 0xFF; |
ubhat | 2:78df92a365c2 | 171 | BuffAddr[BuffPtr++] = ( (int16_t) Accl_Value[0] ) & 0xFF; |
ubhat | 2:78df92a365c2 | 172 | BuffAddr[BuffPtr++] = ( (int16_t) Accl_Value[1] >> 8 ) & 0xFF; |
ubhat | 2:78df92a365c2 | 173 | BuffAddr[BuffPtr++] = ( (int16_t) Accl_Value[1] ) & 0xFF; |
ubhat | 2:78df92a365c2 | 174 | BuffAddr[BuffPtr++] = ( (int16_t) Accl_Value[2] >> 8 ) & 0xFF; |
ubhat | 2:78df92a365c2 | 175 | BuffAddr[BuffPtr++] = ( (int16_t) Accl_Value[2] ) & 0xFF; |
ubhat | 2:78df92a365c2 | 176 | } |
ubhat | 2:78df92a365c2 | 177 | #endif |
ubhat | 0:42863a11464a | 178 | break; |
ubhat | 0:42863a11464a | 179 | } |
ubhat | 0:42863a11464a | 180 | |
ubhat | 0:42863a11464a | 181 | case AppPushButton: |
ubhat | 0:42863a11464a | 182 | { |
ubhat | 0:42863a11464a | 183 | uint16_t PushButtonCnt; |
ubhat | 0:42863a11464a | 184 | uint8_t *p = (uint8_t *) &PushButtonCnt; |
ubhat | 0:42863a11464a | 185 | |
ubhat | 0:42863a11464a | 186 | PushButtonCnt = LoRaMacUplinkStatus.UplinkCounter; |
ubhat | 0:42863a11464a | 187 | |
ubhat | 0:42863a11464a | 188 | memcpy( &BuffAddr[BuffPtr], p, sizeof(uint16_t) ); |
ubhat | 0:42863a11464a | 189 | |
ubhat | 0:42863a11464a | 190 | break; |
ubhat | 0:42863a11464a | 191 | } |
terence304 | 4:a8706ec8a6d0 | 192 | |
terence304 | 4:a8706ec8a6d0 | 193 | case AppExtLight: |
terence304 | 4:a8706ec8a6d0 | 194 | { |
terence304 | 4:a8706ec8a6d0 | 195 | uint16_t lux = (uint16_t)(ext_light.read_u16()); |
terence304 | 4:a8706ec8a6d0 | 196 | |
terence304 | 4:a8706ec8a6d0 | 197 | //ext_LED = 1; |
terence304 | 4:a8706ec8a6d0 | 198 | |
terence304 | 4:a8706ec8a6d0 | 199 | printf("light raw data: %d\r\n", lux); |
terence304 | 4:a8706ec8a6d0 | 200 | //printf("button raw data: %d\r\n", ext_button.read_u16()); |
terence304 | 4:a8706ec8a6d0 | 201 | |
terence304 | 4:a8706ec8a6d0 | 202 | BuffAddr[BuffPtr++] = ((lux) >> 8) & 0xff; |
terence304 | 4:a8706ec8a6d0 | 203 | BuffAddr[BuffPtr++] = (lux) & 0xff; |
terence304 | 4:a8706ec8a6d0 | 204 | |
terence304 | 4:a8706ec8a6d0 | 205 | break; |
terence304 | 4:a8706ec8a6d0 | 206 | } |
ubhat | 0:42863a11464a | 207 | |
terence304 | 5:f04a6f68e159 | 208 | case AppExtLED: |
terence304 | 5:f04a6f68e159 | 209 | { |
terence304 | 5:f04a6f68e159 | 210 | //ext_LED = 1; |
terence304 | 5:f04a6f68e159 | 211 | |
terence304 | 5:f04a6f68e159 | 212 | printf("LED status: %d\r\n", ext_LED); |
terence304 | 5:f04a6f68e159 | 213 | //printf("button raw data: %d\r\n", ext_button.read_u16()); |
terence304 | 5:f04a6f68e159 | 214 | |
terence304 | 5:f04a6f68e159 | 215 | BuffAddr[BuffPtr++] = ext_LED; |
terence304 | 5:f04a6f68e159 | 216 | |
terence304 | 5:f04a6f68e159 | 217 | break; |
terence304 | 5:f04a6f68e159 | 218 | } |
terence304 | 5:f04a6f68e159 | 219 | |
ubhat | 0:42863a11464a | 220 | default: |
ubhat | 0:42863a11464a | 221 | { |
ubhat | 0:42863a11464a | 222 | break; |
ubhat | 0:42863a11464a | 223 | } |
ubhat | 0:42863a11464a | 224 | } |
ubhat | 0:42863a11464a | 225 | } |
ubhat | 0:42863a11464a | 226 | |
ubhat | 0:42863a11464a | 227 | /* |
ubhat | 0:42863a11464a | 228 | static void OnRedLedTimerEvent( void ) |
ubhat | 0:42863a11464a | 229 | { |
ubhat | 0:42863a11464a | 230 | TimerStop( &RedLedTimer.LedTimer ); |
ubhat | 0:42863a11464a | 231 | |
ubhat | 0:42863a11464a | 232 | if( RedLed == LED_OFF ) |
ubhat | 0:42863a11464a | 233 | { |
ubhat | 0:42863a11464a | 234 | RedLed = LED_ON; |
ubhat | 0:42863a11464a | 235 | } |
ubhat | 0:42863a11464a | 236 | else |
ubhat | 0:42863a11464a | 237 | { |
ubhat | 0:42863a11464a | 238 | RedLed = LED_OFF; |
ubhat | 0:42863a11464a | 239 | } |
ubhat | 0:42863a11464a | 240 | } |
ubhat | 0:42863a11464a | 241 | |
ubhat | 0:42863a11464a | 242 | static void OnYellowLedTimerEvent( void ) |
ubhat | 0:42863a11464a | 243 | { |
ubhat | 0:42863a11464a | 244 | TimerStop( &YellowLedTimer.LedTimer ); |
ubhat | 0:42863a11464a | 245 | |
ubhat | 0:42863a11464a | 246 | if( YellowLed == LED_OFF ) |
ubhat | 0:42863a11464a | 247 | { |
ubhat | 0:42863a11464a | 248 | YellowLed = LED_ON; |
ubhat | 0:42863a11464a | 249 | } |
ubhat | 0:42863a11464a | 250 | else |
ubhat | 0:42863a11464a | 251 | { |
ubhat | 0:42863a11464a | 252 | YellowLed = LED_OFF; |
ubhat | 0:42863a11464a | 253 | } |
ubhat | 0:42863a11464a | 254 | } |
ubhat | 0:42863a11464a | 255 | |
ubhat | 0:42863a11464a | 256 | static void OnGreenLedTimerEvent( void ) |
ubhat | 0:42863a11464a | 257 | { |
ubhat | 0:42863a11464a | 258 | TimerStop( &GreenLedTimer.LedTimer ); |
ubhat | 0:42863a11464a | 259 | |
ubhat | 0:42863a11464a | 260 | if( GreenLed == LED_OFF ) |
ubhat | 0:42863a11464a | 261 | { |
ubhat | 0:42863a11464a | 262 | GreenLed = LED_ON; |
ubhat | 0:42863a11464a | 263 | } |
ubhat | 0:42863a11464a | 264 | else |
ubhat | 0:42863a11464a | 265 | { |
ubhat | 0:42863a11464a | 266 | GreenLed = LED_OFF; |
ubhat | 0:42863a11464a | 267 | } |
ubhat | 0:42863a11464a | 268 | } |
ubhat | 0:42863a11464a | 269 | |
ubhat | 0:42863a11464a | 270 | TimerLed::TimerLed( eLedType led ) |
ubhat | 0:42863a11464a | 271 | { |
ubhat | 0:42863a11464a | 272 | switch( led ) |
ubhat | 0:42863a11464a | 273 | { |
ubhat | 0:42863a11464a | 274 | case Red: |
ubhat | 0:42863a11464a | 275 | { |
ubhat | 0:42863a11464a | 276 | TimerInit( &LedTimer, OnRedLedTimerEvent ); |
ubhat | 0:42863a11464a | 277 | break; |
ubhat | 0:42863a11464a | 278 | } |
ubhat | 0:42863a11464a | 279 | |
ubhat | 0:42863a11464a | 280 | case Yellow: |
ubhat | 0:42863a11464a | 281 | { |
ubhat | 0:42863a11464a | 282 | TimerInit( &LedTimer, OnYellowLedTimerEvent ); |
ubhat | 0:42863a11464a | 283 | break; |
ubhat | 0:42863a11464a | 284 | } |
ubhat | 0:42863a11464a | 285 | |
ubhat | 0:42863a11464a | 286 | case Green: |
ubhat | 0:42863a11464a | 287 | { |
ubhat | 0:42863a11464a | 288 | TimerInit( &LedTimer, OnGreenLedTimerEvent ); |
ubhat | 0:42863a11464a | 289 | break; |
ubhat | 0:42863a11464a | 290 | } |
ubhat | 0:42863a11464a | 291 | } |
ubhat | 0:42863a11464a | 292 | |
ubhat | 0:42863a11464a | 293 | } |
ubhat | 0:42863a11464a | 294 | |
ubhat | 0:42863a11464a | 295 | TimerLed::~TimerLed( ) |
ubhat | 0:42863a11464a | 296 | { |
ubhat | 0:42863a11464a | 297 | } |
ubhat | 0:42863a11464a | 298 | |
ubhat | 0:42863a11464a | 299 | void BlinkLED( eLedType led, uint32_t time ) |
ubhat | 0:42863a11464a | 300 | { |
ubhat | 0:42863a11464a | 301 | switch( led ) |
ubhat | 0:42863a11464a | 302 | { |
ubhat | 0:42863a11464a | 303 | case Red: |
ubhat | 0:42863a11464a | 304 | { |
ubhat | 0:42863a11464a | 305 | TimerSetValue( &RedLedTimer.LedTimer, time ); |
ubhat | 0:42863a11464a | 306 | TimerStart( &RedLedTimer.LedTimer ); |
ubhat | 0:42863a11464a | 307 | RedLed = LED_ON; |
ubhat | 0:42863a11464a | 308 | break; |
ubhat | 0:42863a11464a | 309 | } |
ubhat | 0:42863a11464a | 310 | |
ubhat | 0:42863a11464a | 311 | case Yellow: |
ubhat | 0:42863a11464a | 312 | { |
ubhat | 0:42863a11464a | 313 | TimerSetValue( &YellowLedTimer.LedTimer, time ); |
ubhat | 0:42863a11464a | 314 | TimerStart( &YellowLedTimer.LedTimer ); |
ubhat | 0:42863a11464a | 315 | YellowLed = LED_ON; |
ubhat | 0:42863a11464a | 316 | break; |
ubhat | 0:42863a11464a | 317 | } |
ubhat | 0:42863a11464a | 318 | |
ubhat | 0:42863a11464a | 319 | case Green: |
ubhat | 0:42863a11464a | 320 | { |
ubhat | 0:42863a11464a | 321 | TimerSetValue( &GreenLedTimer.LedTimer, time ); |
ubhat | 0:42863a11464a | 322 | TimerStart( &GreenLedTimer.LedTimer ); |
ubhat | 0:42863a11464a | 323 | GreenLed = LED_ON; |
ubhat | 0:42863a11464a | 324 | break; |
ubhat | 0:42863a11464a | 325 | } |
ubhat | 0:42863a11464a | 326 | } |
ubhat | 0:42863a11464a | 327 | } |
ubhat | 0:42863a11464a | 328 | |
ubhat | 0:42863a11464a | 329 | void ToggleLED( eLedType led ) |
ubhat | 0:42863a11464a | 330 | { |
ubhat | 0:42863a11464a | 331 | switch( led ) |
ubhat | 0:42863a11464a | 332 | { |
ubhat | 0:42863a11464a | 333 | case Red: |
ubhat | 0:42863a11464a | 334 | { |
ubhat | 0:42863a11464a | 335 | if( RedLed == LED_OFF ) |
ubhat | 0:42863a11464a | 336 | { |
ubhat | 0:42863a11464a | 337 | RedLed = LED_ON; |
ubhat | 0:42863a11464a | 338 | } |
ubhat | 0:42863a11464a | 339 | else |
ubhat | 0:42863a11464a | 340 | { |
ubhat | 0:42863a11464a | 341 | RedLed = LED_OFF; |
ubhat | 0:42863a11464a | 342 | } |
ubhat | 0:42863a11464a | 343 | break; |
ubhat | 0:42863a11464a | 344 | } |
ubhat | 0:42863a11464a | 345 | |
ubhat | 0:42863a11464a | 346 | case Yellow: |
ubhat | 0:42863a11464a | 347 | { |
ubhat | 0:42863a11464a | 348 | if( YellowLed == LED_OFF ) |
ubhat | 0:42863a11464a | 349 | { |
ubhat | 0:42863a11464a | 350 | YellowLed = LED_ON; |
ubhat | 0:42863a11464a | 351 | } |
ubhat | 0:42863a11464a | 352 | else |
ubhat | 0:42863a11464a | 353 | { |
ubhat | 0:42863a11464a | 354 | YellowLed = LED_OFF; |
ubhat | 0:42863a11464a | 355 | } |
ubhat | 0:42863a11464a | 356 | break; |
ubhat | 0:42863a11464a | 357 | } |
ubhat | 0:42863a11464a | 358 | |
ubhat | 0:42863a11464a | 359 | case Green: |
ubhat | 0:42863a11464a | 360 | { |
ubhat | 0:42863a11464a | 361 | if( GreenLed == LED_OFF ) |
ubhat | 0:42863a11464a | 362 | { |
ubhat | 0:42863a11464a | 363 | GreenLed = LED_ON; |
ubhat | 0:42863a11464a | 364 | } |
ubhat | 0:42863a11464a | 365 | else |
ubhat | 0:42863a11464a | 366 | { |
ubhat | 0:42863a11464a | 367 | GreenLed = LED_OFF; |
ubhat | 0:42863a11464a | 368 | } |
ubhat | 0:42863a11464a | 369 | break; |
ubhat | 0:42863a11464a | 370 | } |
ubhat | 0:42863a11464a | 371 | } |
ubhat | 0:42863a11464a | 372 | } |
ubhat | 0:42863a11464a | 373 | |
ubhat | 0:42863a11464a | 374 | void CtrlLED( eLedType led, uint8_t state ) |
ubhat | 0:42863a11464a | 375 | { |
ubhat | 0:42863a11464a | 376 | switch( led ) |
ubhat | 0:42863a11464a | 377 | { |
ubhat | 0:42863a11464a | 378 | case Red: |
ubhat | 0:42863a11464a | 379 | { |
ubhat | 0:42863a11464a | 380 | RedLed = state; |
ubhat | 0:42863a11464a | 381 | break; |
ubhat | 0:42863a11464a | 382 | } |
ubhat | 0:42863a11464a | 383 | |
ubhat | 0:42863a11464a | 384 | case Yellow: |
ubhat | 0:42863a11464a | 385 | { |
ubhat | 0:42863a11464a | 386 | YellowLed = state; |
ubhat | 0:42863a11464a | 387 | break; |
ubhat | 0:42863a11464a | 388 | } |
ubhat | 0:42863a11464a | 389 | |
ubhat | 0:42863a11464a | 390 | case Green: |
ubhat | 0:42863a11464a | 391 | { |
ubhat | 0:42863a11464a | 392 | GreenLed = state; |
ubhat | 0:42863a11464a | 393 | break; |
ubhat | 0:42863a11464a | 394 | } |
ubhat | 0:42863a11464a | 395 | |
ubhat | 0:42863a11464a | 396 | case Usr: |
ubhat | 0:42863a11464a | 397 | { |
ubhat | 0:42863a11464a | 398 | if( state ) |
ubhat | 0:42863a11464a | 399 | { |
ubhat | 0:42863a11464a | 400 | UsrLed = LED_ON; |
ubhat | 0:42863a11464a | 401 | } |
ubhat | 0:42863a11464a | 402 | else |
ubhat | 0:42863a11464a | 403 | { |
ubhat | 0:42863a11464a | 404 | UsrLed = LED_OFF; |
ubhat | 0:42863a11464a | 405 | } |
ubhat | 0:42863a11464a | 406 | break; |
ubhat | 0:42863a11464a | 407 | } |
ubhat | 0:42863a11464a | 408 | } |
ubhat | 0:42863a11464a | 409 | } |
ubhat | 0:42863a11464a | 410 | */ |
ubhat | 0:42863a11464a | 411 | void CheckOrientation( void ) |
ubhat | 0:42863a11464a | 412 | { |
ubhat | 0:42863a11464a | 413 | /* |
ubhat | 0:42863a11464a | 414 | uint8_t statusReg; |
ubhat | 0:42863a11464a | 415 | |
ubhat | 0:42863a11464a | 416 | // Read the PS_STATUS register |
ubhat | 0:42863a11464a | 417 | statusReg = Mma8451q.read_single( MMA8451_PL_STATUS ); |
ubhat | 0:42863a11464a | 418 | |
ubhat | 0:42863a11464a | 419 | // If Orientation of the Mote changed then populate Upper Nibble of 0th Byte of Tx Buffer |
ubhat | 0:42863a11464a | 420 | if( ( statusReg & 0x40 ) != 0 ) |
ubhat | 0:42863a11464a | 421 | { |
ubhat | 0:42863a11464a | 422 | CtrlLED( Green, LED_OFF ); |
ubhat | 0:42863a11464a | 423 | VerticalStatus = false; // horizontal |
ubhat | 0:42863a11464a | 424 | } |
ubhat | 0:42863a11464a | 425 | else |
ubhat | 0:42863a11464a | 426 | { |
ubhat | 0:42863a11464a | 427 | CtrlLED( Green, LED_ON ); |
ubhat | 0:42863a11464a | 428 | VerticalStatus = true; // vertical |
ubhat | 0:42863a11464a | 429 | } |
ubhat | 0:42863a11464a | 430 | */ |
ubhat | 0:42863a11464a | 431 | } |