Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BLE_API mbed nRF51822
Fork of BLE_GATT_Example by
Revision 23:d63b6764b95d, committed 2017-04-23
- Comitter:
- Super_Mario
- Date:
- Sun Apr 23 20:48:42 2017 +0000
- Parent:
- 22:406127954d1f
- Commit message:
- Little domotic project: controlling RGB color intensity of the JUMA SMP Tag from an Android App'; ; Here's the matching App's source code --> https://github.com/NordineKhelfi/Android_Bluetooth_Low_Energy
Changed in this revision
diff -r 406127954d1f -r d63b6764b95d BLE_API.lib --- a/BLE_API.lib Mon Nov 09 17:08:47 2015 +0000 +++ b/BLE_API.lib Sun Apr 23 20:48:42 2017 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/teams/Bluetooth-Low-Energy/code/BLE_API/#a097e1be76f4 +http://mbed.org/teams/Bluetooth-Low-Energy/code/BLE_API/#65474dc93927
diff -r 406127954d1f -r d63b6764b95d main.cpp
--- a/main.cpp Mon Nov 09 17:08:47 2015 +0000
+++ b/main.cpp Sun Apr 23 20:48:42 2017 +0000
@@ -2,22 +2,47 @@
#include "ble/BLE.h"
DigitalOut led(LED1, 1);
-uint16_t customServiceUUID = 0xA000;
+Serial pc(P0_0, P0_1);
+
+DigitalOut dSwitch(P0_4);
+
+PwmOut ledB(P0_5);
+PwmOut ledG(P0_6);
+PwmOut ledR(P0_7);
+
+uint16_t customServiceUUID = 0x1812;
+
uint16_t readCharUUID = 0xA001;
uint16_t writeCharUUID = 0xA002;
+uint16_t writeRedCharUUID = 0xA003;
+uint16_t writeGreenCharUUID = 0xA004;
-const static char DEVICE_NAME[] = "ChangeMe!!"; // change this
+
+const static char DEVICE_NAME[] = "GATT Example"; // change this
static const uint16_t uuid16_list[] = {0xFFFF}; //Custom UUID, FFFF is reserved for development
-/* Set Up custom Characteristics */
+
+
+/* Set Up custom Characteristics -----------------------------------------------------------------------------------------------------*/
static uint8_t readValue[10] = {0};
ReadOnlyArrayGattCharacteristic<uint8_t, sizeof(readValue)> readChar(readCharUUID, readValue);
static uint8_t writeValue[10] = {0};
WriteOnlyArrayGattCharacteristic<uint8_t, sizeof(writeValue)> writeChar(writeCharUUID, writeValue);
+//On construit un "WriteOnlyArrayGattCharacteristic" --> writeRedChar
+static uint8_t writeRedValue[10] = {0};
+WriteOnlyArrayGattCharacteristic<uint8_t, sizeof(writeRedValue)> writeRedChar(writeRedCharUUID, writeRedValue);
+
+static uint8_t writeGreenValue[10] = {0};
+WriteOnlyArrayGattCharacteristic<uint8_t, sizeof(writeGreenValue)> writeGreenChar(writeGreenCharUUID, writeGreenValue);
+
+
+/* ---------------------------------------------------------------------------------------------------------------------*/
+
+
/* Set up custom service */
-GattCharacteristic *characteristics[] = {&readChar, &writeChar};
+GattCharacteristic *characteristics[] = {&readChar, &writeChar, &writeRedChar, &writeGreenChar};
GattService customService(customServiceUUID, characteristics, sizeof(characteristics) / sizeof(GattCharacteristic *));
@@ -36,22 +61,33 @@
{
/* Check to see what characteristic was written, by handle */
if(params->handle == writeChar.getValueHandle()) {
- /* toggle LED if only 1 byte is written */
- if(params->len == 1) {
- led = params->data[0];
- (params->data[0] == 0x00) ? printf("led on\n\r") : printf("led off\n\r"); // print led toggle
- }
- /* Print the data if more than 1 byte is written */
- else {
- printf("Data received: length = %d, data = 0x",params->len);
- for(int x=0; x < params->len; x++) {
- printf("%x", params->data[x]);
- }
- printf("\n\r");
- }
+
+ float fPwm = (float) ( 100 - params->data[0] ) / 100.0;
+ pc.printf("fPwm --> %f\n", fPwm);
+ ledB.write(fPwm);
+
/* Update the readChar with the value of writeChar */
BLE::Instance(BLE::DEFAULT_INSTANCE).gattServer().write(readChar.getValueHandle(), params->data, params->len);
}
+ /* Check to see what characteristic was written, by handle */
+ else if(params->handle == writeRedChar.getValueHandle()) {
+
+ float fPwm = (float) ( 100 - params->data[0] ) / 100.0;
+ pc.printf("fPwm --> %f\n", fPwm);
+ ledR.write(fPwm);
+
+ if(fPwm >= 0.50)
+ dSwitch = true;
+ else
+ dSwitch = false;
+ }
+ /* Check to see what characteristic was written, by handle */
+ else if(params->handle == writeGreenChar.getValueHandle()) {
+
+ float fPwm = (float) ( 100 - params->data[0] ) / 100.0;
+ pc.printf("fPwm --> %f\n", fPwm);
+ ledG.write(fPwm);
+ }
}
/*
* Initialization callback
@@ -60,7 +96,7 @@
{
BLE &ble = params->ble;
ble_error_t error = params->error;
-
+
if (error != BLE_ERROR_NONE) {
return;
}
@@ -88,14 +124,22 @@
int main(void)
{
/* initialize stuff */
- printf("\n\r********* Starting Main Loop *********\n\r");
+ pc.printf("\n\r********* Starting Main Loop *********\n\r");
+
+ ledB = 1;
+ ledG = 1;
+ ledR = 1;
+ dSwitch = false;
+
BLE& ble = BLE::Instance(BLE::DEFAULT_INSTANCE);
ble.init(bleInitComplete);
-
+
/* SpinWait for initialization to complete. This is necessary because the
* BLE object is used in the main loop below. */
- while (ble.hasInitialized() == false) { /* spin loop */ }
+ while (ble.hasInitialized() == false) {
+ /* spin loop */
+ }
/* Infinite loop waiting for BLE interrupt events */
while (true) {
diff -r 406127954d1f -r d63b6764b95d mbed.bld --- a/mbed.bld Mon Nov 09 17:08:47 2015 +0000 +++ b/mbed.bld Sun Apr 23 20:48:42 2017 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/9296ab0bfc11 \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/093f2bd7b9eb \ No newline at end of file
diff -r 406127954d1f -r d63b6764b95d nRF51822.lib --- a/nRF51822.lib Mon Nov 09 17:08:47 2015 +0000 +++ b/nRF51822.lib Sun Apr 23 20:48:42 2017 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/teams/Nordic-Semiconductor/code/nRF51822/#bf85bf7e73d5 +http://mbed.org/teams/Nordic-Semiconductor/code/nRF51822/#c90ae1400bf2
