ramapcsx2 / gbs-control

GNU General Public License v3.0
784 stars 110 forks source link

Preset Select with Hardware Switch #337

Open ILAHWWINC opened 2 years ago

ILAHWWINC commented 2 years ago

3 years ago rama send me a code fragment to put in the sourcecode. The result was the possibility to change between Preset 1 and Preset 2 with a hardware switch. Will it be possible to do the same with the actual code?

https://github.com/ramapcsx2/gbs-control/issues/66

jsteel44 commented 2 years ago

I just found that old post and adapted it to work with the latest code. This works for me, I'm no expert but the preset gets applied only when I flick the switch so I think it's a good place for it, I only had to change preset 1 and 2 to A and B, otherwise it's identical to what we suggested before:

--- a/gbs-control.ino
+++ b/gbs-control.ino
@@ -6789,6 +6789,29 @@ void runSyncWatcher()
     SerialM.println();
     goLowPowerWithInputDetection(); // does not further nest, so it can be called here // sets reset parameters
   }
+
+  static const int switchPin = 13;
+  pinMode(switchPin, INPUT_PULLUP);
+  static uint8_t oldSwitchState = 1;
+  int switchState = 1;
+  if (detectedVideoMode > 0) {
+    switchState = digitalRead(switchPin);
+
+    if (switchState != oldSwitchState) {
+      //uopt->presetPreference = 5;
+      if (switchState == 1) {
+        SerialM.println("slot A");
+        uopt->presetSlot = 'A';
+      }
+      else if (switchState == 0) {
+        SerialM.println("slot B");
+        uopt->presetSlot = 'B';
+      }
+      saveUserPrefs();
+      applyPresets(detectedVideoMode);
+    }
+    oldSwitchState = switchState;
+  }
 }

 boolean checkBoardPower()

Just apply with $ patch -N -i switch.patch. I thought I would just have to wire to 3.3v on one side of the switch, but it wasn't working (nothing seemed to happen at all) until I wired the other side to ground, so now the switch toggles D7 between 3.3v and ground and it works as expected.

[edit] Actually I did comment out the presetPreference bit there as I think that's to do with changing the resolution, but I just want the resolution that's saved in the preset, or what was selected last time if that isn't a preset setting [/edit]

israpps commented 1 year ago

interesting idea, any one has diagrams of how to connect the board buttons?

israpps commented 1 year ago

what about the handleButtons() and all the code stored inside HAVE_BUTTONS macro?

When i get more confident on this one i Might make a modification to make the down and up buttons traverse the preset array.

And maybe a Pull request?

israpps commented 1 year ago

I made this crap https://github.com/israpps/gbs-control/tree/preset-traverse-button Any of you thinks it will work??

I've seen the oled code uses chars from A to G to pick presets.

Not sure if i should do the same