Ottawa Bootcamp Publish

Dependencies:   SX127x lorawan1v1

Revision:
6:795461780e10
Parent:
5:53cd6c24a4ab
Child:
8:efe6002910df
--- a/sensorDemoVT100.cpp	Fri Apr 06 17:32:22 2018 -0700
+++ b/sensorDemoVT100.cpp	Wed Apr 11 14:50:01 2018 -0700
@@ -162,8 +162,22 @@
 #endif
 
 #if defined(TARGET_FF_ARDUINO)
-InterruptIn d8(D8);
-DigitalOut extLed(D15);
+    #ifdef TARGET_DISCO_L072CZ_LRWAN1
+        #define LED_GREEN       LED1
+        #define LED_RED2        LED2    // next to LD7
+        #define LED_BLUE        LED3
+        #define LED_RED4        LED4
+        InterruptIn button_pin(USER_BUTTON);
+        #define BUTTON_PRESSED      0
+        DigitalOut extLed(LED_RED4);
+        AnalogIn ain_temp(PA_0);
+    #else
+        InterruptIn button_pin(D8);
+        #define BUTTON_PRESSED      1
+        DigitalOut extLed(D15);
+        AnalogIn ain_pot(A1);
+        AnalogIn ain_temp(A3);
+    #endif
 #endif /* TARGET_FF_ARDUINO */
 
 #if defined(TARGET_FF_MORPHO) && !defined(TARGET_DISCO_L072CZ_LRWAN1)
@@ -270,11 +284,11 @@
 #define CAYENNE_CH_DOUT     2
 #define CAYENNE_CH_AOUT     3
 #define CAYENNE_CH_TEMP     0
-#define CAYENNE_CH_POT      1
+#ifndef TARGET_DISCO_L072CZ_LRWAN1
+    #define CAYENNE_CH_POT      1
+#endif /* !TARGET_DISCO_L072CZ_LRWAN1 */
 #define CAYENNE_CH_DIN      4
 
-AnalogIn a1(A1);
-AnalogIn a3(A3);
 
 const unsigned R0 = 100000;
 const unsigned B = 4275;
@@ -295,7 +309,7 @@
         switch (c_ch) {
             case CAYENNE_CH_TEMP:
                 AppData[gAppDataSize++] = LPP_TEMPERATURE;
-                u16 = a3.read_u16() >> 4;
+                u16 = ain_temp.read_u16() >> 4;
                 R = 4096.0 / u16 - 1.0;
                 R = R0 * R;
                 t = 1.0/(log(R/R0)/B+1/298.15)-273.15;
@@ -303,14 +317,16 @@
                 AppData[gAppDataSize++] = u16 >> 8;
                 AppData[gAppDataSize++] = u16;
                 break;
+#ifndef TARGET_DISCO_L072CZ_LRWAN1
             case CAYENNE_CH_POT:
                 AppData[gAppDataSize++] = LPP_ANALOG_INPUT;
-                u16 = a1.read_u16();    // pot (rotary angle)
+                u16 = ain_pot.read_u16();    // pot (rotary angle)
                 f = u16 / 198.6;    // scale 65535/3.3 to 0.01v per bit
                 rot = (uint16_t) f;
                 AppData[gAppDataSize++] = rot >> 8;
                 AppData[gAppDataSize++] = rot;
                 break;
+#endif /* !TARGET_DISCO_L072CZ_LRWAN1 */
             case CAYENNE_CH_DOUT:
                 AppData[gAppDataSize++] = LPP_DIGITAL_OUTPUT;
                 AppData[gAppDataSize++] = extLed.read();
@@ -339,7 +355,7 @@
         cayenne_ack_ch = -1;
     }
 
-    while (d8.read() == 1) {
+    while (button_pin.read() == BUTTON_PRESSED) {
         us_timestamp_t duration = LoRaMacReadTimer() - buttonStartAt;
         if (duration > 1000000) {
             gAppDataSize = 0;
@@ -355,20 +371,27 @@
             gAppDataSize = 0;
             AppData[gAppDataSize++] = CAYENNE_CH_TEMP;
             AppData[gAppDataSize++] = LPP_TEMPERATURE;
-            u16 = a3.read_u16() >> 4;
+
+            //vt.SetCursorPos( ROW_END-1, 1 );
+
+            u16 = ain_temp.read_u16() >> 4;
+            //vt.printf("0x%03x ", u16);
             R = 4096.0 / u16 - 1.0;
             R = R0 * R;
             t = 1.0/(log(R/R0)/B+1/298.15)-273.15;
+            //vt.printf("%.1fC\e[K", t);
             u16 = t * 10;  // 0.1C per bit
             AppData[gAppDataSize++] = u16 >> 8;
             AppData[gAppDataSize++] = u16;
+    #ifndef TARGET_DISCO_L072CZ_LRWAN1
             AppData[gAppDataSize++] = CAYENNE_CH_POT;
             AppData[gAppDataSize++] = LPP_ANALOG_INPUT;
-            u16 = a1.read_u16();    // pot (rotary angle)
+            u16 = ain_pot.read_u16();    // pot (rotary angle)
             f = u16 / 198.6;    // scale 65535/3.3 to 0.01v per bit
             rot = (uint16_t) f;
             AppData[gAppDataSize++] = rot >> 8;
             AppData[gAppDataSize++] = rot;
+    #endif /* !TARGET_DISCO_L072CZ_LRWAN1 */
 
             /* limited packet size: either ack downlink, or send sequence number */
             if (dout_downlink) {
@@ -1047,7 +1070,7 @@
     }
 }
 
-static void d8isr()
+static void button_isr()
 {
     c_ch = 0xff;
     DeviceState = DEVICE_STATE_SEND;
@@ -1118,8 +1141,12 @@
                 pwm.period(1.0 / 60);
                 cayenne_ack_ch = -1;
                 c_ch = 0xff;
-                d8.mode(PullDown);                
-                d8.rise(d8isr);
+                button_pin.mode(PullDown);                
+#ifdef TARGET_DISCO_L072CZ_LRWAN1
+                button_pin.fall(button_isr);
+#else
+                button_pin.rise(button_isr);
+#endif
 
                 mibReq.Type = MIB_ADR;
                 mibReq.Param.AdrEnable = LORAWAN_ADR_ON;