LR Initial Publish

Dependencies:   X_NUCLEO_IKS01A2 driver_mbed_TH02 mbed LoRaWAN-lib-v1_0_1 SX1272Lib

Fork of Training-Aug2018-SX1272-X-NUCLEO-IKS01A2 by Uttam Bhat

Committer:
bootcamps
Date:
Sat Oct 06 01:43:37 2018 +0000
Revision:
12:5222f008392b
Parent:
10:bba416e2c3e1
Update LR

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 2:19dd7bfcacf7 19 float sensor_data;
ubhat 2:19dd7bfcacf7 20
ubhat 0:6cc76d70e2a1 21 int32_t Accl_Value[3] = {0};
ubhat 10:bba416e2c3e1 22
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 10:bba416e2c3e1 31 uint8_t maxLPPsize[5] = {4, 4, 3, 8, 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 10:bba416e2c3e1 65 {
ubhat 0:6cc76d70e2a1 66
ubhat 10:bba416e2c3e1 67 hum_temp->get_temperature(&sensor_data);
ubhat 10:bba416e2c3e1 68
ubhat 2:19dd7bfcacf7 69 printf("Temp = %f, %d\r\n", sensor_data, (int8_t) sensor_data);
ubhat 0:6cc76d70e2a1 70
ubhat 0:6cc76d70e2a1 71 if( ( BuffPtr + 1 ) <= LORAWAN_APP_DATA_SIZE )
ubhat 0:6cc76d70e2a1 72 {
ubhat 0:6cc76d70e2a1 73 #ifdef USE_CAYENNE_LPP
ubhat 2:19dd7bfcacf7 74 int16_t tmp_data = (int16_t) (sensor_data*10 + 0.5);
ubhat 2:19dd7bfcacf7 75 BuffAddr[BuffPtr++] = (int8_t) ( ( tmp_data >> 8 ) & 0xFF );
ubhat 2:19dd7bfcacf7 76 BuffAddr[BuffPtr++] = (int8_t) tmp_data & 0xFF;
ubhat 0:6cc76d70e2a1 77 #else
ubhat 2:19dd7bfcacf7 78 BuffAddr[BuffPtr++] = (int8_t) sensor_data;
ubhat 0:6cc76d70e2a1 79 #endif
ubhat 0:6cc76d70e2a1 80 }
ubhat 2:19dd7bfcacf7 81
ubhat 0:6cc76d70e2a1 82 break;
ubhat 0:6cc76d70e2a1 83 }
ubhat 0:6cc76d70e2a1 84
ubhat 0:6cc76d70e2a1 85 // Appends 2 Bytes to TX buffer
ubhat 0:6cc76d70e2a1 86 case AppPressr:
ubhat 10:bba416e2c3e1 87 {
ubhat 10:bba416e2c3e1 88 press_temp->get_pressure(&sensor_data);
ubhat 0:6cc76d70e2a1 89
ubhat 2:19dd7bfcacf7 90 printf("Pressure = %f, %d\r\n", sensor_data, (uint16_t) sensor_data);
ubhat 0:6cc76d70e2a1 91
ubhat 0:6cc76d70e2a1 92 if( ( BuffPtr + 2 ) <= LORAWAN_APP_DATA_SIZE )
ubhat 0:6cc76d70e2a1 93 {
ubhat 0:6cc76d70e2a1 94 #ifdef USE_CAYENNE_LPP
ubhat 0:6cc76d70e2a1 95 int16_t tmp;
ubhat 0:6cc76d70e2a1 96
ubhat 2:19dd7bfcacf7 97 tmp = (int16_t) ( sensor_data * 10 );
ubhat 0:6cc76d70e2a1 98 BuffAddr[BuffPtr++] = ( tmp >> 8 ) & 0xFF;
ubhat 0:6cc76d70e2a1 99 BuffAddr[BuffPtr++] = ( tmp ) & 0xFF;
ubhat 0:6cc76d70e2a1 100 #else
ubhat 2:19dd7bfcacf7 101 BuffAddr[BuffPtr++] = ( (int16_t) sensor_data >> 8 ) & 0xFF;
ubhat 2:19dd7bfcacf7 102 BuffAddr[BuffPtr++] = ( (int16_t) sensor_data ) & 0xFF;
ubhat 0:6cc76d70e2a1 103 #endif
ubhat 0:6cc76d70e2a1 104 }
ubhat 10:bba416e2c3e1 105
ubhat 0:6cc76d70e2a1 106 break;
ubhat 0:6cc76d70e2a1 107 }
ubhat 0:6cc76d70e2a1 108
ubhat 0:6cc76d70e2a1 109 // Appends 2 Bytes to TX buffer
ubhat 0:6cc76d70e2a1 110 case AppHumid:
ubhat 10:bba416e2c3e1 111 {
ubhat 10:bba416e2c3e1 112
ubhat 10:bba416e2c3e1 113 hum_temp->get_humidity(&sensor_data);
ubhat 2:19dd7bfcacf7 114
ubhat 2:19dd7bfcacf7 115 printf("Humidity = %f, %d\r\n", sensor_data, (uint8_t) sensor_data);
ubhat 0:6cc76d70e2a1 116
ubhat 0:6cc76d70e2a1 117 if( ( BuffPtr + 1 ) <= LORAWAN_APP_DATA_SIZE )
ubhat 0:6cc76d70e2a1 118 {
ubhat 0:6cc76d70e2a1 119 #ifdef USE_CAYENNE_LPP
ubhat 2:19dd7bfcacf7 120 BuffAddr[BuffPtr++] = (uint8_t) ( sensor_data * 2 );
ubhat 0:6cc76d70e2a1 121 #else
ubhat 2:19dd7bfcacf7 122 BuffAddr[BuffPtr++] = (int8_t) sensor_data;
ubhat 0:6cc76d70e2a1 123 #endif
ubhat 0:6cc76d70e2a1 124 }
ubhat 2:19dd7bfcacf7 125
ubhat 0:6cc76d70e2a1 126 break;
ubhat 0:6cc76d70e2a1 127 }
ubhat 10:bba416e2c3e1 128
ubhat 10:bba416e2c3e1 129 // Appends 2 Bytes to TX buffer
ubhat 10:bba416e2c3e1 130 case AppGyro:
ubhat 10:bba416e2c3e1 131 {
ubhat 10:bba416e2c3e1 132 acc_gyro->get_g_axes(Accl_Value);
ubhat 10:bba416e2c3e1 133
ubhat 10:bba416e2c3e1 134 printf("Gyro X/Y/Z = %d/%d/%d\r\n", Accl_Value[0], Accl_Value[1], Accl_Value[2]);
ubhat 10:bba416e2c3e1 135
ubhat 10:bba416e2c3e1 136 if( ( BuffPtr + 6 ) <= LORAWAN_APP_DATA_SIZE )
ubhat 10:bba416e2c3e1 137 {
ubhat 10:bba416e2c3e1 138 Accl_Value[0] /= 10;
ubhat 10:bba416e2c3e1 139 BuffAddr[BuffPtr++] = ( (int16_t) Accl_Value[0] >> 8 ) & 0xFF;
ubhat 10:bba416e2c3e1 140 BuffAddr[BuffPtr++] = ( (int16_t) Accl_Value[0] ) & 0xFF;
ubhat 10:bba416e2c3e1 141 Accl_Value[1] /= 10;
ubhat 10:bba416e2c3e1 142 BuffAddr[BuffPtr++] = ( (int16_t) Accl_Value[1] >> 8 ) & 0xFF;
ubhat 10:bba416e2c3e1 143 BuffAddr[BuffPtr++] = ( (int16_t) Accl_Value[1] ) & 0xFF;
ubhat 10:bba416e2c3e1 144 Accl_Value[2] /= 10;
ubhat 10:bba416e2c3e1 145 BuffAddr[BuffPtr++] = ( (int16_t) Accl_Value[2] >> 8 ) & 0xFF;
ubhat 10:bba416e2c3e1 146 BuffAddr[BuffPtr++] = ( (int16_t) Accl_Value[2] ) & 0xFF;
ubhat 10:bba416e2c3e1 147 }
ubhat 10:bba416e2c3e1 148
ubhat 10:bba416e2c3e1 149 break;
ubhat 10:bba416e2c3e1 150 }
ubhat 0:6cc76d70e2a1 151
ubhat 0:6cc76d70e2a1 152 // Appends 1 Byte to TX buffer
ubhat 0:6cc76d70e2a1 153 case AppBat:
ubhat 0:6cc76d70e2a1 154 {
ubhat 0:6cc76d70e2a1 155 if( ( BuffPtr + 1 ) <= LORAWAN_APP_DATA_SIZE )
ubhat 0:6cc76d70e2a1 156 {
ubhat 0:6cc76d70e2a1 157 BuffAddr[BuffPtr++] = BoardGetBatteryLevel( ); // Per LoRaWAN spec; 0 = Charging; 1...254 = level, 255 = N/A
ubhat 0:6cc76d70e2a1 158 }
ubhat 0:6cc76d70e2a1 159 break;
ubhat 0:6cc76d70e2a1 160 }
ubhat 0:6cc76d70e2a1 161
ubhat 0:6cc76d70e2a1 162 // Appends incremental values of 1 Byte each to TX buffer until Full
ubhat 0:6cc76d70e2a1 163 case AppRamp:
ubhat 0:6cc76d70e2a1 164 {
ubhat 0:6cc76d70e2a1 165 int32_t i, j;
ubhat 0:6cc76d70e2a1 166
ubhat 0:6cc76d70e2a1 167 // Populate Tx Buffer with increasing byte values starting from 0x00, 0x01, 0x02 ...
ubhat 0:6cc76d70e2a1 168 for( i = BuffPtr, j = 0; i < LORAWAN_APP_DATA_SIZE; i++ )
ubhat 0:6cc76d70e2a1 169 {
ubhat 0:6cc76d70e2a1 170 BuffAddr[i] = j++;
ubhat 0:6cc76d70e2a1 171 }
ubhat 0:6cc76d70e2a1 172 BuffPtr = LORAWAN_APP_DATA_SIZE;
ubhat 0:6cc76d70e2a1 173 break;
ubhat 0:6cc76d70e2a1 174 }
ubhat 0:6cc76d70e2a1 175
ubhat 0:6cc76d70e2a1 176 // Appends 2 Bytes to TX buffer
ubhat 0:6cc76d70e2a1 177 case AppAccl:
ubhat 0:6cc76d70e2a1 178 {
ubhat 0:6cc76d70e2a1 179
ubhat 10:bba416e2c3e1 180 accelerometer->get_x_axes(Accl_Value);
ubhat 0:6cc76d70e2a1 181
ubhat 0:6cc76d70e2a1 182 printf("X/Y/Z = %d/%d/%d\r\n", Accl_Value[0], Accl_Value[1], Accl_Value[2]);
ubhat 0:6cc76d70e2a1 183
ubhat 0:6cc76d70e2a1 184 if( ( BuffPtr + 6 ) <= LORAWAN_APP_DATA_SIZE )
ubhat 0:6cc76d70e2a1 185 {
ubhat 0:6cc76d70e2a1 186 BuffAddr[BuffPtr++] = ( (int16_t) Accl_Value[0] >> 8 ) & 0xFF;
ubhat 0:6cc76d70e2a1 187 BuffAddr[BuffPtr++] = ( (int16_t) Accl_Value[0] ) & 0xFF;
ubhat 0:6cc76d70e2a1 188 BuffAddr[BuffPtr++] = ( (int16_t) Accl_Value[1] >> 8 ) & 0xFF;
ubhat 0:6cc76d70e2a1 189 BuffAddr[BuffPtr++] = ( (int16_t) Accl_Value[1] ) & 0xFF;
ubhat 0:6cc76d70e2a1 190 BuffAddr[BuffPtr++] = ( (int16_t) Accl_Value[2] >> 8 ) & 0xFF;
ubhat 10:bba416e2c3e1 191 BuffAddr[BuffPtr++] = ( (int16_t) Accl_Value[2] ) & 0xFF;
ubhat 10:bba416e2c3e1 192 }
ubhat 10:bba416e2c3e1 193
ubhat 0:6cc76d70e2a1 194 break;
ubhat 0:6cc76d70e2a1 195 }
ubhat 0:6cc76d70e2a1 196
ubhat 0:6cc76d70e2a1 197 case AppPushButton:
ubhat 0:6cc76d70e2a1 198 {
ubhat 9:a47750bce9f8 199 static uint8_t PushButtonCnt = 0;
ubhat 0:6cc76d70e2a1 200
ubhat 0:6cc76d70e2a1 201 PushButtonCnt = LoRaMacUplinkStatus.UplinkCounter;
ubhat 9:a47750bce9f8 202 PushButtonCnt = (PushButtonCnt + 1) & 0xFF;
ubhat 0:6cc76d70e2a1 203
ubhat 9:a47750bce9f8 204 //memcpy( &BuffAddr[BuffPtr], p, sizeof(uint16_t) );
ubhat 9:a47750bce9f8 205 BuffAddr[BuffPtr] = PushButtonCnt;
ubhat 0:6cc76d70e2a1 206
ubhat 0:6cc76d70e2a1 207 break;
ubhat 0:6cc76d70e2a1 208 }
ubhat 0:6cc76d70e2a1 209
ubhat 0:6cc76d70e2a1 210 default:
ubhat 0:6cc76d70e2a1 211 {
ubhat 0:6cc76d70e2a1 212 break;
ubhat 0:6cc76d70e2a1 213 }
ubhat 0:6cc76d70e2a1 214 }
ubhat 0:6cc76d70e2a1 215 }
ubhat 0:6cc76d70e2a1 216
ubhat 0:6cc76d70e2a1 217 /*
ubhat 0:6cc76d70e2a1 218 static void OnRedLedTimerEvent( void )
ubhat 0:6cc76d70e2a1 219 {
ubhat 0:6cc76d70e2a1 220 TimerStop( &RedLedTimer.LedTimer );
ubhat 0:6cc76d70e2a1 221
ubhat 0:6cc76d70e2a1 222 if( RedLed == LED_OFF )
ubhat 0:6cc76d70e2a1 223 {
ubhat 0:6cc76d70e2a1 224 RedLed = LED_ON;
ubhat 0:6cc76d70e2a1 225 }
ubhat 0:6cc76d70e2a1 226 else
ubhat 0:6cc76d70e2a1 227 {
ubhat 0:6cc76d70e2a1 228 RedLed = LED_OFF;
ubhat 0:6cc76d70e2a1 229 }
ubhat 0:6cc76d70e2a1 230 }
ubhat 0:6cc76d70e2a1 231
ubhat 0:6cc76d70e2a1 232 static void OnYellowLedTimerEvent( void )
ubhat 0:6cc76d70e2a1 233 {
ubhat 0:6cc76d70e2a1 234 TimerStop( &YellowLedTimer.LedTimer );
ubhat 0:6cc76d70e2a1 235
ubhat 0:6cc76d70e2a1 236 if( YellowLed == LED_OFF )
ubhat 0:6cc76d70e2a1 237 {
ubhat 0:6cc76d70e2a1 238 YellowLed = LED_ON;
ubhat 0:6cc76d70e2a1 239 }
ubhat 0:6cc76d70e2a1 240 else
ubhat 0:6cc76d70e2a1 241 {
ubhat 0:6cc76d70e2a1 242 YellowLed = LED_OFF;
ubhat 0:6cc76d70e2a1 243 }
ubhat 0:6cc76d70e2a1 244 }
ubhat 0:6cc76d70e2a1 245
ubhat 0:6cc76d70e2a1 246 static void OnGreenLedTimerEvent( void )
ubhat 0:6cc76d70e2a1 247 {
ubhat 0:6cc76d70e2a1 248 TimerStop( &GreenLedTimer.LedTimer );
ubhat 0:6cc76d70e2a1 249
ubhat 0:6cc76d70e2a1 250 if( GreenLed == LED_OFF )
ubhat 0:6cc76d70e2a1 251 {
ubhat 0:6cc76d70e2a1 252 GreenLed = LED_ON;
ubhat 0:6cc76d70e2a1 253 }
ubhat 0:6cc76d70e2a1 254 else
ubhat 0:6cc76d70e2a1 255 {
ubhat 0:6cc76d70e2a1 256 GreenLed = LED_OFF;
ubhat 0:6cc76d70e2a1 257 }
ubhat 0:6cc76d70e2a1 258 }
ubhat 0:6cc76d70e2a1 259
ubhat 0:6cc76d70e2a1 260 TimerLed::TimerLed( eLedType led )
ubhat 0:6cc76d70e2a1 261 {
ubhat 0:6cc76d70e2a1 262 switch( led )
ubhat 0:6cc76d70e2a1 263 {
ubhat 0:6cc76d70e2a1 264 case Red:
ubhat 0:6cc76d70e2a1 265 {
ubhat 0:6cc76d70e2a1 266 TimerInit( &LedTimer, OnRedLedTimerEvent );
ubhat 0:6cc76d70e2a1 267 break;
ubhat 0:6cc76d70e2a1 268 }
ubhat 0:6cc76d70e2a1 269
ubhat 0:6cc76d70e2a1 270 case Yellow:
ubhat 0:6cc76d70e2a1 271 {
ubhat 0:6cc76d70e2a1 272 TimerInit( &LedTimer, OnYellowLedTimerEvent );
ubhat 0:6cc76d70e2a1 273 break;
ubhat 0:6cc76d70e2a1 274 }
ubhat 0:6cc76d70e2a1 275
ubhat 0:6cc76d70e2a1 276 case Green:
ubhat 0:6cc76d70e2a1 277 {
ubhat 0:6cc76d70e2a1 278 TimerInit( &LedTimer, OnGreenLedTimerEvent );
ubhat 0:6cc76d70e2a1 279 break;
ubhat 0:6cc76d70e2a1 280 }
ubhat 0:6cc76d70e2a1 281 }
ubhat 0:6cc76d70e2a1 282
ubhat 0:6cc76d70e2a1 283 }
ubhat 0:6cc76d70e2a1 284
ubhat 0:6cc76d70e2a1 285 TimerLed::~TimerLed( )
ubhat 0:6cc76d70e2a1 286 {
ubhat 0:6cc76d70e2a1 287 }
ubhat 0:6cc76d70e2a1 288
ubhat 0:6cc76d70e2a1 289 void BlinkLED( eLedType led, uint32_t time )
ubhat 0:6cc76d70e2a1 290 {
ubhat 0:6cc76d70e2a1 291 switch( led )
ubhat 0:6cc76d70e2a1 292 {
ubhat 0:6cc76d70e2a1 293 case Red:
ubhat 0:6cc76d70e2a1 294 {
ubhat 0:6cc76d70e2a1 295 TimerSetValue( &RedLedTimer.LedTimer, time );
ubhat 0:6cc76d70e2a1 296 TimerStart( &RedLedTimer.LedTimer );
ubhat 0:6cc76d70e2a1 297 RedLed = LED_ON;
ubhat 0:6cc76d70e2a1 298 break;
ubhat 0:6cc76d70e2a1 299 }
ubhat 0:6cc76d70e2a1 300
ubhat 0:6cc76d70e2a1 301 case Yellow:
ubhat 0:6cc76d70e2a1 302 {
ubhat 0:6cc76d70e2a1 303 TimerSetValue( &YellowLedTimer.LedTimer, time );
ubhat 0:6cc76d70e2a1 304 TimerStart( &YellowLedTimer.LedTimer );
ubhat 0:6cc76d70e2a1 305 YellowLed = LED_ON;
ubhat 0:6cc76d70e2a1 306 break;
ubhat 0:6cc76d70e2a1 307 }
ubhat 0:6cc76d70e2a1 308
ubhat 0:6cc76d70e2a1 309 case Green:
ubhat 0:6cc76d70e2a1 310 {
ubhat 0:6cc76d70e2a1 311 TimerSetValue( &GreenLedTimer.LedTimer, time );
ubhat 0:6cc76d70e2a1 312 TimerStart( &GreenLedTimer.LedTimer );
ubhat 0:6cc76d70e2a1 313 GreenLed = LED_ON;
ubhat 0:6cc76d70e2a1 314 break;
ubhat 0:6cc76d70e2a1 315 }
ubhat 0:6cc76d70e2a1 316 }
ubhat 0:6cc76d70e2a1 317 }
ubhat 0:6cc76d70e2a1 318
ubhat 0:6cc76d70e2a1 319 void ToggleLED( eLedType led )
ubhat 0:6cc76d70e2a1 320 {
ubhat 0:6cc76d70e2a1 321 switch( led )
ubhat 0:6cc76d70e2a1 322 {
ubhat 0:6cc76d70e2a1 323 case Red:
ubhat 0:6cc76d70e2a1 324 {
ubhat 0:6cc76d70e2a1 325 if( RedLed == LED_OFF )
ubhat 0:6cc76d70e2a1 326 {
ubhat 0:6cc76d70e2a1 327 RedLed = LED_ON;
ubhat 0:6cc76d70e2a1 328 }
ubhat 0:6cc76d70e2a1 329 else
ubhat 0:6cc76d70e2a1 330 {
ubhat 0:6cc76d70e2a1 331 RedLed = LED_OFF;
ubhat 0:6cc76d70e2a1 332 }
ubhat 0:6cc76d70e2a1 333 break;
ubhat 0:6cc76d70e2a1 334 }
ubhat 0:6cc76d70e2a1 335
ubhat 0:6cc76d70e2a1 336 case Yellow:
ubhat 0:6cc76d70e2a1 337 {
ubhat 0:6cc76d70e2a1 338 if( YellowLed == LED_OFF )
ubhat 0:6cc76d70e2a1 339 {
ubhat 0:6cc76d70e2a1 340 YellowLed = LED_ON;
ubhat 0:6cc76d70e2a1 341 }
ubhat 0:6cc76d70e2a1 342 else
ubhat 0:6cc76d70e2a1 343 {
ubhat 0:6cc76d70e2a1 344 YellowLed = LED_OFF;
ubhat 0:6cc76d70e2a1 345 }
ubhat 0:6cc76d70e2a1 346 break;
ubhat 0:6cc76d70e2a1 347 }
ubhat 0:6cc76d70e2a1 348
ubhat 0:6cc76d70e2a1 349 case Green:
ubhat 0:6cc76d70e2a1 350 {
ubhat 0:6cc76d70e2a1 351 if( GreenLed == LED_OFF )
ubhat 0:6cc76d70e2a1 352 {
ubhat 0:6cc76d70e2a1 353 GreenLed = LED_ON;
ubhat 0:6cc76d70e2a1 354 }
ubhat 0:6cc76d70e2a1 355 else
ubhat 0:6cc76d70e2a1 356 {
ubhat 0:6cc76d70e2a1 357 GreenLed = LED_OFF;
ubhat 0:6cc76d70e2a1 358 }
ubhat 0:6cc76d70e2a1 359 break;
ubhat 0:6cc76d70e2a1 360 }
ubhat 0:6cc76d70e2a1 361 }
ubhat 0:6cc76d70e2a1 362 }
ubhat 0:6cc76d70e2a1 363
ubhat 0:6cc76d70e2a1 364 void CtrlLED( eLedType led, uint8_t state )
ubhat 0:6cc76d70e2a1 365 {
ubhat 0:6cc76d70e2a1 366 switch( led )
ubhat 0:6cc76d70e2a1 367 {
ubhat 0:6cc76d70e2a1 368 case Red:
ubhat 0:6cc76d70e2a1 369 {
ubhat 0:6cc76d70e2a1 370 RedLed = state;
ubhat 0:6cc76d70e2a1 371 break;
ubhat 0:6cc76d70e2a1 372 }
ubhat 0:6cc76d70e2a1 373
ubhat 0:6cc76d70e2a1 374 case Yellow:
ubhat 0:6cc76d70e2a1 375 {
ubhat 0:6cc76d70e2a1 376 YellowLed = state;
ubhat 0:6cc76d70e2a1 377 break;
ubhat 0:6cc76d70e2a1 378 }
ubhat 0:6cc76d70e2a1 379
ubhat 0:6cc76d70e2a1 380 case Green:
ubhat 0:6cc76d70e2a1 381 {
ubhat 0:6cc76d70e2a1 382 GreenLed = state;
ubhat 0:6cc76d70e2a1 383 break;
ubhat 0:6cc76d70e2a1 384 }
ubhat 0:6cc76d70e2a1 385
ubhat 0:6cc76d70e2a1 386 case Usr:
ubhat 0:6cc76d70e2a1 387 {
ubhat 0:6cc76d70e2a1 388 if( state )
ubhat 0:6cc76d70e2a1 389 {
ubhat 0:6cc76d70e2a1 390 UsrLed = LED_ON;
ubhat 0:6cc76d70e2a1 391 }
ubhat 0:6cc76d70e2a1 392 else
ubhat 0:6cc76d70e2a1 393 {
ubhat 0:6cc76d70e2a1 394 UsrLed = LED_OFF;
ubhat 0:6cc76d70e2a1 395 }
ubhat 0:6cc76d70e2a1 396 break;
ubhat 0:6cc76d70e2a1 397 }
ubhat 0:6cc76d70e2a1 398 }
ubhat 0:6cc76d70e2a1 399 }
ubhat 0:6cc76d70e2a1 400 */
ubhat 0:6cc76d70e2a1 401 void CheckOrientation( void )
ubhat 0:6cc76d70e2a1 402 {
ubhat 0:6cc76d70e2a1 403 /*
ubhat 0:6cc76d70e2a1 404 uint8_t statusReg;
ubhat 0:6cc76d70e2a1 405
ubhat 0:6cc76d70e2a1 406 // Read the PS_STATUS register
ubhat 0:6cc76d70e2a1 407 statusReg = Mma8451q.read_single( MMA8451_PL_STATUS );
ubhat 0:6cc76d70e2a1 408
ubhat 0:6cc76d70e2a1 409 // If Orientation of the Mote changed then populate Upper Nibble of 0th Byte of Tx Buffer
ubhat 0:6cc76d70e2a1 410 if( ( statusReg & 0x40 ) != 0 )
ubhat 0:6cc76d70e2a1 411 {
ubhat 0:6cc76d70e2a1 412 CtrlLED( Green, LED_OFF );
ubhat 0:6cc76d70e2a1 413 VerticalStatus = false; // horizontal
ubhat 0:6cc76d70e2a1 414 }
ubhat 0:6cc76d70e2a1 415 else
ubhat 0:6cc76d70e2a1 416 {
ubhat 0:6cc76d70e2a1 417 CtrlLED( Green, LED_ON );
ubhat 0:6cc76d70e2a1 418 VerticalStatus = true; // vertical
ubhat 0:6cc76d70e2a1 419 }
ubhat 0:6cc76d70e2a1 420 */
ubhat 0:6cc76d70e2a1 421 }