Zachary J. Fields
Published © Beerware

ThrustMaster® Mark II FCS: The Resurrection

In the mid-late 90's, I saved up and bought a ThrustMaster P/C compatible joystick. After a decade in the closet, it's time has come.

Work in progress8,324
ThrustMaster® Mark II FCS: The Resurrection

Things used in this project

Hardware components

Spark Core
Particle Spark Core
I chose this MCU because of the built-in wireless communication
×1
DB15 D-SUB female jack 15pin port Terminal Breakout PCB Board 2 row screw
This is necessary to prototype the joystick, without having to cut the DB-15 serial connector cable.
×1
400-pt Solderless Breadboard
×1
Solderless Flexible Breadboard Jumper Wires (male-male)
×10
47K Ohm Resistor
The code supplied is calibrated to this value of resistance.
×3

Story

Read more

Code

file_9783.txt

C/C++
Test code
// Filename:thrustmaster-mark-ii-fcs.ino
// Author: Zachary J. Fields
// Created: 2015 JAN 27
// License: Beerware

#include <cstdint>

const uint32_t SAMPLING_RATE_HZ = 4;
const uint32_t SAMPLING_DELAY_MS = (1000 / SAMPLING_RATE_HZ);

union button_state_t {
    struct button_t {
        uint32_t hat_up : 1;
        uint32_t hat_right : 1;
        uint32_t hat_down : 1;
        uint32_t hat_left : 1;
        uint32_t button_1 : 1;
        uint32_t button_2 : 1;
        uint32_t button_3 : 1;
        uint32_t trigger : 1;
        uint32_t joystick_x : 12;
        uint32_t joystick_y : 12;
    } button;
    uint32_t data;
} button_state;

void setup() {
    Serial.begin(9600);
    
    // Setup digital pins
    pinMode(D5, INPUT_PULLDOWN);    // button 1
    pinMode(D4, INPUT_PULLDOWN);    // button 2
    pinMode(D6, INPUT_PULLDOWN);    // button 3
    pinMode(D7, INPUT_PULLDOWN);    // trigger
    
    // Setup analog pins (ALL REQUIRE EXTERNAL PULLDOWN - 47K)
    pinMode(A0, INPUT);    // joystick-x
    pinMode(A1, INPUT);    // joystick-y
    pinMode(A6, INPUT);    // hat
    
    return;
}

void loop() {
    delay(SAMPLING_DELAY_MS);
    sampleState();
    reportValues();
}

void reportValues() {
    // Report hat value
    Serial.print("Hat Position: ");
    if ( button_state.button.hat_up ) {
        Serial.println("UP");
    } else if ( button_state.button.hat_right ) {
        Serial.println("RIGHT");
    } else if ( button_state.button.hat_down ) {
        Serial.println("DOWN");
    } else if ( button_state.button.hat_left ) {
        Serial.println("LEFT");
    } else {
        Serial.println("CENTER");
    }
    Serial.println();
    
    // Report digital values
    Serial.print("Button 1: ");
    Serial.println(button_state.button.button_1 ? "DOWN" : "UP");
    
    Serial.print("Trigger: ");
    Serial.println(button_state.button.trigger ? "DOWN" : "UP");
    
    Serial.print("Button 2: ");
    Serial.println(button_state.button.button_2 ? "DOWN" : "UP");
    
    Serial.print("Button 3: ");
    Serial.println(button_state.button.button_3 ? "DOWN" : "UP");
    Serial.println();
    
    // Report analog values
    Serial.print("Joystick X: ");
    Serial.println(button_state.button.joystick_x);
    
    Serial.print("Joystick Y: ");
    Serial.println(button_state.button.joystick_y);
    Serial.println("\n==================\n");
    
    return;
}

void sampleState() {
    // Sample/convert hat state
    const uint32_t hat_raw = analogRead(A6);
    button_state.button.hat_up = (hat_raw >= 4000);
    button_state.button.hat_right = (hat_raw < 3500 && hat_raw >= 2500);
    button_state.button.hat_down = (hat_raw < 2500 && hat_raw >= 2000);
    button_state.button.hat_left = (hat_raw < 2000 && hat_raw >= 1750);
    
    // Sample digital state
    button_state.button.button_1 = digitalRead(D4);
    button_state.button.button_2 = digitalRead(D5);
    button_state.button.button_3 = digitalRead(D6);
    button_state.button.trigger = digitalRead(D7);
    
    // Sample analog state
    button_state.button.joystick_x = analogRead(A0);
    button_state.button.joystick_y = analogRead(A1);
    
    return;
}

Credits

Zachary J. Fields

Zachary J. Fields

18 projects • 152 followers
I like to make stuff.

Comments