code crashes accessing randomization code

Dependencies:   LoRaWAN-SX1272-Application-24-31-9sec X_NUCLEO_IKS01A1 driver_mbed_TH02 LoRaWAN-lib-v1_0_1 SX1272Lib mbed

Fork of LoRaWAN-SX1272-Application-24-31-9sec by Oleh Zvonarov

Committer:
ubhat
Date:
Thu Apr 06 21:59:50 2017 +0000
Revision:
0:6cc76d70e2a1
Child:
2:19dd7bfcacf7
LoRaWAN SX1272 Application

Who changed what in which revision?

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