Julia DESMAZES / Mbed 2 deprecated Hexapode

Dependencies:   mbed BLE_API X_NUCLEO_IDB0XA1 MODSERIAL

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Sheald_BLE.cpp Source File

Sheald_BLE.cpp

00001 #include "Sheald_BLE.h" 
00002 #include "LOGGER.h"
00003 
00004 static Logger *Ordi = Logger::Instance();
00005 
00006 STM32_BLE::STM32_BLE()
00007 {
00008   char tmp[]= "BlueNRG_UART";
00009   DEVICE_NAME= tmp;
00010    c = 'A';
00011   connected = false;
00012   UpdatedEnabled = false;
00013  }
00014 /* Callback called when the device is disconnected */
00015 void STM32_BLE::disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason)
00016 {
00017   Ordi->log("Disconnected!\n\r");
00018   Ordi->log("Restarting the advertising process\n\r"); 
00019   ble.startAdvertising();
00020   connected = false;
00021 }
00022  
00023 /* Callback called when the device is connected */
00024 void STM32_BLE::connectionCallback(Gap::Handle_t handle, const Gap::ConnectionParams_t *reason)
00025 {
00026   Ordi->log("Connected ");
00027  
00028   connected = true;
00029 }
00030 
00031 /* Callback called when the client enables updates */
00032 void STM32_BLE::onUpdatesEnabled(uint16_t attributeHandle)
00033 {
00034   Ordi->log("**onUpdatesEnabled** ");
00035   UpdatedEnabled = true;
00036 }
00037  
00038 /* Callback called when the client disable updates */
00039 void STM32_BLE::onUpdatesDisabled(uint16_t attributeHandle)
00040 {
00041   Ordi->log("**onUpdatesDisabled** ");
00042   UpdatedEnabled = false;
00043 }
00044  
00045 /* Main */
00046 bool STM_32::init()
00047 {
00048   Ordi->log("Initialising ");
00049   ble.init();
00050 #if 1
00051 /* Set callback functions */
00052   ble.onDisconnection(disconnectionCallback);
00053   ble.onConnection(connectionCallback);
00054   ble.onUpdatesEnabled(onUpdatesEnabled);
00055   ble.onUpdatesDisabled(onUpdatesDisabled);
00056  
00057   DeviceInformationService deviceInfo(ble, "ST", "Nucleo", "SN1", "hw-rev1", "fw-rev1", "soft-rev1");
00058   /* setup advertising */
00059   ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED);
00060   ble.setAdvertisingType          (GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
00061     
00062   ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME            , (const uint8_t *)"BlueNRG_UART"          , sizeof("BlueNRG_UART") - 1);
00063   ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS, (const uint8_t *)UARTServiceUUID_reversed, sizeof(UARTServiceUUID_reversed));
00064   ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME             , (uint8_t *)DEVICE_NAME                   , sizeof(DEVICE_NAME));
00065  
00066   /* Start advertising */
00067   ble.setAdvertisingInterval(160);
00068   ble.startAdvertising();
00069  
00070   UARTService uartService(ble);
00071   uartServicePtr = &uartService;
00072  }
00073  /*void unchecked()
00074  {
00075   while (true) 
00076   {
00077     ble.waitForEvent();
00078         
00079     if(connected == true)
00080     {
00081       if ((user_button_pressed == true) && (UpdatedEnabled == true))
00082       {
00083         user_button_pressed = false;
00084         Ordi->log("Current Char: %c ",c);
00085         ble.updateCharacteristicValue(uartServicePtr->getRXCharacteristicHandle(), &c, 1);
00086                 
00087         c++;
00088                 
00089         if(c == ('Z'+1))
00090         {
00091           c = 'A';
00092         }
00093       }
00094     }
00095   }
00096 #else
00097   while (true) 
00098   {
00099     if (user_button_pressed == true)
00100     {
00101       user_button_pressed = false;
00102       Ordi->log("Current Char: %c ",c);
00103                 
00104       c++;
00105                 
00106       if(c == ('Z'+1))
00107       {
00108         c = 'A';
00109       }
00110     }
00111   }
00112 #endif
00113 }*/