Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Hexi_KW40Z Hexi_OLED_SSD1351
Fork of Hexi_BLE_Example_Modified by
Revision 5:52965830cd7c, committed 2018-06-12
- Comitter:
- catchvibes95
- Date:
- Tue Jun 12 21:24:01 2018 +0000
- Parent:
- 4:20d4eebfa986
- Commit message:
- q2
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Fri May 04 08:56:11 2018 +0000
+++ b/main.cpp Tue Jun 12 21:24:01 2018 +0000
@@ -44,18 +44,38 @@
uint16_t y = 5000;
uint16_t z = 10000;
+
+void attach_buttonSlide(button_t btnFct);
+
+int flag=0;
+
/****************************Call Back Functions*******************************/
void ButtonRight(void)
{
StartHaptic();
- kw40z_device.ToggleAdvertisementMode();
+ flag=4;
+ //kw40z_device.ToggleAdvertisementMode();
+}
+
+void ButtonUp(void)
+{
+ StartHaptic();
+ flag=1;
+ //kw40z_device.ToggleAdvertisementMode();
}
void ButtonLeft(void)
{
StartHaptic();
- kw40z_device.ToggleAdvertisementMode();
+ flag=3;
+ //kw40z_device.ToggleAdvertisementMode();
}
+void ButtonDown(void)
+{
+ StartHaptic();
+ flag=2;
+}
+
void PassKey(void)
{
@@ -101,6 +121,9 @@
/* Register callbacks to application functions */
kw40z_device.attach_buttonLeft(&ButtonLeft);
kw40z_device.attach_buttonRight(&ButtonRight);
+ kw40z_device.attach_buttonDown(&ButtonDown);
+ kw40z_device.attach_buttonUp(&ButtonUp);
+ // kw40z_device.attach_buttonSlide(&buttonSlide);
kw40z_device.attach_passkey(&PassKey);
kw40z_device.attach_alert(&AlertReceived);
@@ -153,32 +176,35 @@
while (true)
{
+ if (kw40z_device.GetLinkState() == 0)
+ {
+ pc.printf("toggling advert mode\r\n");
+ kw40z_device.ToggleAdvertisementMode();
+ }
+
UpdateSensorData();
/*Notify Hexiwear App that it is running Sensor Tag mode*/
kw40z_device.SendSetApplicationMode(GUI_CURRENT_APP_SENSOR_TAG);
- /*The following is sending dummy data over BLE. Replace with real data*/
-
- /*Send Battery Level for 20% */
kw40z_device.SendBatteryLevel(battery);
/*Send Ambient Light Level at 50% */
- kw40z_device.SendAmbientLight(light);
+ //kw40z_device.SendAmbientLight(light);
/*Send Humidity at 90% */
- kw40z_device.SendHumidity(humidity);
+ //kw40z_device.SendHumidity(humidity);
/*Send Temperature at 25 degrees Celsius */
- kw40z_device.SendTemperature(temperature);
+ //kw40z_device.SendTemperature(temperature);
/*Send Pressure at 100kPA */
- kw40z_device.SendPressure(pressure);
+ //kw40z_device.SendPressure(pressure);
/*Send Mag,Accel,Gyro Data. */
- kw40z_device.SendGyro(x,y,z);
- kw40z_device.SendAccel(z,x,y);
- kw40z_device.SendMag(y,z,x);
+ //kw40z_device.SendGyro(x,y,z);
+ //kw40z_device.SendAccel(z,x,y);
+ //kw40z_device.SendMag(y,z,x);
Thread::wait(1000);
}
@@ -186,24 +212,42 @@
void UpdateSensorData(void)
{
- battery -= 5;
- if(battery < 5) battery = 100;
-
- light += 20;
- if(light > 100) light = 0;
-
- humidity += 500;
- if(humidity > 8000) humidity = 2000;
+ //battery -= 5;
+ if(flag==1)
+ {
+ battery = 1;
+ flag=0;
+ }
+ if(flag==2)
+ {
+ battery = 2;
+ flag=0;
+ }
+ if(flag==3)
+ {
+ battery = 3;
+ flag=0;
+ }
+ if(flag==4)
+ {
+ battery = 4;
+ flag=5;
+ }
- temperature -= 200;
- if(temperature < 200) temperature = 4200;
+ //if(light > 100) light = 0;
+
+ // humidity += 500;
+ //if(humidity > 8000) humidity = 2000;
- pressure += 300;
- if(pressure > 10300) pressure = 7500;
+ //temperature -= 200;
+ //if(temperature < 200) temperature = 4200;
- x += 1400;
- y -= 2300;
- z += 1700;
+ //pressure += 300;
+ //if(pressure > 10300) pressure = 7500;
+
+ //x += 1400;
+ //y -= 2300;
+ //z += 1700;
}
void StartHaptic(void) {
