|
@@ -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);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+
|