diff --git a/receiver/platformio.ini b/receiver/platformio.ini index d35cc8d..2a57617 100644 --- a/receiver/platformio.ini +++ b/receiver/platformio.ini @@ -27,3 +27,11 @@ build_flags = -D PIXELPIN=4 -D NUMPIXELS=600 -D CHANNEL=1 + + -D PIN_IN1=14 + -D PIN_IN2=13 + -D PIN_IN3=12 + -D PIN_IN4=11 + + -D DEBOUNCETIME_WIRED=10 + diff --git a/receiver/src/main.cpp b/receiver/src/main.cpp index 165d563..37cde0f 100644 --- a/receiver/src/main.cpp +++ b/receiver/src/main.cpp @@ -28,21 +28,31 @@ Adafruit_NeoPixel statuspixel(1, PIN_NEOPIXEL, NEO_GRB + NEO_KHZ800); USBHIDKeyboard Keyboard; #define NUM_CONTROLLERS 4 +#define NUM_CONTROLLERS_WIRED 4 uint32_t controllercolors[]={\ statuspixel.Color(255, 0,0),\ statuspixel.Color(0, 255,0),\ statuspixel.Color(0,0, 255),\ -statuspixel.Color(255, 255,0)\ +statuspixel.Color(255, 0,255)\ }; uint8_t keyassignments[NUM_CONTROLLERS][INPUT_SIZE]; +uint8_t keyassignmentsWired[NUM_CONTROLLERS_WIRED]; +bool in_last_wired[NUM_CONTROLLERS_WIRED]; + void setup() { Serial.begin(115200); - - + pinMode(PIN_IN1,INPUT_PULLUP); + pinMode(PIN_IN2,INPUT_PULLUP); + pinMode(PIN_IN3,INPUT_PULLUP); + pinMode(PIN_IN4,INPUT_PULLUP); + keyassignmentsWired[0]=HID_KEY_V; + keyassignmentsWired[1]=HID_KEY_B; + keyassignmentsWired[2]=HID_KEY_N; + keyassignmentsWired[3]=HID_KEY_M; keyassignments[0][KEY_LEFT]=HID_KEY_A; keyassignments[0][KEY_RIGHT]=HID_KEY_D; @@ -71,7 +81,6 @@ void setup() { keyassignments[3][KEY_DOWN]=HID_KEY_ARROW_DOWN; keyassignments[3][KEY_A]=HID_KEY_CONTROL_LEFT; keyassignments[3][KEY_B]=HID_KEY_SHIFT_LEFT; - initESPNOW(); @@ -115,6 +124,24 @@ void setup() { void loop() { unsigned long loopmillis=millis(); + bool in[NUM_CONTROLLERS_WIRED]; + in[0]=digitalRead(PIN_IN1); + in[1]=digitalRead(PIN_IN2); + in[2]=digitalRead(PIN_IN3); + in[3]=digitalRead(PIN_IN4); + static unsigned long last_in_time[NUM_CONTROLLERS_WIRED]; + + for (uint8_t i=0;i=DEBOUNCETIME_WIRED) { //changed? + if (!in[i]) { + Keyboard.pressRaw(keyassignmentsWired[i]); + }else{ + Keyboard.releaseRaw(keyassignmentsWired[i]); + } + last_in_time[i]=millis(); + } + in_last_wired[i]=in[i]; + } } @@ -132,10 +159,6 @@ void processCommand(struct_message espnowdata) { //espnow data from remote } - - - - if (espnowdata.action==PRESS){ statuspixel.setPixelColor(0, controllercolors[espnowdata.id]); //change status led when packet arrives Keyboard.pressRaw(keyassignments[espnowdata.id][espnowdata.input]);