Hexiwear Code for Game Controls

Dependencies:   FXAS21002 FXOS8700 Hexi_KW40Z Hexi_OLED_SSD1351

Fork of Hexi_Final_Project by Destin Raymundo

Files at this revision

API Documentation at this revision

Comitter:
calvinha721
Date:
Fri Jun 15 16:01:27 2018 +0000
Parent:
6:8a9b0eb4835d
Commit message:
Hexi Final

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Tue Jun 12 03:39:57 2018 +0000
+++ b/main.cpp	Fri Jun 15 16:01:27 2018 +0000
@@ -54,13 +54,28 @@
 void ButtonRight(void)
 {
     StartHaptic();
-    kw40z_device.ToggleAdvertisementMode();
+    //kw40z_device.ToggleAdvertisementMode();
+    kw40z_device.SendBatteryLevel(0);
 }
 
 void ButtonLeft(void)
 {
     StartHaptic();
-    kw40z_device.ToggleAdvertisementMode();
+    //kw40z_device.ToggleAdvertisementMode();
+    kw40z_device.SendBatteryLevel(1);
+}
+void ButtonUp(void)
+{
+    StartHaptic();
+    //kw40z_device.ToggleAdvertisementMode();
+    kw40z_device.SendBatteryLevel(2);
+}
+
+void ButtonDown(void)
+{
+    StartHaptic();
+    //kw40z_device.ToggleAdvertisementMode();
+    kw40z_device.SendBatteryLevel(3);
 }
 
 void PassKey(void)
@@ -107,6 +122,8 @@
     /* Register callbacks to application functions */
     kw40z_device.attach_buttonLeft(&ButtonLeft);
     kw40z_device.attach_buttonRight(&ButtonRight);
+    kw40z_device.attach_buttonUp(&ButtonUp);
+    kw40z_device.attach_buttonDown(&ButtonDown);
     kw40z_device.attach_passkey(&PassKey);
     kw40z_device.attach_alert(&AlertReceived);
     
@@ -172,13 +189,18 @@
         // So we will use SendBattery
         // But since SendBattery cannot send multiple values at a time
         // We will have to advertise to Pi what value it should expect next
+    if(abs_x >50 && abs_z< 50){
+        StartHaptic();
+        kw40z_device.SendBatteryLevel(4);
+        /* //Code for sending raw orientation data below
         kw40z_device.SendBatteryLevel('x');
         kw40z_device.SendBatteryLevel(abs_x);
         kw40z_device.SendBatteryLevel('y');
         kw40z_device.SendBatteryLevel(abs_y);
         kw40z_device.SendBatteryLevel('z');
         kw40z_device.SendBatteryLevel(abs_z);
-
+        */
+    }
         Thread::wait(1000);                 
     }
 }