BLE Nano LED control
Dependencies: BLE_API mbed nRF51822
ble_nanoled_service.cpp
00001 #include "ble_nanoled_service.h" 00002 #include "Led.h" 00003 00004 namespace { 00005 // The Nordic UART Service 00006 const uint8_t UUID_BASE[] = {0x71, 0x3D, 0, 0, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E}; 00007 const uint8_t UUID_TX[] = {0x71, 0x3D, 0, 3, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E}; 00008 const uint8_t UUID_RX[] = {0x71, 0x3D, 0, 2, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E}; 00009 } 00010 00011 00012 void ServiceUart::addService(BLE& ble) 00013 { 00014 mChars[0] = new GattCharacteristic( 00015 UUID_TX, 00016 mTxPayload, 00017 1, 00018 TXRX_BUF_LEN, 00019 GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE 00020 ); 00021 mChars[1] = new GattCharacteristic( 00022 UUID_RX, 00023 mRxPayload, 00024 1, 00025 TXRX_BUF_LEN, 00026 GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY 00027 ); 00028 GattService* pService = new GattService(UUID_BASE, mChars, CHAR_NUM); 00029 ble.addService(*pService); 00030 } 00031 00032 00033 void ServiceUart::writtenHandler(BLE& ble, const GattWriteCallbackParams* params) 00034 { 00035 if (params->handle == mChars[0]->getValueAttribute().getHandle()) { 00036 uint8_t buf[TXRX_BUF_LEN]; 00037 uint16_t bytesRead; 00038 00039 ble.readCharacteristicValue(mChars[0]->getValueAttribute().getHandle(), buf, &bytesRead); 00040 if(buf[0] == 0x01) { 00041 LedOn(); 00042 } else { 00043 LedOff(); 00044 } 00045 } 00046 } 00047 00048 void ServiceUart::readHandler(BLE& ble, const GattReadCallbackParams* params) 00049 { 00050 if (params->handle == mChars[1]->getValueAttribute().getHandle()) { 00051 //... 00052 } 00053 } 00054
Generated on Sat Jul 16 2022 07:31:50 by 1.7.2