shithub: m8c

Download patch

ref: 79a0c686d8bad464feed10a9c45ae0ae2a1eeb07
parent: a6a0098d0d37998ace5b3df4b57cd842d4c3922f
author: Jonne Kokkonen <jonne.kokkonen@gmail.com>
date: Tue Nov 30 18:31:53 EST 2021

input.c cleanup

--- a/config.ini
+++ b/config.ini
@@ -32,8 +32,8 @@
 gamepad_opt=1
 gamepad_edit=0
 
-gamepad_analog_threshold=32766 ;the threshold for analog sticks to trigger cursor movement (range: 1-32767)
-gamepad_analog_invert=false ;invert up/down and left/right axis (true/false)
+gamepad_analog_threshold=32766 ;the threshold for analog sticks to trigger cursor movement (working values: 1-32766)
+gamepad_analog_invert=false ;NOT IMPLEMENTED YET: invert up/down and left/right axis (true/false)
 
 ; these need to be the decimal value of the controller axis
 ; you can use -1 if you do not wish to map the function to an analog axis
--- a/input.c
+++ b/input.c
@@ -33,6 +33,7 @@
 uint8_t keyjazz_base_octave = 2;
 
 static uint8_t keycode = 0; // value of the pressed key
+static int num_joysticks = 0;
 
 input_msg_s key = {normal, 0};
 
@@ -44,7 +45,7 @@
 // Opens available game controllers and returns the amount of opened controllers
 int initialize_game_controllers() {
 
-  int num_joysticks = SDL_NumJoysticks();
+  num_joysticks = SDL_NumJoysticks();
   int controller_index = 0;
 
   SDL_Log("Looking for game controllers\n");
@@ -223,33 +224,6 @@
   return key;
 }
 
-/*static input_msg_s handle_game_controller_buttons(SDL_Event *event,
-                                                  config_params_s *conf,
-                                                  uint8_t keyvalue) {
-  input_msg_s key = {normal, keyvalue};
-
-  if (event->cbutton.button == conf->gamepad_up) {
-    key.value |= key_up;
-  } else if (event->cbutton.button == conf->gamepad_left) {
-    key.value |= key_left;
-  } else if (event->cbutton.button == conf->gamepad_down) {
-    key.value |= key_down;
-  } else if (event->cbutton.button == conf->gamepad_right) {
-    key.value |= key_right;
-  } else if (event->cbutton.button == conf->gamepad_select) {
-    key.value |= key_select;
-  } else if (event->cbutton.button == conf->gamepad_start) {
-    key.value |= key_start;
-  } else if (event->cbutton.button == conf->gamepad_opt) {
-    key.value |= key_opt;
-  } else if (event->cbutton.button == conf->gamepad_edit) {
-    key.value |= key_edit;
-  } else {
-    key.value = 0;
-  }
-  return key;
-} */
-
 int axis_in_threshold(int axis_value, int threshold) {
   if (axis_value <= 0 - threshold || axis_value >= threshold) {
     return 1;
@@ -320,7 +294,7 @@
   int key = 0;
 
   // Cycle through every active game controller
-  for (int gc = 0; gc < SDL_NumJoysticks(); gc++) {
+  for (int gc = 0; gc < num_joysticks; gc++) {
     // Cycle through all M8 buttons
     for (int button = 0; button < (input_buttons_t)INPUT_MAX; button++) {
       // If the button is active, add the keycode to the variable containing
--