It is the Nordic nRF8001 BLE library for RedBearLab BLE Shield v2.1 or above. It is compatible with the platforms those soldered Arduino compatible form factor. The library is ported to mbed from Sandeep's arduino-BLEPeripheral library for Arduino: https://github.com/sandeepmistry/arduino-BLEPeripheral. We have tested it on KL05, KL25, MK20 and SeeedStudio Arch platforms and it works well.
Dependents: nRF8001_SimpleChat nRF8001_SimpleControls mbed_BLE2 mbed_BLEtry2 ... more
nRF8001.h
00001 #ifndef _NRF_8001_H_ 00002 #define _NRF_8001_H_ 00003 00004 #include "Arduino.h" 00005 00006 #include <utility/lib_aci.h> 00007 #include <utility/aci_setup.h> 00008 00009 #include "BLEAttribute.h" 00010 #include "BLECharacteristic.h" 00011 00012 class nRF8001; 00013 00014 class nRF8001EventListener 00015 { 00016 public: 00017 virtual void nRF8001Connected(nRF8001& nRF8001, const unsigned char* address) = 0; 00018 virtual void nRF8001Disconnected(nRF8001& nRF8001) = 0; 00019 00020 virtual void nRF8001CharacteristicValueChanged(nRF8001& nRF8001, BLECharacteristic& characteristic, const unsigned char* value, unsigned char valueLength) = 0; 00021 virtual void nRF8001CharacteristicSubscribedChanged(nRF8001& nRF8001, BLECharacteristic& characteristic, bool subscribed) = 0; 00022 00023 virtual void nRF8001AddressReceived(nRF8001& nRF8001, const unsigned char* address) = 0; 00024 virtual void nRF8001TemperatureReceived(nRF8001& nRF8001, float temperature) = 0; 00025 virtual void nRF8001BatteryLevelReceived(nRF8001& nRF8001, float batteryLevel) = 0; 00026 }; 00027 00028 00029 class nRF8001 00030 { 00031 friend class BLEPeripheral; 00032 00033 protected: 00034 struct pipeInfo { 00035 BLECharacteristic* characteristic; 00036 00037 unsigned short valueHandle; 00038 unsigned short configHandle; 00039 00040 unsigned char startPipe; 00041 unsigned char txPipe; 00042 unsigned char txAckPipe; 00043 unsigned char rxPipe; 00044 unsigned char rxAckPipe; 00045 unsigned char setPipe; 00046 00047 bool txPipeOpen; 00048 bool txAckPipeOpen; 00049 }; 00050 00051 nRF8001(DigitalInOut *req, DigitalInOut *rdy, DigitalInOut *rst); 00052 00053 virtual ~nRF8001(); 00054 00055 void setEventListener(nRF8001EventListener* eventListener); 00056 00057 void begin(const unsigned char* advertisementData, 00058 unsigned char advertisementDataLength, 00059 const unsigned char* scanData, 00060 unsigned char scanDataLength, 00061 BLEAttribute** attributes, 00062 unsigned char numAttributes); 00063 00064 void poll(); 00065 00066 void disconnect(); 00067 00068 bool updateCharacteristicValue(BLECharacteristic& characteristic); 00069 bool canNotifyCharacteristic(BLECharacteristic& characteristic); 00070 bool canIndicateCharacteristic(BLECharacteristic& characteristic); 00071 00072 void requestAddress(); 00073 void requestTemperature(); 00074 void requestBatteryLevel(); 00075 00076 private: 00077 void waitForSetupMode(); 00078 void sendSetupMessage(hal_aci_data_t* data); 00079 void sendCrc(); 00080 00081 private: 00082 struct aci_state_t _aciState; 00083 hal_aci_evt_t _aciData; 00084 00085 struct pipeInfo* _pipeInfo; 00086 unsigned char _numPipeInfo; 00087 00088 unsigned short _crcSeed; 00089 00090 nRF8001EventListener* _eventListener; 00091 }; 00092 00093 #endif
Generated on Tue Jul 12 2022 18:13:45 by 1.7.2