Beoran 4 years ago
parent
commit
0be41ff402
5 changed files with 85 additions and 8 deletions
  1. 72 0
      os/linux/input/input_linux.go
  2. 1 1
      os/linux/input_linux.go
  3. 3 1
      os/linux/linux32.go
  4. 4 1
      os/linux/linux64.go
  5. 5 5
      os/linux/types.go

+ 72 - 0
os/linux/input/input_linux.go

@@ -62,11 +62,83 @@ func (d * Device) Name() (string, error) {
     return string(buffer[0:len(buffer)]), err
 }
 
+func BitsToLong(bits int) int {
+    var ul linux.UnsignedLong 
+    return ((bits) + 8 * unsafe.Sizeof(ul) - 1) / (8 * unsafe.Sizeof(ul))
+}
+
+func TestBit(bit int, array []uint8) { 
+    
+      
+const BITS_PER_LONG = sizeof(long) * 8)
+#define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1)
+#define OFF(x)  ((x)%BITS_PER_LONG)
+#define BIT(x)  (1UL<<OFF(x))
+#define LONG(x) ((x)/BITS_PER_LONG)
+#define test_bit(bit, array)	((array[LONG(bit)] >> OFF(bit)) & 1)
+
+
+
 func (d * Device) Id() (linux.INPUT_id, error) {
     var result linux.INPUT_id 
     err := d.Ioctl(linux.EVIOCGID, unsafe.Pointer(&result))
     return result, err
+
+
+
+	int fd, rd, i, j, k;
+	struct input_event ev[64];
+	int version;
+	unsigned short id[4];
+	unsigned long bit[EV_MAX][NBITS(KEY_MAX)];
+	char name[256] = "Unknown";
+	int abs[5];
+
+
+func (d * Device) SupportedEvents() ([]uint32, error) (
+	var bit [linux.EV_MAX] uint64
+	device.Ioctl(fd, EVIOCGBIT(0, EV_MAX), unsafe.Pointer(&bit));
+	printf("Supported events:\n");
+	for (i = 0; i < EV_MAX; i++)
+		if (test_bit(i, bit[0])) {
+		}
+		
+
+	printf("Testing ... (interrupt to exit)\n");
+
+	while (1) {
+		rd = read(fd, ev, sizeof(struct input_event) * 64);
+
+		if (rd < (int) sizeof(struct input_event)) {
+			printf("yyy\n");
+			perror("\nevtest: error reading");
+			return 1;
+		}
+
+		for (i = 0; i < rd / sizeof(struct input_event); i++)
+
+			if (ev[i].type == EV_SYN) {
+				printf("Event: time %ld.%06ld, -------------- %s ------------\n",
+					ev[i].time.tv_sec, ev[i].time.tv_usec, ev[i].code ? "Config Sync" : "Report Sync" );
+			} else if (ev[i].type == EV_MSC && (ev[i].code == MSC_RAW || ev[i].code == MSC_SCAN)) {
+				printf("Event: time %ld.%06ld, type %d (%s), code %d (%s), value %02x\n",
+					ev[i].time.tv_sec, ev[i].time.tv_usec, ev[i].type,
+					events[ev[i].type] ? events[ev[i].type] : "?",
+					ev[i].code,
+					names[ev[i].type] ? (names[ev[i].type][ev[i].code] ? names[ev[i].type][ev[i].code] : "?") : "?",
+					ev[i].value);
+			} else {
+				printf("Event: time %ld.%06ld, type %d (%s), code %d (%s), value %d\n",
+					ev[i].time.tv_sec, ev[i].time.tv_usec, ev[i].type,
+					events[ev[i].type] ? events[ev[i].type] : "?",
+					ev[i].code,
+					names[ev[i].type] ? (names[ev[i].type][ev[i].code] ? names[ev[i].type][ev[i].code] : "?") : "?",
+					ev[i].value);
+			}	
+
+	}
 }
 
 
 
+

+ 1 - 1
os/linux/input_linux.go

@@ -6,7 +6,7 @@ import "unsafe"
 // This file is a Go version of <linux/input.h>
 
 type INPUT_event struct {
-	Time    timeval
+	Time    Timeval
 	Type    uint16
 	Code    uint16
 	Value   int32

+ 3 - 1
os/linux/linux32.go

@@ -11,6 +11,8 @@ package linux
 // platform specific for 64 bits linux platforms
 
 
-type long = int32
+type Long = int32
+type UnsignedLong = uint32
+
 
 

+ 4 - 1
os/linux/linux64.go

@@ -7,6 +7,9 @@ package linux
 
 // platform specific for 64 bits linux platforms
 
-type long = int64
+type Long = int64
+
+type UnsignedLong = uint64
+
 
 

+ 5 - 5
os/linux/types.go

@@ -1,15 +1,15 @@
 package linux 
 
 // suseconds_t varies by platform, 32 on 32 bits, 64 on 64 bits
-type suseconds_t = long
+type Suseconds_t = Long
 // time_t is aways 64 bits signed, even on 32 bits platforms.
-type time_t = int64
+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 suseconds_t  // Microseconds.
+type Timeval struct {
+    Tv_sec Time_t	// Seconds.
+    Tv_usec Suseconds_t  // Microseconds.
 }