example firmware for nRF51-Dongle to use with Opentrigger
Dependencies: BLE_API mbed nRF51822
Fork of BLE_Button by
Diff: main.cpp
- Revision:
- 11:5b6d98e98127
- Parent:
- 10:7943b5c1117a
- Child:
- 12:2cb903df877d
--- a/main.cpp Wed Dec 30 09:54:06 2015 +0000 +++ b/main.cpp Tue Jun 07 13:22:48 2016 +0000 @@ -19,7 +19,7 @@ #include "ButtonService.h" DigitalOut led1(LED1); -InterruptIn button(BUTTON1); +InterruptIn button(P0_15); const static char DEVICE_NAME[] = "Button"; static const uint16_t uuid16_list[] = {ButtonService::BUTTON_SERVICE_UUID}; @@ -33,6 +33,10 @@ static ButtonService *buttonServicePtr; +void blinkLed(void){ + led1 = !led1; +} + void buttonPressedCallback(void) { /* Note that the buttonPressedCallback() executes in interrupt context, so it is safer to access @@ -54,7 +58,7 @@ void periodicCallback(void) { - led1 = !led1; /* Do blinky on LED1 to indicate system aliveness. */ + //blinkLed(); } /** @@ -65,6 +69,12 @@ /* Initialization error handling should go here */ } +void setPir(uint8_t pir){ + uint8_t data[] = { 0xff, 0xee, 0xff, 0x04, 0x01, 0x11, 0x07, 0x00 }; + data[7] = pir; + BLE::Instance().gap().accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, data, sizeof(data)); +} + /** * Callback triggered when the ble initialization process has finished */ @@ -83,6 +93,9 @@ if(ble.getInstanceID() != BLE::DEFAULT_INSTANCE) { return; } + + const uint8_t address1[] = {0xe7,0xAA,0xAA,0xAA,0xAA,0xAA}; + ble.gap().setAddress(BLEProtocol::AddressType::PUBLIC, address1); ble.gap().onDisconnection(disconnectionCallback); @@ -94,14 +107,17 @@ ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)uuid16_list, sizeof(uuid16_list)); ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME)); ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); - ble.gap().setAdvertisingInterval(1000); /* 1000ms. */ + ble.gap().setAdvertisingInterval(300); /* ms. */ + setPir(0x00); ble.gap().startAdvertising(); } + + int main(void) { - led1 = 1; + led1 = !0; Ticker ticker; ticker.attach(periodicCallback, 1); button.fall(buttonPressedCallback); @@ -117,6 +133,9 @@ while (true) { if (buttonState != IDLE) { buttonServicePtr->updateButtonState(buttonState); + + if(buttonState == PRESSED) {led1=!1;setPir(0x01);} + if(buttonState == RELEASED) {led1=!0;setPir(0x00);} buttonState = IDLE; }