работает в паре с micro:bit мигалкой

Dependencies:   mbed BLE_API nRF51822

Программа для управляющего устройства на nRF51822. Используется одна Button1 для включения\выключения светодиода на устройстве приемнике.

Revision:
13:7b6d69a11fb5
Parent:
12:1cd9fd69a4f4
Child:
14:e31da6a3279f
--- a/main.cpp	Sat Dec 14 07:01:45 2019 +0000
+++ b/main.cpp	Sat Dec 14 07:44:31 2019 +0000
@@ -20,6 +20,8 @@
 #include "ble/DiscoveredService.h"
 
 DigitalOut alivenessLED(LED1, 1);
+DigitalOut connectLED(P0_22, 0);
+
 Serial pc(USBTX, USBRX);
 
 bool                     triggerLedCharacteristic = false;
@@ -28,10 +30,12 @@
 BLE        ble;
 Ticker ticker;
 
+//событие по таймеру
 void periodicCallback(void) {
+//Мигаем светодиодом
     alivenessLED = !alivenessLED; /* Do blinky on LED1 while we're waiting for BLE events */
 }
-
+//результат сканирования
 void advertisementCallback(const Gap::AdvertisementCallbackParams_t *params) {
 /*    if (params->peerAddr[0] != 0x37) { // !ALERT! Alter this filter to suit your device.
         return;
@@ -42,7 +46,7 @@
 
     BLE::Instance().gap().connect(params->peerAddr, Gap::ADDR_TYPE_RANDOM_STATIC, NULL, NULL);
 }
-
+//поиск сервисов
 void serviceDiscoveryCallback(const DiscoveredService *service) {
     if (service->getUUID().shortOrLong() == UUID::UUID_TYPE_SHORT) {
         printf("S UUID-%x attrs[%u %u]\r\n", service->getUUID().getShortUUID(), service->getStartHandle(), service->getEndHandle());
@@ -55,7 +59,7 @@
         printf(" attrs[%u %u]\r\n", service->getStartHandle(), service->getEndHandle());
     }
 }
-
+//поиск характеристик и вывод инфы
 void characteristicDiscoveryCallback(const DiscoveredCharacteristic *characteristicP) {
     printf("  C UUID-%x valueAttr[%u] props[%x]\r\n", characteristicP->getUUID().getShortUUID(), characteristicP->getValueHandle(), (uint8_t)characteristicP->getProperties().broadcast());
     if (characteristicP->getUUID().getShortUUID() == 0xa001) { /* !ALERT! Alter this filter to suit your device. */
@@ -67,7 +71,7 @@
 void discoveryTerminationCallback(Gap::Handle_t connectionHandle) {
     printf("terminated SD for handle %u\r\n", connectionHandle);
 }
-
+//Действие при событии "onConnection"
 void connectionCallback(const Gap::ConnectionCallbackParams_t *params) {
     if (params->role == Gap::CENTRAL) {
         BLE::Instance().gattClient().onServiceDiscoveryTermination(discoveryTerminationCallback);
@@ -99,13 +103,9 @@
         printf("onDataWrite\r\n");
     }
 }
-/*
-void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params) {Gap::Handle_t handle, Gap::DisconnectionReason_t reason
-    printf("disconnected\r\n");
-}*/
 
+//Действие при событии "Disconnect"
 void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params) {
-//    BLE&        ble   = params->ble;
     printf("disconnected\r\n");
     pc.printf("Rescan\r\n");
     ble.gap().startScan(advertisementCallback);