Browse Source

Switch saveState and restoreState signature to use pin_t type.
onekey:joystick : add a second axis, virtual and programmatically animated.

a-chol 6 years ago
parent
commit
1d8102183f

+ 1 - 1
keyboards/handwired/onekey/keymaps/joystick/config.h

@@ -1,3 +1,3 @@
 #pragma once
-#define JOYSTICK_AXES_COUNT 1
+#define JOYSTICK_AXES_COUNT 2
 #define JOYSTICK_BUTTON_COUNT 1

+ 15 - 1
keyboards/handwired/onekey/keymaps/joystick/keymap.c

@@ -2,10 +2,24 @@
 
 #include "joystick.h"
 
+#ifndef ADC_PIN
+#    define ADC_PIN F6
+#endif
+
 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
   LAYOUT( JS_BUTTON0 )
 };
+
+void matrix_scan_user() {
+  int16_t val = (((uint32_t)timer_read()%5000 - 2500) * 255) / 5000;
+  if (val != joystick_status.axes[1]) {
+    joystick_status.axes[1] = val;
+    joystick_status.status |= JS_UPDATED;
+  }
+}
+
 //joystick config
 joystick_config_t joystick_axes[JOYSTICK_AXES_COUNT] = {
-  [0] = JOYSTICK_AXIS_IN(A0, 0, 512, 1024)
+    [0] = JOYSTICK_AXIS_IN(ADC_PIN, 0, 512, 1023)
+  , [1] = JOYSTICK_AXIS_VIRTUAL
 };

+ 2 - 0
keyboards/handwired/onekey/promicro/config.h

@@ -21,3 +21,5 @@
 #define MATRIX_COL_PINS { F4 }
 #define MATRIX_ROW_PINS { F5 }
 #define UNUSED_PINS
+
+#define ADC_PIN F6

+ 2 - 0
keyboards/handwired/onekey/proton_c/config.h

@@ -28,3 +28,5 @@
 #define BACKLIGHT_PAL_MODE      2
 
 #define RGB_DI_PIN A1
+
+#define ADC_PIN A0

+ 2 - 0
quantum/joystick.h

@@ -8,6 +8,8 @@
 #    define JOYSTICK_AXES_COUNT 4
 #endif
 
+#include "quantum.h"
+
 #include <stdint.h>
 
 // configure on input_pin of the joystick_axes array entry to JS_VIRTUAL_AXIS