EEPROM for SX1272

Dependencies:   X_NUCLEO_IKS01A1 driver_mbed_TH02 LoRaWAN-lib-v1_0_1 SX1272Lib mbed

Fork of Canada-SX1272-LoRaWAN-Bootcamp by Uttam Bhat

Committer:
terence304
Date:
Wed Feb 14 01:16:06 2018 +0000
Revision:
9:4c8f32a4044d
Parent:
2:19dd7bfcacf7
Update to support NUCLEO_L073RZ

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 0:6cc76d70e2a1 196 uint16_t PushButtonCnt;
ubhat 0:6cc76d70e2a1 197 uint8_t *p = (uint8_t *) &PushButtonCnt;
ubhat 0:6cc76d70e2a1 198
ubhat 0:6cc76d70e2a1 199 PushButtonCnt = LoRaMacUplinkStatus.UplinkCounter;
ubhat 0:6cc76d70e2a1 200
ubhat 0:6cc76d70e2a1 201 memcpy( &BuffAddr[BuffPtr], p, sizeof(uint16_t) );
ubhat 0:6cc76d70e2a1 202
ubhat 0:6cc76d70e2a1 203 break;
ubhat 0:6cc76d70e2a1 204 }
ubhat 0:6cc76d70e2a1 205
ubhat 0:6cc76d70e2a1 206 default:
ubhat 0:6cc76d70e2a1 207 {
ubhat 0:6cc76d70e2a1 208 break;
ubhat 0:6cc76d70e2a1 209 }
ubhat 0:6cc76d70e2a1 210 }
ubhat 0:6cc76d70e2a1 211 }
ubhat 0:6cc76d70e2a1 212
ubhat 0:6cc76d70e2a1 213 /*
ubhat 0:6cc76d70e2a1 214 static void OnRedLedTimerEvent( void )
ubhat 0:6cc76d70e2a1 215 {
ubhat 0:6cc76d70e2a1 216 TimerStop( &RedLedTimer.LedTimer );
ubhat 0:6cc76d70e2a1 217
ubhat 0:6cc76d70e2a1 218 if( RedLed == LED_OFF )
ubhat 0:6cc76d70e2a1 219 {
ubhat 0:6cc76d70e2a1 220 RedLed = LED_ON;
ubhat 0:6cc76d70e2a1 221 }
ubhat 0:6cc76d70e2a1 222 else
ubhat 0:6cc76d70e2a1 223 {
ubhat 0:6cc76d70e2a1 224 RedLed = LED_OFF;
ubhat 0:6cc76d70e2a1 225 }
ubhat 0:6cc76d70e2a1 226 }
ubhat 0:6cc76d70e2a1 227
ubhat 0:6cc76d70e2a1 228 static void OnYellowLedTimerEvent( void )
ubhat 0:6cc76d70e2a1 229 {
ubhat 0:6cc76d70e2a1 230 TimerStop( &YellowLedTimer.LedTimer );
ubhat 0:6cc76d70e2a1 231
ubhat 0:6cc76d70e2a1 232 if( YellowLed == LED_OFF )
ubhat 0:6cc76d70e2a1 233 {
ubhat 0:6cc76d70e2a1 234 YellowLed = LED_ON;
ubhat 0:6cc76d70e2a1 235 }
ubhat 0:6cc76d70e2a1 236 else
ubhat 0:6cc76d70e2a1 237 {
ubhat 0:6cc76d70e2a1 238 YellowLed = LED_OFF;
ubhat 0:6cc76d70e2a1 239 }
ubhat 0:6cc76d70e2a1 240 }
ubhat 0:6cc76d70e2a1 241
ubhat 0:6cc76d70e2a1 242 static void OnGreenLedTimerEvent( void )
ubhat 0:6cc76d70e2a1 243 {
ubhat 0:6cc76d70e2a1 244 TimerStop( &GreenLedTimer.LedTimer );
ubhat 0:6cc76d70e2a1 245
ubhat 0:6cc76d70e2a1 246 if( GreenLed == LED_OFF )
ubhat 0:6cc76d70e2a1 247 {
ubhat 0:6cc76d70e2a1 248 GreenLed = LED_ON;
ubhat 0:6cc76d70e2a1 249 }
ubhat 0:6cc76d70e2a1 250 else
ubhat 0:6cc76d70e2a1 251 {
ubhat 0:6cc76d70e2a1 252 GreenLed = LED_OFF;
ubhat 0:6cc76d70e2a1 253 }
ubhat 0:6cc76d70e2a1 254 }
ubhat 0:6cc76d70e2a1 255
ubhat 0:6cc76d70e2a1 256 TimerLed::TimerLed( eLedType led )
ubhat 0:6cc76d70e2a1 257 {
ubhat 0:6cc76d70e2a1 258 switch( led )
ubhat 0:6cc76d70e2a1 259 {
ubhat 0:6cc76d70e2a1 260 case Red:
ubhat 0:6cc76d70e2a1 261 {
ubhat 0:6cc76d70e2a1 262 TimerInit( &LedTimer, OnRedLedTimerEvent );
ubhat 0:6cc76d70e2a1 263 break;
ubhat 0:6cc76d70e2a1 264 }
ubhat 0:6cc76d70e2a1 265
ubhat 0:6cc76d70e2a1 266 case Yellow:
ubhat 0:6cc76d70e2a1 267 {
ubhat 0:6cc76d70e2a1 268 TimerInit( &LedTimer, OnYellowLedTimerEvent );
ubhat 0:6cc76d70e2a1 269 break;
ubhat 0:6cc76d70e2a1 270 }
ubhat 0:6cc76d70e2a1 271
ubhat 0:6cc76d70e2a1 272 case Green:
ubhat 0:6cc76d70e2a1 273 {
ubhat 0:6cc76d70e2a1 274 TimerInit( &LedTimer, OnGreenLedTimerEvent );
ubhat 0:6cc76d70e2a1 275 break;
ubhat 0:6cc76d70e2a1 276 }
ubhat 0:6cc76d70e2a1 277 }
ubhat 0:6cc76d70e2a1 278
ubhat 0:6cc76d70e2a1 279 }
ubhat 0:6cc76d70e2a1 280
ubhat 0:6cc76d70e2a1 281 TimerLed::~TimerLed( )
ubhat 0:6cc76d70e2a1 282 {
ubhat 0:6cc76d70e2a1 283 }
ubhat 0:6cc76d70e2a1 284
ubhat 0:6cc76d70e2a1 285 void BlinkLED( eLedType led, uint32_t time )
ubhat 0:6cc76d70e2a1 286 {
ubhat 0:6cc76d70e2a1 287 switch( led )
ubhat 0:6cc76d70e2a1 288 {
ubhat 0:6cc76d70e2a1 289 case Red:
ubhat 0:6cc76d70e2a1 290 {
ubhat 0:6cc76d70e2a1 291 TimerSetValue( &RedLedTimer.LedTimer, time );
ubhat 0:6cc76d70e2a1 292 TimerStart( &RedLedTimer.LedTimer );
ubhat 0:6cc76d70e2a1 293 RedLed = LED_ON;
ubhat 0:6cc76d70e2a1 294 break;
ubhat 0:6cc76d70e2a1 295 }
ubhat 0:6cc76d70e2a1 296
ubhat 0:6cc76d70e2a1 297 case Yellow:
ubhat 0:6cc76d70e2a1 298 {
ubhat 0:6cc76d70e2a1 299 TimerSetValue( &YellowLedTimer.LedTimer, time );
ubhat 0:6cc76d70e2a1 300 TimerStart( &YellowLedTimer.LedTimer );
ubhat 0:6cc76d70e2a1 301 YellowLed = LED_ON;
ubhat 0:6cc76d70e2a1 302 break;
ubhat 0:6cc76d70e2a1 303 }
ubhat 0:6cc76d70e2a1 304
ubhat 0:6cc76d70e2a1 305 case Green:
ubhat 0:6cc76d70e2a1 306 {
ubhat 0:6cc76d70e2a1 307 TimerSetValue( &GreenLedTimer.LedTimer, time );
ubhat 0:6cc76d70e2a1 308 TimerStart( &GreenLedTimer.LedTimer );
ubhat 0:6cc76d70e2a1 309 GreenLed = LED_ON;
ubhat 0:6cc76d70e2a1 310 break;
ubhat 0:6cc76d70e2a1 311 }
ubhat 0:6cc76d70e2a1 312 }
ubhat 0:6cc76d70e2a1 313 }
ubhat 0:6cc76d70e2a1 314
ubhat 0:6cc76d70e2a1 315 void ToggleLED( eLedType led )
ubhat 0:6cc76d70e2a1 316 {
ubhat 0:6cc76d70e2a1 317 switch( led )
ubhat 0:6cc76d70e2a1 318 {
ubhat 0:6cc76d70e2a1 319 case Red:
ubhat 0:6cc76d70e2a1 320 {
ubhat 0:6cc76d70e2a1 321 if( RedLed == LED_OFF )
ubhat 0:6cc76d70e2a1 322 {
ubhat 0:6cc76d70e2a1 323 RedLed = LED_ON;
ubhat 0:6cc76d70e2a1 324 }
ubhat 0:6cc76d70e2a1 325 else
ubhat 0:6cc76d70e2a1 326 {
ubhat 0:6cc76d70e2a1 327 RedLed = LED_OFF;
ubhat 0:6cc76d70e2a1 328 }
ubhat 0:6cc76d70e2a1 329 break;
ubhat 0:6cc76d70e2a1 330 }
ubhat 0:6cc76d70e2a1 331
ubhat 0:6cc76d70e2a1 332 case Yellow:
ubhat 0:6cc76d70e2a1 333 {
ubhat 0:6cc76d70e2a1 334 if( YellowLed == LED_OFF )
ubhat 0:6cc76d70e2a1 335 {
ubhat 0:6cc76d70e2a1 336 YellowLed = LED_ON;
ubhat 0:6cc76d70e2a1 337 }
ubhat 0:6cc76d70e2a1 338 else
ubhat 0:6cc76d70e2a1 339 {
ubhat 0:6cc76d70e2a1 340 YellowLed = LED_OFF;
ubhat 0:6cc76d70e2a1 341 }
ubhat 0:6cc76d70e2a1 342 break;
ubhat 0:6cc76d70e2a1 343 }
ubhat 0:6cc76d70e2a1 344
ubhat 0:6cc76d70e2a1 345 case Green:
ubhat 0:6cc76d70e2a1 346 {
ubhat 0:6cc76d70e2a1 347 if( GreenLed == LED_OFF )
ubhat 0:6cc76d70e2a1 348 {
ubhat 0:6cc76d70e2a1 349 GreenLed = LED_ON;
ubhat 0:6cc76d70e2a1 350 }
ubhat 0:6cc76d70e2a1 351 else
ubhat 0:6cc76d70e2a1 352 {
ubhat 0:6cc76d70e2a1 353 GreenLed = LED_OFF;
ubhat 0:6cc76d70e2a1 354 }
ubhat 0:6cc76d70e2a1 355 break;
ubhat 0:6cc76d70e2a1 356 }
ubhat 0:6cc76d70e2a1 357 }
ubhat 0:6cc76d70e2a1 358 }
ubhat 0:6cc76d70e2a1 359
ubhat 0:6cc76d70e2a1 360 void CtrlLED( eLedType led, uint8_t state )
ubhat 0:6cc76d70e2a1 361 {
ubhat 0:6cc76d70e2a1 362 switch( led )
ubhat 0:6cc76d70e2a1 363 {
ubhat 0:6cc76d70e2a1 364 case Red:
ubhat 0:6cc76d70e2a1 365 {
ubhat 0:6cc76d70e2a1 366 RedLed = state;
ubhat 0:6cc76d70e2a1 367 break;
ubhat 0:6cc76d70e2a1 368 }
ubhat 0:6cc76d70e2a1 369
ubhat 0:6cc76d70e2a1 370 case Yellow:
ubhat 0:6cc76d70e2a1 371 {
ubhat 0:6cc76d70e2a1 372 YellowLed = state;
ubhat 0:6cc76d70e2a1 373 break;
ubhat 0:6cc76d70e2a1 374 }
ubhat 0:6cc76d70e2a1 375
ubhat 0:6cc76d70e2a1 376 case Green:
ubhat 0:6cc76d70e2a1 377 {
ubhat 0:6cc76d70e2a1 378 GreenLed = state;
ubhat 0:6cc76d70e2a1 379 break;
ubhat 0:6cc76d70e2a1 380 }
ubhat 0:6cc76d70e2a1 381
ubhat 0:6cc76d70e2a1 382 case Usr:
ubhat 0:6cc76d70e2a1 383 {
ubhat 0:6cc76d70e2a1 384 if( state )
ubhat 0:6cc76d70e2a1 385 {
ubhat 0:6cc76d70e2a1 386 UsrLed = LED_ON;
ubhat 0:6cc76d70e2a1 387 }
ubhat 0:6cc76d70e2a1 388 else
ubhat 0:6cc76d70e2a1 389 {
ubhat 0:6cc76d70e2a1 390 UsrLed = LED_OFF;
ubhat 0:6cc76d70e2a1 391 }
ubhat 0:6cc76d70e2a1 392 break;
ubhat 0:6cc76d70e2a1 393 }
ubhat 0:6cc76d70e2a1 394 }
ubhat 0:6cc76d70e2a1 395 }
ubhat 0:6cc76d70e2a1 396 */
ubhat 0:6cc76d70e2a1 397 void CheckOrientation( void )
ubhat 0:6cc76d70e2a1 398 {
ubhat 0:6cc76d70e2a1 399 /*
ubhat 0:6cc76d70e2a1 400 uint8_t statusReg;
ubhat 0:6cc76d70e2a1 401
ubhat 0:6cc76d70e2a1 402 // Read the PS_STATUS register
ubhat 0:6cc76d70e2a1 403 statusReg = Mma8451q.read_single( MMA8451_PL_STATUS );
ubhat 0:6cc76d70e2a1 404
ubhat 0:6cc76d70e2a1 405 // If Orientation of the Mote changed then populate Upper Nibble of 0th Byte of Tx Buffer
ubhat 0:6cc76d70e2a1 406 if( ( statusReg & 0x40 ) != 0 )
ubhat 0:6cc76d70e2a1 407 {
ubhat 0:6cc76d70e2a1 408 CtrlLED( Green, LED_OFF );
ubhat 0:6cc76d70e2a1 409 VerticalStatus = false; // horizontal
ubhat 0:6cc76d70e2a1 410 }
ubhat 0:6cc76d70e2a1 411 else
ubhat 0:6cc76d70e2a1 412 {
ubhat 0:6cc76d70e2a1 413 CtrlLED( Green, LED_ON );
ubhat 0:6cc76d70e2a1 414 VerticalStatus = true; // vertical
ubhat 0:6cc76d70e2a1 415 }
ubhat 0:6cc76d70e2a1 416 */
ubhat 0:6cc76d70e2a1 417 }