Protonerd / FX-SaberOS

System code for Arduino based Lightsaber replicas for DIYino family boards
Creative Commons Zero v1.0 Universal
92 stars 42 forks source link

Suggestion for One Button menu modification - Gravity Config Menu #51

Closed DonSaber closed 4 years ago

DonSaber commented 6 years ago

I hope this is the proper place for a code mod proposal.

I was having hard times with the configuration menu on my saber wired with a single button. Mainly, I was not able to have a double click recognized by the board and configuring the saber was a real pain. Don't know the reason, perhaps i's due to the AV push button I'm using or perhaps it's just me.

So, I decided to modify the way the user interacts with the menu, removing the double click and integrating a kind of Gravity selection mode.

Reusing the code designed to identify the orientation of the saber in the color selection process for string blades, I modified the code to have the following behavior.

To get this behavior it's necessary to align the SD card with your switch. On different install layouts it's easy enough to move the functions to other orientations.

The code is modified for the following menu items (only in One Button mode): CS_VOLUME, CS_SOUNDFONT, CS_FLICKERTYPE, CS_MAINCOLOR, CS_CLASHCOLOR, CS_BLASTCOLOR, CS_SWINGSENSITIVITY.

Regarding the modifications to the code I did:

FX-SabersOS int8_t orientation = 0;

Buttons.cpp extern int8_t orientation;

ifdef COLOR_PROFILE

define COLORPROFILES_QUANTITY 14

(I'm showing the color selection routine only, but in the code all indicated menu items are modified in thew same way)

    if (ButtonActionType==SINGLE_CLICK){
  orientation = GravityVector();
      switch (orientation) {
        case (0): // switch oriz back
          NextConfigState();
          break;
        case (1):
          // action
          break;              
        case (2):
          // action
          break;              
        case (3):
          // action
          break;
        case (4): // switch down
          confParseValue(modification, 0, COLORPROFILES_QUANTITY - 1, -1*incrementSign);
          break;
        case (5): // switch up
          confParseValue(modification, 0, COLORPROFILES_QUANTITY - 1, incrementSign);
          break;
      }
        modification = value;
        getColorFix(modification);
    }

I also added the new variable COLORPROFILES_QUANTITY to the color profile selection routine, so it is easier to add or remove color profiles from the list without the need to modify the functions in other places of the code.

I'm attaching the modified files for review. Be kind, it's my first programming since ages and an absolute first with Arduino.

OneButtonGravityConfig.zip

Protonerd commented 6 years ago

This is great! I have been looking for such a solution for a long time now. It was very convenient to have 3 different possibilities to interact with the buttons (click, long press, double click), it opened up the way to include all the functions a saber with two buttons can do. But to be completely honest I'm also a bit uncertain as to whether the double click is a good idea. I would like to replace it completely with a different kind of interaction - let's call it like that - because it's as you rightly said a pain.

I did not consider the method you described although its implementation was lying there all the while. Good work!!!

Some other possibilities: