Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

convert core GPIO pin mappings from button-to-pin to pin-to-action #504

Merged
merged 53 commits into from
Oct 27, 2023

Conversation

bsstephan
Copy link
Contributor

this changes the core board config and gamepad behavior to be that the settings/user configures what each pin does, rather than the old behavior which configures what pin each button is assigned to. this allows for the new configuration to have one canonical location for what each of the pins does, and removes the limitation that a button can only normally be activated by one pin --- now it is trivial to assign many pins to take the same action

"actions" are all button presses right now, but they may be other things in the future as this branch expands. this is just the core functionality and migration code for now, further changes (removing extra input addon, refactoring DDI, maybe refactoring the sliders, working the profiles into this scheme, etc.) to come

@bsstephan bsstephan changed the title WIP: convert core GPIO pin mappings from button2pin to pin2action WIP: convert core GPIO pin mappings from button-to-pin to pin-to-action Sep 6, 2023
@bsstephan bsstephan force-pushed the configuration-by-pins branch 2 times, most recently from cf8bf11 to 5a77cdd Compare September 19, 2023 04:15
@bsstephan bsstephan force-pushed the configuration-by-pins branch 2 times, most recently from 5bbed01 to 0839f45 Compare October 23, 2023 19:42
bsstephan and others added 24 commits October 23, 2023 16:09
this changes the core board config and gamepad behavior to be that the
settings/user configures what each pin does, rather than the old
behavior which configures what pin each button is assigned to. this
allows for the new configuration to have one canonical location for what
each of the pins does, and removes the limitation that a button can only
normally be activated by one pin --- now it is trivial to assign many
pins to take the same action

"actions" are all button presses right now, but they may be other things
in the future as this branch expands. this is just the core
functionality and migration code for now, further changes (removing
extra input addon, refactoring DDI, maybe refactoring the sliders,
working the profiles into this scheme, etc.) to come
motivation for this is the migration sets everything to NONE anyway, so
the 0 value isn't super important to us, and protobuf by convention
seems to use the lowest value as a default (e.g. in the python GUI
editor), so setting that to NONE is idiomatic in both cases
the rest of the DDI settings remain untouched, and the whole addon is
basically where it always was, this just allows for centralization in
the new GPIO mappings
ArduinoJson retains the reference to the string until write time, so it
was only actually publishing the value for pin29
there's not much left of the addon other than the config for what to do
when nothing is held, so, this is a great candidate for getting folded
into core
Pelsin and others added 5 commits October 23, 2023 19:29
@bsstephan bsstephan marked this pull request as ready for review October 25, 2023 19:28
@bsstephan bsstephan changed the title WIP: convert core GPIO pin mappings from button-to-pin to pin-to-action convert core GPIO pin mappings from button-to-pin to pin-to-action Oct 25, 2023
bsstephan and others added 16 commits October 25, 2023 14:42
this also removes the protobuf isValidPin(foo) check and replaces it
with a has_ + a nested check that it's between 0 and 29, so that if a
user set a button to -1, we don't fallback to the BoardConfig.h, which
would clobber their intentional unmapping
I believe that it would be possible, without this history, for someone
to unmap certain gpioMappings (or hotkeys) for intentional reasons and
then accidentally trigger a re-conversion of the old BoardConfig.h
values, meaning they could never unmap certain hotkeys or gpioMappings.
this bool avoids that by only running the migration code once ever

maybe it makes startup faster too, idk
Copy link
Contributor

@arntsonl arntsonl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So clean!!!

headers/addons/jslider.h Outdated Show resolved Hide resolved
src/addons/dualdirectional.cpp Outdated Show resolved Hide resolved
src/addons/jslider.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@arntsonl arntsonl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me!

@arntsonl arntsonl merged commit 6915370 into OpenStickCommunity:main Oct 27, 2023
62 checks passed
jack2game added a commit to jack2game/GP2040-CE that referenced this pull request Oct 29, 2023
…penStickCommunity#504) (#11)

* convert core GPIO pin mappings from button2pin to pin2action

this changes the core board config and gamepad behavior to be that the
settings/user configures what each pin does, rather than the old
behavior which configures what pin each button is assigned to. this
allows for the new configuration to have one canonical location for what
each of the pins does, and removes the limitation that a button can only
normally be activated by one pin --- now it is trivial to assign many
pins to take the same action

"actions" are all button presses right now, but they may be other things
in the future as this branch expands. this is just the core
functionality and migration code for now, further changes (removing
extra input addon, refactoring DDI, maybe refactoring the sliders,
working the profiles into this scheme, etc.) to come

* remove the extra button addon, it is unnecessary now

* unset deprecated pin mappings after migration

* unset the extra button addon pin after migration

* fix the processing of the aux state/Fn button

* renumber the non-managed pin enum entries

motivation for this is the migration sets everything to NONE anyway, so
the 0 value isn't super important to us, and protobuf by convention
seems to use the lowest value as a default (e.g. in the python GUI
editor), so setting that to NONE is idiomatic in both cases

* fix the unsetting of the extra input addon after migrating

* convert DDI pins to gpioMappings

the rest of the DDI settings remain untouched, and the whole addon is
basically where it always was, this just allows for centralization in
the new GPIO mappings

* add TODO for fixing the pin UI

* fix the checking of the DDI masks

* convert get/setPinMappings API to match refactor

* "hardcode" the writing of 30 pins to JSON

ArduinoJson retains the reference to the string until write time, so it
was only actually publishing the value for pin29

* convert the JS slider pins to the centralized config

there's not much left of the addon other than the config for what to do
when nothing is held, so, this is a great candidate for getting folded
into core

* rename default JS mode option for consistency w/SOCD slider

* preliminary SOCD slider port to gpioMappings

* correct JS slider migration to refer to proper config/defines

* correct SOCD slider migration by referring to proper settings

* Global pin state action example using zustand

* Export baseUrl

* Pin to action ui playground, using global state with zustand

* Hide som actions from dropdown. make the select disabled if action is set from board

* Add a form for semantics

* Add translation for labels, dynamic columns.

* Remove pin -> action PoC from playground

* Make savePins return promise

* Replace pin mapping with pin -> action

* Remove unused handler in usePinStore

* remove DDI pins from addon page, point at Pin Mapping page

* add more add-on pin usages to the UI

* flag miscellaneous addon pins as ASSIGNED in migration

* when saving addons/display pins in web config, mark them ASSIGNED

* don't allow profiles to touch RESERVED/ASSIGNED_TO_ADDON

this is partially a problem now (we shouldn't let a profile assign a pin
that is normally reserved or on a addon), and partially a problem in the
future (we shouldn't let a profile SET a pin to reserved/for an addon),
when the profiles are refactored to use gpio mappings

* Add better typing for usePinStore

* - Create a new Capture button component that is reusable for any input.
- Make new pin mapping handle labels for all input modes including swapTpShareLabels

* don't include ASSIGNED_TO_ADDON in getUsedPins

temporary measure as the addons' validation needs reworking to support
a response that includes their own pins

* don't allow setPinMappings to set/change addon/reserved pins

* addons API shouldn't refer to DDI pins anymore now that they're "core"

* remove unused API stuff from the dev server JSON

* DRY on the simple protobuf-or-boardconfig pin migrations

this also removes the protobuf isValidPin(foo) check and replaces it
with a has_ + a nested check that it's between 0 and 29, so that if a
user set a button to -1, we don't fallback to the BoardConfig.h, which
would clobber their intentional unmapping

* set ASSIGNED_TO_ADDON -> NONE if the new addon pin is invalid

* un-ASSIGNED_TO_ADDON the Dminus pins when unsetting the Dplus pins

* Remove double call on context

* Remove useState for selectedBoard as it's only set once

* Remove unused imports

* Remove setLoading on getPinMappings as this creates race conditions, remove log

* Map new pin actions to button mappings for profile settings

* Remove unused lodash import

* Remove export

* remove unused EXTRA_BUTTON_ENABLED define

* track when migrations have occurred

I believe that it would be possible, without this history, for someone
to unmap certain gpioMappings (or hotkeys) for intentional reasons and
then accidentally trigger a re-conversion of the old BoardConfig.h
values, meaning they could never unmap certain hotkeys or gpioMappings.
this bool avoids that by only running the migration code once ever

maybe it makes startup faster too, idk

* remove unnecessary save()s in slider addons

* define types for a pin and a gamepad mask

---------

Co-authored-by: Brian S. Stephan <bss@incorporeal.org>
Co-authored-by: ian <ian@vidales.se>
jack2game pushed a commit to jack2game/GP2040-CE that referenced this pull request Nov 1, 2023
…penStickCommunity#504)

* convert core GPIO pin mappings from button2pin to pin2action

this changes the core board config and gamepad behavior to be that the
settings/user configures what each pin does, rather than the old
behavior which configures what pin each button is assigned to. this
allows for the new configuration to have one canonical location for what
each of the pins does, and removes the limitation that a button can only
normally be activated by one pin --- now it is trivial to assign many
pins to take the same action

"actions" are all button presses right now, but they may be other things
in the future as this branch expands. this is just the core
functionality and migration code for now, further changes (removing
extra input addon, refactoring DDI, maybe refactoring the sliders,
working the profiles into this scheme, etc.) to come

* remove the extra button addon, it is unnecessary now

* unset deprecated pin mappings after migration

* unset the extra button addon pin after migration

* fix the processing of the aux state/Fn button

* renumber the non-managed pin enum entries

motivation for this is the migration sets everything to NONE anyway, so
the 0 value isn't super important to us, and protobuf by convention
seems to use the lowest value as a default (e.g. in the python GUI
editor), so setting that to NONE is idiomatic in both cases

* fix the unsetting of the extra input addon after migrating

* convert DDI pins to gpioMappings

the rest of the DDI settings remain untouched, and the whole addon is
basically where it always was, this just allows for centralization in
the new GPIO mappings

* add TODO for fixing the pin UI

* fix the checking of the DDI masks

* convert get/setPinMappings API to match refactor

* "hardcode" the writing of 30 pins to JSON

ArduinoJson retains the reference to the string until write time, so it
was only actually publishing the value for pin29

* convert the JS slider pins to the centralized config

there's not much left of the addon other than the config for what to do
when nothing is held, so, this is a great candidate for getting folded
into core

* rename default JS mode option for consistency w/SOCD slider

* preliminary SOCD slider port to gpioMappings

* correct JS slider migration to refer to proper config/defines

* correct SOCD slider migration by referring to proper settings

* Global pin state action example using zustand

* Export baseUrl

* Pin to action ui playground, using global state with zustand

* Hide som actions from dropdown. make the select disabled if action is set from board

* Add a form for semantics

* Add translation for labels, dynamic columns.

* Remove pin -> action PoC from playground

* Make savePins return promise

* Replace pin mapping with pin -> action

* Remove unused handler in usePinStore

* remove DDI pins from addon page, point at Pin Mapping page

* add more add-on pin usages to the UI

* flag miscellaneous addon pins as ASSIGNED in migration

* when saving addons/display pins in web config, mark them ASSIGNED

* don't allow profiles to touch RESERVED/ASSIGNED_TO_ADDON

this is partially a problem now (we shouldn't let a profile assign a pin
that is normally reserved or on a addon), and partially a problem in the
future (we shouldn't let a profile SET a pin to reserved/for an addon),
when the profiles are refactored to use gpio mappings

* Add better typing for usePinStore

* - Create a new Capture button component that is reusable for any input.
- Make new pin mapping handle labels for all input modes including swapTpShareLabels

* don't include ASSIGNED_TO_ADDON in getUsedPins

temporary measure as the addons' validation needs reworking to support
a response that includes their own pins

* don't allow setPinMappings to set/change addon/reserved pins

* addons API shouldn't refer to DDI pins anymore now that they're "core"

* remove unused API stuff from the dev server JSON

* DRY on the simple protobuf-or-boardconfig pin migrations

this also removes the protobuf isValidPin(foo) check and replaces it
with a has_ + a nested check that it's between 0 and 29, so that if a
user set a button to -1, we don't fallback to the BoardConfig.h, which
would clobber their intentional unmapping

* set ASSIGNED_TO_ADDON -> NONE if the new addon pin is invalid

* un-ASSIGNED_TO_ADDON the Dminus pins when unsetting the Dplus pins

* Remove double call on context

* Remove useState for selectedBoard as it's only set once

* Remove unused imports

* Remove setLoading on getPinMappings as this creates race conditions, remove log

* Map new pin actions to button mappings for profile settings

* Remove unused lodash import

* Remove export

* remove unused EXTRA_BUTTON_ENABLED define

* track when migrations have occurred

I believe that it would be possible, without this history, for someone
to unmap certain gpioMappings (or hotkeys) for intentional reasons and
then accidentally trigger a re-conversion of the old BoardConfig.h
values, meaning they could never unmap certain hotkeys or gpioMappings.
this bool avoids that by only running the migration code once ever

maybe it makes startup faster too, idk

* remove unnecessary save()s in slider addons

* define types for a pin and a gamepad mask

---------

Co-authored-by: ian <ian@vidales.se>
jack2game added a commit to jack2game/GP2040-CE that referenced this pull request Nov 2, 2023
* Add Rotate, update doc, separate SOCD for LS&RS

* Indentation

* Indentation

* convert core GPIO pin mappings from button-to-pin to pin-to-action (OpenStickCommunity#504)

* convert core GPIO pin mappings from button2pin to pin2action

this changes the core board config and gamepad behavior to be that the
settings/user configures what each pin does, rather than the old
behavior which configures what pin each button is assigned to. this
allows for the new configuration to have one canonical location for what
each of the pins does, and removes the limitation that a button can only
normally be activated by one pin --- now it is trivial to assign many
pins to take the same action

"actions" are all button presses right now, but they may be other things
in the future as this branch expands. this is just the core
functionality and migration code for now, further changes (removing
extra input addon, refactoring DDI, maybe refactoring the sliders,
working the profiles into this scheme, etc.) to come

* remove the extra button addon, it is unnecessary now

* unset deprecated pin mappings after migration

* unset the extra button addon pin after migration

* fix the processing of the aux state/Fn button

* renumber the non-managed pin enum entries

motivation for this is the migration sets everything to NONE anyway, so
the 0 value isn't super important to us, and protobuf by convention
seems to use the lowest value as a default (e.g. in the python GUI
editor), so setting that to NONE is idiomatic in both cases

* fix the unsetting of the extra input addon after migrating

* convert DDI pins to gpioMappings

the rest of the DDI settings remain untouched, and the whole addon is
basically where it always was, this just allows for centralization in
the new GPIO mappings

* add TODO for fixing the pin UI

* fix the checking of the DDI masks

* convert get/setPinMappings API to match refactor

* "hardcode" the writing of 30 pins to JSON

ArduinoJson retains the reference to the string until write time, so it
was only actually publishing the value for pin29

* convert the JS slider pins to the centralized config

there's not much left of the addon other than the config for what to do
when nothing is held, so, this is a great candidate for getting folded
into core

* rename default JS mode option for consistency w/SOCD slider

* preliminary SOCD slider port to gpioMappings

* correct JS slider migration to refer to proper config/defines

* correct SOCD slider migration by referring to proper settings

* Global pin state action example using zustand

* Export baseUrl

* Pin to action ui playground, using global state with zustand

* Hide som actions from dropdown. make the select disabled if action is set from board

* Add a form for semantics

* Add translation for labels, dynamic columns.

* Remove pin -> action PoC from playground

* Make savePins return promise

* Replace pin mapping with pin -> action

* Remove unused handler in usePinStore

* remove DDI pins from addon page, point at Pin Mapping page

* add more add-on pin usages to the UI

* flag miscellaneous addon pins as ASSIGNED in migration

* when saving addons/display pins in web config, mark them ASSIGNED

* don't allow profiles to touch RESERVED/ASSIGNED_TO_ADDON

this is partially a problem now (we shouldn't let a profile assign a pin
that is normally reserved or on a addon), and partially a problem in the
future (we shouldn't let a profile SET a pin to reserved/for an addon),
when the profiles are refactored to use gpio mappings

* Add better typing for usePinStore

* - Create a new Capture button component that is reusable for any input.
- Make new pin mapping handle labels for all input modes including swapTpShareLabels

* don't include ASSIGNED_TO_ADDON in getUsedPins

temporary measure as the addons' validation needs reworking to support
a response that includes their own pins

* don't allow setPinMappings to set/change addon/reserved pins

* addons API shouldn't refer to DDI pins anymore now that they're "core"

* remove unused API stuff from the dev server JSON

* DRY on the simple protobuf-or-boardconfig pin migrations

this also removes the protobuf isValidPin(foo) check and replaces it
with a has_ + a nested check that it's between 0 and 29, so that if a
user set a button to -1, we don't fallback to the BoardConfig.h, which
would clobber their intentional unmapping

* set ASSIGNED_TO_ADDON -> NONE if the new addon pin is invalid

* un-ASSIGNED_TO_ADDON the Dminus pins when unsetting the Dplus pins

* Remove double call on context

* Remove useState for selectedBoard as it's only set once

* Remove unused imports

* Remove setLoading on getPinMappings as this creates race conditions, remove log

* Map new pin actions to button mappings for profile settings

* Remove unused lodash import

* Remove export

* remove unused EXTRA_BUTTON_ENABLED define

* track when migrations have occurred

I believe that it would be possible, without this history, for someone
to unmap certain gpioMappings (or hotkeys) for intentional reasons and
then accidentally trigger a re-conversion of the old BoardConfig.h
values, meaning they could never unmap certain hotkeys or gpioMappings.
this bool avoids that by only running the migration code once ever

maybe it makes startup faster too, idk

* remove unnecessary save()s in slider addons

* define types for a pin and a gamepad mask

---------

Co-authored-by: ian <ian@vidales.se>

* Update with v0.7.5 latency testing (OpenStickCommunity#605)

Tests were done using Ferals optamized testing sketch found here:
https://github.com/FeralAI/usblag_optimized/blob/main/usblag_optimized.ino

* Input Macro Add-on Button labels (OpenStickCommunity#603)

* Fix for missing value in input macro add-on page

* - Allow capture button to not have any text if small prop
- Send one label for macro page
- Align button and inputs on macro page

---------

Co-authored-by: ian <ian@vidales.se>

---------

Co-authored-by: Brian S. Stephan <bss@incorporeal.org>
Co-authored-by: ian <ian@vidales.se>
Co-authored-by: TheTrain <32771064+TheTrainGoes@users.noreply.github.com>
Co-authored-by: Luke Arntson <arntsonl@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants