switch support: 1st draft (not working for now)
This commit is contained in:
parent
fdb968f02c
commit
c3d9294019
1 changed files with 27 additions and 6 deletions
|
|
@ -6,8 +6,8 @@
|
||||||
|
|
||||||
// The thresholds are also dependent on SAMPLE_CACHE_LENGTH, if you
|
// The thresholds are also dependent on SAMPLE_CACHE_LENGTH, if you
|
||||||
// changed SAMPLE_CACHE_LENGTH, you should also adjust thresholds
|
// changed SAMPLE_CACHE_LENGTH, you should also adjust thresholds
|
||||||
#define HIT_THRES 1750
|
#define HIT_THRES 300
|
||||||
#define RESET_THRES 200
|
#define RESET_THRES 70
|
||||||
|
|
||||||
// Sampling period in μs, e.g., 500μs = 0.5ms = 2000Hz
|
// Sampling period in μs, e.g., 500μs = 0.5ms = 2000Hz
|
||||||
#define SAMPLING_PERIOD 500
|
#define SAMPLING_PERIOD 500
|
||||||
|
|
@ -36,10 +36,21 @@
|
||||||
#define R_DON_KEY 'j'
|
#define R_DON_KEY 'j'
|
||||||
#define R_KAT_KEY 'k'
|
#define R_KAT_KEY 'k'
|
||||||
|
|
||||||
|
// Switch controller output for each channel
|
||||||
|
#define L_DON_KEY_NS NSGAMEPAD_DPAD_RIGHT
|
||||||
|
#define L_KAT_KEY_NS NSButton_LeftTrigger
|
||||||
|
#define R_DON_KEY_NS NSButton_A
|
||||||
|
#define R_KAT_KEY_NS NSButton_RightTrigger
|
||||||
|
|
||||||
// Enable debug mode to view analog input values from the Serial
|
// Enable debug mode to view analog input values from the Serial
|
||||||
// Enabling this also disables the keyboard simulation
|
// Enabling this also disables the keyboard simulation
|
||||||
#define DEBUG 0
|
#define DEBUG 0
|
||||||
|
|
||||||
|
// 0 = keyboard; 1 = switch controller
|
||||||
|
#define controller_mode 1
|
||||||
|
|
||||||
|
#include "switch_ESP32.h"
|
||||||
|
NSGamepad Gamepad;
|
||||||
#include "USB.h"
|
#include "USB.h"
|
||||||
#include "USBHIDKeyboard.h"
|
#include "USBHIDKeyboard.h"
|
||||||
#include "cache.h"
|
#include "cache.h"
|
||||||
|
|
@ -56,6 +67,7 @@ unsigned long triggeredTime[CHANNELS];
|
||||||
const byte inPins[] = {L_DON_IN, L_KAT_IN, R_DON_IN, R_KAT_IN};
|
const byte inPins[] = {L_DON_IN, L_KAT_IN, R_DON_IN, R_KAT_IN};
|
||||||
const byte outPins[] = {L_DON_LED, L_KAT_LED, R_DON_LED, R_KAT_LED};
|
const byte outPins[] = {L_DON_LED, L_KAT_LED, R_DON_LED, R_KAT_LED};
|
||||||
const char outKeys[] = {L_DON_KEY, L_KAT_KEY, R_DON_KEY, R_KAT_KEY};
|
const char outKeys[] = {L_DON_KEY, L_KAT_KEY, R_DON_KEY, R_KAT_KEY};
|
||||||
|
const uint8_t outKeysNS[] = {L_DON_KEY_NS, L_KAT_KEY_NS, R_DON_KEY_NS, R_KAT_KEY_NS};
|
||||||
float sensitivities[] = {L_DON_SENS, L_KAT_SENS, R_DON_SENS, R_KAT_SENS};
|
float sensitivities[] = {L_DON_SENS, L_KAT_SENS, R_DON_SENS, R_KAT_SENS};
|
||||||
|
|
||||||
short maxIndex;
|
short maxIndex;
|
||||||
|
|
@ -76,7 +88,11 @@ void setup() {
|
||||||
maxPower = 0;
|
maxPower = 0;
|
||||||
lastTime = micros();
|
lastTime = micros();
|
||||||
#if !DEBUG
|
#if !DEBUG
|
||||||
|
if (controller_mode) {
|
||||||
|
Gamepad.begin();
|
||||||
|
} else {
|
||||||
Keyboard.begin();
|
Keyboard.begin();
|
||||||
|
}
|
||||||
USB.begin();
|
USB.begin();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
@ -109,7 +125,12 @@ void loop() {
|
||||||
triggered = true;
|
triggered = true;
|
||||||
digitalWrite(outPins[maxIndex], HIGH);
|
digitalWrite(outPins[maxIndex], HIGH);
|
||||||
#if !DEBUG
|
#if !DEBUG
|
||||||
|
if (controller_mode) {
|
||||||
|
Gamepad.press(outKeysNS[maxIndex]);
|
||||||
|
Gamepad.loop();
|
||||||
|
} else {
|
||||||
Keyboard.write(outKeys[maxIndex]);
|
Keyboard.write(outKeys[maxIndex]);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue