Browse Source

WIP struggling wth EVIOCGBIT.

Beoran 4 years ago
parent
commit
f264c6c640
3 changed files with 29 additions and 4 deletions
  1. 1 0
      c/pioc/main.c
  2. 11 4
      os/linux/input/input_linux.go
  3. 17 0
      os/linux/input/input_linux_test.go

+ 1 - 0
c/pioc/main.c

@@ -9,6 +9,7 @@ int main(void) {
     pioc(EVIOCGVERSION);
     pioc(EVIOCGID);
     pioc(EVIOCGNAME(256));
+    pioc(EVIOCGBIT(EV_SYN, 3));
     pioc(EVIOCGBIT(EV_SYN, 31));
     pioc(EVIOCGBIT(EV_KEY, 767));
     pioc(EVIOCGBIT(EV_ABS, 767));

+ 11 - 4
os/linux/input/input_linux.go

@@ -77,13 +77,20 @@ func (d * Device) Id() (linux.INPUT_id, error) {
 const SIZEOF_LONG = uint(unsafe.Sizeof(*((*linux.UnsignedLong)(nil))))      
 const BITS_PER_LONG = SIZEOF_LONG * 8
 
-func BitsToLong(ebits uint) uint {
-    bits := uint(ebits)
-    return ((bits) + 8 * SIZEOF_LONG - 1) / (8 * SIZEOF_LONG)
+func BitsToLong(bits uint) uint {
+    return ((bits) + (8 * SIZEOF_LONG) - 1) / (8 * SIZEOF_LONG)
 }
 
 func TestBit(bit uint, array []linux.UnsignedLong) bool {
-    return ((array[ bit / BITS_PER_LONG ]) >> (bit%BITS_PER_LONG)) & 1 != 0
+    elem := array[ bit / ( 8 * SIZEOF_LONG)]
+    flag := linux.UnsignedLong(1) << linux.UnsignedLong(bit % (8 * SIZEOF_LONG))
+    return (elem & flag ) != 0
+}
+
+func (d * Device) Topology() (string, error) {
+    buffer := [256]byte{}
+    err := d.Ioctl(linux.EVIOCGPHYS(uintptr(len(buffer))), unsafe.Pointer(&buffer))
+    return string(buffer[0:len(buffer)]), err
 }
 
 func (d * Device) SupportedEvents() ([]uint, error) {

+ 17 - 0
os/linux/input/input_linux_test.go

@@ -45,6 +45,23 @@ func TestGetName(t * testing.T) {
     t.Logf("GetName: %s", name)
 }
 
+
+func TestGetTopology(t * testing.T) {
+    device , err := Open(IN)
+    if err != nil {
+        t.Errorf("Error Open: %s\n", err)
+        return
+    }
+    defer device.Close()
+    name, err := device.Topology()
+    if err != nil {
+        t.Errorf("Error Topology: %s\n", err)
+        return
+    }
+    t.Logf("Topology: %s", name)
+}
+
+
 func TestGetId(t * testing.T) {
     device , err := Open(IN)
     if err != nil {