ArduSub custom motor control

Didn’t we conclude that the ‘held’ boolean was updated sometime while in the loop once the user releases the button? I don’t see why it would result in an infinite loop if that were the case.

Other uses of the ‘held’ boolean use if statements rather than while loops, so unless I understand exactly how to exit the while loop, I don’t have much to go by for creating a while loop just from looking at the other code.

neighbouring code are using the if statement logic, and going by what I am seeing for other switch statements, I can’t really make sense of how this works with the controller. For k_servo_1_min_toggle for example, when does ‘held’ update to the actions on the controller?

scenario i’m imagining:

  1. I press the button

1a) if i’m still holding button before entering, code enters Sub::handle_jsbutton_press with held as true
1b) if i’m no longer holding button before entering, code enters Sub::handle_jsbutton_press with held as false

  1. since i mapped servo1_min_toggle, code enters k_servo_1_min_toggle switch case with the ‘held’ value from 1a or 1b

that’s what I seem to understand from looking at these if statements… but then I ask myself, what would that toggle function do if the ‘held’ boolean came in as true? because it seems like it would do nothing… so maybe Sub::handle_jsbutton_press is actually called twice? once when i first press the button, then again when i release the button?

I don’t completely understand what is going on here for this case.