SimpleBLE prototype

Dependencies:   BLE_API mbed nRF51822

main.cpp

Committer:
janjongboom
Date:
2016-05-09
Revision:
0:0c885d287f5a
Child:
1:acae50e4bc88

File content as of revision 0:0c885d287f5a:

#include "mbed.h"
#include "SimpleBLE.h"

uint16_t counter = 0;

void onColorCharWrite(const uint8_t* buff, size_t length) {
    printf("Hey got new color! %d %d %d\n", buff[0], buff[1], buff[2]);
}

SimpleBLE ble("HPE_LIGHTSENSOR");
ReadOnlyCharacteristic<uint16_t>* lightChar = ble.createReadOnlyChar<uint16_t>(0x9381, 0x9382, true, counter);
ReadOnlyCharacteristic<uint16_t>* otherChar = ble.createReadOnlyChar<uint16_t>(0x9381, 0x9383, false, 0xaa);
ReadWriteCharacteristic<uint32_t>* colorChar = ble.createReadWriteChar<uint32_t>(0x9384, 0x9385, false, 0x0, &onColorCharWrite);

DigitalOut led(LED1);

void blink() {
    led = !led;
    
    lightChar->update(++counter);
}

int main(int, char**) {
    Ticker t;
    t.attach(blink, 1.0f);
    
    ble.spin();
    
    // will never return
}