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:
ubhat
Date:
Sun Aug 12 06:09:53 2018 +0000
Revision:
9:a47750bce9f8
Parent:
2:19dd7bfcacf7
Child:
10:bba416e2c3e1
Add Cayenne Application for Push Button

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