this is a test about ble
Dependencies: BLE_API LinkNode_TemperatureAdvertising mbed nRF51822
Fork of LinkNode_DataAdvertising1 by
Revision 7:f84b0235958a, committed 2016-04-14
- Comitter:
- helloqi
- Date:
- Thu Apr 14 05:20:39 2016 +0000
- Parent:
- 6:b3d3351aadc6
- Commit message:
- import the project
Changed in this revision
Sensors.lib | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r b3d3351aadc6 -r f84b0235958a Sensors.lib --- a/Sensors.lib Mon Feb 22 08:55:35 2016 +0000 +++ b/Sensors.lib Thu Apr 14 05:20:39 2016 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/users/helloqi/code/Sensors/#ee98296289d0 +https://developer.mbed.org/users/helloqi/code/LinkNode_TemperatureAdvertising/#836584114fd6
diff -r b3d3351aadc6 -r f84b0235958a main.cpp --- a/main.cpp Mon Feb 22 08:55:35 2016 +0000 +++ b/main.cpp Thu Apr 14 05:20:39 2016 +0000 @@ -14,14 +14,17 @@ BLE ble; Sensors tempSensor; -DigitalOut led(P0_20); +DigitalOut led_r(P0_20); +DigitalOut buzzer(P0_22); +InterruptIn btn(P0_28); +InterruptIn btn1(P0_29); static bool triggerTempValueUpdate = false; -const static char DEVICE_NAME[8] = "ls_test"; /*The size of the DEVICE_NAME[] can't change */ +static bool start_flag = false; +const static char DEVICE_NAME[8] = "Linkab"; /*The size of the DEVICE_NAME[] can't change */ void periodicCallback(void) { /* Do blinky on LED1 while we're waiting for BLE events */ - led = !led; triggerTempValueUpdate = true; } @@ -45,7 +48,7 @@ ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, (uint8_t *)&appData, sizeof(ApplicationData_t)); /* Set data */ /* Setup advertising parameters */ ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED); - ble.gap().setAdvertisingInterval(500); + ble.gap().setAdvertisingInterval(300); /* Start advertising */ ble.gap().startAdvertising(); } @@ -64,23 +67,71 @@ ble.gap().startAdvertising(); } +void start_mode(void) +{ + led_r=0; + wait(0.2); + led_r=1; + wait(0.2); + led_r=0; + wait(0.2); + led_r=1; + ble.gap().startAdvertising(); +} +void stop_mode(void) +{ + led_r=0; + wait(0.5); + led_r=1; + wait(0.5); + led_r=0; + wait(0.5); + led_r=1; + ble.gap().stopAdvertising(); +} + +void change_startmode(void) +{ + + start_flag=!start_flag; + if(start_flag==true) + { + start_mode(); + } + else + { + stop_mode(); + } + printf("The state is %d\n",start_flag); +} + + int main(void) { Ticker ticker; - /* Enable trigger every 2 seconds */ - ticker.attach(periodicCallback, 2); - + ticker.attach(periodicCallback,300); ble.init(); - /* Start data advertising */ + led_r=1; + buzzer=0; temperatureValueAdvertising(); - - while (true) { - if (triggerTempValueUpdate) + btn.fall(&change_startmode); + btn1.fall(&updateSensorValueInAdvPayload); + printf("This is a test!\n"); + while(true) + { + if(start_flag==true) + { + if (triggerTempValueUpdate) + { + updateSensorValueInAdvPayload(); + triggerTempValueUpdate = false; + } + ble.waitForEvent(); + } + else { - /* Update data value */ - updateSensorValueInAdvPayload(); - triggerTempValueUpdate = false; + ble.gap().stopAdvertising(); + ble.waitForEvent(); } - ble.waitForEvent(); - } + } }