From 7e728d1e562b5d6f6716fa49150192581ea2f2e9 Mon Sep 17 00:00:00 2001 From: slughead Date: Sun, 26 Nov 2023 18:32:02 +0000 Subject: [PATCH] Added support for A-10C/A-10C2 console lighting. Refactored code into f-16c and 1-10c specific files. --- TMHotasLEDSync.tmc | 34 ++++++++++++++----- a-10c_led_utils.tmh | 48 ++++++++++++++++++++++++++ aircraft_utils.tmh | 5 ++- f-16c_led_utils.tmh | 82 +++++++++++++++++++++++++++++++++++++++++++++ led_utils.tmh | 79 +++---------------------------------------- 5 files changed, 163 insertions(+), 85 deletions(-) create mode 100644 a-10c_led_utils.tmh create mode 100644 f-16c_led_utils.tmh diff --git a/TMHotasLEDSync.tmc b/TMHotasLEDSync.tmc index 40ed63b..72ceb42 100644 --- a/TMHotasLEDSync.tmc +++ b/TMHotasLEDSync.tmc @@ -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); @@ -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; @@ -88,6 +101,11 @@ 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 @@ -95,9 +113,9 @@ int TCPCallback(int buf, int size) } 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]) ); diff --git a/a-10c_led_utils.tmh b/a-10c_led_utils.tmh new file mode 100644 index 0000000..f7d44bb --- /dev/null +++ b/a-10c_led_utils.tmh @@ -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)); + } +} \ No newline at end of file diff --git a/aircraft_utils.tmh b/aircraft_utils.tmh index cbd2a72..4e83248 100644 --- a/aircraft_utils.tmh +++ b/aircraft_utils.tmh @@ -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; diff --git a/f-16c_led_utils.tmh b/f-16c_led_utils.tmh new file mode 100644 index 0000000..b07bd83 --- /dev/null +++ b/f-16c_led_utils.tmh @@ -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)); + } +} \ No newline at end of file diff --git a/led_utils.tmh b/led_utils.tmh index 01f49a8..71d6e1d 100644 --- a/led_utils.tmh +++ b/led_utils.tmh @@ -8,7 +8,7 @@ -- and Warthog devices. -- -- Author: slughead - -- Date: 24/11/2023 + -- Date: 26/11/2023 -- ------------------------------------------------------------------------------*/ @@ -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) { @@ -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;