From 7e181318498bb97054770c5e4e3fa85d93fa6759 Mon Sep 17 00:00:00 2001 From: Joe Finney Date: Mon, 7 Sep 2015 17:09:17 +0100 Subject: [PATCH] microbit: Added MicroBitLEDService One of the standard services defiend with the Bluetooth SIG. Allows remote control of the LED matrix display over BLE. --- inc/MicroBit.h | 8 ++++---- inc/MicroBitConfig.h | 16 +++++++++++++++- source/CMakeLists.txt | 1 + source/MicroBit.cpp | 4 ++++ 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/inc/MicroBit.h b/inc/MicroBit.h index ca85a29..a1845e5 100644 --- a/inc/MicroBit.h +++ b/inc/MicroBit.h @@ -5,9 +5,6 @@ #include "MicroBitConfig.h" #include "MicroBitPanic.h" -#include "ble/BLE.h" -#include "ble/services/DeviceInformationService.h" - #include "ErrorNo.h" #include "MicroBitHeapAllocator.h" @@ -31,8 +28,11 @@ #include "MicroBitCompass.h" #include "MicroBitAccelerometer.h" +#include "ble/BLE.h" +#include "ble/services/DeviceInformationService.h" #include "MicroBitDFUService.h" #include "MicroBitEventService.h" +#include "MicroBitLEDService.h" #include "ExternalEvents.h" // MicroBit::flags values @@ -137,7 +137,7 @@ class MicroBit BLEDevice *ble; MicroBitDFUService *ble_firmware_update_service; MicroBitEventService *ble_event_service; - + MicroBitLEDService *ble_led_service; /** * Constructor. diff --git a/inc/MicroBitConfig.h b/inc/MicroBitConfig.h index 3ea8f74..27a5c42 100644 --- a/inc/MicroBitConfig.h +++ b/inc/MicroBitConfig.h @@ -136,9 +136,23 @@ // This enables the standard BLE device information service. // Set '1' to enable. #ifndef MICROBIT_BLE_DEVICE_INFORMATION_SERVICE -#define MICROBIT_BLE_DEVICE_INFORMATION_SERVICE 1 +#define MICROBIT_BLE_DEVICE_INFORMATION_SERVICE 0 #endif + +// Enable/Disable BLE Service: MicroBitLEDService +// This enables the control and the LED matrix display via BLE. +// Set '1' to enable. +#ifndef MICROBIT_BLE_LED_SERVICE +#define MICROBIT_BLE_LED_SERVICE 1 +#endif + + +// Defines the maximum length strong that can be written to the +// display over BLE. +#ifndef MICROBIT_BLE_MAXIMUM_SCROLLTEXT +#define MICROBIT_BLE_MAXIMUM_SCROLLTEXT 20 +#endif // // Accelerometer options // diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index c3edb67..e902b52 100755 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -28,6 +28,7 @@ set(YOTTA_AUTO_MICROBIT-DAL_CPP_FILES "MicroBitHeapAllocator.cpp" "ble-services/MicroBitDFUService.cpp" "ble-services/MicroBitEventService.cpp" + "ble-services/MicroBitLEDService.cpp" ) if (YOTTA_CFG_MICROBIT_CONFIGFILE) diff --git a/source/MicroBit.cpp b/source/MicroBit.cpp index ce3347e..2faec40 100644 --- a/source/MicroBit.cpp +++ b/source/MicroBit.cpp @@ -117,6 +117,10 @@ void MicroBit::init() ble_event_service = new MicroBitEventService(*ble); #endif +#if CONFIG_ENABLED(MICROBIT_BLE_LED_SERVICE) + ble_led_service = new MicroBitLEDService(*ble); +#endif + // Setup advertising. ble->accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE); ble->accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)MICROBIT_BLE_DEVICE_NAME, sizeof(MICROBIT_BLE_DEVICE_NAME));