masaaki makabe / Mbed 2 deprecated KS7

Dependencies:   BLE_API nRF51822 mbed

Fork of KS7 by masaaki makabe

Revision:
7:9ebf125e405f
Parent:
6:bc960e6fd1ed
Child:
8:32be16b1eaf2
--- a/main.cpp	Fri Nov 06 00:02:56 2015 +0000
+++ b/main.cpp	Fri Nov 06 03:45:16 2015 +0000
@@ -14,14 +14,15 @@
 #define MANUFACTURER_NAME_STRING        "Hacarus" // Manufacturer Name String - shall represent the name of the manufacturer of the device.
 #define MODEL_NUMBER_STRING             "0001" // Model Number String - shall represent the model number that is assigned by the device vendor.
 #define SERIAL_NUMBER_STRING            "000780c0ffeef00d"  // Serial Number String - shall represent the serial number for a particular instance of the device.
-#define FIRMWARE_REVISION_STRING        "v1.00.00.000@rev0006" // Firmware Revision String - shall represent the firmware revision for the firmware within the device.
+#define FIRMWARE_REVISION_STRING        "v1.00.001@rev0007" // Firmware Revision String - shall represent the firmware revision for the firmware within the device.
 
 // Weight Scale Service (Original)
 #define UUID_WEIGHT_SCALE_SERVICE       (0x181D)
 
 // JoyStick
-#define PUSH_THRESHOLD       (100)
-#define PUSH_COUNT           (15)
+#define PUSH_MINTHRESHOLD       (0.2)
+#define PUSH_MAXTHRESHOLD       (0.6)
+#define PUSH_COUNT              (15)
 
 // Mode
 #define MODE_OFF    (0) // LED OFF
@@ -30,9 +31,9 @@
 #define MODE_END    (3) // LED ON -> OFF
 
 // Led
-#define LED_INTERVAL_NSEC   (200000)
+#define LED_INTERVAL_NSEC   (100000)
 #define BRIGHTNESS_ADDVALUE (0.1)
-#define BRIGHTNESS_MINVALUE (0)
+#define BRIGHTNESS_MINVALUE (0.0)
 #define BRIGHTNESS_MAXVALUE (1.0)
 
 // UART for debug
@@ -81,21 +82,37 @@
 GattCharacteristic *DISChars[] = {&ManuName, &ModelNum, &SerialNum, &FWVersion};
 GattService        DIS(GattService::UUID_DEVICE_INFORMATION_SERVICE , DISChars, sizeof(DISChars) / sizeof(GattCharacteristic *));
 
-void ticker_callback()
-{
+/* to confirm joystick */
+bool check_joystick(){
     bool pushing = false;
+    float value_x,value_y;
+    
+    value_x = io.get_x();
+    value_y = io.get_y();
     
-    /* to confirm joystick */
-    int pushvalue = (int)(io.get_x() * 9900 + io.get_y() * 99);
-    if(pushvalue < PUSH_THRESHOLD){
+    if(PUSH_MINTHRESHOLD >= value_x || PUSH_MAXTHRESHOLD <= value_x){
+        pushing = true;
+    }
+    else if(PUSH_MINTHRESHOLD >= value_y || PUSH_MAXTHRESHOLD <= value_y){
+        pushing = true;
+    }
+    
+    if(pushing){
         if(++push_counter >= PUSH_COUNT){
-            pushing = true;
             push_counter = 0;
+            return true;
         }
     }else{
         push_counter = 0;
     }
     
+    return false;
+}
+
+void ticker_callback()
+{
+    bool pushing = check_joystick();
+    
     switch(led_mode){
         case MODE_OFF:
             if(pushing){
@@ -122,7 +139,7 @@
                                                                     sizeof(weight));
                     io.analog_pow(0); // turn analog power off
                     update_counter = 0;
-                }    
+                }   
             }else{
                 if(ble.getGapState().connected){
                     ble.disconnect(Gap::REMOTE_USER_TERMINATED_CONNECTION);