microbit: BUGFIX to MicroBtDFU Service
- Updates to UI handling to avoid starving out the processor. - Clears screen before entering DFU bootloader
This commit is contained in:
parent
122d885ee8
commit
6764c732ea
|
@ -92,6 +92,10 @@ class MicroBitDFUService
|
||||||
|
|
||||||
// Update BLE characteristic to release our flash code.
|
// Update BLE characteristic to release our flash code.
|
||||||
void releaseFlashCode();
|
void releaseFlashCode();
|
||||||
|
|
||||||
|
// Event handlers for button clicks.
|
||||||
|
void onButtonA(MicroBitEvent e);
|
||||||
|
void onButtonB(MicroBitEvent e);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -46,7 +46,7 @@ MicroBitDFUService::MicroBitDFUService(BLEDevice &_ble) :
|
||||||
microBitDFUServiceControlCharacteristicHandle = microBitDFUServiceControlCharacteristic.getValueHandle();
|
microBitDFUServiceControlCharacteristicHandle = microBitDFUServiceControlCharacteristic.getValueHandle();
|
||||||
microBitDFUServiceFlashCodeCharacteristicHandle = microBitDFUServiceFlashCodeCharacteristic.getValueHandle();
|
microBitDFUServiceFlashCodeCharacteristicHandle = microBitDFUServiceFlashCodeCharacteristic.getValueHandle();
|
||||||
|
|
||||||
ble.onDataWritten(this, &MicroBitDFUService::onDataWritten);
|
ble.gattServer().onDataWritten(this, &MicroBitDFUService::onDataWritten);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -88,54 +88,54 @@ int MicroBitDFUService::getName(char *name)
|
||||||
return MICROBIT_DFU_HISTOGRAM_WIDTH;
|
return MICROBIT_DFU_HISTOGRAM_WIDTH;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MicroBitDFUService::onButtonA(MicroBitEvent e)
|
||||||
|
{
|
||||||
|
if (flashCodeRequested)
|
||||||
|
{
|
||||||
|
releaseFlashCode();
|
||||||
|
uBit.display.scroll("");
|
||||||
|
showTick();
|
||||||
|
flashCodeRequested = false;
|
||||||
|
authenticated = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MicroBitDFUService::onButtonB(MicroBitEvent e)
|
||||||
|
{
|
||||||
|
uBit.display.scroll("VERSION: TODO");
|
||||||
|
showNameHistogram();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Begin the pairing process. Typically called when device is powered up with buttons held down.
|
* Begin the pairing process. Typically called when device is powered up with buttons held down.
|
||||||
* Scroll a description on the display, then displays the device ID code as a histogram on the matrix display.
|
* Scroll a description on the display, then displays the device ID code as a histogram on the matrix display.
|
||||||
*/
|
*/
|
||||||
void MicroBitDFUService::pair()
|
void MicroBitDFUService::pair()
|
||||||
{
|
{
|
||||||
ManagedString blueZoneString("BLUE ZONE...");
|
uBit.MessageBus.listen(MICROBIT_ID_BUTTON_A, MICROBIT_BUTTON_EVT_CLICK, this, &MicroBitDFUService::onButtonA);
|
||||||
ManagedString pairString("PAIR?");
|
uBit.MessageBus.listen(MICROBIT_ID_BUTTON_B, MICROBIT_BUTTON_EVT_CLICK, this, &MicroBitDFUService::onButtonB);
|
||||||
|
|
||||||
uBit.display.scroll(blueZoneString);
|
|
||||||
|
|
||||||
|
uBit.display.scroll("BLUE ZONE...");
|
||||||
showNameHistogram();
|
showNameHistogram();
|
||||||
|
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
for (int i=0; i<100; i++)
|
if (flashCodeRequested)
|
||||||
{
|
uBit.display.scroll("PAIR?");
|
||||||
if (flashCodeRequested)
|
|
||||||
{
|
|
||||||
uBit.display.scrollAsync(pairString);
|
|
||||||
for (int j=0; j<40; j++)
|
|
||||||
{
|
|
||||||
if (uBit.buttonA.isPressed())
|
|
||||||
{
|
|
||||||
i=100;
|
|
||||||
releaseFlashCode();
|
|
||||||
showTick();
|
|
||||||
flashCodeRequested = false;
|
|
||||||
authenticated = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
wait(0.1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
wait (0.1);
|
|
||||||
|
|
||||||
// If our peer disconnects, drop all state.
|
// If our peer disconnects, drop all state.
|
||||||
if ((authenticated || flashCodeRequested) && !ble.getGapState().connected)
|
if ((authenticated || flashCodeRequested) && !ble.getGapState().connected)
|
||||||
{
|
{
|
||||||
authenticated = false;
|
authenticated = false;
|
||||||
flashCodeRequested = false;
|
flashCodeRequested = false;
|
||||||
flashCode = 0x00;
|
flashCode = 0x00;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uBit.sleep(500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Callback. Invoked when any of our attributes are written via BLE.
|
* Callback. Invoked when any of our attributes are written via BLE.
|
||||||
*/
|
*/
|
||||||
|
@ -152,6 +152,9 @@ void MicroBitDFUService::onDataWritten(const GattWriteCallbackParams *params)
|
||||||
|
|
||||||
if (authenticated)
|
if (authenticated)
|
||||||
{
|
{
|
||||||
|
uBit.display.scroll("");
|
||||||
|
uBit.display.clear();
|
||||||
|
|
||||||
#if CONFIG_ENABLED(MICROBIT_DBG)
|
#if CONFIG_ENABLED(MICROBIT_DBG)
|
||||||
pc.printf(" ACTIVATING BOOTLOADER.\n");
|
pc.printf(" ACTIVATING BOOTLOADER.\n");
|
||||||
#endif
|
#endif
|
||||||
|
@ -161,6 +164,9 @@ void MicroBitDFUService::onDataWritten(const GattWriteCallbackParams *params)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MICROBIT_DFU_OPCODE_START_PAIR:
|
case MICROBIT_DFU_OPCODE_START_PAIR:
|
||||||
|
#if CONFIG_ENABLED(MICROBIT_DBG)
|
||||||
|
pc.printf(" PAIRING REQUESTED.\n");
|
||||||
|
#endif
|
||||||
flashCodeRequested = true;
|
flashCodeRequested = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue