Third Party > Unsupported Builds

USB charge only mode

<< < (2/2)

while(E):
Sorry to necro this after YEARS... but this feature still doesn't freaking exist... and I was looking for this same functionality, and this post helped remind me I'm a damn software dev and I can accomplish this myself....

So for some background, this is a bitwise operation. You have a bitmask (USBPOWER_BTN_IGNORE) that simply holds the mas of the buttons to ignore in a binary format (0000 1100). Therefore you would ignore whatever buttons that set those two bits when pressed. The (& ~) operators simply mean, (~) get the oppposite (1111 0011), thus only listen for buttons we DONT want to ignore, and the (&) means let's take the returned bit status from button_status() and make sure one of the buttons matches what we're listening to with the inverse of USBPOWER_BTN_IGNORE.  To get more in-depth just look up bitmasks and bitwise operators. They're super useful and simple to understand.

That being said this line is different in current builds, it's now:

--- Code: ---if (detect)
   detect = button_status() & ~USBPOWER_BTN_IGNORE;
--- End code ---

which you can simply change to:

--- Code: ---if (detect)
   detect = !(button_status() & ~USBPOWER_BTN_IGNORE);
--- End code ---

I just compiled, and it worked perfectly. Plug in USB, nothing happens except charging. Plug in USB while holding button, and it goes into USB mode. Hope it helps somone :)

Navigation

[0] Message Index

[*] Previous page

Go to full version