I bought myself a secondhand F-16 FLCS stick http://thrustmaster.vanree.net/flcs.html and a Teensy 3.1, so that I could convert it into a USB stick. Someone has already worked out what each of the five wires from the stick are for, so following that I've connected Brown to Vin, Green to GND, Orange to SCK (Pin 13), Red to SS (Pin 10) and Yellow to DIN/MISO (12) and I'm using this code:
Unfortunately, that doesn't work. The only button that does anything is the red pinky button at the base of the stick, which triggers on all buttons 1-18 and upper-right diagonal on the hat as well!
Has anyone got any ideas where the problem might be?
I note the guides all seem to say to select "USB -> Joystick" in Arduino but I don't have that, only "Keyboard + Mouse + Joystick" or "Serial + Keyboard + Mouse + Joystick", so will either of those work just as well? I've been using the former.
Code:
/* USB FLCS Grip
You must select Joystick from the "Tools > USB Type" menu
*/
// Buttons are muxed into shift registers, use the SPI protocol to read them
#include <SPI.h>
const int slaveSelectPin = 10;
unsigned int buttonInputs1; // data read from SPI
unsigned int buttonInputs2;
unsigned int buttonInputs3;
// Use some macros to clean things up
#define S3 !(buttonInputs1 & 0x80) /* Pinky Switch */
#define TG1 !(buttonInputs1 & 0x40) /* Trigger 1 */
#define TG2 !(buttonInputs1 & 0x20) /* Trigger 2 */
#define S1 !(buttonInputs1 & 0x10) /* Nose Wheel Steering */
#define S4 !(buttonInputs1 & 0x08) /* Paddle Switch */
#define S2 !(buttonInputs1 & 0x04) /* Pickle */
#define H1D !(buttonInputs2 & 0x80) /* Trim */
#define H1R !(buttonInputs2 & 0x40)
#define H1U !(buttonInputs2 & 0x20)
#define H1L !(buttonInputs2 & 0x10)
#define H4U !(buttonInputs2 & 0x08) /* CMS */
#define H4L !(buttonInputs2 & 0x04)
#define H4D !(buttonInputs2 & 0x02)
#define H4R !(buttonInputs2 & 0x01)
#define H3D !(buttonInputs3 & 0x80) /* DMS */
#define H3R !(buttonInputs3 & 0x40)
#define H3U !(buttonInputs3 & 0x20)
#define H3L !(buttonInputs3 & 0x10)
#define H2D !(buttonInputs3 & 0x08) /* TMS */
#define H2R !(buttonInputs3 & 0x04)
#define H2U !(buttonInputs3 & 0x02)
#define H2L !(buttonInputs3 & 0x01)
// setup() runs once on boot
void setup() {
// set the slaveSelectPin as an output:
pinMode (slaveSelectPin, OUTPUT);
// start the SPI library:
SPI.begin();
// configure the joystick to manual send mode. This gives precise
// control over when the computer receives updates, but it does
// require you to manually call Joystick.send_now().
Joystick.useManualSend(true);
}
// loop() runs for as long as power is applied
void loop() {
// take the SS pin low to select the chip
digitalWrite(slaveSelectPin,LOW);
// send a value of 0 to read the SPI bytes
buttonInputs1 = SPI.transfer(0x00);
buttonInputs2 = SPI.transfer(0x00);
buttonInputs3 = SPI.transfer(0x00);
// take the SS pin high to de-select the chip:
digitalWrite(slaveSelectPin,HIGH);
// Write to joystick buttons
Joystick.button(1, TG1);
Joystick.button(2, S2);
Joystick.button(3, S3);
Joystick.button(4, S4);
Joystick.button(5, S1);
Joystick.button(6, TG2);
Joystick.button(7, H2U);
Joystick.button(8, H2R);
Joystick.button(9, H2D);
Joystick.button(10, H2L);
Joystick.button(11, H3U);
Joystick.button(12, H3R);
Joystick.button(13, H3D);
Joystick.button(14, H3L);
Joystick.button(15, H4U);
Joystick.button(16, H4R);
Joystick.button(17, H4D);
Joystick.button(18, H4L);
//Joystick.button(19, H1U);
//Joystick.button(20, H1R);
//Joystick.button(21, H1D);
//Joystick.button(22, H1L);
// Determine Joystick Hat Position
int angle = -1;
if (H1U) {
if (H1R) {
angle = 45;
} else if (H1L) {
angle = 315;
} else {
angle = 0;
}
} else if (H1D) {
if (H1R) {
angle = 135;
} else if (H1L) {
angle = 225;
} else {
angle = 180;
}
} else if (H1R) {
angle = 90;
} else if (H1L) {
angle = 270;
}
Joystick.hat(angle);
// Because setup configured the Joystick manual send,
// the computer does not see any of the changes yet.
// This send_now() transmits everything all at once.
Joystick.send_now();
}
Unfortunately, that doesn't work. The only button that does anything is the red pinky button at the base of the stick, which triggers on all buttons 1-18 and upper-right diagonal on the hat as well!
Has anyone got any ideas where the problem might be?
I note the guides all seem to say to select "USB -> Joystick" in Arduino but I don't have that, only "Keyboard + Mouse + Joystick" or "Serial + Keyboard + Mouse + Joystick", so will either of those work just as well? I've been using the former.