Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: LoRaWAN-lib SX1272Lib lib_gps lib_mma8451q lib_mpl3115a2 mbed
Fork of LoRaWAN-NAMote72-Application-Demo_Multitech by
Diff: app/LoRaApp.cpp
- Revision:
- 13:6b6f4be13633
- Parent:
- 7:92f4f419f91f
- Child:
- 14:f687ec277e1b
--- a/app/LoRaApp.cpp Fri Aug 05 20:45:12 2016 +0000
+++ b/app/LoRaApp.cpp Tue Aug 30 06:35:16 2016 +0000
@@ -81,22 +81,54 @@
}
// Appends 1 Byte to TX buffer
+ case AppPrsr:
+ {
+ if( ( BuffPtr + 2 ) <= LORAWAN_APP_DATA_SIZE )
+ {
+ volatile uint8_t stat;
+ float val;
+
+ Mpl3115a2.SetModeBarometer();
+ Mpl3115a2.ToggleOneShot( );
+
+ stat = Mpl3115a2.read(STATUS_REG);
+ while( (stat & 0x04) != 0x04 ) {
+ wait(0.01);
+ stat = Mpl3115a2.read(STATUS_REG);
+ }
+
+ val = Mpl3115a2.ReadBarometer()/100.0;
+
+ BuffAddr[BuffPtr++] = ( ( uint16_t ) val >> 8 ) & 0xFF;
+ BuffAddr[BuffPtr++] = ( ( uint16_t ) val ) & 0xFF;
+
+ }
+ break;
+ }
+
+ // Appends 1 Byte to TX buffer
case AppTemp:
{
Mpl3115a2.ReadTemperature( );
if( ( BuffPtr + 1 ) <= LORAWAN_APP_DATA_SIZE )
{
- BuffAddr[BuffPtr++] = ( int32_t )Mpl3115a2.Temperature; // Signed degrees Celcius in half degree units. So, +/-63 °C
+ BuffAddr[BuffPtr++] = ( int32_t )Mpl3115a2.Temperature; // Signed degrees Celcius in half degree units. So, +/-63 °C
}
break;
- }
+ }
// Appends 1 Byte to TX buffer
case AppBat:
{
if( ( BuffPtr + 1 ) <= LORAWAN_APP_DATA_SIZE )
{
+#ifdef BAT_VAL_PERCENT
+ uint16_t value;
+ value = BoardGetBatteryLevel();
+ BuffAddr[BuffPtr++] = ( value * 100 ) >> 8; // Bat level in %
+#else
BuffAddr[BuffPtr++] = BoardGetBatteryLevel( ); // Per LoRaWAN spec; 0 = Charging; 1...254 = level, 255 = N/A
+#endif
}
break;
}
@@ -186,6 +218,62 @@
break;
}
+ case AppAcclSensor:
+ {
+ uint8_t statusReg;
+ uint8_t regVal;
+ uint16_t axesData;
+
+ // Read the PS_STATUS register
+ statusReg = Mma8451q.read_single( MMA8451_PL_STATUS );
+
+ /* Display Orientation of NAMote on Serial Port */
+ SerialAcclMetrDisplay( statusReg );
+
+ // If Orientation of the Mote changed then populate Upper Nibble of 0th Byte of Tx Buffer
+ if( ( statusReg & 0x80 ) != 0 )
+ {
+ CtrlLED( Green, LED_ON );
+ }
+ else
+ {
+ CtrlLED( Green, LED_OFF );
+ }
+
+ // Read and populate device orientation in Tx Buffer
+ if( ( BuffPtr + 6 ) <= LORAWAN_APP_DATA_SIZE )
+ {
+ uint8_t addr;
+ addr = MMA8451_OUT_X_MSB;
+
+ // Read X-axis Data
+ regVal = Mma8451q.read_single( addr++ );
+ axesData = regVal << 8;
+ regVal = Mma8451q.read_single( addr++ );
+ axesData |= regVal;
+ BuffAddr[BuffPtr++] = ( axesData >> 10 ) & 0xFF;
+ BuffAddr[BuffPtr++] = ( axesData >> 2 ) & 0xFF;
+
+ // Read Y-axis Data
+ regVal = Mma8451q.read_single( addr++ );
+ axesData = regVal << 8;
+ regVal = Mma8451q.read_single( addr++ );
+ axesData |= regVal;
+ BuffAddr[BuffPtr++] = ( axesData >> 10 ) & 0xFF;
+ BuffAddr[BuffPtr++] = ( axesData >> 2 ) & 0xFF;
+
+ // Read Z-axis Data
+ regVal = Mma8451q.read_single( addr++ );
+ axesData = regVal << 8;
+ regVal = Mma8451q.read_single( addr++ );
+ axesData |= regVal;
+ BuffAddr[BuffPtr++] = ( axesData >> 10 ) & 0xFF;
+ BuffAddr[BuffPtr++] = ( axesData >> 2 ) & 0xFF;
+ }
+
+ break;
+ }
+
case AppPushButton:
{
uint16_t PushButtonCnt;
