POTATO
Dependencies: Hexi_KW40Z Hexi_OLED_SSD1351
Diff: main.cpp
- Revision:
- 8:de0336411ac1
- Parent:
- 7:3afe21b24e58
- Child:
- 9:fe52fbcc6187
--- a/main.cpp Fri May 03 17:20:07 2019 +0000 +++ b/main.cpp Mon May 06 05:09:55 2019 +0000 @@ -43,26 +43,40 @@ uint16_t x = 0; uint16_t y = 5000; uint16_t z = 10000; +char seconds = 0; +DigitalOut output(PTA10); /****************************Call Back Functions*******************************/ void ButtonRight(void) { pc.printf("Right\r\n"); StartHaptic(); - //kw40z_device.ToggleAdvertisementMode(); + + kw40z_device.ToggleAdvertisementMode(); + uint8_t buf[6] = "Right"; + kw40z_device.SendMessage(buf, 5); + + kw40z_device.ToggleAdvertisementMode(); + kw40z_device.SendMessage(buf, 5); } void ButtonLeft(void) { pc.printf("Left\r\n"); StartHaptic(); - //kw40z_device.ToggleAdvertisementMode(); + + kw40z_device.ToggleAdvertisementMode(); + uint8_t buf[6] = "Left"; + kw40z_device.SendMessage(buf, 5); + + kw40z_device.ToggleAdvertisementMode(); + kw40z_device.SendMessage(buf, 5); } void PassKey(void) { pc.printf("passkey\n"); - StartHaptic(); + //StartHaptic(); strcpy((char *) text,"PAIR CODE"); oled.TextBox((uint8_t *)text,0,25,95,18); @@ -78,22 +92,29 @@ StartHaptic(); data[length] = 0; printf("%s\n\r", data); + oled.TextBox((uint8_t *)data,0,40,95,18); + seconds = data[7]; + if ((seconds - '0')%2 == 0) { + output.write(0); + } else { + output.write(1); + } // data (our command) must 20 bytes long. // CMD for turning on: 'ledonledonledonledon' - if (data[4] == 'n') { - greenLed = LED_ON; - redLed = LED_ON; - blueLed = LED_ON; - pc.printf("on\n\r", data); - - //CMD for turning off: 'ledoffledoffledoffled' - } else if (data[4] == 'f') { - greenLed = LED_OFF; - redLed = LED_OFF; - blueLed = LED_OFF; - pc.printf("off\n\r", data); - } +// if (data[4] == 'n') { +// greenLed = LED_ON; +// redLed = LED_ON; +// blueLed = LED_ON; +// pc.printf("on\n\r", data); +// +// //CMD for turning off: 'ledoffledoffledoffled' +// } else if (data[4] == 'f') { +// greenLed = LED_OFF; +// redLed = LED_OFF; +// blueLed = LED_OFF; +// pc.printf("off\n\r", data); +// } } /***********************End of Call Back Functions*****************************/ @@ -101,14 +122,17 @@ int main() { + pc.baud(9600); + pc.printf("hello\n\r"); + /* Register callbacks to application functions */ kw40z_device.attach_buttonLeft(&ButtonLeft); kw40z_device.attach_buttonRight(&ButtonRight); kw40z_device.attach_passkey(&PassKey); kw40z_device.attach_alert(&alertReceived); + + memset(text, 0, sizeof(char)*20); - pc.baud(115200); - pc.printf("hello\n\r"); /* Turn on the backlight of the OLED Display */ oled.DimScreenON(); @@ -145,9 +169,13 @@ int i = 0; while (true) { - if (i % 20 == 0) + if (i % 20 == 0) +// strcpy((char *) text,"potato"); +// text[0] = 'a' + (i%26); +// oled.Label((uint8_t *)text,17,65); pc.printf("still here, %d\n\r", i); - i = i + 1; +// } + i = (i + 1); // blueLed = !kw40z_device.GetAdvertisementMode(); /*Indicate BLE Advertisment Mode*/ Thread::wait(50); } @@ -157,7 +185,7 @@ /* txTask() transmits the sensor data */ -void txTask(void){ +void txTask(void) { while (true) { @@ -188,6 +216,7 @@ kw40z_device.SendAccel(z,x,y); kw40z_device.SendMag(y,z,x); + uint8_t buf[6] = "Hello"; kw40z_device.SendMessage(buf, 5);