espruino / Espruino

The Espruino JavaScript interpreter - Official Repo
http://www.espruino.com/
Other
2.75k stars 739 forks source link

Add `getSecurityStatus().advertising` property #2337

Closed bobrippling closed 1 year ago

bobrippling commented 1 year ago

As mentioned in espruino/BangleApps#2608, this adds a advertising property to the object returned by NRF.getSecurityStatus(), allowing us to determine whether the chip is idle, advertising or connected.

bobrippling commented 1 year ago

I might've gone down totally the wrong path here with obtaining the BLE advertising status - I figure it's not related to a connection and so picked it up from the ble_advertising module, rather than modifying ble_conn_state, but let me know if there's a better way.

Also waiting on the github firmware builds, I suspect I might need a few ifdefs yet.

gfwilliams commented 1 year ago

Thanks - but I wouldn't change the NRF52 APIs themselves - Bangle.js uses the v15 API anyway.

What I'd intended was you use:

so just bleStatus&BLE_IS_ADVERTISING - no need for a special function.

bobrippling commented 1 year ago

Thanks, that's a much easier route - let me know if there's any other changes you'd prefer, I've popped in some typescript for the security status too

gfwilliams commented 1 year ago

Thanks! But would it be possible to put that code in jsble_get_security_status instead? That's where we set all the other fields, and it would avoid the duplication (although it would still have to be copied for NRF52/ESP32 I guess)

bobrippling commented 1 year ago

Ah yeah of course - I was thinking bleStatus belonged to libs/bluetooth/ and I wouldn't be able to include it from "down the chain" if you get me, but I hadn't looked to confirm where it was! Thanks again for your guidance

gfwilliams commented 1 year ago

Thanks for those changes - this looks great now!