Sigve Sebastian Farstad
/
Example_Puck_BLE
.
Revision 0:fb6e10232b73, committed 2015-03-04
- Comitter:
- sigveseb
- Date:
- Wed Mar 04 12:18:13 2015 +0000
- Commit message:
- add button notify
Changed in this revision
diff -r 000000000000 -r fb6e10232b73 Puck.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Puck.lib Wed Mar 04 12:18:13 2015 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/teams/Nordic-Pucks/code/Puck/#7d728fed55ab
diff -r 000000000000 -r fb6e10232b73 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Mar 04 12:18:13 2015 +0000 @@ -0,0 +1,64 @@ +#define LOG_LEVEL_INFO +#include "Puck.h" + +Puck* puck = &Puck::getPuck(); + +InterruptIn pb1(BUTTON1); +InterruptIn pb2(BUTTON2); + +uint8_t currentlyPushedButton = 0; + +void onButton1Pushed(void) { + currentlyPushedButton = 1; +} + +void onButton2Pushed(void) { + currentlyPushedButton = 2; +} + +void onButton3Pushed(void) { + currentlyPushedButton = 3; +} + +void onButton4Pushed(void) { + currentlyPushedButton = 4; +} + +// Sample Gatt characteristic and service UUIDs +const UUID SAMPLE_GATT_SERVICE = stringToUUID("bftj sample "); +const UUID SAMPLE_GATT_CHARACTERISTIC = stringToUUID("bftj sample char"); + +int main(void) { + + pb1.rise(&onButton1Pushed); + pb1.enable_irq(); + + pb2.rise(&onButton2Pushed); + pb2.enable_irq(); + + + + // Add the Gatt characteristic + int characteristicValueLength = 1; + puck->addCharacteristic( + SAMPLE_GATT_SERVICE, + SAMPLE_GATT_CHARACTERISTIC, + characteristicValueLength, + GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY); + + // Initialize the puck + puck->init(0xFEED); + + // Set the initial value of the characteristic + uint8_t new_value = 0; + puck->updateCharacteristicValue(SAMPLE_GATT_CHARACTERISTIC, &new_value, characteristicValueLength); + + // Let the puck do its thing + while(puck->drive()) { + if(currentlyPushedButton) { + puck->updateCharacteristicValue(SAMPLE_GATT_CHARACTERISTIC, ¤tlyPushedButton, 1); + LOG_INFO("button: %i\n", currentlyPushedButton); + currentlyPushedButton = 0; + } + }; +} \ No newline at end of file
diff -r 000000000000 -r fb6e10232b73 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Mar 04 12:18:13 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/9ad691361fac \ No newline at end of file