Node code for sx1272 LoRa transciever

Dependencies:   mbed BMP085 BufferedSerial DHT Sds021 Chainable_RGB_LED DigitDisplay LoRaWAN-lib SX1272Lib

Fork of LoRaWAN-demo-72-bootcamp by Semtech

Revision:
3:d4142832d5af
Parent:
2:48d8d4806d48
Child:
4:de084e23d884
--- a/app/main.cpp	Mon Mar 07 13:54:25 2016 +0000
+++ b/app/main.cpp	Wed Mar 09 16:05:08 2016 +0000
@@ -70,7 +70,7 @@
 /*!
  * LoRaWAN application port
  */
-#define LORAWAN_APP_PORT                            15
+#define LORAWAN_APP_PORT                            10
 
 /*!
  * User application data buffer size
@@ -79,7 +79,7 @@
 #define LORAWAN_APP_DATA_SIZE                       6
 
 #else
-#define LORAWAN_APP_DATA_SIZE                       1
+#define LORAWAN_APP_DATA_SIZE                       5
 
 #endif
 
@@ -159,25 +159,45 @@
  */
 static bool NextTx = true;
 
+/*!
+ * Hold the value returned from the Light Sensor
+ */
+static float LightValue = 0.0;
 
-static float LightValue = 0.0; 
+/*!
+ * Control the 3-color LED 
+ * 0: automatic (LED goes brigther as the light decrease, 
+ * 1: manual (The LED is controlled by the user)
+ */
 static uint8_t LightMode = 0;  // 0:automatic, 1:manual
+
+/*!
+ * Ticker to create a PWM for the buzzer
+ */
 Ticker BuzTimer;
 
-#define NUM_LED 3
-
 
-AnalogIn LightSens( A1 ); 
+/*!
+ * Constructor for Buzzer
+ */
+DigitalOut buzzer(A3);
+
+/*!
+ * Constructor for the 3-color LED
+ */
+#define NUM_LED 3
 ChainableLED color_led(D6, D7, NUM_LED);
-DigitDisplay display(A2, A3);
-DigitalOut buzzer(A2);
-
 
-static void OnBuzTimerEvent( void )
-{
-    buzzer = 0;
-    BuzTimer.detach( );
-}
+/*!
+ * Constructor for Light Sensor
+ */
+AnalogIn LightSens( A1 ); 
+
+/*!
+ * Constructor for 4 Digit 7 semgent display
+ */
+DigitDisplay display(D8, D9);
+
 /*!
  * Device states
  */
@@ -300,24 +320,20 @@
  */
 static void PrepareTxFrame( uint8_t port )
 {
+    uint32_t tempValue;
+    
     switch( port )
     {
-     
     case 10:
         {  
-        uint32_t tempValue = (uint32_t)(LightValue*1000000.0);
-        
-        debug( "[Tx] LightValue=%d 0x%x\n\r" , tempValue, tempValue);
-        
-        AppData[0] = LightMode;
-        AppData[1] = ((tempValue&0xFF000000)>>24)&0xFF;
-        AppData[2] = ((tempValue&0x00FF0000)>>16)&0xFF;
-        AppData[3] = ((tempValue&0x0000FF00)>>8)&0xFF;
-        AppData[4] = (tempValue&0x000000FF);    
+            tempValue = ( uint32_t )( LightValue * 1000000.0 );
+            AppData[0] = LightMode;
+            AppData[1] = ( ( tempValue & 0xFF000000 ) >> 24 ) & 0xFF;
+            AppData[2] = ( ( tempValue & 0x00FF0000 ) >> 16 ) & 0xFF;
+            AppData[3] = ( ( tempValue & 0x0000FF00 ) >> 8 ) & 0xFF;
+            AppData[4] = ( tempValue & 0x000000FF );    
         }
         break;
-        
-        
     case 15:
         {
             AppData[0] = AppLedStateOn;
@@ -469,6 +485,15 @@
 }
 
 /*!
+ * \brief Function executed on Buzzer Timeout event
+ */
+static void OnBuzTimerEvent( void )
+{
+    buzzer = 0;
+    BuzTimer.detach( );
+}
+
+/*!
  * \brief   MCPS-Confirm event function
  *
  * \param   [IN] McpsConfirm - Pointer to the confirm structure,
@@ -599,7 +624,6 @@
             
         case 20:
             LightMode = McpsIndication->Buffer[0];
-            debug( "[Rx] LightMode=%x - R G B= 0x%x 0x%x 0x%x\n\r" , LightMode, McpsIndication->Buffer[1], McpsIndication->Buffer[2], McpsIndication->Buffer[3]);
             if( LightMode )
             {
                 color_led.setColorRGB(0, McpsIndication->Buffer[1], McpsIndication->Buffer[2], McpsIndication->Buffer[3] );
@@ -748,7 +772,7 @@
  */
 int main( void )
 {
-    float tempLightValue = 0;   
+    float tempLightValue = 0.0;   
     
     LightMode = 0;      // 0: manual,   1: automatic
     buzzer = 0;         // 0: OFF,      1: ON