Comments (8)
@bojh it would be great if there was a more generic API, the nRF8001 and nRf51822 both have temp. sensors on board, but future supported boards might not.
What do you think of?
enum BLEDeviceRequest {
// ..
BLEDeviceRequest Address,
BLEDeviceRequest BatteryLevel,
BLEDeviceRequest Temperature
};
bool BLEPeripheral::request(BLEDeviceRequest request); // returns true on success, false on failure (no sensors)
void setResposneHandler(BLEDeviceRequest request, BLEDeviceResponseHandler response);
Maybe, it's getting too fancy ..
Note: Right now, if you extend BLEPeripheral
you can already override,
virtual void BLEDeviceAddressReceived(BLEDevice& device, const unsigned char* address);
virtual void BLEDeviceTemperatureReceived(BLEDevice& device, float temperature);
virtual void BLEDeviceBatteryLevelReceived(BLEDevice& device, float batteryLevel);
and have acces to the following BLEDevices
API's:
virtual void requestAddress() { }
virtual void requestTemperature() { }
virtual void requestBatteryLevel() { }
from arduino-bleperipheral.
@sandeepmistry The question is cerainly justified and I allready had it realized, as you have proposed by a derived BLEPeripheral class.
On the other hand, I expect also following chipsets (..nrf52x) will also support such universal functions.
From my point of view the fancy way seems a little bit more intuitive, ... but BLEDeviceResponseHandler has to be defined and we have different response value types :-)
... but surely depends a little bit on taste.
from arduino-bleperipheral.
@prjh we could make it a union?
union BLEDeviceResponse {
float f;
char[6] address;
// ....
};
typedef void (* BLEDeviceResponseHandler)(BLEDevice& central, BLEDeviceResponse& response);
Slightly unrelated, I've been also thinking about making a breaking change to the API, to expose BLEDevice
, changing:
BLEPeripheral blePeripheral = BLEPeripheral(BLE_REQ, BLE_RDY, BLE_RST);
to something like:
// nRF8001
BLENRF8001Device nRF80001 = BLENRF8001Device(BLE_REQ, BLE_RDY, BLE_RST);
BLEPeripheral blePeripheral = BLEPeripheral(nRF80001);
// nRF51822
BLENRF51822Device nRF51822 = BLENRF51822Device();
BLEPeripheral blePeripheral = BLEPeripheral(nRF51822);
It would make sketches less portable (require one line change), but would support other slave boards like the nRF8001.
from arduino-bleperipheral.
@bojh @prjh anything else to discuss on this?
from arduino-bleperipheral.
@sandeepmistry OK the union would al be fine, but I we than have to use a discriminator value (may be BLEDeviceRequest ) to know the callback reason.
Your ideas to the API is OK for me, because the hardware does no change so often for real projects. From compatibility view, I think it's OK to have a individual HW dependend constructor.
from arduino-bleperipheral.
OK for me
from arduino-bleperipheral.
Re-opening, as this is not implemented yet :)
from arduino-bleperipheral.
I will provide an minimal, incremental solution as PR, making the BLEDevice::requestTemperature() function accessible from the BLEPeripheral class.
from arduino-bleperipheral.
Related Issues (20)
- Can't detect remote devices
- NRF5: CCCDs aren't persisted for bonded peers
- How to set service name ? HOT 1
- ANCS Implementation canWrite is false
- Speed / baudrate of the BLE connection?
- Numpad key codes, anyone?
- How to send more than 20bytes in each transaction with bleSerial.write()?
- Olimexino-nano + Olimexino-nano-ble freezes after begin()
- Why is my BLE Service not appearing after a successful flash? HOT 2
- [Question] Sending long string BLECharacteristic
- Abandoned project?
- nrf52840 HOT 4
- Freeze on blePeripheral.begin(); HOT 7
- BLE Scan
- softdevice_sys_evt_handler_set()
- RFDuino using BLEPerfipheralObserver to scan for iBeacons - Issue HOT 2
- Update iBeacon broadcast packet after starting
- Setting chip to idle state in between measurements
- nRF52832 Supported?
- UART Rx hangs after a few seconds when BLEPeripheral.begin(); is called on nRF51802
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from arduino-bleperipheral.