lancaster-university / codal-microbit-v2

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

`isPressed()` returns false when button is pressed down while resetting the board #388

Open microbit-carlos opened 11 months ago

microbit-carlos commented 11 months ago

Simple program, on startup if Button A is pressed it displays the letter A, otherwise ?:

#include "MicroBit.h"

MicroBit uBit;

int main() {
    uBit.init();

    if (uBit.buttonA.isPressed()) {
        uBit.display.print('A');
    } else {
        uBit.display.print('?');
    }
    while (true) uBit.sleep(1000);
}

MICROBIT.hex.zip

microbit-carlos commented 11 months ago

With this provided codal.json file, the issue is resolved with MICROBIT_BLE_PAIRING_MODE=1, but breaks with MICROBIT_BLE_PAIRING_MODE=0.

{
    "target": {
        "name": "codal-microbit-v2",
        "url": "https://github.com/lancaster-university/codal-microbit-v2",
        "branch": "master",
        "type": "git"
    },
    "config":{
        "DEVICE_BLE": 1,
        "MICROBIT_BLE_ENABLED" : 0,
        "MICROBIT_BLE_PAIRING_MODE": 0
    }
}
microbit-carlos commented 11 months ago

With MICROBIT_BLE_PAIRING_MODE=0, adding uBit.sleep(100) before the uBit.buttonA.isPressed() (which happens in uBit.init() when pairing mode is enabled) seems to resolve the issue. 🤔