|
@@ -62,45 +62,56 @@ 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
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
+const SIZEOF_LONG = uint(unsafe.Sizeof(*((*linux.UnsignedLong)(nil))))
|
|
|
+const BITS_PER_LONG = SIZEOF_LONG * 8
|
|
|
|
|
|
+func BitsToLong(ebits linux.EventType) uint {
|
|
|
+ bits := uint(ebits)
|
|
|
+ return ((bits) + 8 * SIZEOF_LONG - 1) / (8 * SIZEOF_LONG)
|
|
|
+}
|
|
|
|
|
|
- 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 TestBit(bit uint, array []linux.UnsignedLong) bool {
|
|
|
+ return ((array[ bit / BITS_PER_LONG ]) & (1 << (bit%BITS_PER_LONG))) != 0
|
|
|
+}
|
|
|
|
|
|
+func (d * Device) SupportedEvents() ([]linux.EventType, error) {
|
|
|
+ size := BitsToLong(linux.EV_MAX)
|
|
|
+ bits := make([]linux.UnsignedLong, size)
|
|
|
+ for i := uint(0); i < size; i ++ {
|
|
|
+ bits[i] = 0
|
|
|
+ }
|
|
|
+ err := d.Ioctl(linux.EVIOCGBIT(0, uintptr(size)), unsafe.Pointer(&bits));
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ fmt.Printf("size %d, bits: %v\n", size, bits)
|
|
|
+ result := []linux.EventType{}
|
|
|
+ for i := uint(0); i < uint(linux.EV_MAX); i++ {
|
|
|
+ if (TestBit(i, bits)) {
|
|
|
+ result = append(result, linux.EventType(i))
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return result, nil
|
|
|
+}
|
|
|
|
|
|
-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])) {
|
|
|
+ if (TestBit(i, bit[0])) {
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|
|
@@ -138,7 +149,7 @@ func (d * Device) SupportedEvents() ([]uint32, error) (
|
|
|
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+*/
|
|
|
|
|
|
|
|
|
|