Browse Source

Experiments...

Beoran 4 years ago
parent
commit
55073e5352

+ 0 - 0
controller/c/tryio.c


+ 3 - 3
controller/controller.go

@@ -1,6 +1,6 @@
-package gamepad
-
+package controller
 
+/*
 var Driver ControllerDriver = nil 
 
 func Install(out chan<-Event) {
@@ -63,4 +63,4 @@ func ControllerById(id int) Controller {
     } 
     return Driver.ControllerById()    
 } 
-
+*/

+ 23 - 12
controller/controller_linux.go

@@ -1,20 +1,31 @@
 package controller
 
-
-// suseconds_t varies by platform, 32 on 32 bits, 64 on 64 bits
-type suseconds_t = long
-// time_t is aways 64 bits signed, even on 32 bits platforms.
-type time_t = int64
-
-// A time value that is accurate to the nearest
-// microsecond but also has a range of years.
-type timeval struct {
-    tv_sec time_t	// Seconds.
-    tv_usec susecond_t  // Microseconds.
+import "gitlab.com/beoran/galago/os/linux"
+import "os"
+import "unsafe"
+import "syscall"
+import "fmt"
+
+func Ioctl(file * os.File, code uint32, pointer unsafe.Pointer) error {
+    fmt.Printf("ioctl: %d %d %d\n", uintptr(file.Fd()), uintptr(code), uintptr(pointer))
+    _, _, errno := syscall.Syscall(
+        syscall.SYS_IOCTL,
+        uintptr(file.Fd()),
+        uintptr(code),
+        uintptr(pointer))
+    if (errno != 0) {
+        return errno
+    }
+    return nil
 }
 
 
-
+func GetDriverVersion(file * os.File) (int32, error) {
+    res := int32(0) 
+    data := unsafe.Pointer(&res)
+    err := Ioctl(file, linux.EVIOCGVERSION, data)
+    return res, err
+}
 
 
 

+ 25 - 0
controller/controller_linux_test.go

@@ -0,0 +1,25 @@
+package controller
+
+import "testing"
+import "os"
+import "syscall"
+// import "fmt"
+
+const IN = "/dev/input/by-id/usb-0583_USB_2-axis_8-button_gamepad-event-joystick"
+
+func Test1(t * testing.T) {
+    file , err := os.OpenFile(IN, syscall.O_RDWR, 0666)
+    if err != nil {
+        t.Errorf("Error OpenFile: %s\n", err)
+        return
+    }
+    defer file.Close()
+    version, err := GetDriverVersion(file)
+    if err != nil {
+        t.Errorf("Error GetDriverVersion: %s\n", err)
+        return
+    }
+    t.Logf("GetDriverVersion: %d", version)
+}
+
+

+ 1 - 1
controller/haptic.go

@@ -1 +1 @@
-package gamepad
+package controller

+ 1 - 1
controller/haptic_linux.go

@@ -1,3 +1,3 @@
-package gamepad
+package controller
 
 

+ 3 - 0
go.mod

@@ -0,0 +1,3 @@
+module gitlab.com/beoran/galago
+
+go 1.12

+ 72 - 72
os/linux/input_linux.go

@@ -5,7 +5,7 @@ import "unsafe"
 
 // This file is a Go version of <linux/input.h>
 
-type input_event struct {
+type INPUT_event struct {
 	time    timeval
 	type_   uint16
 	code    uint16
@@ -22,7 +22,7 @@ const EV_VERSION=0x010001
  * IOCTLs (0x00 - 0x7f)
  */
 
-type input_id struct {
+type INPUT_id struct {
 	bustype uint16
 	vendor uint16
 	product uint16
@@ -30,7 +30,7 @@ type input_id struct {
 }
 
 /**
- * struct input_absinfo - used by EVIOCGABS/EVIOCSABS ioctls
+ * struct INPUT_absinfo - used by EVIOCGABS/EVIOCSABS ioctls
  * @value: latest reported value for the axis.
  * @minimum: specifies minimum value for the axis.
  * @maximum: specifies maximum value for the axis.
@@ -48,7 +48,7 @@ type input_id struct {
  * units per millimeter (units/mm), resolution for rotational axes
  * (ABS_RX, ABS_RY, ABS_RZ) is reported in units per radian.
  */
-type input_absinfo struct {
+type INPUT_absinfo struct {
 	value int32;
 	minimum int32;
 	maximum int32;
@@ -61,7 +61,7 @@ const INPUT_KEYMAP_BYINDEX	= (1 << 0)
 
 
 /**
- * struct input_keymap_entry - used by EVIOCGKEYCODE/EVIOCSKEYCODE ioctls
+ * struct INPUT_keymap_entry - used by EVIOCGKEYCODE/EVIOCSKEYCODE ioctls
  * @scancode: scancode represented in machine-endian form.
  * @len: length of the scancode that resides in @scancode buffer.
  * @index: index in the keymap, may be used instead of scancode
@@ -75,7 +75,7 @@ const INPUT_KEYMAP_BYINDEX	= (1 << 0)
  * in keymap entry. EVIOCGKEYCODE will also return scancode or index
  * (depending on which element was used to perform lookup).
  */
-type input_keymap_entry struct {
+type INPUT_keymap_entry struct {
 	flags uint8;
 	len uint8;
 	index uint16;
@@ -83,7 +83,7 @@ type input_keymap_entry struct {
 	scancode [32]uint8;
 };
 
-type input_mask struct {
+type INPUT_mask struct {
 	type_ uint32;
 	codes_size uint32;
 	codes_ptr uint32;
@@ -94,23 +94,23 @@ type uint32p = [2]uint32
 const sizeof_uint32p = unsafe.Sizeof(*((*uint32p)(nil)))
 const sizeof_int32 = unsafe.Sizeof(*((*int32)(nil)))
 const sizeof_uint32 = unsafe.Sizeof(*((*uint32)(nil)))
-const sizeof_input_id = unsafe.Sizeof(*((*input_id)(nil)))
-const sizeof_input_keymap_entry = unsafe.Sizeof(*((*input_keymap_entry)(nil)))
-const sizeof_input_absinfo = unsafe.Sizeof(*((*input_absinfo)(nil)))
-const sizeof_input_mask = unsafe.Sizeof(*((*input_mask)(nil)))
-const sizeof_ff_effect = unsafe.Sizeof(*((*ff_effect)(nil)))
+const sizeof_INPUT_id = unsafe.Sizeof(*((*INPUT_id)(nil)))
+const sizeof_INPUT_keymap_entry = unsafe.Sizeof(*((*INPUT_keymap_entry)(nil)))
+const sizeof_INPUT_absinfo = unsafe.Sizeof(*((*INPUT_absinfo)(nil)))
+const sizeof_INPUT_mask = unsafe.Sizeof(*((*INPUT_mask)(nil)))
+const sizeof_FF_effect = unsafe.Sizeof(*((*FF_effect)(nil)))
 
 
 
 var EVIOCGVERSION =	IOR('E', 0x01, sizeof_int32)		/* get driver version */
-var EVIOCGID	  = IOR('E', 0x02, sizeof_input_id)	/* get device ID */
+var EVIOCGID	  = IOR('E', 0x02, sizeof_INPUT_id)	/* get device ID */
 var EVIOCGREP	  = IOR('E', 0x03, sizeof_uint32p)	/* get repeat settings */
 var EVIOCSREP	  = IOW('E', 0x03, sizeof_uint32p)	/* set repeat settings */
 
 var EVIOCGKEYCODE	= IOR('E', 0x04, sizeof_uint32)        /* get keycode */
-var EVIOCGKEYCODE_V2= IOR('E', 0x04, sizeof_input_keymap_entry)
+var EVIOCGKEYCODE_V2= IOR('E', 0x04, sizeof_INPUT_keymap_entry)
 var EVIOCSKEYCODE	= IOW('E', 0x04, sizeof_uint32p)        /* set keycode */
-var EVIOCSKEYCODE_V2= IOW('E', 0x04, sizeof_input_keymap_entry)
+var EVIOCSKEYCODE_V2= IOW('E', 0x04, sizeof_INPUT_keymap_entry)
 
 func EVIOCGNAME(len uintptr) uint32{	
     return IOC(IOC_READ, 'E', 0x06, len)		/* get device name */
@@ -134,7 +134,7 @@ func EVIOCGPROP(len uintptr) uint32 {
  *
  * The ioctl buffer argument should be binary equivalent to
  *
- * type input_mt_request_layout struct {
+ * type INPUT_mt_request_layout struct {
  *	__u32 code;
  *	__s32 values[num_slots];
  * };
@@ -177,14 +177,14 @@ func EVIOCGBIT(ev uint32, len uintptr) uint32 {
 }
 
 func EVIOCGABS(abs uint32) uint32 { 
-    return IOR('E', 0x40 + (abs), sizeof_input_absinfo)	/* get abs value/limits */
+    return IOR('E', 0x40 + (abs), sizeof_INPUT_absinfo)	/* get abs value/limits */
 }
 
 func EVIOCSABS(abs uint32) uint32 {	
-    return IOW('E', 0xc0 + (abs), sizeof_input_absinfo)	/* set abs value/limits */
+    return IOW('E', 0xc0 + (abs), sizeof_INPUT_absinfo)	/* set abs value/limits */
 }
 
-var EVIOCSFF = IOW('E', 0x80, sizeof_ff_effect)	/* send a force effect to a force feedback device */
+var EVIOCSFF = IOW('E', 0x80, sizeof_FF_effect)	/* send a force effect to a force feedback device */
 var EVIOCRMFF = IOW('E', 0x81, sizeof_int32)			/* Erase a force effect */
 var EVIOCGEFFECTS = IOR('E', 0x84, sizeof_int32)		/* Report number of effects playable at the same time */
 
@@ -195,7 +195,7 @@ var EVIOCREVOKE = IOW('E', 0x91, sizeof_int32)			/* Revoke device access */
  * EVIOCGMASK - Retrieve current event mask
  *
  * This ioctl allows user to retrieve the current event mask for specific
- * event type. The argument must be of type "struct input_mask" and
+ * event type. The argument must be of type "struct INPUT_mask" and
  * specifies the event type to query, the address of the receive buffer and
  * the size of the receive buffer.
  *
@@ -220,7 +220,7 @@ var EVIOCREVOKE = IOW('E', 0x91, sizeof_int32)			/* Revoke device access */
  * if the receive-buffer points to invalid memory, or EINVAL if the kernel
  * does not implement the ioctl.
  */
-var EVIOCGMASK = IOR('E', 0x92, sizeof_input_mask)	/* Get event-masks */
+var EVIOCGMASK = IOR('E', 0x92, sizeof_INPUT_mask)	/* Get event-masks */
 
 /**
  * EVIOCSMASK - Set event mask
@@ -243,7 +243,7 @@ var EVIOCGMASK = IOR('E', 0x92, sizeof_input_mask)	/* Get event-masks */
  * returned if the receive-buffer points to invalid memory. EINVAL is returned
  * if the kernel does not implement the ioctl.
  */
-var EVIOCSMASK = IOW('E', 0x93, sizeof_input_mask)	/* Set event-masks */
+var EVIOCSMASK = IOW('E', 0x93, sizeof_INPUT_mask)	/* Set event-masks */
 
 var EVIOCSCLOCKID = IOW('E', 0xa0, sizeof_int32) /* Set clockid to be used for timestamps */
 
@@ -294,7 +294,7 @@ const FF_STATUS_MAX = 0x01
 
 /*
  * Structures used in ioctls to upload effects to a device
- * They are pieces of a bigger structure (called ff_effect)
+ * They are pieces of a bigger structure (called FF_effect)
  */
 
 /*
@@ -303,27 +303,27 @@ const FF_STATUS_MAX = 0x01
  */
 
 /**
- * struct ff_replay - defines scheduling of the force-feedback effect
+ * struct FF_replay - defines scheduling of the force-feedback effect
  * @length: duration of the effect
  * @delay: delay before effect should start playing
  */
-type ff_replay struct {
+type FF_replay struct {
 	length uint16
 	delay uint16
 };
 
 /**
- * struct ff_trigger - defines what triggers the force-feedback effect
+ * struct FF_trigger - defines what triggers the force-feedback effect
  * @button: number of the button triggering the effect
  * @interval: controls how soon the effect can be re-triggered
  */
-type ff_trigger struct {
+type FF_trigger struct {
 	button uint16
 	interval uint16
 };
 
 /**
- * struct ff_envelope - generic force-feedback effect envelope
+ * struct FF_envelope - generic force-feedback effect envelope
  * @attack_length: duration of the attack (ms)
  * @attack_level: level at the beginning of the attack
  * @fade_length: duration of fade (ms)
@@ -334,7 +334,7 @@ type ff_trigger struct {
  * value based on polarity of the default level of the effect.
  * Valid range for the attack and fade levels is 0x0000 - 0x7fff
  */
-type ff_envelope struct {
+type FF_envelope struct {
 	attack_length uint16
 	attack_level uint16
 	fade_length uint16
@@ -342,29 +342,29 @@ type ff_envelope struct {
 };
 
 /**
- * struct ff_constant_effect - defines parameters of a constant force-feedback effect
+ * struct FF_constant_effect - defines parameters of a constant force-feedback effect
  * @level: strength of the effect; may be negative
  * @envelope: envelope data
  */
-type ff_constant_effect struct {
+type FF_constant_effect struct {
 	level int16
-	envelope ff_envelope
+	envelope FF_envelope
 };
 
 /**
- * struct ff_ramp_effect - defines parameters of a ramp force-feedback effect
+ * struct FF_ramp_effect - defines parameters of a ramp force-feedback effect
  * @start_level: beginning strength of the effect; may be negative
  * @end_level: final strength of the effect; may be negative
  * @envelope: envelope data
  */
-type ff_ramp_effect struct {
+type FF_ramp_effect struct {
 	start_level int16
 	end_level int16
-	envelope ff_envelope
+	envelope FF_envelope
 };
 
 /**
- * struct ff_condition_effect - defines a spring or friction force-feedback effect
+ * struct FF_condition_effect - defines a spring or friction force-feedback effect
  * @right_saturation: maximum level when joystick moved all way to the right
  * @left_saturation: same for the left side
  * @right_coeff: controls how fast the force grows when the joystick moves
@@ -373,7 +373,7 @@ type ff_ramp_effect struct {
  * @deadband: size of the dead zone, where no force is produced
  * @center: position of the dead zone
  */
-type ff_condition_effect struct {
+type FF_condition_effect struct {
 	right_saturation uint16
 	left_saturation uint16
 
@@ -385,7 +385,7 @@ type ff_condition_effect struct {
 };
 
 /**
- * struct ff_periodic_effect - defines parameters of a periodic force-feedback effect
+ * struct FF_periodic_effect - defines parameters of a periodic force-feedback effect
  * @waveform: kind of the effect (wave)
  * @period: period of the wave (ms)
  * @magnitude: peak value
@@ -402,44 +402,44 @@ type ff_condition_effect struct {
  * Note: the data pointed by custom_data is copied by the driver.
  * You can therefore dispose of the memory after the upload/update.
  */
-type ff_periodic_effect struct {
+type FF_periodic_effect struct {
 	waveform uint16
 	period uint16
 	magnitude int16
 	offset int16
 	phase uint16
 
-	envelope ff_envelope
+	envelope FF_envelope
 
 	custom_len uint32
 	custom_data *int16;
 };
 
 /**
- * struct ff_rumble_effect - defines parameters of a periodic force-feedback effect
+ * struct FF_rumble_effect - defines parameters of a periodic force-feedback effect
  * @strong_magnitude: magnitude of the heavy motor
  * @weak_magnitude: magnitude of the light one
  *
  * Some rumble pads have two motors of different weight. Strong_magnitude
  * represents the magnitude of the vibration generated by the heavy one.
  */
-type ff_rumble_effect struct {
+type FF_rumble_effect struct {
 	strong_magnitude uint16
 	weak_magnitude uint16
 };
 
-const ff_effect_union_size = unsafe.Sizeof(*((*ff_periodic_effect)(nil)))
+const FF_effect_union_size = unsafe.Sizeof(*((*FF_periodic_effect)(nil)))
 
 /**
- * struct ff_effect - defines force feedback effect
+ * struct FF_effect - defines force feedback effect
  * @type: type of the effect (FF_CONSTANT, FF_PERIODIC, FF_RAMP, FF_SPRING,
  *	FF_FRICTION, FF_DAMPER, FF_RUMBLE, FFINERTIA, or FF_CUSTOM)
  * @id: an unique id assigned to an effect
  * @direction: direction of the effect
- * @trigger: trigger conditions (struct ff_trigger)
- * @replay: scheduling of the effect (struct ff_replay)
- * @u: effect-specific structure (one of ff_constant_effect, ff_ramp_effect,
- *	ff_periodic_effect, ff_condition_effect, ff_rumble_effect) further
+ * @trigger: trigger conditions (struct FF_trigger)
+ * @replay: scheduling of the effect (struct FF_replay)
+ * @u: effect-specific structure (one of FF_constant_effect, FF_ramp_effect,
+ *	FF_periodic_effect, FF_condition_effect, FF_rumble_effect) further
  *	defining effect parameters
  *
  * This structure is sent through ioctl from the application to the driver.
@@ -453,61 +453,61 @@ const ff_effect_union_size = unsafe.Sizeof(*((*ff_periodic_effect)(nil)))
  *	180 deg -> 0x8000 (up)
  *	270 deg -> 0xC000 (right)
  */
-type ff_effect struct {
+type FF_effect struct {
 	type_ uint16
 	id int16
 	direction uint16
-	trigger ff_trigger
-	replay ff_replay
+	trigger FF_trigger
+	replay FF_replay
     // This was a union in C, somulate with a byte buffer with size of largest element
-    u [ff_effect_union_size]byte
+    u [FF_effect_union_size]byte
 };
 
-type ff_effect_u_constant struct {
+type FF_effect_u_constant struct {
 	type_ uint16
 	id int16
 	direction uint16
-	trigger ff_trigger
-	replay ff_replay
-    constant ff_constant_effect
+	trigger FF_trigger
+	replay FF_replay
+    constant FF_constant_effect
 };
 
 
-type ff_effect_u_ramp struct {
+type FF_effect_u_ramp struct {
 	type_ uint16
 	id int16
 	direction uint16
-	trigger ff_trigger
-	replay ff_replay
-	ramp ff_ramp_effect
+	trigger FF_trigger
+	replay FF_replay
+	ramp FF_ramp_effect
 };
 
 
-type ff_effect_u_periodic struct {
+type FF_effect_u_periodic struct {
 	type_ uint16
 	id int16
 	direction uint16
-	trigger ff_trigger
-	replay ff_replay
-    periodic ff_periodic_effect
+	trigger FF_trigger
+	replay FF_replay
+    periodic FF_periodic_effect
 };
 
-type ff_effect_u_condition struct {
+type FF_effect_u_condition struct {
 	type_ uint16
 	id int16
 	direction uint16
-	trigger ff_trigger
-	replay ff_replay
-    condition [2]ff_condition_effect; /* One for each axis */
+	trigger FF_trigger
+	replay FF_replay
+    condition [2]FF_condition_effect; /* One for each axis */
 };
 
-type ff_effect_u_rumble struct {
+type FF_effect_u_rumble struct {
 	type_ uint16
 	id int16
 	direction uint16
-	trigger ff_trigger
-	replay ff_replay
-    rumble ff_rumble_effect
+	trigger FF_trigger
+	replay FF_replay
+    rumble FF_rumble_effect
 };