123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- /* package input is a thing Go wrapper around the Linux kernel input event
- * system. */
- package input
- import "gitlab.com/beoran/galago/os/linux"
- import "os"
- import "unsafe"
- import "syscall"
- import "fmt"
- import "path/filepath"
- // Device models an input device
- type Device struct {
- *os.File
- }
- const Directory = "/dev/input"
- func Open(name string) (*Device, error) {
- f, err := os.OpenFile(filepath.Join(Directory, name), os.O_RDWR, 0666)
- if err != nil {
- return nil, err
- }
- return &Device{File: f}, nil
- }
- func List() ([]string, error) {
- dir, err := os.Open(Directory)
- if err != nil {
- return nil, err
- }
- return dir.Readdirnames(-1)
- }
- // Icotl performs an ioctl on the given de
- func (d * Device) Ioctl(code uint32, pointer unsafe.Pointer) error {
- fmt.Printf("ioctl: %d %d %d\n", uintptr(d.Fd()), uintptr(code), uintptr(pointer))
- _, _, errno := syscall.Syscall(
- syscall.SYS_IOCTL,
- uintptr(d.Fd()),
- uintptr(code),
- uintptr(pointer))
- if (errno != 0) {
- return errno
- }
- return nil
- }
- func (d * Device) DriverVersion() (int32, error) {
- res := int32(0)
- data := unsafe.Pointer(&res)
- err := d.Ioctl(linux.EVIOCGVERSION, data)
- return res, err
- }
- func (d * Device) Name() (string, error) {
- buffer := [256]byte{}
- err := d.Ioctl(linux.EVIOCGNAME(uintptr(len(buffer))), unsafe.Pointer(&buffer))
- return string(buffer[0:len(buffer)]), err
- }
- func (d * Device) Id() (linux.INPUT_id, error) {
- var result linux.INPUT_id
- err := d.Ioctl(linux.EVIOCGID, unsafe.Pointer(&result))
- return result, err
- }
|