V4 updates for beta testing (#147)
* change simulator svg
* change radio image
* Remove google fonts cdn
* change color of 'advanced' button
* font fix
* font fix 2
* display fix
* change fullsceen simulator bg
* Continuous servo
* handle continuous state
* adding shims
* update rendering for continuous servos
* fixing sim
* fix sig
* typo
* fix sim
* bump pxt
* bump pxt
* rerun travis
* Input blocks revision
- add Button and Pin event types
- merge onPinPressed & onPinReleased in new onPinEvent function
- create new onButtonEvent function
* update input blocks in docs and tests
* remove device_pin_release block
* Hide DAL.x behind Enum
* bring back deprecated blocks, but hide them
* shims and locales files
* fix input.input. typing
* remove buildpr
* bump V3
* update simulator aspect ratio
* add Loudness Block
* revoke loudness block
* Adds soundLevel
To be replaced by pxt-common-packages when DAL is updated.
* Remove P0 & P3 from AnalogPin
* Fix Sound and replace AnalogPin.P0
* remove approved extensions
* V4 Updates from remote Repo
* locales
* add storage functions
* fix storage functions
* fix int/float values
* decrease decimal precision
* reorder blocks
* Update BLE Settings and Storage Blocks
* Fetch MicroBit changes up to v4.0.18
* Update timing for LED Matrix usage
* use 32kb ram (mini v2)
* resize gatt table
* Revert "use 32kb ram (mini v2)"
This reverts commit 4b15592f0f.
* fix missleading indentation
* add support for 32kb and 16kb ram
* only MIT extensions in preferredRepos
* remove extensions without MIT License file
* add updated extensions
* add extensions with MIT license
Co-authored-by: Juri <gitkraken@juriwolf.de>
Co-authored-by: Juri <info@juriwolf.de>
			
			
This commit is contained in:
		@@ -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
 | 
			
		||||
//================================================================
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -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();
 | 
			
		||||
    } 
 | 
			
		||||
 
 | 
			
		||||
@@ -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);
 | 
			
		||||
 
 | 
			
		||||
@@ -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,8 @@
 | 
			
		||||
                "stack_size": 1280,
 | 
			
		||||
                "gatt_table_size": "0x700"
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    },
 | 
			
		||||
    "installedVersion": "vzlhfd"
 | 
			
		||||
}
 | 
			
		||||
        },
 | 
			
		||||
        "userConfigs": [
 | 
			
		||||
        ]
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										8
									
								
								libs/bluetooth/shims.d.ts
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										8
									
								
								libs/bluetooth/shims.d.ts
									
									
									
									
										vendored
									
									
								
							@@ -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;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user