translateAxis only when required, add debug to esp32-n64-bt but too unreliable to use
This commit is contained in:
parent
cb663f2df3
commit
eaf0c1bd41
|
@ -27,3 +27,5 @@ Code and/or inspiration was (or will be) taken from these places, in no particul
|
|||
* [dreamcast_usb](https://github.com/raphnet/dreamcast_usb)
|
||||
* [SNES-NRF24](https://github.com/baldengineer/SNES-NRF24)
|
||||
* https://github.com/NicoHood/Nintendo
|
||||
* https://github.com/darthcloud/BlueRetro
|
||||
* https://github.com/raphnet/gc_n64_usb-v3
|
||||
|
|
59
src/N64.cpp
59
src/N64.cpp
|
@ -4,14 +4,33 @@
|
|||
//#define PRINT_Y_AXIS_VALUES 1
|
||||
//#define PRINT_X_AXIS_VALUES 1
|
||||
//#define PLOT_CONSOLE_POLLING 1
|
||||
#define DEBUG
|
||||
|
||||
#ifndef GAMEPAD_COUNT
|
||||
#define GAMEPAD_COUNT 1
|
||||
#endif
|
||||
|
||||
#define AXIS_CENTER_IN 0
|
||||
#define AXIS_MAX_IN 60
|
||||
#define AXIS_MIN_IN -60
|
||||
|
||||
#include "gamepad/Gamepad.h"
|
||||
#include "util.cpp"
|
||||
|
||||
/*
|
||||
LOOKING AT THE PLUG
|
||||
/---------\
|
||||
PIN 1-> / o o o \
|
||||
/-------------\
|
||||
|
||||
|
||||
PIN # USAGE
|
||||
|
||||
GND
|
||||
DATA
|
||||
VCC +3.3V ONLY
|
||||
*/
|
||||
|
||||
#define DATA_PIN 13
|
||||
|
||||
#define LINE_WRITE_HIGH pinMode(DATA_PIN, INPUT_PULLUP)
|
||||
|
@ -263,7 +282,9 @@ void updateOffsetsAndResolution() {
|
|||
ControllerData controller;
|
||||
|
||||
void setup() {
|
||||
#ifdef DEBUG
|
||||
Serial.begin(115200);
|
||||
#endif
|
||||
|
||||
gamepad.begin();
|
||||
|
||||
|
@ -286,7 +307,7 @@ void setup() {
|
|||
}
|
||||
|
||||
void loop() {
|
||||
Serial.println("sending command to n64");
|
||||
//Serial.println("sending command to n64");
|
||||
// send command 0x01 to n64 controller
|
||||
sendCommand(0x01);
|
||||
|
||||
|
@ -317,19 +338,41 @@ void loop() {
|
|||
}
|
||||
auto hat = calculateDpadDirection(controller.DPadUp, controller.DPadDown, controller.DPadLeft, controller.DPadRight);
|
||||
auto cHat = dpadToAxis(calculateDpadDirection(controller.CUp, controller.CDown, controller.CLeft, controller.CRight));
|
||||
// todo: need to scale max/min to our max/min
|
||||
gamepad.setAxis(c, controller.xAxis, controller.yAxis, cHat.x, cHat.y, 0, 0, hat);
|
||||
gamepad.setAxis(c, translateAxis(controller.xAxis), translateAxis(controller.yAxis), cHat.x, cHat.y, 0, 0, hat);
|
||||
|
||||
// polling must not occur faster than every 20 ms
|
||||
delay(14);
|
||||
|
||||
//checkUpdateCombo(&controller);
|
||||
|
||||
//Serial.printf("DPAD: %i %i %i %i \n", controller.DPadUp, controller.DPadDown, controller.DPadLeft, controller.DPadRight);
|
||||
//Serial.printf("C: %i %i %i %i \n", controller.CUp, controller.CDown, controller.CLeft, controller.CRight);
|
||||
//Serial.printf("Y: %i X: %i\n", controller.yAxis, controller.xAxis);
|
||||
//Serial.print("C: ");
|
||||
//Serial.println(controller.CUp);
|
||||
#ifdef DEBUG
|
||||
Serial.print("buttons: ");
|
||||
Serial.print(controller.buttonA ? "A" : "-");
|
||||
Serial.print(controller.buttonB ? "B" : "-");
|
||||
Serial.print(controller.buttonZ ? "Z" : "-");
|
||||
Serial.print(controller.buttonL ? "L" : "-");
|
||||
Serial.print(controller.buttonR ? "R" : "-");
|
||||
Serial.print(controller.buttonStart ? "S" : "-");
|
||||
Serial.print(" DPAD: ");
|
||||
Serial.print(controller.DPadUp ? "U" : "-");
|
||||
Serial.print(controller.DPadDown ? "D" : "-");
|
||||
Serial.print(controller.DPadLeft ? "L" : "-");
|
||||
Serial.print(controller.DPadRight ? "R" : "-");
|
||||
Serial.print(" C: ");
|
||||
Serial.print(controller.CUp ? "U" : "-");
|
||||
Serial.print(controller.CDown ? "D" : "-");
|
||||
Serial.print(controller.CLeft ? "L" : "-");
|
||||
Serial.print(controller.CRight ? "R" : "-");
|
||||
Serial.print(" Y: ");
|
||||
Serial.print(controller.yAxis);
|
||||
Serial.print(" YT: ");
|
||||
Serial.print(translateAxis(controller.yAxis));
|
||||
Serial.print(" X: ");
|
||||
Serial.print(controller.xAxis);
|
||||
Serial.print(" XT: ");
|
||||
Serial.print(translateAxis(controller.xAxis));
|
||||
Serial.println();
|
||||
#endif
|
||||
|
||||
//delay(500);
|
||||
}
|
||||
|
|
|
@ -51,9 +51,14 @@ PIN # USAGE
|
|||
|
||||
#define JOYSTICK_STATE_SIZE 6
|
||||
|
||||
#define AXIS_CENTER_IN 128
|
||||
#define AXIS_MAX_IN 255
|
||||
#define AXIS_MIN_IN 0
|
||||
|
||||
//#define DEBUG
|
||||
|
||||
#include "gamepad/Gamepad.h"
|
||||
#include "util.cpp"
|
||||
|
||||
GAMEPAD_CLASS gamepad;
|
||||
|
||||
|
@ -180,12 +185,6 @@ class Joystick_ {
|
|||
}
|
||||
}
|
||||
|
||||
int16_t translateAxis(uint8_t v) {
|
||||
//map(value, fromLow, fromHigh, toLow, toHigh)
|
||||
// todo: don't map at all if translation isn't required...
|
||||
return v == 128 ? AXIS_CENTER : map(v, 0, 255, AXIS_MIN, AXIS_MAX);
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
void printBin(uint8_t c) {
|
||||
//Serial.print(c);
|
||||
|
|
|
@ -83,6 +83,16 @@
|
|||
#define DPAD_CENTERED DPAD_CENTER
|
||||
// end aliases
|
||||
|
||||
#ifndef AXIS_CENTER_IN
|
||||
#define AXIS_CENTER_IN 0
|
||||
#endif
|
||||
#ifndef AXIS_MAX_IN
|
||||
#define AXIS_MAX_IN 32768
|
||||
#endif
|
||||
#ifndef AXIS_MIN_IN
|
||||
#define AXIS_MIN_IN -32767
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
#define BUTTON_1 1
|
||||
#define BUTTON_2 2
|
||||
|
|
16
src/util.cpp
16
src/util.cpp
|
@ -61,3 +61,19 @@ struct Axis dpadToAxis(uint8_t dpad) {
|
|||
// todo: panic here?
|
||||
return axis(AXIS_CENTER, AXIS_CENTER);
|
||||
}
|
||||
|
||||
/*
|
||||
long map(long x, long in_min, long in_max, long out_min, long out_max) {
|
||||
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
|
||||
}
|
||||
*/
|
||||
|
||||
inline int16_t translateAxis(int16_t v) {
|
||||
// don't map at all if translation isn't required...
|
||||
#if AXIS_CENTER_IN == AXIS_CENTER && AXIS_MIN_IN == AXIS_MIN && AXIS_MAX_IN == AXIS_MAX
|
||||
return v; // noop
|
||||
#else
|
||||
//return v == AXIS_CENTER_IN ? AXIS_CENTER : map(v, AXIS_MIN_IN, AXIS_MAX_IN, AXIS_MIN, AXIS_MAX);
|
||||
return v == AXIS_CENTER_IN ? AXIS_CENTER : (v - AXIS_MIN_IN) * (AXIS_MAX - AXIS_MIN) / (AXIS_MAX_IN - AXIS_MIN_IN) + AXIS_MIN;
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue