package main import ( "encoding/binary" "fmt" "io" "net/http" "os" "path/filepath" "strconv" "strings" "unsafe" "golang.org/x/sys/unix" ) const ( evSyn = 0x00 evKey = 0x01 evAbs = 0x03 btnTouch = 0x14a absX = 0x00 absY = 0x01 inputPropDirect = 0x01 sizeofInputEvent = 24 ) func evIoc(nr, size uintptr) uintptr { const iocRead = 2 return iocRead<<30 | size<<16 | 'E'<<8 | nr } type touchDev struct { f *os.File minX, maxX, minY, maxY int32 } var touchscreen *touchDev // Picks the direct-input device that reports absolute X and Y — the same // probe cabletest runs, so both ends name the same hardware. Events written // to the node are fed into the input core as if the hardware produced them, // so cabletest sees a finger without carrying any injection code. func openTouchscreen() (*touchDev, error) { paths, err := filepath.Glob("/dev/input/event*") if err != nil { return nil, err } for _, p := range paths { f, err := os.OpenFile(p, os.O_RDWR, 0) if err != nil { continue } var props, absBits uint64 if _, _, errno := unix.Syscall(unix.SYS_IOCTL, f.Fd(), evIoc(0x09, 8), uintptr(unsafe.Pointer(&props))); errno != 0 { f.Close() continue } if _, _, errno := unix.Syscall(unix.SYS_IOCTL, f.Fd(), evIoc(0x20+evAbs, 8), uintptr(unsafe.Pointer(&absBits))); errno != 0 { f.Close() continue } if props&(1<