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.
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-deviceLORAWAN_APPLICATION_EUI
(8 Bytes)LORAWAN_APPLICATION_KEY
(or DEVKEY) (16 Bytes)
Activation by Personalization (ABP) can be enabled as shown in the figure below.
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-deviceLORAWAN_NWKSKEY
(16 Bytes)LORAWAN_APPSKEY
(16 Bytes)
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
- 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 thatAPP_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 anACK
by the network server in the subsequent RX window. When set to 0, noACK
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)
The baud-rate for serial terminal display is 115200
app/LoRaApp.cpp@2:78df92a365c2, 2016-08-27 (annotated)
- Committer:
- ubhat
- Date:
- Sat Aug 27 04:03:02 2016 +0000
- Revision:
- 2:78df92a365c2
- Parent:
- 0:42863a11464a
- Child:
- 3:4bca7f8f731a
X_Nucleo_IKS01A1 Sensor application (Port 8)
Who changed what in which revision?
User | Revision | Line number | New 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 | 0:42863a11464a | 24 | bool VerticalStatus = false; |
ubhat | 0:42863a11464a | 25 | |
ubhat | 0:42863a11464a | 26 | |
ubhat | 0:42863a11464a | 27 | Application::Application( uint8_t * memptr ) |
ubhat | 0:42863a11464a | 28 | { |
ubhat | 0:42863a11464a | 29 | BuffAddr = memptr; |
ubhat | 0:42863a11464a | 30 | memset( BuffAddr, 0, LORAWAN_APP_DATA_MAX_SIZE ); |
ubhat | 0:42863a11464a | 31 | BuffPtr = 0; |
ubhat | 0:42863a11464a | 32 | } |
ubhat | 0:42863a11464a | 33 | |
ubhat | 0:42863a11464a | 34 | Application::~Application( ) |
ubhat | 0:42863a11464a | 35 | { |
ubhat | 0:42863a11464a | 36 | } |
ubhat | 0:42863a11464a | 37 | |
ubhat | 0:42863a11464a | 38 | void Application::ApplicationAppendData( uint8_t *pData, uint8_t len ) |
ubhat | 0:42863a11464a | 39 | { |
ubhat | 0:42863a11464a | 40 | memcpy( BuffAddr + BuffPtr, pData, len ); |
ubhat | 0:42863a11464a | 41 | BuffPtr += len; |
ubhat | 0:42863a11464a | 42 | } |
ubhat | 0:42863a11464a | 43 | |
ubhat | 0:42863a11464a | 44 | void Application::ApplicationPtrPos( uint8_t ptrPos ) |
ubhat | 0:42863a11464a | 45 | { |
ubhat | 0:42863a11464a | 46 | BuffPtr = ptrPos; |
ubhat | 0:42863a11464a | 47 | } |
ubhat | 0:42863a11464a | 48 | |
ubhat | 0:42863a11464a | 49 | void Application::ApplicationCall( eAppType App ) |
ubhat | 0:42863a11464a | 50 | { |
ubhat | 0:42863a11464a | 51 | switch( App ) |
ubhat | 2:78df92a365c2 | 52 | { |
ubhat | 0:42863a11464a | 53 | // Appends 1 Byte to TX buffer |
ubhat | 0:42863a11464a | 54 | case AppTemp: |
ubhat | 0:42863a11464a | 55 | { |
ubhat | 2:78df92a365c2 | 56 | #ifdef USE_IKS01A1_SENSOR |
ubhat | 2:78df92a365c2 | 57 | |
ubhat | 2:78df92a365c2 | 58 | temp_sensor1->GetTemperature(&iks01a1_data); |
ubhat | 2:78df92a365c2 | 59 | |
ubhat | 2:78df92a365c2 | 60 | printf("Temp = %f, %d\r\n", iks01a1_data, (int8_t) iks01a1_data); |
ubhat | 2:78df92a365c2 | 61 | |
ubhat | 0:42863a11464a | 62 | if( ( BuffPtr + 1 ) <= LORAWAN_APP_DATA_SIZE ) |
ubhat | 0:42863a11464a | 63 | { |
ubhat | 2:78df92a365c2 | 64 | BuffAddr[BuffPtr++] = (int8_t) iks01a1_data; |
ubhat | 2:78df92a365c2 | 65 | } |
ubhat | 2:78df92a365c2 | 66 | |
ubhat | 2:78df92a365c2 | 67 | #endif |
ubhat | 2:78df92a365c2 | 68 | break; |
ubhat | 2:78df92a365c2 | 69 | } |
ubhat | 2:78df92a365c2 | 70 | |
ubhat | 2:78df92a365c2 | 71 | // Appends 2 Bytes to TX buffer |
ubhat | 2:78df92a365c2 | 72 | case AppPressr: |
ubhat | 2:78df92a365c2 | 73 | { |
ubhat | 2:78df92a365c2 | 74 | #ifdef USE_IKS01A1_SENSOR |
ubhat | 2:78df92a365c2 | 75 | |
ubhat | 2:78df92a365c2 | 76 | pressure_sensor->GetPressure(&iks01a1_data); |
ubhat | 2:78df92a365c2 | 77 | |
ubhat | 2:78df92a365c2 | 78 | printf("Pressure = %f, %d\r\n", iks01a1_data, (uint16_t) iks01a1_data); |
ubhat | 2:78df92a365c2 | 79 | |
ubhat | 2:78df92a365c2 | 80 | if( ( BuffPtr + 2 ) <= LORAWAN_APP_DATA_SIZE ) |
ubhat | 2:78df92a365c2 | 81 | { |
ubhat | 2:78df92a365c2 | 82 | BuffAddr[BuffPtr++] = ( (int16_t) iks01a1_data >> 8 ) & 0xFF; |
ubhat | 2:78df92a365c2 | 83 | BuffAddr[BuffPtr++] = ( (int16_t) iks01a1_data ) & 0xFF; |
ubhat | 0:42863a11464a | 84 | } |
ubhat | 2:78df92a365c2 | 85 | |
ubhat | 2:78df92a365c2 | 86 | #endif |
ubhat | 2:78df92a365c2 | 87 | break; |
ubhat | 2:78df92a365c2 | 88 | } |
ubhat | 2:78df92a365c2 | 89 | |
ubhat | 2:78df92a365c2 | 90 | // Appends 2 Bytes to TX buffer |
ubhat | 2:78df92a365c2 | 91 | case AppHumid: |
ubhat | 2:78df92a365c2 | 92 | { |
ubhat | 2:78df92a365c2 | 93 | #ifdef USE_IKS01A1_SENSOR |
ubhat | 2:78df92a365c2 | 94 | |
ubhat | 2:78df92a365c2 | 95 | humidity_sensor->GetHumidity(&iks01a1_data); |
ubhat | 2:78df92a365c2 | 96 | |
ubhat | 2:78df92a365c2 | 97 | printf("Humidity = %f, %d\r\n", iks01a1_data, (uint8_t) iks01a1_data); |
ubhat | 2:78df92a365c2 | 98 | |
ubhat | 2:78df92a365c2 | 99 | if( ( BuffPtr + 1 ) <= LORAWAN_APP_DATA_SIZE ) |
ubhat | 2:78df92a365c2 | 100 | { |
ubhat | 2:78df92a365c2 | 101 | BuffAddr[BuffPtr++] = (int8_t) iks01a1_data; |
ubhat | 2:78df92a365c2 | 102 | } |
ubhat | 2:78df92a365c2 | 103 | |
ubhat | 2:78df92a365c2 | 104 | #endif |
ubhat | 0:42863a11464a | 105 | break; |
ubhat | 0:42863a11464a | 106 | } |
ubhat | 0:42863a11464a | 107 | |
ubhat | 0:42863a11464a | 108 | // Appends 1 Byte to TX buffer |
ubhat | 0:42863a11464a | 109 | case AppBat: |
ubhat | 0:42863a11464a | 110 | { |
ubhat | 0:42863a11464a | 111 | if( ( BuffPtr + 1 ) <= LORAWAN_APP_DATA_SIZE ) |
ubhat | 0:42863a11464a | 112 | { |
ubhat | 0:42863a11464a | 113 | BuffAddr[BuffPtr++] = BoardGetBatteryLevel( ); // Per LoRaWAN spec; 0 = Charging; 1...254 = level, 255 = N/A |
ubhat | 0:42863a11464a | 114 | } |
ubhat | 0:42863a11464a | 115 | break; |
ubhat | 0:42863a11464a | 116 | } |
ubhat | 0:42863a11464a | 117 | |
ubhat | 0:42863a11464a | 118 | // Appends incremental values of 1 Byte each to TX buffer until Full |
ubhat | 0:42863a11464a | 119 | case AppRamp: |
ubhat | 0:42863a11464a | 120 | { |
ubhat | 0:42863a11464a | 121 | int32_t i, j; |
ubhat | 0:42863a11464a | 122 | |
ubhat | 0:42863a11464a | 123 | // Populate Tx Buffer with increasing byte values starting from 0x00, 0x01, 0x02 ... |
ubhat | 0:42863a11464a | 124 | for( i = BuffPtr, j = 0; i < LORAWAN_APP_DATA_SIZE; i++ ) |
ubhat | 0:42863a11464a | 125 | { |
ubhat | 0:42863a11464a | 126 | BuffAddr[i] = j++; |
ubhat | 0:42863a11464a | 127 | } |
ubhat | 0:42863a11464a | 128 | BuffPtr = LORAWAN_APP_DATA_SIZE; |
ubhat | 0:42863a11464a | 129 | break; |
ubhat | 0:42863a11464a | 130 | } |
ubhat | 0:42863a11464a | 131 | |
ubhat | 0:42863a11464a | 132 | // Appends 2 Bytes to TX buffer |
ubhat | 0:42863a11464a | 133 | case AppAccl: |
ubhat | 0:42863a11464a | 134 | { |
ubhat | 2:78df92a365c2 | 135 | #ifdef USE_IKS01A1_SENSOR |
ubhat | 2:78df92a365c2 | 136 | |
ubhat | 2:78df92a365c2 | 137 | accelerometer->Get_X_Axes(Accl_Value); |
ubhat | 2:78df92a365c2 | 138 | |
ubhat | 2:78df92a365c2 | 139 | printf("X/Y/Z = %d/%d/%d\r\n", Accl_Value[0], Accl_Value[1], Accl_Value[2]); |
ubhat | 2:78df92a365c2 | 140 | |
ubhat | 2:78df92a365c2 | 141 | if( ( BuffPtr + 6 ) <= LORAWAN_APP_DATA_SIZE ) |
ubhat | 0:42863a11464a | 142 | { |
ubhat | 2:78df92a365c2 | 143 | BuffAddr[BuffPtr++] = ( (int16_t) Accl_Value[0] >> 8 ) & 0xFF; |
ubhat | 2:78df92a365c2 | 144 | BuffAddr[BuffPtr++] = ( (int16_t) Accl_Value[0] ) & 0xFF; |
ubhat | 2:78df92a365c2 | 145 | BuffAddr[BuffPtr++] = ( (int16_t) Accl_Value[1] >> 8 ) & 0xFF; |
ubhat | 2:78df92a365c2 | 146 | BuffAddr[BuffPtr++] = ( (int16_t) Accl_Value[1] ) & 0xFF; |
ubhat | 2:78df92a365c2 | 147 | BuffAddr[BuffPtr++] = ( (int16_t) Accl_Value[2] >> 8 ) & 0xFF; |
ubhat | 2:78df92a365c2 | 148 | BuffAddr[BuffPtr++] = ( (int16_t) Accl_Value[2] ) & 0xFF; |
ubhat | 2:78df92a365c2 | 149 | } |
ubhat | 2:78df92a365c2 | 150 | #endif |
ubhat | 0:42863a11464a | 151 | break; |
ubhat | 0:42863a11464a | 152 | } |
ubhat | 0:42863a11464a | 153 | |
ubhat | 0:42863a11464a | 154 | case AppPushButton: |
ubhat | 0:42863a11464a | 155 | { |
ubhat | 0:42863a11464a | 156 | uint16_t PushButtonCnt; |
ubhat | 0:42863a11464a | 157 | uint8_t *p = (uint8_t *) &PushButtonCnt; |
ubhat | 0:42863a11464a | 158 | |
ubhat | 0:42863a11464a | 159 | PushButtonCnt = LoRaMacUplinkStatus.UplinkCounter; |
ubhat | 0:42863a11464a | 160 | |
ubhat | 0:42863a11464a | 161 | memcpy( &BuffAddr[BuffPtr], p, sizeof(uint16_t) ); |
ubhat | 0:42863a11464a | 162 | |
ubhat | 0:42863a11464a | 163 | break; |
ubhat | 0:42863a11464a | 164 | } |
ubhat | 0:42863a11464a | 165 | |
ubhat | 0:42863a11464a | 166 | default: |
ubhat | 0:42863a11464a | 167 | { |
ubhat | 0:42863a11464a | 168 | break; |
ubhat | 0:42863a11464a | 169 | } |
ubhat | 0:42863a11464a | 170 | } |
ubhat | 0:42863a11464a | 171 | } |
ubhat | 0:42863a11464a | 172 | |
ubhat | 0:42863a11464a | 173 | /* |
ubhat | 0:42863a11464a | 174 | static void OnRedLedTimerEvent( void ) |
ubhat | 0:42863a11464a | 175 | { |
ubhat | 0:42863a11464a | 176 | TimerStop( &RedLedTimer.LedTimer ); |
ubhat | 0:42863a11464a | 177 | |
ubhat | 0:42863a11464a | 178 | if( RedLed == LED_OFF ) |
ubhat | 0:42863a11464a | 179 | { |
ubhat | 0:42863a11464a | 180 | RedLed = LED_ON; |
ubhat | 0:42863a11464a | 181 | } |
ubhat | 0:42863a11464a | 182 | else |
ubhat | 0:42863a11464a | 183 | { |
ubhat | 0:42863a11464a | 184 | RedLed = LED_OFF; |
ubhat | 0:42863a11464a | 185 | } |
ubhat | 0:42863a11464a | 186 | } |
ubhat | 0:42863a11464a | 187 | |
ubhat | 0:42863a11464a | 188 | static void OnYellowLedTimerEvent( void ) |
ubhat | 0:42863a11464a | 189 | { |
ubhat | 0:42863a11464a | 190 | TimerStop( &YellowLedTimer.LedTimer ); |
ubhat | 0:42863a11464a | 191 | |
ubhat | 0:42863a11464a | 192 | if( YellowLed == LED_OFF ) |
ubhat | 0:42863a11464a | 193 | { |
ubhat | 0:42863a11464a | 194 | YellowLed = LED_ON; |
ubhat | 0:42863a11464a | 195 | } |
ubhat | 0:42863a11464a | 196 | else |
ubhat | 0:42863a11464a | 197 | { |
ubhat | 0:42863a11464a | 198 | YellowLed = LED_OFF; |
ubhat | 0:42863a11464a | 199 | } |
ubhat | 0:42863a11464a | 200 | } |
ubhat | 0:42863a11464a | 201 | |
ubhat | 0:42863a11464a | 202 | static void OnGreenLedTimerEvent( void ) |
ubhat | 0:42863a11464a | 203 | { |
ubhat | 0:42863a11464a | 204 | TimerStop( &GreenLedTimer.LedTimer ); |
ubhat | 0:42863a11464a | 205 | |
ubhat | 0:42863a11464a | 206 | if( GreenLed == LED_OFF ) |
ubhat | 0:42863a11464a | 207 | { |
ubhat | 0:42863a11464a | 208 | GreenLed = LED_ON; |
ubhat | 0:42863a11464a | 209 | } |
ubhat | 0:42863a11464a | 210 | else |
ubhat | 0:42863a11464a | 211 | { |
ubhat | 0:42863a11464a | 212 | GreenLed = LED_OFF; |
ubhat | 0:42863a11464a | 213 | } |
ubhat | 0:42863a11464a | 214 | } |
ubhat | 0:42863a11464a | 215 | |
ubhat | 0:42863a11464a | 216 | TimerLed::TimerLed( eLedType led ) |
ubhat | 0:42863a11464a | 217 | { |
ubhat | 0:42863a11464a | 218 | switch( led ) |
ubhat | 0:42863a11464a | 219 | { |
ubhat | 0:42863a11464a | 220 | case Red: |
ubhat | 0:42863a11464a | 221 | { |
ubhat | 0:42863a11464a | 222 | TimerInit( &LedTimer, OnRedLedTimerEvent ); |
ubhat | 0:42863a11464a | 223 | break; |
ubhat | 0:42863a11464a | 224 | } |
ubhat | 0:42863a11464a | 225 | |
ubhat | 0:42863a11464a | 226 | case Yellow: |
ubhat | 0:42863a11464a | 227 | { |
ubhat | 0:42863a11464a | 228 | TimerInit( &LedTimer, OnYellowLedTimerEvent ); |
ubhat | 0:42863a11464a | 229 | break; |
ubhat | 0:42863a11464a | 230 | } |
ubhat | 0:42863a11464a | 231 | |
ubhat | 0:42863a11464a | 232 | case Green: |
ubhat | 0:42863a11464a | 233 | { |
ubhat | 0:42863a11464a | 234 | TimerInit( &LedTimer, OnGreenLedTimerEvent ); |
ubhat | 0:42863a11464a | 235 | break; |
ubhat | 0:42863a11464a | 236 | } |
ubhat | 0:42863a11464a | 237 | } |
ubhat | 0:42863a11464a | 238 | |
ubhat | 0:42863a11464a | 239 | } |
ubhat | 0:42863a11464a | 240 | |
ubhat | 0:42863a11464a | 241 | TimerLed::~TimerLed( ) |
ubhat | 0:42863a11464a | 242 | { |
ubhat | 0:42863a11464a | 243 | } |
ubhat | 0:42863a11464a | 244 | |
ubhat | 0:42863a11464a | 245 | void BlinkLED( eLedType led, uint32_t time ) |
ubhat | 0:42863a11464a | 246 | { |
ubhat | 0:42863a11464a | 247 | switch( led ) |
ubhat | 0:42863a11464a | 248 | { |
ubhat | 0:42863a11464a | 249 | case Red: |
ubhat | 0:42863a11464a | 250 | { |
ubhat | 0:42863a11464a | 251 | TimerSetValue( &RedLedTimer.LedTimer, time ); |
ubhat | 0:42863a11464a | 252 | TimerStart( &RedLedTimer.LedTimer ); |
ubhat | 0:42863a11464a | 253 | RedLed = LED_ON; |
ubhat | 0:42863a11464a | 254 | break; |
ubhat | 0:42863a11464a | 255 | } |
ubhat | 0:42863a11464a | 256 | |
ubhat | 0:42863a11464a | 257 | case Yellow: |
ubhat | 0:42863a11464a | 258 | { |
ubhat | 0:42863a11464a | 259 | TimerSetValue( &YellowLedTimer.LedTimer, time ); |
ubhat | 0:42863a11464a | 260 | TimerStart( &YellowLedTimer.LedTimer ); |
ubhat | 0:42863a11464a | 261 | YellowLed = LED_ON; |
ubhat | 0:42863a11464a | 262 | break; |
ubhat | 0:42863a11464a | 263 | } |
ubhat | 0:42863a11464a | 264 | |
ubhat | 0:42863a11464a | 265 | case Green: |
ubhat | 0:42863a11464a | 266 | { |
ubhat | 0:42863a11464a | 267 | TimerSetValue( &GreenLedTimer.LedTimer, time ); |
ubhat | 0:42863a11464a | 268 | TimerStart( &GreenLedTimer.LedTimer ); |
ubhat | 0:42863a11464a | 269 | GreenLed = LED_ON; |
ubhat | 0:42863a11464a | 270 | break; |
ubhat | 0:42863a11464a | 271 | } |
ubhat | 0:42863a11464a | 272 | } |
ubhat | 0:42863a11464a | 273 | } |
ubhat | 0:42863a11464a | 274 | |
ubhat | 0:42863a11464a | 275 | void ToggleLED( eLedType led ) |
ubhat | 0:42863a11464a | 276 | { |
ubhat | 0:42863a11464a | 277 | switch( led ) |
ubhat | 0:42863a11464a | 278 | { |
ubhat | 0:42863a11464a | 279 | case Red: |
ubhat | 0:42863a11464a | 280 | { |
ubhat | 0:42863a11464a | 281 | if( RedLed == LED_OFF ) |
ubhat | 0:42863a11464a | 282 | { |
ubhat | 0:42863a11464a | 283 | RedLed = LED_ON; |
ubhat | 0:42863a11464a | 284 | } |
ubhat | 0:42863a11464a | 285 | else |
ubhat | 0:42863a11464a | 286 | { |
ubhat | 0:42863a11464a | 287 | RedLed = LED_OFF; |
ubhat | 0:42863a11464a | 288 | } |
ubhat | 0:42863a11464a | 289 | break; |
ubhat | 0:42863a11464a | 290 | } |
ubhat | 0:42863a11464a | 291 | |
ubhat | 0:42863a11464a | 292 | case Yellow: |
ubhat | 0:42863a11464a | 293 | { |
ubhat | 0:42863a11464a | 294 | if( YellowLed == LED_OFF ) |
ubhat | 0:42863a11464a | 295 | { |
ubhat | 0:42863a11464a | 296 | YellowLed = LED_ON; |
ubhat | 0:42863a11464a | 297 | } |
ubhat | 0:42863a11464a | 298 | else |
ubhat | 0:42863a11464a | 299 | { |
ubhat | 0:42863a11464a | 300 | YellowLed = LED_OFF; |
ubhat | 0:42863a11464a | 301 | } |
ubhat | 0:42863a11464a | 302 | break; |
ubhat | 0:42863a11464a | 303 | } |
ubhat | 0:42863a11464a | 304 | |
ubhat | 0:42863a11464a | 305 | case Green: |
ubhat | 0:42863a11464a | 306 | { |
ubhat | 0:42863a11464a | 307 | if( GreenLed == LED_OFF ) |
ubhat | 0:42863a11464a | 308 | { |
ubhat | 0:42863a11464a | 309 | GreenLed = LED_ON; |
ubhat | 0:42863a11464a | 310 | } |
ubhat | 0:42863a11464a | 311 | else |
ubhat | 0:42863a11464a | 312 | { |
ubhat | 0:42863a11464a | 313 | GreenLed = LED_OFF; |
ubhat | 0:42863a11464a | 314 | } |
ubhat | 0:42863a11464a | 315 | break; |
ubhat | 0:42863a11464a | 316 | } |
ubhat | 0:42863a11464a | 317 | } |
ubhat | 0:42863a11464a | 318 | } |
ubhat | 0:42863a11464a | 319 | |
ubhat | 0:42863a11464a | 320 | void CtrlLED( eLedType led, uint8_t state ) |
ubhat | 0:42863a11464a | 321 | { |
ubhat | 0:42863a11464a | 322 | switch( led ) |
ubhat | 0:42863a11464a | 323 | { |
ubhat | 0:42863a11464a | 324 | case Red: |
ubhat | 0:42863a11464a | 325 | { |
ubhat | 0:42863a11464a | 326 | RedLed = state; |
ubhat | 0:42863a11464a | 327 | break; |
ubhat | 0:42863a11464a | 328 | } |
ubhat | 0:42863a11464a | 329 | |
ubhat | 0:42863a11464a | 330 | case Yellow: |
ubhat | 0:42863a11464a | 331 | { |
ubhat | 0:42863a11464a | 332 | YellowLed = state; |
ubhat | 0:42863a11464a | 333 | break; |
ubhat | 0:42863a11464a | 334 | } |
ubhat | 0:42863a11464a | 335 | |
ubhat | 0:42863a11464a | 336 | case Green: |
ubhat | 0:42863a11464a | 337 | { |
ubhat | 0:42863a11464a | 338 | GreenLed = state; |
ubhat | 0:42863a11464a | 339 | break; |
ubhat | 0:42863a11464a | 340 | } |
ubhat | 0:42863a11464a | 341 | |
ubhat | 0:42863a11464a | 342 | case Usr: |
ubhat | 0:42863a11464a | 343 | { |
ubhat | 0:42863a11464a | 344 | if( state ) |
ubhat | 0:42863a11464a | 345 | { |
ubhat | 0:42863a11464a | 346 | UsrLed = LED_ON; |
ubhat | 0:42863a11464a | 347 | } |
ubhat | 0:42863a11464a | 348 | else |
ubhat | 0:42863a11464a | 349 | { |
ubhat | 0:42863a11464a | 350 | UsrLed = LED_OFF; |
ubhat | 0:42863a11464a | 351 | } |
ubhat | 0:42863a11464a | 352 | break; |
ubhat | 0:42863a11464a | 353 | } |
ubhat | 0:42863a11464a | 354 | } |
ubhat | 0:42863a11464a | 355 | } |
ubhat | 0:42863a11464a | 356 | */ |
ubhat | 0:42863a11464a | 357 | void CheckOrientation( void ) |
ubhat | 0:42863a11464a | 358 | { |
ubhat | 0:42863a11464a | 359 | /* |
ubhat | 0:42863a11464a | 360 | uint8_t statusReg; |
ubhat | 0:42863a11464a | 361 | |
ubhat | 0:42863a11464a | 362 | // Read the PS_STATUS register |
ubhat | 0:42863a11464a | 363 | statusReg = Mma8451q.read_single( MMA8451_PL_STATUS ); |
ubhat | 0:42863a11464a | 364 | |
ubhat | 0:42863a11464a | 365 | // If Orientation of the Mote changed then populate Upper Nibble of 0th Byte of Tx Buffer |
ubhat | 0:42863a11464a | 366 | if( ( statusReg & 0x40 ) != 0 ) |
ubhat | 0:42863a11464a | 367 | { |
ubhat | 0:42863a11464a | 368 | CtrlLED( Green, LED_OFF ); |
ubhat | 0:42863a11464a | 369 | VerticalStatus = false; // horizontal |
ubhat | 0:42863a11464a | 370 | } |
ubhat | 0:42863a11464a | 371 | else |
ubhat | 0:42863a11464a | 372 | { |
ubhat | 0:42863a11464a | 373 | CtrlLED( Green, LED_ON ); |
ubhat | 0:42863a11464a | 374 | VerticalStatus = true; // vertical |
ubhat | 0:42863a11464a | 375 | } |
ubhat | 0:42863a11464a | 376 | */ |
ubhat | 0:42863a11464a | 377 | } |