accessory

package module
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 29, 2024 License: MIT Imports: 6 Imported by: 0

README

Introduction

The go-accessoryhid package is an implementation of the AOA 2.0 protocol for Android HID devices.

Dependence on gousb and libusb-1.0.

Documentation

TODO.

Installation

go get -u github.com/Tryanks/go-accessoryhid

Usage

Example:

package main

import accessory "github.com/Tryanks/go-accessoryhid"

func main() {
	devices, err := accessory.GetDevices(2)
	if err != nil {
		panic(err)
	}
	phone := devices[0]
	defer phone.Close()
	keyboard, err := phone.Register(accessory.KeyboardReportDesc) // Register keyboard report descriptor
	err = keyboard.SendEvent([]byte{
		0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
	}) // Hid event (pressing 'a')
	if err != nil {
		panic(err)
	}
	err = keyboard.SendEvent([]byte{
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	}) // Hid event (releasing 'a')
	if err != nil {
		panic(err)
	}
}

Documentation

Index

Constants

View Source
const (
	AccessoryRegisterHid      uint8 = 54
	AccessoryUnregisterHid          = 55
	AccessorySetHidReportDesc       = 56
	AccessorySendHidEvent           = 57

	AccessoryGetProtocol = 51
)

AOAv2 Basic Protocol

USB Control transfer type

Variables

View Source
var (
	ErrorNoAccessoryDevice   = errors.New("ErrorNoAccessoryDevice")
	ErrorFailedToGetProtocol = errors.New("ErrorFailedToGetProtocol")
)

Error definitions

View Source
var ConsumerReportDesc = []byte{
	0x05, 0x0c,
	0x09, 0x01,
	0xa1, 0x01,
	0x15, 0x00,
	0x25, 0x01,
	0x75, 0x01,
	0x95, 0x04,
	0x0a, 0x23, 0x02,
	0x0a, 0x24, 0x02,
	0x09, 0x40,
	0x09, 0x34,
	0x81, 0x06,
	0x75, 0x04,
	0x95, 0x01,
	0x81, 0x03,
	0xc0,
}

ConsumerReportDesc is the HID report descriptor for a consumer control.

View Source
var KeyboardReportDesc = []byte{
	0x05, 0x01,
	0x09, 0x06,
	0xA1, 0x01,
	0x05, 0x07,
	0x19, 0xE0,
	0x29, 0xE7,
	0x15, 0x00,
	0x25, 0x01,
	0x75, 0x01,
	0x95, 0x08,
	0x81, 0x02,
	0x75, 0x08,
	0x95, 0x01,
	0x81, 0x01,
	0x05, 0x08,
	0x19, 0x01,
	0x29, 0x05,
	0x75, 0x01,
	0x95, 0x05,
	0x91, 0x02,
	0x75, 0x03,
	0x95, 0x01,
	0x91, 0x01,
	0x05, 0x07,
	0x19, 0x00,
	0x29, scHidKeyboardKeys - 1,
	0x15, 0x00,
	0x25, scHidKeyboardKeys - 1,
	0x75, 0x08,
	0x95, reportKeyboardMaxKeys,
	0x81, 0x00,
	0xC0,
}

KeyboardReportDesc is the HID report descriptor for a keyboard.

View Source
var MouseReportDesc = []byte{
	0x05, 0x01,
	0x09, 0x02,
	0xA1, 0x01,
	0x09, 0x01,
	0xA1, 0x00,
	0x05, 0x09,
	0x19, 0x01,
	0x29, 0x05,
	0x15, 0x00,
	0x25, 0x01,
	0x95, 0x05,
	0x75, 0x01,
	0x81, 0x02,
	0x95, 0x01,
	0x75, 0x03,
	0x81, 0x01,
	0x05, 0x01,
	0x09, 0x30,
	0x09, 0x31,
	0x09, 0x38,
	0x15, 0x81,
	0x25, 0x7F,
	0x75, 0x08,
	0x95, 0x03,
	0x81, 0x06,
	0xC0,
	0xC0,
}

MouseReportDesc is the HID report descriptor for a mouse.

View Source
var SkipList = []uint16{
	0x8087,
	0x1d6b,
	0x2109,
}

SkipList is a list of vendor IDs that are known to not support the accessory protocol and should be skipped TODO: Add more vendor IDs to the list

View Source
var TouchscreenReportDesc = []byte{
	0x05, 0x0d,
	0x09, 0x04,
	0xa1, 0x01,
	0x09, 0x22,
	0xa1, 0x00,
	0x09, 0x42,
	0x09, 0x51,
	0x15, 0x00,
	0x25, 0x01,
	0x75, 0x01,
	0x95, 0x02,
	0x81, 0x02,
	0x95, 0x0e,
	0x81, 0x03,
	0x05, 0x01,
	0x75, 0x10,
	0x95, 0x01,
	0x55, 0x0d,
	0x65, 0x33,
	0x15, 0x00,
	0x26, 0xff, 0x7f,
	0x09, 0x30,
	0x81, 0x02,
	0x09, 0x31,
	0x81, 0x02,
	0xc0,
	0xc0,
}

TouchscreenReportDesc is the HID report descriptor for a touchscreen.

Functions

This section is empty.

Types

type Accessory

type Accessory struct {
	ParentDevice *AccessoryDevice
	// contains filtered or unexported fields
}

func (*Accessory) SendEvent

func (a *Accessory) SendEvent(event []byte) error

func (*Accessory) Unregister

func (a *Accessory) Unregister() error

type AccessoryDevice

type AccessoryDevice struct {
	Device       *gousb.Device
	Protocol     uint16
	Manufacturer string
	// contains filtered or unexported fields
}

AccessoryDevice Connected Android Device

func GetDevices

func GetDevices(protocolVersion uint16) (accessoryList []*AccessoryDevice, err error)

GetDevices return a list of devices that support the specified protocol version

func NewAccessoryDevice

func NewAccessoryDevice(device *gousb.Device, protocol uint16, manu string) *AccessoryDevice

NewAccessoryDevice Create a new AccessoryDevice

func (*AccessoryDevice) Close

func (a *AccessoryDevice) Close() error

func (*AccessoryDevice) Register

func (a *AccessoryDevice) Register(reportDesc []byte) (accessory *Accessory, err error)

func (*AccessoryDevice) SendHidEvent

func (a *AccessoryDevice) SendHidEvent(hidID uint16, event []byte) error

func (*AccessoryDevice) Unregister

func (a *AccessoryDevice) Unregister(hidID uint16) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL