masaaki makabe / Mbed 2 deprecated KS7

Dependencies:   BLE_API nRF51822 mbed

Fork of KS7 by masaaki makabe

Revision:
19:05526fe9365e
Parent:
18:d1d15ec580fa
Child:
20:c3fadeef5842
--- a/main.cpp	Thu Jan 14 02:12:19 2016 +0000
+++ b/main.cpp	Fri Jan 15 04:17:08 2016 +0000
@@ -2,6 +2,7 @@
 #include "io.h"
 #include "BLE.h"
 #include "common.h"
+#include <stdlib.h>
 
 // BLE
 #define INTERVAL_500MSEC        (500UL)
@@ -108,7 +109,8 @@
     
     return ((sum_data / SW_SAMPLECOUNT) >= SW_THRESHOLD);
 */
-    return(io.get_switch());
+//    return(io.get_switch());
+    return(0); // ignore switch
 }
 
 uint32_t quick_ieee11073_from_float(float data)
@@ -218,6 +220,8 @@
     BleInitialize();
     AppInit();
 
+    led_mode = MODE_START;
+    int tm = 0;
     for (;; ) {
         // 100msec waitForEvent
         t.reset();
@@ -226,8 +230,8 @@
             ble.waitForEvent();
             t.stop();
         }
-        
         io.analog_pow(1);
+//        pc.printf("#%d %d %d\r\n", io.get_switch(), d0, d1);
         // ticker処理
         switch(led_mode){
             case MODE_OFF:
@@ -260,18 +264,23 @@
                                                                             (uint8_t *)&scale,
                                                                             sizeof(scale));
                                                                             
-                    weight = io.get_weight_raw() / WEIGHT_COEFFICIENT;
+//                    weight = io.get_weight_raw() / WEIGHT_COEFFICIENT;
+                    tm++;
+                    if (tm == 100){
+                        tm = 0;
+                        weight = (float)(rand() % 2000);
 //                    pc.printf("w=%f\r\n", weight);
-                    if(weight < 0){
-                        weight = 0;
-                    }
-                    io.display_value = (uint16_t)weight; // dummy display
-                    if(++update_counter >= 5){
-                        weight_data = quick_ieee11073_from_float(weight);
-                        ble.updateCharacteristicValue(WeightMeasurement.getValueAttribute().getHandle(),
+                        if(weight < 0){
+                            weight = 0;
+                        }
+                        io.display_value = (uint16_t)weight; // dummy display
+                        if(++update_counter >= 5){
+                            weight_data = quick_ieee11073_from_float(weight);
+                            ble.updateCharacteristicValue(WeightMeasurement.getValueAttribute().getHandle(),
                                                                             (uint8_t *)&weight_data,
                                                                             sizeof(weight_data));
-                        update_counter = 0;
+                            update_counter = 0;
+                        }
                     }
                 }
             break;