From a957cf979748bbf98b3dd94778381841c9cfab92 Mon Sep 17 00:00:00 2001 From: Melchior FRANZ Date: Fri, 7 Oct 2011 14:20:30 +0200 Subject: [PATCH] warthog: support multiple overlay files; stick rotate; read hw state --- Input/Joysticks/ThrustMaster/Warthog/README | 15 +++++- .../Warthog/Stick/stick_rotate.xml | 54 +++++++++++++++++++ .../ThrustMaster/Warthog/Warthog-Stick.xml | 5 +- .../ThrustMaster/Warthog/Warthog-Throttle.xml | 5 +- .../ThrustMaster/Warthog/warthog.nas | 51 +++++++++++++----- 5 files changed, 109 insertions(+), 21 deletions(-) create mode 100644 Input/Joysticks/ThrustMaster/Warthog/Stick/stick_rotate.xml diff --git a/Input/Joysticks/ThrustMaster/Warthog/README b/Input/Joysticks/ThrustMaster/Warthog/README index aced0ebcf..6e50bc028 100644 --- a/Input/Joysticks/ThrustMaster/Warthog/README +++ b/Input/Joysticks/ThrustMaster/Warthog/README @@ -16,9 +16,11 @@ by the contents of property "x": - generic.xml - helicopter.xml (only helicopters) - .xml (some aircraft set this property to "seaplane") - - .xml (not used by the system; meant to + - .xml (not used by the system; meant to be set on the command line or in wrapper scripts, - for example: --prop:input/joysticks/overlay=modern_jet) + for example: --prop:input/joysticks/overlays=modern_jet; + accepts a single overlay file name -- withtout extension -- + or a list of names separated by colon ":") - .xml (aircraft name, for example "harrier.xml") @@ -37,6 +39,15 @@ and variables. +Standard overlay files: +- stick_rotate: rotates stick X/Y axis by given angle. Apparently desired + by some users who have the stick between their knees and want to move it + in a more natural fashion. Usage: + + fgfs --prop:input/joysticks/overlays=stick_rotate --prop:d:input/joysticks/stick-angle=15 + + + Joystick configuration from within FlightGear under Linux: diff --git a/Input/Joysticks/ThrustMaster/Warthog/Stick/stick_rotate.xml b/Input/Joysticks/ThrustMaster/Warthog/Stick/stick_rotate.xml new file mode 100644 index 000000000..e467ae1e8 --- /dev/null +++ b/Input/Joysticks/ThrustMaster/Warthog/Stick/stick_rotate.xml @@ -0,0 +1,54 @@ + + + + + + + + + + 0.00001 + + nasal + + + + + + 0.00001 + + nasal + + + + diff --git a/Input/Joysticks/ThrustMaster/Warthog/Warthog-Stick.xml b/Input/Joysticks/ThrustMaster/Warthog/Warthog-Stick.xml index 896b6192c..3128b555e 100644 --- a/Input/Joysticks/ThrustMaster/Warthog/Warthog-Stick.xml +++ b/Input/Joysticks/ThrustMaster/Warthog/Warthog-Stick.xml @@ -24,7 +24,6 @@ var popup = func gui.popupTip(call(sprintf, arg)); var is_helicopter = (func {(var n = props.globals.getNode("rotors", 0)) != nil and n.getAttribute("children")})(); var aircraft_type = getprop("/sim/type"); - var overlay = getprop("/input/joysticks/overlay"); var load_overlay = func(name) { foreach (var dir; [getprop("/sim/fg-home"), getprop("/sim/fg-root")]) { @@ -66,8 +65,8 @@ load_overlay("helicopter"); if (aircraft_type) load_overlay(aircraft_type); - if (overlay) - load_overlay(overlay); + foreach (var o; split(":", getprop("/input/joysticks/overlays") or "")) + load_overlay(o); load_overlay(getprop("/sim/aircraft")); diff --git a/Input/Joysticks/ThrustMaster/Warthog/Warthog-Throttle.xml b/Input/Joysticks/ThrustMaster/Warthog/Warthog-Throttle.xml index 4df6572b8..f46360c74 100644 --- a/Input/Joysticks/ThrustMaster/Warthog/Warthog-Throttle.xml +++ b/Input/Joysticks/ThrustMaster/Warthog/Warthog-Throttle.xml @@ -19,7 +19,6 @@ var popup = func gui.popupTip(call(sprintf, arg)); var is_helicopter = (func {(var n = props.globals.getNode("rotors", 0)) != nil and n.getAttribute("children")})(); var aircraft_type = getprop("/sim/type"); - var overlay = getprop("/input/joysticks/overlay"); var load_overlay = func(name) { foreach (var dir; [getprop("/sim/fg-home"), getprop("/sim/fg-root")]) { @@ -65,8 +64,8 @@ load_overlay("helicopter"); if (aircraft_type) load_overlay(aircraft_type); - if (overlay) - load_overlay(overlay); + foreach (var o; split(":", getprop("/input/joysticks/overlays") or "")) + load_overlay(o); load_overlay(getprop("/sim/aircraft")); diff --git a/Input/Joysticks/ThrustMaster/Warthog/warthog.nas b/Input/Joysticks/ThrustMaster/Warthog/warthog.nas index 56cf3d96a..f67232aba 100644 --- a/Input/Joysticks/ThrustMaster/Warthog/warthog.nas +++ b/Input/Joysticks/ThrustMaster/Warthog/warthog.nas @@ -1,61 +1,86 @@ -# Hardware Interface (currently Linux/HIDRAW-only; see README) +# Hardware Interface (currently Linux/HIDRAW-only) +# see README and http://members.aon.at/mfranz/warthog.html + + +if (io.stat("/dev/input") != nil and io.stat("/dev/input/hidraw") == nil) { + print("warthog: read file $FG_ROOT/Input/Joysticks/ThrustMaster/Warthog/README"); + print(" for how to enable FlightGear to set backlight and LEDs etc."); +} + var device = { new: func(path, bufsize) { var m = { parents: [device] }; m.path = path; m.bufsize = bufsize; - m.leds = 0; - m.bright = 0; + m.data = bits.buf(m.bufsize); var stat = io.stat(m.path); if (stat == nil or stat[11] != "chr") - m.send = func { nil }; + m.send = m.receive = func {}; return m; }, send: func { var buf = bits.buf(me.bufsize); - buf[0] = 1; forindex (var i; arg) - buf[i + 1] = arg[i]; + buf[i] = arg[i]; var file = io.open(me.path, "wb"); io.write(file, buf); io.close(file); }, + receive: func { + var file = io.open(me.path, "rb"); + io.read(file, me.data, me.bufsize); + io.close(file); + }, }; var joystick = { parents: [device.new("/dev/input/hidraw/Thustmaster_Joystick_-_HOTAS_Warthog", 12)], + init: func { + me.receive(); + }, }; var throttle = { parents: [device.new("/dev/input/hidraw/Thrustmaster_Throttle_-_HOTAS_Warthog", 36)], + init: func { + me.receive(); + me.leds = me.data[26]; + me.brightness = me.data[27]; + }, set_leds: func(state, which...) { # on/off, list of leds (0: background, 1-5) + var leds = me.leds; foreach (var w; which) me.leds = bits.switch(me.leds, me._ledmap[w], state); - me.send(6, me.leds, me.bright); + if (me.leds != leds) + me.send(1, 6, me.leds, me.brightness); }, toggle_leds: func(which...) { foreach (var w; which) me.leds = bits.toggle(me.leds, me._ledmap[w]); - me.send(6, me.leds, me.bright); + me.send(1, 6, me.leds, me.brightness); }, set_brightness: func(v) { # clamped to [0,5], where 0 is off and 5 is bright - me.send(6, me.leds, me.bright = v < 0 ? 0 : v > 5 ? 5 : v); + if (v != me.brightness) + me.send(1, 6, me.leds, me.brightness = v < 0 ? 0 : v > 5 ? 5 : v); }, brighter: func { me.leds = bits.set(me.leds, me._ledmap[0]); - me.set_brightness(me.bright + 1); + me.set_brightness(me.brightness + 1); }, darker: func { me.leds = bits.set(me.leds, me._ledmap[0]); - me.set_brightness(me.bright - 1); + me.set_brightness(me.brightness - 1); }, _ledmap: {0: 3, 1: 2, 2: 1, 3: 4, 4: 0, 5: 6}, }; -throttle.set_brightness(1); # LEDs dark (but on) -throttle.set_leds(1, 0); # backlight on +joystick.init(); +throttle.init(); # read configuration + +throttle.set_brightness(1); # LEDs dark (but on) +throttle.set_leds(1, 0); # backlight on setlistener("/sim/signals/exit", func throttle.set_leds(0, 1, 2, 3, 4, 5), 1); # other LEDs off (now and at exit)