Skip to content

Commit

Permalink
Added support for A-10C/A-10C2 console lighting.
Browse files Browse the repository at this point in the history
Refactored code into f-16c and 1-10c specific files.
  • Loading branch information
iknowkungfutoo committed Nov 26, 2023
1 parent 584eb1c commit 7e728d1
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 85 deletions.
34 changes: 26 additions & 8 deletions TMHotasLEDSync.tmc
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
/*-------------------------------------------------------------------------------
--
-- ViperTQSLEDSync.tmc
-- TMHotasLEDSync.tmc
--
-- Use at own risk without warranty.
--
-- Target script to set the state of LEDs on a Thrustmaster ViperTQS.
-- Target script to set the state of LEDs on Thrustmaster Warthog,
-- Viper Mission Pack and Viper Panel devices.
--
-- Receives TCP packets on port 2323 that indicate the state for
-- gear and RWR lamps of the F-16C_50.
-- various lamps and console lighting of a variety of aircraft.
--
-- Author: slughead
-- Date: 24/11/2023
-- Date: 26/11/2023
--
------------------------------------------------------------------------------*/

include "target.tmh"
include "aircraft_utils.tmh"
include "led_utils.tmh"
include "a-10c_led_utils.tmh"
include "f-16c_led_utils.tmh"

define VERSION "1.0.2"

define DEBUG 0

int main()
{
printf( "\xaTMHotasLEDSync v%s\xa\xa", VERSION );

// Excluded devices
Configure(&Joystick, MODE_EXCLUDED);
Configure(&JoystickF18, MODE_EXCLUDED);
Expand Down Expand Up @@ -70,13 +80,16 @@ int TCPCallback(int buf, int size)
{
int i;

char version; Dim(&version, 25);

char packet;
Map(&packet, buf); Dim(&packet, size);

char packet_string;
Map(&packet_string, buf); Dim(&packet_string, size+1);
packet_string[size] = 0; // null terminate so can be printed
printf("%s : %d bytes received\xa", &packet_string, size);

if (DEBUG) printf("%s : %d bytes received\xa", &packet_string, size);

if (size == 0) return 0;

Expand All @@ -88,16 +101,21 @@ int TCPCallback(int buf, int size)
{
reset_leds();
}
else if (packet[0] == 'v')
{
strsub(&version, &packet_string, 1, strlen(&packet_string)-1);
printf("%s\xa", &version);
}
else if (packet[0] == 'm')
{
// read the aircraft type
aircraft = get_aircraft( &packet_string );
}
else if (packet[0] == 'u') // update status of lamps
{
if (aircraft == F_16C_50) set_led_status( &packet );
if (aircraft == A_10C) set_speed_brake_leds( char_to_int(packet[1]) );
if (aircraft == A_10C_2) set_speed_brake_leds( char_to_int(packet[1]) );
if (aircraft == F_16C_50) set_f_16c_led_status( &packet );
if (aircraft == A_10C) set_a_10c_led_status( &packet );
if (aircraft == A_10C_2) set_a_10c_led_status( &packet );
if (aircraft == FA_18C_HORNET) set_speed_brake_leds( char_to_int(packet[1]) );
if (aircraft == SU_25T) set_speed_brake_leds( char_to_int(packet[1]) );
if (aircraft == SU_33) set_speed_brake_leds( char_to_int(packet[1]) );
Expand Down
48 changes: 48 additions & 0 deletions a-10c_led_utils.tmh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*-------------------------------------------------------------------------------
--
-- a-10c_led_utils.tmh
--
-- Use at own risk without warranty.
--
-- A-10C/A-10C2 specific utility functions to program the state of LEDs
-- on Thrustmaster Warthog Throttle.
--
-- Author: slughead
-- Date: 26/11/2023
--
------------------------------------------------------------------------------*/

//include "warthog_defines.tmh"
//include "warthog_utils.tmh"

int set_a_10c_led_status( alias led_states )
{
int speed_brake_position = char_to_int(led_states[1]);
int console_light = char_to_int(led_states[2]);

if (&Throttle != &joy0)
{
set_a_10c_speed_brake_leds( speed_brake_position );
set_backlight(&Throttle, console_light);
}
}

int set_a_10c_speed_brake_leds(int speed_brake_position)
{
if (&Throttle != &joy0)
{
set_led(&Throttle, get_tm_warthog_led_id( WH_LED1 ), (speed_brake_position >= 1));
set_led(&Throttle, get_tm_warthog_led_id( WH_LED2 ), (speed_brake_position >= 2));
set_led(&Throttle, get_tm_warthog_led_id( WH_LED3 ), (speed_brake_position >= 3));
set_led(&Throttle, get_tm_warthog_led_id( WH_LED4 ), (speed_brake_position >= 4));
set_led(&Throttle, get_tm_warthog_led_id( WH_LED5 ), (speed_brake_position >= 5));
}
}

int set_backlight(int device, int intensity)
{
if (device == &Throttle)
{
ActKey(PULSE+KEYON+LED(device, LED_INTENSITY, intensity * 51));
}
}
5 changes: 2 additions & 3 deletions aircraft_utils.tmh
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ int get_aircraft( alias packet_string )
int id = AIRCRAFT_UNDEFINED;

char aircraft; Dim(&aircraft, 20);

printf("%s\xa", &packet_string);
strsub(&aircraft, &packet_string, 1, strlen(&packet_string)-1);
printf("%s\xa", &aircraft);

if (strcmp(&aircraft, "A-10C") == 0) id = A_10C;
if (strcmp(&aircraft, "A-10C_2") == 0) id = A_10C;
if (strcmp(&aircraft, "A-10C_2") == 0) id = A_10C_2;
if (strcmp(&aircraft, "F-16C_50") == 0) id = F_16C_50;
if (strcmp(&aircraft, "FA-18C_hornet") == 0) id = FA_18C_HORNET;
if (strcmp(&aircraft, "Su-25T") == 0) id = SU_25T;
Expand Down
82 changes: 82 additions & 0 deletions f-16c_led_utils.tmh
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*-------------------------------------------------------------------------------
--
-- a-10c_led_utils.tmh
--
-- Use at own risk without warranty.
--
-- F-16C specific utility functions to program the state of LEDs
-- on Thrustmaster Viper Mission Pack / Panel.
--
-- Author: slughead
-- Date: 26/11/2023
--
------------------------------------------------------------------------------*/

//include "viper_defines.tmh"
//include "viper_utils.tmh"


int set_f_16c_led_status( alias led_states )
{
int gear_nose_status = char_to_int(led_states[1]);
int gear_left_status = char_to_int(led_states[2]);
int gear_right_status = char_to_int(led_states[3]);
int gear_warning_status = char_to_int(led_states[4]);
int rwr_search_status = char_to_int(led_states[5]);
int rwr_activity_status = char_to_int(led_states[6]);
int rwr_a_power_status = char_to_int(led_states[7]);
int rwr_alt_low_status = char_to_int(led_states[8]);
int rwr_alt_status = char_to_int(led_states[9]);
int rwr_system_power_status = char_to_int(led_states[10]);
int speed_brake_position = char_to_int(led_states[11]);

int device = get_viper_device();

if (device != &joy0)
{
set_led(device, LED_GEAR_NOSE, gear_nose_status);
set_led(device, LED_GEAR_LEFT, gear_left_status);
set_led(device, LED_GEAR_RIGHT, gear_right_status);
set_led(device, LED_GEAR_WARNING, gear_warning_status);

set_led(device, LED_RWR_SEARCH, rwr_search_status);
set_led(device, LED_RWR_A_POWER, rwr_activity_status);

// Thrustmaster limitation for ACT/PWR indication - only one LED.
// Power should be lit when rwr_system_power_status is on and A
// should be light amber when rwr_activity_status is on.
// One compromise would be to light the LED when rwr_system_power_status
// is on and flash the LED if rwr_system_power_status is on and
// rwr_activity_status is also on.
//set_led(device, LED_RWR_A_POWER, rwr_a_power_status);

if (rwr_alt_low_status == 1)
{
set_led(device, LED_RWR_LOW_ALT_GREEN, LED_STATE_OFF);
set_led(device, LED_RWR_LOW_ALT_RED, rwr_alt_low_status);
}
else
{
set_led(device, LED_RWR_LOW_ALT_RED, LED_STATE_OFF);
set_led(device, LED_RWR_LOW_ALT_GREEN, rwr_alt_status);
}

set_led(device, LED_RWR_SYSTEM_POWER, rwr_system_power_status);
}

set_f_16c_speed_brake_leds(speed_brake_position);
}

int set_f_16c_speed_brake_leds(int speed_brake_position)
{
int device = get_viper_device();

if (device != &joy0)
{
set_led(device, LED_USER_LEFT_1, (speed_brake_position >= 1));
set_led(device, LED_USER_LEFT_2, (speed_brake_position >= 2));
set_led(device, LED_USER_LEFT_3, (speed_brake_position >= 3));
set_led(device, LED_USER_LEFT_4, (speed_brake_position >= 4));
set_led(device, LED_USER_LEFT_5, (speed_brake_position >= 5));
}
}
79 changes: 5 additions & 74 deletions led_utils.tmh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
-- and Warthog devices.
--
-- Author: slughead
-- Date: 24/11/2023
-- Date: 26/11/2023
--
------------------------------------------------------------------------------*/

Expand Down Expand Up @@ -73,84 +73,16 @@ int reset_leds()
set_led(&Throttle, get_tm_warthog_led_id( WH_LED3 ), LED_STATE_OFF);
set_led(&Throttle, get_tm_warthog_led_id( WH_LED4 ), LED_STATE_OFF);
set_led(&Throttle, get_tm_warthog_led_id( WH_LED5 ), LED_STATE_OFF);
}
}

int set_led_status( alias led_states )
{
int gear_nose_status = char_to_int(led_states[1]);
int gear_left_status = char_to_int(led_states[2]);
int gear_right_status = char_to_int(led_states[3]);
int gear_warning_status = char_to_int(led_states[4]);
int rwr_search_status = char_to_int(led_states[5]);
int rwr_activity_status = char_to_int(led_states[6]);
int rwr_a_power_status = char_to_int(led_states[7]);
int rwr_alt_low_status = char_to_int(led_states[8]);
int rwr_alt_status = char_to_int(led_states[9]);
int rwr_system_power_status = char_to_int(led_states[10]);
int speed_brake_position = char_to_int(led_states[11]);

int device = get_viper_device();

printf("SetLedStatus: device: %d\xa", device);

if (device != &joy0)
{
set_led(device, LED_GEAR_NOSE, gear_nose_status);
set_led(device, LED_GEAR_LEFT, gear_left_status);
set_led(device, LED_GEAR_RIGHT, gear_right_status);
set_led(device, LED_GEAR_WARNING, gear_warning_status);

set_led(device, LED_RWR_SEARCH, rwr_search_status);
set_led(device, LED_RWR_A_POWER, rwr_activity_status);

// Thrustmaster limitation for ACT/PWR indication - only one LED.
// Power should be lit when rwr_system_power_status is on and A
// should be light amber when rwr_activity_status is on.
// One compromise would be to light the LED when rwr_system_power_status
// is on and flash the LED if rwr_system_power_status is on and
// rwr_activity_status is also on.
//set_led(device, LED_RWR_A_POWER, rwr_a_power_status);

if (rwr_alt_low_status == 1)
{
set_led(device, LED_RWR_LOW_ALT_GREEN, LED_STATE_OFF);
set_led(device, LED_RWR_LOW_ALT_RED, rwr_alt_low_status);
}
else
{
set_led(device, LED_RWR_LOW_ALT_RED, LED_STATE_OFF);
set_led(device, LED_RWR_LOW_ALT_GREEN, rwr_alt_status);
}

set_led(device, LED_RWR_SYSTEM_POWER, rwr_system_power_status);
set_backlight(&Throttle, 3);
}

set_speed_brake_leds(speed_brake_position);
}

int set_speed_brake_leds(int speed_brake_position)
{
int device;

if (aircraft == F_16C_50)
{
device = get_viper_device();

if (device != &joy0)
{
set_led(device, LED_USER_LEFT_1, (speed_brake_position >= 1));
set_led(device, LED_USER_LEFT_2, (speed_brake_position >= 2));
set_led(device, LED_USER_LEFT_3, (speed_brake_position >= 3));
set_led(device, LED_USER_LEFT_4, (speed_brake_position >= 4));
set_led(device, LED_USER_LEFT_5, (speed_brake_position >= 5));
}
}
else if ( aircraft == A_10C |
aircraft == A_10C_2 |
aircraft == FA_18C_HORNET |
aircraft == SU_25T |
aircraft == SU_33 )
if ( aircraft == FA_18C_HORNET |
aircraft == SU_25T |
aircraft == SU_33 )
{
if (&Throttle != &joy0)
{
Expand All @@ -163,7 +95,6 @@ int set_speed_brake_leds(int speed_brake_position)
}
}


// TODO led flashing currently does not support individual flashing LEDs
// and is only supported on ViperTQS/ViperBBox for Search indicator.
int flash_led = 0;
Expand Down

0 comments on commit 7e728d1

Please sign in to comment.