V4 Updates from remote Repo

This commit is contained in:
JW
2021-11-25 17:27:39 +01:00
parent 438c8bcf66
commit e8471373a1
110 changed files with 9653 additions and 7169 deletions

View File

@ -1,8 +1,58 @@
#include "MicroBitConfig.h"
#include "ble/UUID.h"
#include "BLEHF2Service.h"
#include "MicroBitEvent.h"
//================================================================
#if MICROBIT_CODAL
//================================================================
const uint8_t BLEHF2Service::service_base_uuid[ 16] =
{ 0xb1,0x12,0x00,0x00,0x26,0x79,0x30,0xda,0xa2,0x6e,0x02,0x73,0xb6,0x04,0x38,0x49 };
const uint8_t BLEHF2Service::char_base_uuid[ 16] =
{ 0xb1,0x12,0x00,0x00,0x26,0x79,0x30,0xda,0xa2,0x6e,0x02,0x73,0xb6,0x04,0x38,0x4a };
const uint16_t BLEHF2Service::serviceUUID = 0xf5e6;
const uint16_t BLEHF2Service::charUUID[ mbbs_cIdxCOUNT] = { 0xf5e6 };
BLEHF2Service::BLEHF2Service(BLEDevice &_ble) :
ble(_ble)
{
// Initialise our characteristic values.
memset(&txCharacteristicMessage, 0, sizeof(txCharacteristicMessage));
// Register the base UUID and create the service.
RegisterBaseUUID( service_base_uuid);
CreateService( serviceUUID);
RegisterBaseUUID( char_base_uuid);
CreateCharacteristic( mbbs_cIdxMESSAGE, charUUID[ mbbs_cIdxMESSAGE],
(uint8_t *)&txCharacteristicMessage,
sizeof(txCharacteristicMessage), sizeof(txCharacteristicMessage),
microbit_propNOTIFY);
}
void BLEHF2Service::sendSerial(const char *data, int len, bool isError) {
if (getConnected())
{
int32_t sent = 0;
while(sent < len) {
int32_t n = min(BLEHF2_DATA_LENGTH, len - sent);
txCharacteristicMessage.command = (isError ? BLEHF2_FLAG_SERIAL_OUT : BLEHF2_FLAG_SERIAL_ERR) | n;
memcpy(&txCharacteristicMessage.data, data + sent, n);
notifyChrValue(mbbs_cIdxMESSAGE,(uint8_t *)&txCharacteristicMessage, sizeof(txCharacteristicMessage));
sent += n;
}
}
}
//================================================================
#else // MICROBIT_CODAL
//================================================================
#include "ble/UUID.h"
BLEHF2Service::BLEHF2Service(BLEDevice &_ble) :
ble(_ble)
{
@ -47,4 +97,8 @@ const uint8_t BLEHF2ServiceUUID[] = {
const uint8_t BLEHF2TxCharacteristicUUID[] = {
0xb1,0x12,0xf5,0xe6,0x26,0x79,0x30,0xda,0xa2,0x6e,0x02,0x73,0xb6,0x04,0x38,0x4a
};
};
//================================================================
#endif // MICROBIT_CODAL
//================================================================

View File

@ -2,7 +2,6 @@
#define BLE_HF2_SERVICE_H
#include "MicroBitConfig.h"
#include "ble/BLE.h"
#include "MicroBitThermometer.h"
#include "EventModel.h"
#include "pxt.h"
@ -22,6 +21,65 @@ struct BLEHF2Packet {
uint8_t data[BLEHF2_DATA_LENGTH];
};
//================================================================
#if MICROBIT_CODAL
//================================================================
#include "MicroBitBLEManager.h"
#include "MicroBitBLEService.h"
class BLEHF2Service : public MicroBitBLEService
{
public:
/**
* Constructor.
* Create a representation of the TemperatureService
* @param _ble The instance of a BLE device that we're running on.
*/
BLEHF2Service(BLEDevice &_ble);
/**
* Sends text
*/
void sendSerial(const char *data, int len, bool isError);
private:
// Bluetooth stack we're running on.
BLEDevice &ble;
// memory for buffers.
BLEHF2Packet txCharacteristicMessage;
// Index for each charactersitic in arrays of handles and UUIDs
typedef enum mbbs_cIdx
{
mbbs_cIdxMESSAGE,
mbbs_cIdxCOUNT
} mbbs_cIdx;
// UUIDs for our service and characteristics
static const uint8_t service_base_uuid[ 16];
static const uint8_t char_base_uuid[ 16];
static const uint16_t serviceUUID;
static const uint16_t charUUID[ mbbs_cIdxCOUNT];
// Data for each characteristic when they are held by Soft Device.
MicroBitBLEChar chars[ mbbs_cIdxCOUNT];
public:
int characteristicCount() { return mbbs_cIdxCOUNT; };
MicroBitBLEChar *characteristicPtr( int idx) { return &chars[ idx]; };
};
//================================================================
#else // MICROBIT_CODAL
//================================================================
#include "ble/BLE.h"
class BLEHF2Service
{
public:
@ -50,5 +108,8 @@ class BLEHF2Service
GattAttribute::Handle_t txCharacteristicHandle;
};
//================================================================
#endif // MICROBIT_CODAL
//================================================================
#endif
#endif

View File

@ -14,7 +14,7 @@ namespace bluetooth {
BLEHF2Service* pHF2 = NULL;
//%
void __log(String msg) {
void __log(int priority, String msg) {
if (NULL == pHF2)
pHF2 = new BLEHF2Service(*uBit.ble);
pHF2->sendSerial(msg->getUTF8Data(), msg->getUTF8Size(), false);
@ -125,19 +125,18 @@ namespace bluetooth {
startUartService();
int bytes = uart->rxBufferedSize();
auto buffer = mkBuffer(NULL, bytes);
auto res = buffer;
registerGCObj(buffer);
int read = uart->read(buffer->data, buffer->length);
// read failed
if (read < 0) {
decrRC(buffer);
return mkBuffer(NULL, 0);
res = mkBuffer(NULL, 0);
} else if (read != buffer->length) {
// could not fill the buffer
res = mkBuffer(buffer->data, read);
}
// could not fill the buffer
if (read != buffer->length) {
auto tmp = mkBuffer(buffer->data, read);
decrRC(buffer);
buffer = tmp;
}
return buffer;
unregisterGCObj(buffer);
return res;
}
/**
@ -184,6 +183,7 @@ namespace bluetooth {
//% blockId=eddystone_advertise_url block="bluetooth advertise url %url|with power %power|connectable %connectable"
//% parts=bluetooth weight=11 blockGap=8
//% help=bluetooth/advertise-url blockExternalInputs=1
//% hidden=1 deprecated=1
void advertiseUrl(String url, int power, bool connectable) {
#if CONFIG_ENABLED(MICROBIT_BLE_EDDYSTONE_URL)
power = min(MICROBIT_BLE_POWER_LEVELS-1, max(0, power));
@ -199,7 +199,7 @@ namespace bluetooth {
* @param power power level between 0 and 7, eg: 7
* @param connectable true to keep bluetooth connectable for other services, false otherwise.
*/
//% parts=bluetooth weight=12 advanced=true
//% parts=bluetooth weight=12 advanced=true deprecated=1
void advertiseUidBuffer(Buffer nsAndInstance, int power, bool connectable) {
#if CONFIG_ENABLED(MICROBIT_BLE_EDDYSTONE_UID)
auto buf = nsAndInstance;
@ -227,6 +227,7 @@ namespace bluetooth {
//% blockId=eddystone_stop_advertising block="bluetooth stop advertising"
//% parts=bluetooth weight=10
//% help=bluetooth/stop-advertising advanced=true
//% hidden=1 deprecated=1
void stopAdvertising() {
uBit.bleManager.stopAdvertising();
}

View File

@ -10,10 +10,10 @@ namespace bluetooth {
* Internal use
*/
//% shim=bluetooth::__log
export function __log(msg: string) {
export function __log(priority: number, msg: string) {
return;
}
console.addListener(function (msg) { __log(msg) });
console.addListener(function (_pri, msg) { __log(_pri, msg) });
/**
* Writes to the Bluetooth UART service buffer. From there the data is transmitted over Bluetooth to a connected device.
@ -78,6 +78,7 @@ namespace bluetooth {
//% blockId=eddystone_advertise_uid block="bluetooth advertise UID|namespace (bytes 6-9)%ns|instance (bytes 2-6)%instance|with power %power|connectable %connectable"
//% parts=bluetooth weight=12 blockGap=8
//% help=bluetooth/advertise-uid blockExternalInputs=1
//% hidden=1 deprecated=1
export function advertiseUid(ns: number, instance: number, power: number, connectable: boolean) {
const buf = pins.createBuffer(16);
buf.setNumber(NumberFormat.Int32BE, 6, ns);

View File

@ -10,12 +10,13 @@
"BLEHF2Service.h",
"BLEHF2Service.cpp"
],
"weight": 10,
"searchOnly": true,
"icon": "./static/packages/bluetooth/icon.png",
"public": true,
"dependencies": {
"core": "file:../core"
},
"disablesVariants": ["mbcodal"],
"yotta": {
"config": {
"microbit-dal": {
@ -29,7 +30,18 @@
"stack_size": 1280,
"gatt_table_size": "0x700"
}
}
},
"installedVersion": "vzlhfd"
}
},
"userConfigs": [
{
"description": "Disable Bluetooth Event Service",
"config": {
"microbit-dal": {
"bluetooth": {
"event_service": 0
}
}
}
}
]
}
}

View File

@ -109,7 +109,8 @@ declare namespace bluetooth {
*/
//% blockId=eddystone_advertise_url block="bluetooth advertise url %url|with power %power|connectable %connectable"
//% parts=bluetooth weight=11 blockGap=8
//% help=bluetooth/advertise-url blockExternalInputs=1 shim=bluetooth::advertiseUrl
//% help=bluetooth/advertise-url blockExternalInputs=1
//% hidden=1 deprecated=1 shim=bluetooth::advertiseUrl
function advertiseUrl(url: string, power: int32, connectable: boolean): void;
/**
@ -118,7 +119,7 @@ declare namespace bluetooth {
* @param power power level between 0 and 7, eg: 7
* @param connectable true to keep bluetooth connectable for other services, false otherwise.
*/
//% parts=bluetooth weight=12 advanced=true shim=bluetooth::advertiseUidBuffer
//% parts=bluetooth weight=12 advanced=true deprecated=1 shim=bluetooth::advertiseUidBuffer
function advertiseUidBuffer(nsAndInstance: Buffer, power: int32, connectable: boolean): void;
/**
@ -134,7 +135,8 @@ declare namespace bluetooth {
*/
//% blockId=eddystone_stop_advertising block="bluetooth stop advertising"
//% parts=bluetooth weight=10
//% help=bluetooth/stop-advertising advanced=true shim=bluetooth::stopAdvertising
//% help=bluetooth/stop-advertising advanced=true
//% hidden=1 deprecated=1 shim=bluetooth::stopAdvertising
function stopAdvertising(): void;
}