lancaster-university / microbit-dal

http://lancaster-university.github.io/microbit-docs
Other
256 stars 130 forks source link

Pairing mode starts advertising and shows the tick before pairing info is saved to flash #414

Open microbit-sam opened 5 years ago

microbit-sam commented 5 years ago

340

In MicroBitBLEManager, bleDisconnectionCallback calls advertise() immediately but defers saving of the pairing info to the idle callback. The delay is only a few milliseconds, but seems to be long enough for a waiting client device to reconnect before the save to flash. I noticed this seemed to cause a problem when pairing with Windows and I understand this may be causing a problem with some Android clients.

securitySetupCompletedCallback sets the flags that trigger the LEDs tick and the disconnect-and-save sequence in the idle callback. If "PAIRING MODE!" has finished scrolling, the delay between tick and save is probably long enough for a user waiting for the tick to reset micro:bit before the pairing info is saved.

The disconnect-and-save idle callback is not created until "PAIRING MODE!" has finished scrolling. If a user or client device does not need to wait for the LEDs histogram or pairing code display, the client device may be informed that pairing has completed 6 seconds or more before the pairing info is saved.

microbit-sam commented 5 years ago

@martinwork tried to tag you as a review but couldn't!

martinwork commented 5 years ago

pairingComplete doesn't look right. I'm sorry - it looks like I have said something very similar "Looks good" before here: https://github.com/lancaster-university/microbit-dal/issues/340#issuecomment-441087587.

The tick or cross will show when MICROBIT_BLE_PAIR_COMPLETE is set. So the idea is to delay setting that for the success case until the info is saved in idleTick.

If I am following right, this PR just moves it down a line. I think pairingComplete needs to be like in this comment: https://github.com/lancaster-university/microbit-dal/issues/340#issuecomment-381731175

microbit-sam commented 5 years ago

You're right, looks like I didn't actually finish this one off. Thanks Martin