2022-02-01 15:56:15 +01:00
|
|
|
// Copyright 2022 The Ebiten Authors
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2022-08-12 05:40:23 +02:00
|
|
|
//go:build !android && !nintendosdk
|
2022-02-01 15:56:15 +01:00
|
|
|
|
|
|
|
package gamepad
|
|
|
|
|
|
|
|
import (
|
|
|
|
"unsafe"
|
2022-10-29 16:23:13 +02:00
|
|
|
|
|
|
|
"golang.org/x/sys/unix"
|
2022-02-01 15:56:15 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
_ABS_HAT0X = 0x10
|
|
|
|
_ABS_HAT3Y = 0x17
|
|
|
|
_ABS_MAX = 0x3f
|
|
|
|
_ABS_CNT = _ABS_MAX + 1
|
|
|
|
|
|
|
|
_BTN_MISC = 0x100
|
|
|
|
|
|
|
|
_IOC_NONE = 0
|
|
|
|
_IOC_WRITE = 1
|
|
|
|
_IOC_READ = 2
|
|
|
|
|
|
|
|
_IOC_NRBITS = 8
|
|
|
|
_IOC_TYPEBITS = 8
|
|
|
|
_IOC_SIZEBITS = 14
|
|
|
|
_IOC_DIRBITS = 2
|
|
|
|
|
|
|
|
_IOC_NRSHIFT = 0
|
|
|
|
_IOC_TYPESHIFT = _IOC_NRSHIFT + _IOC_NRBITS
|
|
|
|
_IOC_SIZESHIFT = _IOC_TYPESHIFT + _IOC_TYPEBITS
|
|
|
|
_IOC_DIRSHIFT = _IOC_SIZESHIFT + _IOC_SIZEBITS
|
|
|
|
|
|
|
|
_KEY_MAX = 0x2ff
|
|
|
|
_KEY_CNT = _KEY_MAX + 1
|
|
|
|
|
|
|
|
_SYN_REPORT = 0
|
|
|
|
_SYN_DROPPED = 3
|
|
|
|
)
|
|
|
|
|
|
|
|
func _IOC(dir, typ, nr, size uint) uint {
|
|
|
|
return dir<<_IOC_DIRSHIFT | typ<<_IOC_TYPESHIFT | nr<<_IOC_NRSHIFT | size<<_IOC_SIZESHIFT
|
|
|
|
}
|
|
|
|
|
|
|
|
func _IOR(typ, nr, size uint) uint {
|
|
|
|
return _IOC(_IOC_READ, typ, nr, size)
|
|
|
|
}
|
|
|
|
|
|
|
|
func _EVIOCGABS(abs uint) uint {
|
|
|
|
return _IOR('E', 0x40+abs, uint(unsafe.Sizeof(input_absinfo{})))
|
|
|
|
}
|
|
|
|
|
|
|
|
func _EVIOCGBIT(ev, len uint) uint {
|
|
|
|
return _IOC(_IOC_READ, 'E', 0x20+ev, len)
|
|
|
|
}
|
|
|
|
|
|
|
|
func _EVIOCGID() uint {
|
|
|
|
return _IOR('E', 0x02, uint(unsafe.Sizeof(input_id{})))
|
|
|
|
}
|
|
|
|
|
|
|
|
func _EVIOCGNAME(len uint) uint {
|
|
|
|
return _IOC(_IOC_READ, 'E', 0x06, len)
|
|
|
|
}
|
|
|
|
|
|
|
|
type input_absinfo struct {
|
|
|
|
value int32
|
|
|
|
minimum int32
|
|
|
|
maximum int32
|
|
|
|
fuzz int32
|
|
|
|
flat int32
|
|
|
|
resolution int32
|
|
|
|
}
|
|
|
|
|
|
|
|
type input_event struct {
|
2022-10-29 16:23:13 +02:00
|
|
|
time unix.Timeval
|
2022-02-01 15:56:15 +01:00
|
|
|
typ uint16
|
|
|
|
code uint16
|
|
|
|
value int32
|
|
|
|
}
|
|
|
|
|
|
|
|
type input_id struct {
|
|
|
|
bustype uint16
|
|
|
|
vendor uint16
|
|
|
|
product uint16
|
|
|
|
version uint16
|
|
|
|
}
|
|
|
|
|
|
|
|
func ioctl(fd int, request uint, ptr unsafe.Pointer) error {
|
2022-10-29 16:23:13 +02:00
|
|
|
r, _, e := unix.Syscall(unix.SYS_IOCTL, uintptr(fd), uintptr(request), uintptr(ptr))
|
2022-02-01 15:56:15 +01:00
|
|
|
if r < 0 {
|
2022-10-29 16:23:13 +02:00
|
|
|
return unix.Errno(e)
|
2022-02-01 15:56:15 +01:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|