1
0
Fork 0

warthog: improve linux/hidraw interface

This commit is contained in:
Melchior FRANZ 2011-10-02 22:19:24 +02:00
parent d281490ae1
commit 556f07b212
3 changed files with 20 additions and 12 deletions

View file

@ -69,7 +69,7 @@ via raw HID support.
If you don't have a user group "js" (for joystick hardware access) either If you don't have a user group "js" (for joystick hardware access) either
create one or, in the fourth line, use a group instead where all joystick create one or, in the fourth line, use a group instead where all joystick
users are member, e.g. GROUP:="users". Then plug your Warthog devices out users are member, e.g. GROUP:="users". Then plug your Warthog devices out
and in again and check if this created two device files under /dev/hid/: and in again and check if this created two device links:
$ ls -l /dev/input/hidraw/* $ ls -l /dev/input/hidraw/*
lrwxrwxrwx 1 root root 10 Oct 2 14:23 Thrustmaster_Throttle_-_HOTAS_Warthog -> ../hidraw1 lrwxrwxrwx 1 root root 10 Oct 2 14:23 Thrustmaster_Throttle_-_HOTAS_Warthog -> ../hidraw1
@ -80,7 +80,7 @@ via raw HID support.
$ ls -l /dev/hidraw* $ ls -l /dev/hidraw*
crw-rw---- 1 root js 251, 0 Oct 2 09:11 /dev/hidraw0 crw-rw---- 1 root js 251, 0 Oct 2 09:11 /dev/hidraw0
crw-rw---- 1 root js 251, 1 Oct 2 14:23 /dev/hidraw1 crw-rw---- 1 root js 251, 1 Oct 2 14:23 /dev/hidraw1
^^ ^^
(3) Allow FlightGear to write to the two devices. The best way to do this is (3) Allow FlightGear to write to the two devices. The best way to do this is

View file

@ -50,7 +50,8 @@
warthog.throttle.set_leds(0, 1, 2, 3, 4, 5); warthog.throttle.set_leds(0, 1, 2, 3, 4, 5);
settimer(gearcheck, 0.5); settimer(gearcheck, 0.5);
}; };
init and gearcheck(); if (init)
gearcheck();
var mod = 0; var mod = 0;
var m = props.globals.initNode("/devices/status/joysticks/warthog/modifier", mod, "INT"); var m = props.globals.initNode("/devices/status/joysticks/warthog/modifier", mod, "INT");

View file

@ -1,4 +1,4 @@
# HIDRAW Interface (currently Linux-only; see README) # Hardware Interface (currently Linux/HIDRAW-only; see README)
var device = { var device = {
new: func(path, bufsize) { new: func(path, bufsize) {
@ -21,9 +21,19 @@ var device = {
io.write(file, buf); io.write(file, buf);
io.close(file); io.close(file);
}, },
set_leds: func(on, which...) { # on/off, list of leds (0: background, 1-5) };
var joystick = {
parents: [device.new("/dev/input/hidraw/Thustmaster_Joystick_-_HOTAS_Warthog", 12)],
};
var throttle = {
parents: [device.new("/dev/input/hidraw/Thrustmaster_Throttle_-_HOTAS_Warthog", 36)],
set_leds: func(state, which...) { # on/off, list of leds (0: background, 1-5)
foreach (var w; which) foreach (var w; which)
me.leds = bits.switch(me.leds, me._ledmap[w], on); me.leds = bits.switch(me.leds, me._ledmap[w], state);
me.send(6, me.leds, me.bright); me.send(6, me.leds, me.bright);
}, },
toggle_leds: func(which...) { toggle_leds: func(which...) {
@ -31,7 +41,7 @@ var device = {
me.leds = bits.toggle(me.leds, me._ledmap[w]); me.leds = bits.toggle(me.leds, me._ledmap[w]);
me.send(6, me.leds, me.bright); me.send(6, me.leds, me.bright);
}, },
set_brightness: func(v) { 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); me.send(6, me.leds, me.bright = v < 0 ? 0 : v > 5 ? 5 : v);
}, },
brighter: func { brighter: func {
@ -46,9 +56,6 @@ var device = {
}; };
var joystick = device.new("/dev/input/hidraw/Thustmaster_Joystick_-_HOTAS_Warthog", 12); throttle.set_brightness(1); # LEDs dark (but on)
var throttle = device.new("/dev/input/hidraw/Thrustmaster_Throttle_-_HOTAS_Warthog", 36);
throttle.set_brightness(1);
throttle.set_leds(1, 0); # backlight on throttle.set_leds(1, 0); # backlight on
throttle.set_leds(0, 1, 2, 3, 4, 5); # other LEDs off setlistener("/sim/signals/exit", func throttle.set_leds(0, 1, 2, 3, 4, 5), 1); # other LEDs off (now and at exit)