Espotel / Mbed 2 deprecated LoRaWAN_Serial_port_driven_and_configurable_ELMO_based_on_TxRx_Template

Dependencies:   SX1272lib-PABOOST-HW-Modification mbed

Fork of LoRaWAN_ELMO_TxRx_Template by Espotel

Revision:
7:3d16d6fe3b12
Parent:
6:71b489e70063
Child:
9:c7c39e01bda1
--- a/main.cpp	Tue Apr 19 21:48:58 2016 +0000
+++ b/main.cpp	Fri Oct 07 11:40:18 2016 +0000
@@ -16,6 +16,8 @@
 
 #include "mbed.h"
 #include "RadioHandler.h"
+#include "Comissioning.h"
+
 
 // --- Important notes! ---
 // USE_BAND_868 has been defined in LoRaMac-board.h
@@ -27,60 +29,63 @@
 // dConduitBugs at LoRaMac.cpp patches a bug in Multitech Conduit Firmware 1.1.2 2016-01-13T09:59:04
 
 DigitalOut Led1(LED1);
-
-/*
- * True if ELMO button was pressed
- */
 static bool ButtonPressed = false;
 
-/*
-    ELMO Pushbutton interrupt
-*/
+//ELMO Pushbutton interrupt
 void ButtonHandler( void )
 {
     ButtonPressed = true;
 }
 
-/**
- * Main application entry point.
- */
+//Main application entry point.
 int main( void )
 {
     char XmitBuffer[100]; // Max 16 bytes in LoRa packet!
-    uint16_t PacketCount = 0;
+    char data[100];
+    uint16_t index = 0;
     InterruptIn pushButton(USER_BUTTON);
     Serial debugPort(SERIAL_TX, SERIAL_RX);
-
     debugPort.baud(9600);
-
     debugPort.printf("\r\n\r\nELMO Debug Screen\r\n");
-
     pushButton.rise(&ButtonHandler);
     pushButton.enable_irq();
-
     RadioInit();
 
     while( 1 )
     {
-        // Show some debug stuff in case Elmo button is pressed. Request packet transmission
+        // Show some debug stuff in case Elmo button is pressed. Request packet transmission    
+        if (debugPort.readable()) {
+            data[index]=debugPort.getc();
+            
+            if (data[index]=='\n'){
+                debugPort.printf("Your input was: %s\r\n", data);
+                sprintf(XmitBuffer, "%s\r\n", data);
+                Led1 = !Led1;
+                RequestPacketTx(XmitBuffer, false);
+                memset(data,' ', sizeof(data));
+                index=0;
+                }
+            index++;
+            if (index>100) {
+                index=0;
+                }
+        }  
+        
+
+
+
+
+                
         if (ButtonPressed)
-        {
+        {        
             debugPort.printf("\r\nButton was pressed\r\n");
+            RadioSetup();
+            debugPort.printf("JOB DONE\r\n");
             Led1 = !Led1;
-            sprintf(XmitBuffer, "Elmo calling %d", PacketCount);
-            RequestPacketTx(XmitBuffer, true);  // true = enable periodic transmissions. False = send just one packet
-            if(PacketCount < 99)
-            {
-                PacketCount++;
-            }
-            else
-            {
-                // Start from 1 when 99 is reached
-                PacketCount = 1;
-            }
+            //State/Status resets for next time
             ButtonPressed = false;
         }
-
+        
         RadioHandler();
     }
 }
\ No newline at end of file