Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MICROBIT_BLE_UTILITY_SERVICE_PAIRING defaults for MakeCode & MicroPython #354

Closed
microbit-carlos opened this issue Jul 24, 2023 · 5 comments
Assignees
Labels
Milestone

Comments

@microbit-carlos
Copy link
Collaborator

microbit-carlos commented Jul 24, 2023

For MakeCode:

  • In a normal project with Radio:
    • Without the datalogging extension the utility service shouldn't be compiled at all
    • If datalogging extension is used, it should add the utility service to pairing mode only (not application mode, as BLE is not enabled)
  • When the BLE extension is added, without user needing to add any BLE blocks:
    • The utility service should always be added to pairing mode
    • The utility service should always be added to the application mode

For MicroPython:

  • The utility service should always be added to pairing mode

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

@martinwork
Copy link
Collaborator

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
Copy link
Collaborator

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 (microsoft/pxt-microbit#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
Copy link
Collaborator Author

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 microbit-carlos modified the milestones: v0.2.65, v0.2.66 Nov 14, 2023
@microbit-carlos microbit-carlos modified the milestones: v0.2.68, v0.2.67 Feb 27, 2024
@microbit-carlos
Copy link
Collaborator Author

Conclusion:

  • We need to set the CODAL default to ON, so that CODAL and MicroPython programmes can have it enabled without additional user action (as there issn't a way to automatically enable it if this feature is used by user code)

@microbit-carlos
Copy link
Collaborator Author

microbit-carlos commented Mar 27, 2024

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 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants