Main > Driving & Racing Cabinets

Maximum Tune 3 (WMMT 3DX) - Cab Conversion Help

<< < (4/5) > >>

PL1:

--- Quote from: baritonomarchetto on November 15, 2021, 01:18:23 pm ---If I add two buttons I also have to change the sketch name :D

--- End quote ---
OK.  How about adding a "GamepadJoystickAndButtons.ino" sketch?


--- Quote from: baritonomarchetto on November 15, 2021, 01:18:23 pm ---They are based on well documented libraries

--- End quote ---
"Well documented" assumes that people can find a good example and understand the code and comments.   ;)
- There are lots of not-so-great examples and comments that make sense to experienced coders but not to beginners.


--- Quote from: baritonomarchetto on November 15, 2021, 01:18:23 pm ---About the shifter decoding logic: as far as you have enought inputs for your switches, you can literally do everithing comes to your mind with those microcontroller boards

--- End quote ---
The question wasn't, "Can an experienced coder put shifter logic into a gamepad sketch?" -- that is rather obvious.   ::)   :lol

The question is, "Do these general steps with two sets of variables (pin states and decoded button states) and if/else branching to subroutines sound like a good approach for adding shifter logic to a gamepad sketch, or is there a better way like a seven-line truth table to do it?"
- No sense sinking time into an ill-suited, convoluted, or highly inefficient approach.


Scott

Vee21:
Just a quick update from my end, I've updated the sketch and now have the Mode and View buttons configured. I still haven't looked into getting the actual button LEDs to light up but switches work in control panel. I've just wired up the four digital input wires for the shifter and will be trying to get that working next. The sketch is based on baritonomarchetto sketch and the example included with the Joystick library.


--- Code: ---/* ArcadeHID - steering wheel handling example
 * gamepad emulation
 *
 * by Barito, 2021
 * Rev-3 - Steering, Accelerator, Brake + 2 Buttons
*/

#include <Joystick.h>

Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,JOYSTICK_TYPE_MULTI_AXIS,
2, 0,                  // Button Count, Hat Switch Count
false, false, false,    // X, Y, Z Axis
false, false, false,   //Rx, Ry, Rz
false, false,          //rudder, throttle
true, true, true);   //accelerator, brake, steering
 
const int steerPin = A0;
const int brakePin = A1;
const int accelPin = A2;
int steerValue;
int brakeValue;
int accelValue;


void setup() {
//Steering Options - X Axis or Steering
//Joystick.setXAxisRange(0, 1023); //Steering Wheel - Joystick.setXAxisRange(min, max);
Joystick.setSteeringRange(0, 960);

//Brake Options - Y Axis or Brake
//Joystick.setYAxisRange(0, 1023); //Brake Pedal - Joystick.setYAxisRange(min, max);
Joystick.setBrakeRange(366, 767);
Serial.begin(9600); // Testing analog input

//Accelerator Options - Z Axis or Acceleratro
//Joystick.setZAxisRange(0, 1023); //Accel Pedal - Joystick.setZAxisRange(min, max);
Joystick.setAcceleratorRange(490, 915);

//Default Buttons - WMMT (Mode (Red Button) and View (Green Button))
//Initialise button pins
pinMode(7, INPUT_PULLUP);
pinMode(8, INPUT_PULLUP);

//Start Joystick
Joystick.begin();
}

// Constant that maps the phyical pin to the joystick button.
const int pinToButtonMap = 7;

// Last state of the button
int lastButtonState[2] = {0,0};

void loop() {
BrakePedal();
SteerWheel();
AccelPedal();
ReadButtons();
}

void SteerWheel(){
steerValue = analogRead(steerPin);
//Joystick.setXAxis(steerValue);
Joystick.setSteering(steerValue);
delay(1);
}

void BrakePedal(){
brakeValue = analogRead(brakePin);
//Joystick.setYAxis(brakeValue);
Joystick.setBrake(brakeValue);
Serial.println(brakeValue); // Testing analog input
delay(1);
}

void AccelPedal(){
accelValue = analogRead(accelPin);
//Joystick.setZAxis(accelValue);
Joystick.setAccelerator(accelValue);
delay(1);
}

void ReadButtons(){
  // Read digital pin values
  for (int index = 0; index < 2; index++)
  {
    int currentButtonState = !digitalRead(index + pinToButtonMap);
    if (currentButtonState != lastButtonState[index])
    {
      Joystick.setButton(index, currentButtonState);
      lastButtonState[index] = currentButtonState;
    }
  }
  delay(50);
}
--- End code ---

Vee21:

--- Quote from: PL1 on November 14, 2021, 04:22:38 am ---
It's not that unusual for pedals to have a limited range of motion resulting in a limited range of values.

As long as the values aren't jumpy/jittery as you move through the range, it should work fine.

Calibrate the pedals in Windows Control Panel and in the in-game calibration menu and you should be fine.   :cheers:


--- End quote ---

Thanks mate good to know, I thought the pots might need replacing or something. They don't seem jittery when logging the values and I tested the accelerator pedal in the windows game controllers calibration and it seems to be working as it should as in part throttle and full throttle.

Vee21:
So I've done some very basic code to check the status/logic of the switches on the shifter and map it to a "gear". Now to convert these to Joystick outputs! wish me luck!  :dizzy:


--- Code: ---  //Setup Shifter pins
  const int bluePin = 10;
  const int yellowPin = 11;
  const int brownPin = 12;
  const int greenPin = 13;

void setup() {
  //start serial connection
  Serial.begin(9600);
  //configure Namco WMMT 6 Speed shifter pins as an input
  pinMode(10, INPUT_PULLUP); //Shifter (Blue)
  pinMode(11, INPUT_PULLUP); //Shifter (Yellow)
  pinMode(12, INPUT_PULLUP); //Shifter (Brown)
  pinMode(13, INPUT_PULLUP); //Shifter (Green)
}

void loop() {
  //Set state of Shifter Gear
  char shifterGear = '0';
  int bluePinState = digitalRead(bluePin);
  int yellowPinState = digitalRead(yellowPin);
  int brownPinState = digitalRead(brownPin);
  int greenPinState = digitalRead(greenPin);
  //print out the value current selected gear
  Serial.print("Blue Pin State:");
  Serial.println(bluePinState);
  Serial.print("Yellow Pin State:");
  Serial.println(yellowPinState);
  Serial.print("Brown Pin State:");
  Serial.println(brownPinState);
  Serial.print("Green Pin State:");
  Serial.println(greenPinState);
 
  if(bluePinState == 1 && yellowPinState == 1 && brownPinState == 1 && greenPinState == 1) {
    shifterGear = 'N';
    Serial.println(shifterGear);
  }
 
  if(bluePinState == 0 && yellowPinState == 1 && brownPinState == 0 && greenPinState == 1) {
    shifterGear = '6';
    Serial.println(shifterGear);
  }

  if(bluePinState == 1 && yellowPinState == 1 && brownPinState == 0 && greenPinState == 0) {
    shifterGear = '5';
    Serial.println(shifterGear);
  }
 
  if(bluePinState == 0 && yellowPinState == 1 && brownPinState == 1 && greenPinState == 1) {
    shifterGear = '4';
    Serial.println(shifterGear);
  }

  if(bluePinState == 1 && yellowPinState == 1 && brownPinState == 1 && greenPinState == 0) {
    shifterGear = '3';
    Serial.println(shifterGear);
  }

  if(bluePinState == 0 && yellowPinState == 0 && brownPinState == 1 && greenPinState == 1) {
    shifterGear = '2';
    Serial.println(shifterGear);
  }

  if(bluePinState == 1 && yellowPinState == 0 && brownPinState == 1 && greenPinState == 0) {
    shifterGear = '1';
    Serial.println(shifterGear);
  }
   
  delay(1000);
 
}
--- End code ---

 :cheers:

PL1:
Looks like a solid start on the "truth table" approach.   :cheers:

You may want to find the answers to these questions before you proceed too much further.

1. What type of input does Teknoparrot/MAME and the game(s) you plan to use need from the shifter?
- One button for each gear 1-6, but none for Neutral?
- One button for each gear 1-6 and a button for Neutral?
- A sequential shifter input?

2. Do the emulators/games you plan to use care if the shifter sends gamepad button presses or keystrokes?
- Some games only allow inputs from a single device.

3. Do the emulators/games you plan to use care if gamepad outputs are dinput or xinput?


Scott

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version