-
Notifications
You must be signed in to change notification settings - Fork 18
Arduino library for BLE
This is a draft API for an Arduino library for BLE. Current targets are:
- nRF8001 with nRFgo Studio and
services.h
- nRF8001 configured directly from Arduino
nRF8001:
nRF8001 nrf(4, 10, 3, setup_msgs, pipe_data);
BLEPeripheral peripheral(nrf);
To make it easier for users, we will specify a data type. It is also possible to set up a characteristic as an array of values of the same type. For more complicated data structures, users should either manipulate a array of bytes (or uint8_t
s) or use a struct.
BLECharacteristic<uint8_t> example1(peripheral);
BLECharacteristic<uint8_t, 10> example2(peripheral);
BLECharacteristic<int16_t> example3(peripheral);
example1.write(12);
example1.read();
example3.write(-42);
uint8_t data[10];
example2.read(data);
For nRF8001, we need to specify the pipes that belong to each characteristic. For example, one characteristic might have pin 2 and another might have pins 2 and 3. How should we do this?
We need to be passed the setup and pipe type data structures from services.h.
services.h
can tell us the number of pipes (NUMBER_OF_PIPES) and the type of each pipe (SERVICES_PIPE_TYPE_MAPPING_CONTENT). This means that if we are given the SERVICES_PIPE_TYPE_MAPPING_CONTENT data structure, the user only needs to tell us which pipes belong to each services. This could be done with something like:
BLECharacteristic characteristic(peripheral);
characteristic.addPipe(2);
characteristic.addPipe(3);
This tells the library that pipes 2 and 3 belong to this characteristic, and the library can figure out what they do. Except at this stage BLECharacteristic doesn’t know that it’s an nRF8001. We might need something like this:
nRF8001 nrf(...);
BLEPeripheral peripheral(nrf);
BLECharacteristic characteristic(peripheral);
nrf.addPipe(characteristic, 2);
nrf.addPipe(characteristic, 3);