Skip to content

Commit

Permalink
20240612 more tilt (#44)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* 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 <[email protected]>

* Merge

* 20231111 merge (#20)

* Test combo (#19)

* test 12

* Proof of concept

* 1&2 buttons

* Separate Tilt Rotate

* Update doc

* Delete docs

* text

* Update cpp

* update cpp

---------

Co-authored-by: Brian S. Stephan <[email protected]>
Co-authored-by: ian <[email protected]>
Co-authored-by: TheTrain <[email protected]>
Co-authored-by: Luke Arntson <[email protected]>
  • Loading branch information
5 people authored Jun 24, 2024
1 parent 1a4c4c6 commit 3aa36c4
Show file tree
Hide file tree
Showing 9 changed files with 1,768 additions and 223 deletions.
152 changes: 133 additions & 19 deletions headers/addons/tilt.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,38 @@
#define TILT2_FACTOR_RIGHT_Y 65
#endif

#ifndef TILT3_FACTOR_LEFT_X
#define TILT3_FACTOR_LEFT_X 0
#endif

#ifndef TILT3_FACTOR_LEFT_Y
#define TILT3_FACTOR_LEFT_Y 0
#endif

#ifndef TILT3_FACTOR_RIGHT_X
#define TILT3_FACTOR_RIGHT_X 0
#endif

#ifndef TILT3_FACTOR_RIGHT_Y
#define TILT3_FACTOR_RIGHT_Y 0
#endif

#ifndef TILT4_FACTOR_LEFT_X
#define TILT4_FACTOR_LEFT_X 0
#endif

#ifndef TILT4_FACTOR_LEFT_Y
#define TILT4_FACTOR_LEFT_Y 0
#endif

#ifndef TILT4_FACTOR_RIGHT_X
#define TILT4_FACTOR_RIGHT_X 0
#endif

#ifndef TILT4_FACTOR_RIGHT_Y
#define TILT4_FACTOR_RIGHT_Y 0
#endif

#ifndef PIN_TILT_LEFT_ANALOG_UP
#define PIN_TILT_LEFT_ANALOG_UP -1
#endif
Expand Down Expand Up @@ -81,8 +113,68 @@
#define PIN_TILT_RIGHT_ANALOG_RIGHT -1
#endif

#ifndef TILT_SOCD_MODE
#define TILT_SOCD_MODE SOCD_MODE_NEUTRAL
#ifndef PIN_ROTATE_1
#define PIN_ROTATE_1 -1
#endif

#ifndef PIN_ROTATE_2
#define PIN_ROTATE_2 -1
#endif

#ifndef ROTATE1_FACTOR_LEFT
#define ROTATE1_FACTOR_LEFT 15
#endif

#ifndef ROTATE2_FACTOR_LEFT
#define ROTATE2_FACTOR_LEFT 345
#endif

#ifndef ROTATE3_FACTOR_LEFT
#define ROTATE3_FACTOR_LEFT 0
#endif

#ifndef ROTATE4_FACTOR_LEFT
#define ROTATE4_FACTOR_LEFT 0
#endif

#ifndef ROTATE1_FACTOR_RIGHT
#define ROTATE1_FACTOR_RIGHT 15
#endif

#ifndef ROTATE2_FACTOR_RIGHT
#define ROTATE2_FACTOR_RIGHT 345
#endif

#ifndef ROTATE3_FACTOR_RIGHT
#define ROTATE3_FACTOR_RIGHT 0
#endif

#ifndef ROTATE4_FACTOR_RIGHT
#define ROTATE4_FACTOR_RIGHT 0
#endif

#ifndef TILT_LEFT_SOCD_MODE
#define TILT_LEFT_SOCD_MODE SOCD_MODE_NEUTRAL
#endif

#ifndef TILT_RIGHT_SOCD_MODE
#define TILT_RIGHT_SOCD_MODE SOCD_MODE_NEUTRAL
#endif

#ifndef TILT_1_THEN_2_MODE
#define TILT_1_THEN_2_MODE DPAD_MODE_DIGITAL
#endif

#ifndef TILT_2_THEN_1_MODE
#define TILT_2_THEN_1_MODE DPAD_MODE_DIGITAL
#endif

#ifndef ROTATE_1_THEN_2_MODE
#define ROTATE_1_THEN_2_MODE DPAD_MODE_DIGITAL
#endif

#ifndef ROTATE_2_THEN_1_MODE
#define ROTATE_2_THEN_1_MODE DPAD_MODE_DIGITAL
#endif

// Tilt Module Name
Expand All @@ -91,34 +183,39 @@
class TiltInput : public GPAddon {
public:
virtual bool available();
virtual void setup(); // Tilt Setup
virtual void process(); // Tilt Process
virtual void setup(); // Tilt Setup
virtual void process(); // Tilt Process
virtual void preprocess(); // Tilt Pre-Process (Cheat)
virtual std::string name() { return TiltName; }
private:
void SOCDTiltClean(SOCDMode);
uint8_t SOCDCombine(SOCDMode, uint8_t);
uint8_t SOCDGamepadClean(uint8_t);
void debounce();
void SOCDTiltClean(SOCDMode, SOCDMode);
void OverrideGamepad(Gamepad*, uint8_t, uint8_t);
uint8_t tiltLeftState; // Tilt State
uint8_t tiltRightState; // Tilt Right Analog State
DpadDirection lastGPUD; // Gamepad Last Up-Down
DpadDirection lastGPLR; // Gamepad Last Left-Right
uint8_t tiltLeftState; // Tilt State
uint8_t tiltRightState; // Tilt Right Analog State
DpadDirection leftLastTiltUD; // Tilt Last Up-Down
DpadDirection leftLastTiltLR; // Gamepad Last Left-Right
DpadDirection rightLastTiltUD; // Tilt Last Up-Down
DpadDirection rightLastTiltLR; // Gamepad Last Left-Right
uint32_t dpadTime[4];
uint8_t pinTilt1;
uint8_t tilt1FactorLeftX;
uint8_t tilt1FactorLeftY;
uint8_t tilt1FactorRightX;
uint8_t tilt1FactorRightY;
uint8_t tilt1FactorLeftY;
uint8_t tilt1FactorRightX;
uint8_t tilt1FactorRightY;
uint8_t pinTilt2;
uint8_t tilt2FactorLeftX;
uint8_t tilt2FactorLeftY;
uint8_t tilt2FactorRightX;
uint8_t tilt2FactorRightY;
uint8_t tilt2FactorLeftX;
uint8_t tilt2FactorLeftY;
uint8_t tilt2FactorRightX;
uint8_t tilt2FactorRightY;
uint8_t tilt3FactorLeftX;
uint8_t tilt3FactorLeftY;
uint8_t tilt3FactorRightX;
uint8_t tilt3FactorRightY;
uint8_t tilt4FactorLeftX;
uint8_t tilt4FactorLeftY;
uint8_t tilt4FactorRightX;
uint8_t tilt4FactorRightY;
uint8_t pinTiltLeftAnalogDown;
uint8_t pinTiltLeftAnalogUp;
uint8_t pinTiltLeftAnalogLeft;
Expand All @@ -127,7 +224,24 @@ class TiltInput : public GPAddon {
uint8_t pinTiltRightAnalogUp;
uint8_t pinTiltRightAnalogLeft;
uint8_t pinTiltRightAnalogRight;
SOCDMode tiltSOCDMode;
uint8_t pinRotate1;
uint8_t pinRotate2;
uint16_t rotate1FactorLeft;
uint16_t rotate2FactorLeft;
uint16_t rotate3FactorLeft;
uint16_t rotate4FactorLeft;
uint16_t rotate1FactorRight;
uint16_t rotate2FactorRight;
uint16_t rotate3FactorRight;
uint16_t rotate4FactorRight;
SOCDMode tiltLeftSOCDMode;
SOCDMode tiltRightSOCDMode;
DpadMode tilt1Then2Mode;
DpadMode tilt2Then1Mode;
DpadMode rotate1Then2Mode;
DpadMode rotate2Then1Mode;
bool last1button;
bool last2button;
};

#endif // _Tilt_H
30 changes: 29 additions & 1 deletion proto/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ message TiltOptions
optional int32 tiltRightAnalogRightPin = 12;

optional SOCDMode tiltSOCDMode = 13;

optional int32 factorTilt1LeftX = 14;
optional int32 factorTilt1LeftY = 15;
optional int32 factorTilt1RightX = 16;
Expand All @@ -476,6 +476,34 @@ message TiltOptions
optional int32 factorTilt2LeftY = 19;
optional int32 factorTilt2RightX = 20;
optional int32 factorTilt2RightY = 21;
optional int32 factorTilt3LeftX = 22;
optional int32 factorTilt3LeftY = 23;
optional int32 factorTilt3RightX = 24;
optional int32 factorTilt3RightY = 25;
optional int32 factorTilt4LeftX = 26;
optional int32 factorTilt4LeftY = 27;
optional int32 factorTilt4RightX = 28;
optional int32 factorTilt4RightY = 29;

optional int32 rotate1Pin = 30;
optional int32 rotate2Pin = 31;

optional int32 factorRotate1Left = 32;
optional int32 factorRotate1Right = 33;
optional int32 factorRotate2Left = 34;
optional int32 factorRotate2Right = 35;
optional int32 factorRotate3Left = 36;
optional int32 factorRotate3Right = 37;
optional int32 factorRotate4Left = 38;
optional int32 factorRotate4Right = 39;

optional SOCDMode tiltLeftSOCDMode = 40;
optional SOCDMode tiltRightSOCDMode = 41;

optional DpadMode tilt1Then2Mode = 42;
optional DpadMode tilt2Then1Mode = 43;
optional DpadMode rotate1Then2Mode = 44;
optional DpadMode rotate2Then1Mode = 45;
}

message BuzzerOptions
Expand Down
Loading

0 comments on commit 3aa36c4

Please sign in to comment.