.

Dependencies:   Puck mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #define LOG_LEVEL_INFO
00002 #include "Puck.h"
00003 
00004 Puck* puck = &Puck::getPuck();
00005 
00006 InterruptIn pb1(BUTTON1);
00007 InterruptIn pb2(BUTTON2);
00008 
00009 uint8_t currentlyPushedButton = 0;
00010 
00011 void onButton1Pushed(void) {
00012     currentlyPushedButton = 1;
00013 }
00014 
00015 void onButton2Pushed(void) {
00016     currentlyPushedButton = 2;
00017 }
00018 
00019 void onButton3Pushed(void) {
00020     currentlyPushedButton = 3;
00021 }
00022 
00023 void onButton4Pushed(void) {
00024     currentlyPushedButton = 4;
00025 }
00026 
00027 // Sample Gatt characteristic and service UUIDs
00028 const UUID SAMPLE_GATT_SERVICE = stringToUUID("bftj sample     ");
00029 const UUID SAMPLE_GATT_CHARACTERISTIC = stringToUUID("bftj sample char");
00030 
00031 int main(void) {
00032     
00033     pb1.rise(&onButton1Pushed);
00034     pb1.enable_irq();
00035     
00036     pb2.rise(&onButton2Pushed);
00037     pb2.enable_irq();
00038     
00039     
00040     
00041     // Add the Gatt characteristic
00042     int characteristicValueLength = 1;
00043     puck->addCharacteristic(
00044             SAMPLE_GATT_SERVICE,
00045             SAMPLE_GATT_CHARACTERISTIC,
00046             characteristicValueLength,
00047             GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY);
00048 
00049     // Initialize the puck
00050     puck->init(0xFEED);
00051 
00052     // Set the initial value of the characteristic
00053     uint8_t new_value = 0;
00054     puck->updateCharacteristicValue(SAMPLE_GATT_CHARACTERISTIC, &new_value, characteristicValueLength);
00055 
00056     // Let the puck do its thing
00057     while(puck->drive()) { 
00058         if(currentlyPushedButton) {
00059             puck->updateCharacteristicValue(SAMPLE_GATT_CHARACTERISTIC, &currentlyPushedButton, 1);
00060             LOG_INFO("button: %i\n", currentlyPushedButton);
00061             currentlyPushedButton = 0;    
00062         }
00063     };
00064 }