pgaskin / NickelMenu

The easiest way to launch scripts, change settings, and run actions on Kobo e-readers.
https://pgaskin.net/NickelMenu
MIT License
590 stars 32 forks source link

Implement nickel_bluetooth action #152

Closed onatbas closed 11 months ago

onatbas commented 11 months ago

Implementation of a new action "nickel_bluetooth" to turn Bluetooth on and off via NickelMenu.

Available commands are: enable disable toggle

I've been testing/using this modified version of NickelMenu on my Clara 2E and It should be compatible with all Bluetooth devices.

This should address issue #142

Usage examples: menu_item :main :Bluetooth (enable) :nickel_bluetooth :enable menu_item :main :Bluetooth (disable) :nickel_bluetooth :disable menu_item :main :Bluetooth (toggle) :nickel_bluetooth :toggle

onatbas commented 11 months ago

Thanks. I identified a few problems with the internal Bluetooth driver: in certain conditions, the connection doesn't get established if BT is turned on and off too quickly. I added a few actions and parameters to this fix this and currently testing the changes. In addition to addressing your comments, I shall submit my changes by the end of today.

onatbas commented 11 months ago

I have completed my checks and happy with the current implementation of this feature. The //libnickel checks could probably go even earlier versions but, I haven’t had the chance to validate all versions. let me know if there are other changes, style adjustments I may have missed.

onatbas commented 11 months ago

I'm glad you like it. It's an old pattern called "bitmasking" or "bit flags." The method was going toward multiple booleans, and this pattern is intended for that problem.

It is indeed very simple as you quite rightly put it. Here's a sample from my Clara 2E. (Bluetooth device blinks when it's disconnected/scanning. When the blinking stops, it means connection established.)
https://github.com/pgaskin/NickelMenu/assets/714795/f6f404ee-7f92-45ad-90be-0bd51cd4ea35