atctwo / bbrx

RC receiver controlled using Bluetooth gamepads
1 stars 1 forks source link

multiple button press to get one output #2

Closed NerdsCorp closed 3 weeks ago

NerdsCorp commented 1 month ago

I might be missing it or this might be a future thing, but is it possible to Hold one button down and then click another for the outcome to trigger?

I tried this below but I don't think its built in to the rest of the code. But it would be cool if this was added!

NerdsCorp commented 1 month ago

this would make it so you could free up main buttons and have "config/tuning" in a different layer thus creating more advanced Projects using this.

atctwo commented 1 month ago

I think i might have an idea of how to do this. What if each binding had an optional key called conditionals or something, which can either be an event or a list of events. The binding's action is only executed if all of the conditional events resolve as true. I think each event would be resolved by the same logic as boolean-input actions (like BB_ACTION_SPEED_DOWN), where it is true if the event value is greater than the halfway point between min and max. Because the main event and conditional events might have different ranges, I'll also add a conditional_min (default=0) and conditional_max (default=1).

For example, if you wanted to have speed control stuff gated behind the start button (like in your post) you could do something like this:

- action: BB_ACTION_SPEED_DOWN
  event: BB_EVENT_DPAD_DOWN
  conditionals: BB_EVENT_BTN_START
  min: 0
  max: 1

Another example, if you instead wanted to check that both analog sticks are pushed upwards (ie: Y axis > 0), you could do

- action: BB_ACTION_SPEED_DOWN
  event: BB_EVENT_DPAD_DOWN
  conditionals: [BB_EVENT_ANALOG_LY, BB_EVENT_ANALOG_RY]
  min: 0
  max: 1
  conditional_min: 0
  conditional_max: 511

At least I think this would work? What do you think?

NerdsCorp commented 1 month ago

I think that would make the code Clean and it would make it work. Using the conditionals would also allow for the feedback system that is in the #todo.md.

atctwo commented 1 month ago

hi, i've added this feature, and a little bit of documentation. try it out and let me know if it works!

NerdsCorp commented 4 weeks ago

So i did some testing, I tried it a few different ways i thought it would work but nothing. I only changed one, the very last on my config.yml. The way i understand it this config should have two states on and off, its assigned to x but you have to hold the brake, am i right? Im just using an led on that output pin to test.

Also my questions are from reading the Documents are... Do you have to have conditional min and max for them to work or is it alway 1 or 0, its not very clear... and what are possible limitations with conditionals.

Side note, maybe in the future could we clean up the debug codes, its a little hard to follow.

Heres the output of my serial.

23:22:44.867 -> Bluepad32 (C) 2016-2024 Ricardo Quesada and contributors. 23:22:44.867 -> Version: v4.1.0 23:22:44.867 -> BTstack: Copyright (C) 2017 BlueKitchen GmbH. 23:22:45.495 -> BTstack up and running at B0:B2:1C:F8:73:AE 23:22:47.016 -> [i] [main] 23:22:47.016 -> === bbrx! === 23:22:47.016 -> [i] [main] version: v1.1 23:22:47.016 -> [i] [main] build time: Sep 24 2024 23:04:39 23:22:47.016 -> [i] [main] 23:22:47.016 -> [i] [status] Setting up Status LED 23:22:47.016 -> [d] [status] 1 leds on pin 5, init brightness = 35 23:22:47.049 -> [d] [status] changed state to 1 23:22:47.049 -> [d] [status] setting led to 0 128 0, pulse period = 1000, pulse delay = 4, divider = 7, brightness = 35 23:22:47.049 -> [i] [config] Loading bbrx config file from LittleFS... 23:22:47.115 -> [d] [config] loading deadzones... 23:22:47.115 -> [d] [config] - ly = 40 23:22:47.115 -> [d] [config] - lx = 40 23:22:47.115 -> [d] [config] - ry = 40 23:22:47.115 -> [d] [config] - rx = 40 23:22:47.115 -> [d] [config] - brake = 64 23:22:47.115 -> [d] [config] - throttle = 64 23:22:47.148 -> [d] [config]  23:22:47.148 -> [d] [config] loading beefzones... 23:22:47.148 -> [d] [config] - ly = 500 23:22:47.148 -> [d] [config] - lx = 500 23:22:47.148 -> [d] [config] - ry = 500 23:22:47.148 -> [d] [config] - rx = 500 23:22:47.148 -> [d] [config] - brake = 1000 23:22:47.148 -> [d] [config] - throttle = 1000 23:22:47.148 -> [d] [config]  23:22:47.148 -> [d] [config] parsing binding 0 23:22:47.148 -> [d] [config] - action string BB_ACTION_SERVO 23:22:47.181 -> [d] [config] - action int 2 23:22:47.181 -> [d] [config] - action enum 2 23:22:47.181 -> [d] [config] - event string BB_EVENT_ANALOG_LY 23:22:47.181 -> [d] [config] - event int 1 23:22:47.181 -> [d] [config] - event enum 1 23:22:47.214 -> [d] [config] - min int -512 23:22:47.214 -> [d] [config] - max int 511 23:22:47.214 -> [d] [config] - missing or invalid default_value key 23:22:47.214 -> [d] [config] - pin int 36 23:22:47.214 -> [d] [config] - missing or invalid exec_without_controller key 23:22:47.214 -> [d] [config] - missing or invalid ignore_claims key 23:22:47.214 -> [d] [config] - missing or invalid conditionals key 23:22:47.214 -> [d] [config] - missing or invalid conditionals key 23:22:47.214 -> [d] [config] missing or invalid conditional_min key in binding 0 23:22:47.247 -> [d] [config] missing or invalid conditional_max key in binding 0 23:22:47.247 -> [d] [config] missing or invalid conditional_noexec key in binding 0 23:22:47.247 -> [d] [config] - adding binding 23:22:47.281 -> [d] [config]  23:22:47.281 -> [d] [config] parsing binding 1 23:22:47.281 -> [d] [config] - action string BB_ACTION_SERVO 23:22:47.281 -> [d] [config] - action int 2 23:22:47.281 -> [d] [config] - action enum 2 23:22:47.281 -> [d] [config] - event string BB_EVENT_ANALOG_LX 23:22:47.281 -> [d] [config] - event int 0 23:22:47.281 -> [d] [config] - event enum 0 23:22:47.281 -> [d] [config] - min int 511 23:22:47.281 -> [d] [config] - max int -512 23:22:47.281 -> [d] [config] - missing or invalid default_value key 23:22:47.314 -> [d] [config] - pin int 37 23:22:47.314 -> [d] [config] - missing or invalid exec_without_controller key 23:22:47.314 -> [d] [config] - missing or invalid ignore_claims key 23:22:47.314 -> [d] [config] - missing or invalid conditionals key 23:22:47.347 -> [d] [config] - missing or invalid conditionals key 23:22:47.347 -> [d] [config] missing or invalid conditional_min key in binding 1 23:22:47.347 -> [d] [config] missing or invalid conditional_max key in binding 1 23:22:47.347 -> [d] [config] missing or invalid conditional_noexec key in binding 1 23:22:47.347 -> [d] [config] - adding binding 23:22:47.347 -> [d] [config]  23:22:47.347 -> [d] [config] parsing binding 2 23:22:47.380 -> [d] [config] - action string BB_ACTION_SERVO 23:22:47.380 -> [d] [config] - action int 2 23:22:47.380 -> [d] [config] - action enum 2 23:22:47.380 -> [d] [config] - event string BB_EVENT_ANALOG_RY 23:22:47.380 -> [d] [config] - event int 3 23:22:47.413 -> [d] [config] - event enum 3 23:22:47.413 -> [d] [config] - min int -512 23:22:47.413 -> [d] [config] - max int 511 23:22:47.413 -> [d] [config] - missing or invalid default_value key 23:22:47.413 -> [d] [config] - pin int 38 23:22:47.413 -> [d] [config] - missing or invalid exec_without_controller key 23:22:47.413 -> [d] [config] - missing or invalid ignore_claims key 23:22:47.413 -> [d] [config] - missing or invalid conditionals key 23:22:47.413 -> [d] [config] - missing or invalid conditionals key 23:22:47.446 -> [d] [config] missing or invalid conditional_min key in binding 2 23:22:47.446 -> [d] [config] missing or invalid conditional_max key in binding 2 23:22:47.446 -> [d] [config] missing or invalid conditional_noexec key in binding 2 23:22:47.479 -> [d] [config] - adding binding 23:22:47.479 -> [d] [config]  23:22:47.479 -> [d] [config] parsing binding 3 23:22:47.479 -> [d] [config] - action string BB_ACTION_SERVO 23:22:47.479 -> [d] [config] - action int 2 23:22:47.479 -> [d] [config] - action enum 2 23:22:47.479 -> [d] [config] - event string BB_EVENT_ANALOG_RX 23:22:47.479 -> [d] [config] - event int 2 23:22:47.479 -> [d] [config] - event enum 2 23:22:47.479 -> [d] [config] - min int 511 23:22:47.512 -> [d] [config] - max int -512 23:22:47.512 -> [d] [config] - missing or invalid default_value key 23:22:47.512 -> [d] [config] - pin int 39 23:22:47.512 -> [d] [config] - missing or invalid exec_without_controller key 23:22:47.512 -> [d] [config] - missing or invalid ignore_claims key 23:22:47.545 -> [d] [config] - missing or invalid conditionals key 23:22:47.545 -> [d] [config] - missing or invalid conditionals key 23:22:47.545 -> [d] [config] missing or invalid conditional_min key in binding 3 23:22:47.545 -> [d] [config] missing or invalid conditional_max key in binding 3 23:22:47.545 -> [d] [config] missing or invalid conditional_noexec key in binding 3 23:22:47.545 -> [d] [config] - adding binding 23:22:47.545 -> [d] [config]  23:22:47.578 -> [d] [config] parsing binding 4 23:22:47.578 -> [d] [config] - action string BB_ACTION_SERVO 23:22:47.578 -> [d] [config] - action int 2 23:22:47.578 -> [d] [config] - action enum 2 23:22:47.578 -> [d] [config] - event string BB_EVENT_ANALOG_THROTTLE 23:22:47.611 -> [d] [config] - event int 5 23:22:47.611 -> [d] [config] - event enum 5 23:22:47.611 -> [d] [config] - min int 1023 23:22:47.611 -> [d] [config] - max int -1024 23:22:47.611 -> [d] [config] - missing or invalid default_value key 23:22:47.611 -> [d] [config] - pin int 34 23:22:47.611 -> [d] [config] - missing or invalid exec_without_controller key 23:22:47.611 -> [d] [config] - missing or invalid ignore_claims key 23:22:47.611 -> [d] [config] - missing or invalid conditionals key 23:22:47.644 -> [d] [config] - missing or invalid conditionals key 23:22:47.644 -> [d] [config] missing or invalid conditional_min key in binding 4 23:22:47.644 -> [d] [config] missing or invalid conditional_max key in binding 4 23:22:47.677 -> [d] [config] missing or invalid conditional_noexec key in binding 4 23:22:47.677 -> [d] [config] - adding binding 23:22:47.677 -> [d] [config]  23:22:47.677 -> [d] [config] parsing binding 5 23:22:47.677 -> [d] [config] - action string BB_ACTION_SERVO 23:22:47.677 -> [d] [config] - action int 2 23:22:47.677 -> [d] [config] - action enum 2 23:22:47.677 -> [d] [config] - event string BB_EVENT_ANALOG_BRAKE 23:22:47.677 -> [d] [config] - event int 4 23:22:47.677 -> [d] [config] - event enum 4 23:22:47.710 -> [d] [config] - min int 1023 23:22:47.710 -> [d] [config] - max int -1024 23:22:47.710 -> [d] [config] - missing or invalid default_value key 23:22:47.710 -> [d] [config] - pin int 35 23:22:47.710 -> [d] [config] - missing or invalid exec_without_controller key 23:22:47.743 -> [d] [config] - missing or invalid ignore_claims key 23:22:47.743 -> [d] [config] - missing or invalid conditionals key 23:22:47.743 -> [d] [config] - missing or invalid conditionals key 23:22:47.743 -> [d] [config] missing or invalid conditional_min key in binding 5 23:22:47.743 -> [d] [config] missing or invalid conditional_max key in binding 5 23:22:47.743 -> [d] [config] missing or invalid conditional_noexec key in binding 5 23:22:47.776 -> [d] [config] - adding binding 23:22:47.776 -> [d] [config]  23:22:47.776 -> [d] [config] parsing binding 6 23:22:47.776 -> [d] [config] - action string BB_ACTION_GPIO 23:22:47.776 -> [d] [config] - action int 7 23:22:47.809 -> [d] [config] - action enum 7 23:22:47.809 -> [d] [config] - event string BB_EVENT_BTN_B 23:22:47.809 -> [d] [config] - event int 17 23:22:47.809 -> [d] [config] - event enum 17 23:22:47.809 -> [d] [config] - min int 0 23:22:47.809 -> [d] [config] - max int 1 23:22:47.809 -> [d] [config] - missing or invalid default_value key 23:22:47.809 -> [d] [config] - pin int 2 23:22:47.809 -> [d] [config] - missing or invalid exec_without_controller key 23:22:47.809 -> [d] [config] - missing or invalid ignore_claims key 23:22:47.842 -> [d] [config] - missing or invalid conditionals key 23:22:47.842 -> [d] [config] - missing or invalid conditionals key 23:22:47.842 -> [d] [config] missing or invalid conditional_min key in binding 6 23:22:47.876 -> [d] [config] missing or invalid conditional_max key in binding 6 23:22:47.876 -> [d] [config] missing or invalid conditional_noexec key in binding 6 23:22:47.876 -> [d] [config] - adding binding 23:22:47.876 -> [d] [config]  23:22:47.876 -> [d] [config] parsing binding 7 23:22:47.876 -> [d] [config] - action string BB_ACTION_GPIO 23:22:47.876 -> [d] [config] - action int 7 23:22:47.876 -> [d] [config] - action enum 7 23:22:47.876 -> [d] [config] - event string BB_EVENT_BTN_Y 23:22:47.909 -> [d] [config] - event int 19 23:22:47.909 -> [d] [config] - event enum 19 23:22:47.909 -> [d] [config] - min int 0 23:22:47.909 -> [d] [config] - max int 1 23:22:47.909 -> [d] [config] - missing or invalid default_value key 23:22:47.909 -> [d] [config] - pin int 4 23:22:47.942 -> [d] [config] - missing or invalid exec_without_controller key 23:22:47.942 -> [d] [config] - missing or invalid ignore_claims key 23:22:47.942 -> [d] [config] - missing or invalid conditionals key 23:22:47.942 -> [d] [config] - missing or invalid conditionals key 23:22:47.942 -> [d] [config] missing or invalid conditional_min key in binding 7 23:22:47.942 -> [d] [config] missing or invalid conditional_max key in binding 7 23:22:47.942 -> [d] [config] missing or invalid conditional_noexec key in binding 7 23:22:47.975 -> [d] [config] - adding binding 23:22:47.975 -> [d] [config]  23:22:47.975 -> [d] [config] parsing binding 8 23:22:47.975 -> [d] [config] - action string BB_ACTION_GPIO 23:22:48.008 -> [d] [config] - action int 7 23:22:48.008 -> [d] [config] - action enum 7 23:22:48.008 -> [d] [config] - event string BB_EVENT_BTN_A 23:22:48.008 -> [d] [config] - event int 16 23:22:48.008 -> [d] [config] - event enum 16 23:22:48.008 -> [d] [config] - min int 0 23:22:48.008 -> [d] [config] - max int 1 23:22:48.008 -> [d] [config] - missing or invalid default_value key 23:22:48.008 -> [d] [config] - pin int 17 23:22:48.008 -> [d] [config] - missing or invalid exec_without_controller key 23:22:48.041 -> [d] [config] - missing or invalid ignore_claims key 23:22:48.041 -> [d] [config] - missing or invalid conditionals key 23:22:48.041 -> [d] [config] - missing or invalid conditionals key 23:22:48.041 -> [d] [config] missing or invalid conditional_min key in binding 8 23:22:48.074 -> [d] [config] missing or invalid conditional_max key in binding 8 23:22:48.074 -> [d] [config] missing or invalid conditional_noexec key in binding 8 23:22:48.074 -> [d] [config] - adding binding 23:22:48.074 -> [d] [config]  23:22:48.074 -> [d] [config] parsing binding 9 23:22:48.074 -> [d] [config] - action string BB_ACTION_GPIO 23:22:48.074 -> [d] [config] - action int 7 23:22:48.074 -> [d] [config] - action enum 7 23:22:48.074 -> [d] [config] - event string BB_EVENT_BTN_X 23:22:48.107 -> [d] [config] - event int 18 23:22:48.107 -> [d] [config] - event enum 18 23:22:48.107 -> [d] [config] - min int 0 23:22:48.107 -> [d] [config] - max int 1 23:22:48.107 -> [d] [config] - missing or invalid default_value key 23:22:48.140 -> [d] [config] - pin int 16 23:22:48.140 -> [d] [config] - missing or invalid exec_without_controller key 23:22:48.140 -> [d] [config] - missing or invalid ignore_claims key 23:22:48.140 -> [d] [config] - conditional event string BB_ACTION_BRAKE 23:22:48.140 -> [d] [config] - conditional event int -1 23:22:48.140 -> [w] [config] invalid event for conditionals key in binding 9 23:22:48.140 -> [d] [config] - missing or invalid conditionals key 23:22:48.140 -> [d] [config] - conditional_min int 0 23:22:48.173 -> [d] [config] - conditional_max int 1 23:22:48.173 -> [d] [config] missing or invalid conditional_noexec key in binding 9 23:22:48.173 -> [d] [config]  23:22:48.173 -> [i] [config] Loaded config from LittleFS! 23:22:48.206 -> [i] [controller] Setting up Bluepad32 23:22:48.206 -> [i] [controller] BP32 version: Bluepad32 for Arduino v4.1.0 23:22:48.206 -> [i] [controller] Listening for controllers... 23:22:48.206 -> [i] [events] Initialised binding 0: action=2, event=1, min=-512, max=511 23:22:48.206 -> [i] [events] Initialised binding 1: action=2, event=0, min=511, max=-512 23:22:48.206 -> [i] [events] Initialised binding 2: action=2, event=3, min=-512, max=511 23:22:48.206 -> [i] [events] Initialised binding 3: action=2, event=2, min=511, max=-512 23:22:48.239 -> [i] [events] Initialised binding 4: action=2, event=5, min=1023, max=-1024 23:22:48.239 -> [i] [events] Initialised binding 5: action=2, event=4, min=1023, max=-1024 23:22:48.239 -> [i] [events] Initialised binding 6: action=7, event=17, min=0, max=1 23:22:48.239 -> [i] [events] Initialised binding 7: action=7, event=19, min=0, max=1 23:22:48.272 -> [i] [events] Initialised binding 8: action=7, event=16, min=0, max=1 23:22:48.272 -> [d] [status] changed state to 2 23:22:48.272 -> [d] [status] setting led to 0 0 255, pulse period = 1000, pulse delay = 4, divider = 7, brightness = 35 23:22:48.272 -> [i] [main] Setup complete! 23:23:05.761 -> [i] [controller] Connected to a controller! 23:23:05.761 -> [i] [controller] - model: DualShock 4 23:23:05.761 -> [i] [controller] DS4: Failed to create virtual device 23:23:05.761 -> - battery: 0% 23:23:05.761 -> [d] [controller] BTAddr: 90:89:5f:aa:a5:b3, VID/PID: 054c:09cc, flags: 0x05 23:23:05.761 -> [d] [status] changed state to 3 23:23:05.761 -> [d] [status] setting led to 0 255 255, pulse period = -1, pulse delay = -1, divider = 7, brightness = 35 23:23:10.521 -> [d] [events] Action 2 on pin 34 claimed by binding 4 23:23:11.480 -> [d] [events] Action 7 on pin 17 claimed by binding 8 23:23:11.645 -> [d] [events] Action 7 on pin 17 unclaimed by binding 8 23:23:12.108 -> [d] [events] Action 2 on pin 34 unclaimed by binding 4 23:23:12.934 -> [d] [events] Action 7 on pin 17 claimed by binding 8 23:23:13.166 -> [d] [events] Action 7 on pin 17 unclaimed by binding 8 23:23:13.463 -> [d] [events] Action 7 on pin 17 claimed by binding 8 23:23:13.728 -> [d] [events] Action 7 on pin 17 unclaimed by binding 8 23:23:14.323 -> [d] [events] Action 7 on pin 17 claimed by binding 8 23:23:14.422 -> [d] [events] Action 7 on pin 17 unclaimed by binding 8 23:23:15.248 -> [d] [events] Action 7 on pin 17 claimed by binding 8 23:23:15.381 -> [d] [events] Action 7 on pin 17 unclaimed by binding 8 23:23:17.794 -> [d] [events] Action 2 on pin 34 claimed by binding 4 23:23:18.422 -> [d] [events] Action 2 on pin 34 unclaimed by binding 4 23:23:18.852 -> [d] [events] Action 2 on pin 34 claimed by binding 4 23:23:19.282 -> [d] [events] Action 2 on pin 34 unclaimed by binding 4 23:23:19.678 -> [d] [events] Action 2 on pin 34 claimed by binding 4 23:23:20.207 -> [d] [events] Action 7 on pin 17 claimed by binding 8 23:23:20.373 -> [d] [events] Action 7 on pin 17 unclaimed by binding 8 23:23:20.637 -> [d] [events] Action 7 on pin 17 claimed by binding 8 23:23:20.802 -> [d] [events] Action 7 on pin 17 unclaimed by binding 8 23:23:20.901 -> [d] [events] Action 2 on pin 34 unclaimed by binding 4

Heres My Config.yml

deadzones: ly: 40 lx: 40 ry: 40 rx: 40 brake: 64 throttle: 64

beefzones: ly: 500 lx: 500 ry: 500 rx: 500 brake: 1000 throttle: 1000

bindings:

NerdsCorp commented 4 weeks ago

Never mind its not an issue, when i moved it from the brake to a different button it worked great. ( may put this in the Notes)= conditionals cannot be a analog option on the controller.

also I have verified "sticky Keys" does not work, and we should add a easy Is sticky in the config.yml like below. I think if its needed it can be turned on otherwise it off to eliminate Nooby Confusion.

action: BB_ACTION_GPIO event: BB_EVENT_BTN_A min: 0 max: 1 is_sticky: true or false pin: 17

atctwo commented 4 weeks ago

thanks for trying it out!

I hope this clears it up!

NerdsCorp commented 3 weeks ago

yes this explanation helps a lot! thanks!