lancaster-university / codal-microbit-v2

CODAL target for the micro:bit v2.x series of devices
MIT License
41 stars 50 forks source link

`MICROBIT_BLE_UTILITY_SERVICE_PAIRING` defaults for MakeCode & MicroPython #354

Closed microbit-carlos closed 3 months ago

microbit-carlos commented 11 months ago

For MakeCode:

For MicroPython:

If the data logging storage is empty, the utility service should be able to indicate that.

martinwork commented 11 months ago

Does this means the Data Logger extension needs to be modified to set both MICROBIT_BLE_UTILITY_SERVICE_PAIRING and MICROBIT_BLE_UTILITY_SERVICE to 1, maybe here: https://github.com/microsoft/pxt-microbit/blob/master/libs/datalogger/pxt.json#L11

    "microbit": {
        "config": {
            "MICROBIT_BLE_UTILITY_SERVICE": "1",
            "MICROBIT_BLE_UTILITY_SERVICE_PAIRING": "1"
        }
    },

Or should those definitions be added to the flashlog extension? https://github.com/microsoft/pxt-microbit/blob/master/libs/flashlog/pxt.json#L18

That should work because...

MICROBIT_BLE_UTILITY_SERVICE_PAIRING is checked when CONFIG_ENABLED(DEVICE_BLE) && CONFIG_ENABLED(MICROBIT_BLE_PAIRING_MODE) which is usually the case in MakeCode.

MICROBIT_BLE_UTILITY_SERVICE is checked when CONFIG_ENABLED(DEVICE_BLE) && CONFIG_ENABLED(MICROBIT_BLE_ENABLED) which is when the Bluetooth extension is included.

If the service should always be present when the Bluetooth extension is added, even if Data Logger is not, then perhaps the Bluetooth extension also needs to be modified to set both MICROBIT_BLE_UTILITY_SERVICE_PAIRING and MICROBIT_BLE_UTILITY_SERVICE to 1.

At the moment the CODAL service code is compiled when DEVICE_BLE is 1, like all other services. Do we need to wrap it in additional conditions, so it's only compiled when it might be used? https://github.com/lancaster-university/codal-microbit-v2/blob/master/source/bluetooth/MicroBitUtilityService.cpp#L31 https://github.com/lancaster-university/codal-microbit-v2/blob/master/inc/bluetooth/MicroBitUtilityService.h#L30

martinwork commented 11 months ago

These examples use Project Settings/Edit Settings As text to add the definitions to a Data Logger project in different ways.

It seems the first one doesn't work while the second does, but I'm not sure because MakeCode doesn't always adjust to changes (https://github.com/microsoft/pxt-microbit/issues/4378) unless I do something like switch between Radio and Bluetooth.

Each example has an additional extension cpptest that dumps the configs to serial.

https://makecode.microbit.org/_edXacK9CFKeR

    "microbit": {
        "config": {
            "MICROBIT_BLE_UTILITY_SERVICE": "1",
            "MICROBIT_BLE_UTILITY_SERVICE_PAIRING": "1"
        }
    }

https://makecode.microbit.org/_b2FMMwcY4e8E

    "yotta": {
        "config": {
            "MICROBIT_BLE_UTILITY_SERVICE": "1",
            "MICROBIT_BLE_UTILITY_SERVICE_PAIRING": "1"
        }
    }
microbit-carlos commented 8 months ago

Right now the MICROBIT_BLE_UTILITY_SERVICE and MICROBIT_BLE_UTILITY_SERVICE_PAIRING flags are disabled in CODAL by default.

For the next pxt release with the current CODAL we are enabling the MICROBIT_BLE_UTILITY_SERVICE and MICROBIT_BLE_UTILITY_SERVICE_PAIRING flags to the build, but only when the datalog extension is added. This is achieved via PR, pushed now to be able to have it out before a specific deadline:

This is way was done to avoid using the extra resources when datalogging is not used in MakeCode, which can be controlled via the presence of the datalog extension.

However we don't have a way to to determine if a CODAL user programme uses the feature until compile time, at which point it might be late to enable the flags for the rest of CODAL, like the pairing/bluetooth mode. So the default for CODAL should be to have the features turned on.

For MicroPython builds we can control the flag for the pairing/bluetooth mode in the codal.json file, so either default is fine.

microbit-carlos commented 4 months ago

Conclusion:

microbit-carlos commented 3 months ago

Change of plans 😓

Basically MakeCode guards agains the pxt core and an extension having different values for the config flags. Rather than request this feature to MakeCode let's change the approach to be able to complete this quickly.

So, we'll need to do the following:

As all CODAL related actions are done I'll close this as completed 🎉