SX1276 Shield based Applications

Dependencies:   X_NUCLEO_IKS01A1 LoRaWAN-lib SX1276Lib mbed

LoRaWAN-SX1276-Application Demo uses SX1276MB1LAS mbed component shield on a nucleo board platform to demonstrate a Class-A LoRaWAN device in the 915MHz ISM band for North American region. It uses the LoRaWAN-lib and SX1276Lib libraries.

Comissioning.h (LoRaWAN Network Configuration)

The end-device can be activated in one of the two ways:

Over the Air (OTA) activation can be enabled as shown in the figure below. /media/uploads/ubhat/ota_enable.png

The end-device must be configured with the following parameters:

  • LORAWAN_DEVICE_EUI (8 Bytes) : Fist 3 Bytes is the Organizationally Unique Identifier (OUI) followed by 5 bytes of unique ID. If not defined by user, then the firmware automatically assigns one to the end-device
  • LORAWAN_APPLICATION_EUI (8 Bytes)
  • LORAWAN_APPLICATION_KEY (or DEVKEY) (16 Bytes)

/media/uploads/ubhat/ota_eui.png

Activation by Personalization (ABP) can be enabled as shown in the figure below. /media/uploads/ubhat/abp_enable.png

The end-device must be configured with the following parameters:

  • LORAWAN_DEVICE_ADDRESS (4 Bytes) : If not defined by user, then the firmware automatically assigns one to the end-device
  • LORAWAN_NWKSKEY (16 Bytes)
  • LORAWAN_APPSKEY (16 Bytes)

/media/uploads/ubhat/abp_key.png

Config.h (LoRaWAN Communication Parameters)

  • Mode of Operation : Hybrid If the end-device needs to be configured to operate over 8-channels, then Hybrid Mode needs to be enabled /media/uploads/ubhat/hybridenable.png
  • Mode of Operation : Frequency Hop If the end-device needs to be configured to operate over 64-channels, then Hybrid Mode needs to be disabled
  • Delay between successive JOIN REQUESTs : The delay between successive Join Requests (until the end-device joins the network) can be configured using the parameter OVER_THE_AIR_ACTIVATION_DUTYCYCLE
  • Inter-Frame Delay : One can change the delay between each frame transmission using APP_TX_DUTYCYCLE It is advisable that APP_TX_DUTYCYCLE is greater than or equal to 3sec.
  • Data Rate : The data rate can be configured as per LoRaWAN specification using the paramter LORAWAN_DEFAULT_DATARATE. The range of values are DR_0, DR_1, DR_2, DR_3 and DR_4
  • Confirmed/Unconfirmed Messages : The uplink message or payload can be chosen to be confirmed or unconfirmed using the parameter LORAWAN_CONFIRMED_MSG_ON. When set to 1, the transmitted messages need to be confirmed with an ACK by the network server in the subsequent RX window. When set to 0, no ACK is requested.
  • ADR ON/OFF : The ADR can be enabled or disabled using the parameter LORAWAN_ADR_ON. When set to 1, ADR is enabled and disabled when set to 0.
  • Application Port : The application port can be set using parameter LORAWAN_APP_PORT. A few examples are associated to specific Application Port, and are defined in Config.h
  • Payload Length : The lenght of the payload (in bytes) to be transmitted can be configured using LORAWAN_APP_DATA_SIZE
  • Transmit Power : The transmit power can be configured using LORAWAN_TX_POWER (LoRaMAC verifies if the set power is compliant with the LoRaWAN spec and FCC guidelines)

/media/uploads/ubhat/loraconfig.png

The baud-rate for serial terminal display is 115200

Committer:
ubhat
Date:
Thu Apr 06 16:35:17 2017 +0000
Revision:
3:4bca7f8f731a
Parent:
2:78df92a365c2
Added Cayenne Payload Format for IKAS Mems (PORT# 9)

Who changed what in which revision?

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