chimp

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2018 License: MIT Imports: 10 Imported by: 0

README

Chimp

Chimp is a simple input package (mice, tablets etc). Device support will be added when there is a need for it. The initial purpose of the package is to support drawing tablet input for a paint program yet to be written.

The package builds on top of (a forked) version of golang-evdev trying to provide a more user-friendly API. For example Wacom tablets are exposed as three independent devices by Linux and golang-evdev. This packages opens all three automatically and multiplexes all events from them into one event stream.

Documentation

Use the godoc tool to view API documentation.

Supported OS

Only Linux is supported at the moment but the Linux device events are converted to another representation exported by this package in a platform independent manner.

Sample Programs

There are two sample programs under cmd/ which is built in the standard Go fashion.

Pick your poision:

  • go get github.com/johan-bolmsjo/chimp/cmd/chimp-dump-events
  • cd cmd/chimp-dump-events && go build
  • go install ./...
chimp-dump-events

Open first supported device and dump all events read from it.

chimp-list-devices

List all found supported devices.

Supported devices

  • Wacom Bamboo 16FG 6x8 (Linux)

Documentation

Overview

Package chimp is a simple input package (mice, tablets etc). Device support will be added when there is a need for it. The initial purpose of the package is to support drawing tablet input for a paint program.

Only Linux is supported at the moment but the Linux device events are converted to another representation exported by this package in a platform independent manner.

Supported devices:

Wacom Bamboo 16FG 6x8 (Linux)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Button

type Button uint32

Button is an enumeration of different buttons.

const (
	ButtonPenTip    Button = iota // Tip of pen
	ButtonPenEraser               // Eraser on pen
	ButtonPen1                    // Button 1 on pen
	ButtonPen2                    // Button 2 on pen
	ButtonPen3                    // Button 3 on pen
	ButtonLeft
	ButtonRight
	ButtonForward
	ButtonBack
	ButtonTouch // Single-touch event such as finger on touchpad
)

func (Button) String

func (i Button) String() string

type Capabilities

type Capabilities struct {
	PositionDevices []PositionDevice
	Buttons         []Button
}

Capabilities of device.

func (*Capabilities) HasButton

func (cap *Capabilities) HasButton(button Button) bool

HasButton checks if device has button.

func (*Capabilities) HasPositionDevice

func (cap *Capabilities) HasPositionDevice(device PositionDevice) bool

HasButton checks if device has position device.

func (*Capabilities) String

func (cap *Capabilities) String() string

type Coord2D

type Coord2D struct {
	X, Y float32
}

Coord2D is a two dimensional coordinate.

func (*Coord2D) String

func (c *Coord2D) String() string

type Device

type Device interface {
	// Properties returns properties of device.
	Properties() Properties

	// Capabilities returns capabilities of device.
	Capabilities() *Capabilities

	// Read event from device.
	// TODO: Define how to handle errors, reopening device?
	Read() (Event, error)

	// Close device.
	Close()
}

Device is any opened input device.

type DeviceInfo

type DeviceInfo struct {
	Name string                 // Name of device.
	Type DeviceType             // Device type.
	Open func() (Device, error) // Function that opens the device.
}

DeviceInfo contains some brief device information that can be inspected before deciding to open a device.

func ListDevices

func ListDevices() ([]DeviceInfo, error)

ListDevices lists available input devices that may be opened and used.

type DeviceType

type DeviceType int

DeviceType is an enumeration of basic device types such as "Mouse", "Tablet" etc.

const (
	DeviceTypeTablet DeviceType = iota
	DeviceTypeMouse
)

func (DeviceType) String

func (i DeviceType) String() string

type Event

type Event interface {
	// Time is the time when the event was generated.
	Time() time.Time

	// String returns a textual representation of the event.
	String() string
}

Event is implemented by all event types.

type EventButton

type EventButton struct {
	Timestamp time.Time // Time when event was generated.
	Button    Button    // Button code.
	Pressure  float32   // Pressure on button in range [0, 1], 0 or 1 for digital buttons.
}

EventButton is generated for everything that can be modeled as a digital or analogue button.

func (*EventButton) String

func (e *EventButton) String() string

func (*EventButton) Time

func (e *EventButton) Time() time.Time

type EventPositionFinger

type EventPositionFinger struct {
	Timestamp time.Time // Time when event was generated.
	Coord     Coord2D   // Finger position, axis are in range [0, 1], origo in upper left corner
}

EventPositionFinger is generated for movement of finger on tablet or similar.

func (*EventPositionFinger) String

func (e *EventPositionFinger) String() string

func (*EventPositionFinger) Time

func (e *EventPositionFinger) Time() time.Time

type EventPositionPen

type EventPositionPen struct {
	Timestamp time.Time // Time when event was generated.
	Coord     Coord2D   // Pen position on tablet, axis are in range [0, 1], origo in upper left corner.
	Distance  float32   // Distance of for example pen to tablet in range [0, 1], 0 is on tablet.
}

EventPositionPen is generated for movement of pen on a typical 2D tablet.

func (*EventPositionPen) String

func (e *EventPositionPen) String() string

func (*EventPositionPen) Time

func (e *EventPositionPen) Time() time.Time

type PositionDevice

type PositionDevice uint32

PositionDevice is an enumeration of different position device types.

const (
	PositionDevicePen PositionDevice = iota
	PositionDeviceFinger
)

func (PositionDevice) String

func (i PositionDevice) String() string

type Properties

type Properties map[Property]PropertyValue

Properties of device.

func (Properties) String

func (props Properties) String() (result string)

type Property

type Property string

Property of device

const (
	PropertyDeviceName           Property = "device-name"
	PropertyDeviceType           Property = "device-type"
	PropertyPadWidthMillimeters  Property = "pad-width-millimeters"  // Width of the pad along the X-axis.
	PropertyPadHeightMillimeters Property = "pad-height-millimeters" // Width of the pad along the Y-axis.
	PropertyPadWidthHeightRatio  Property = "pad-width-height-ratio"
)

type PropertyValue

type PropertyValue interface {
	// Type returns the property value type as a string, e.g. "string" or "number".
	Type() string

	// String returns the property value as a string.
	// All types can be converted to a string.
	String() string

	// Number returns the property value as a float.
	// Zero is returned when this is not applicable.
	Number() float64
}

PropertyValue represents property values of different types.

type PropertyValueNumber

type PropertyValueNumber float64

PropertyValueNumber represent numeric property values.

func (PropertyValueNumber) Number

func (val PropertyValueNumber) Number() float64

func (PropertyValueNumber) String

func (val PropertyValueNumber) String() string

func (PropertyValueNumber) Type

func (val PropertyValueNumber) Type() string

type PropertyValueString

type PropertyValueString string

PropertyValueString represent string property values.

func (PropertyValueString) Number

func (val PropertyValueString) Number() float64

func (PropertyValueString) String

func (val PropertyValueString) String() string

func (PropertyValueString) Type

func (val PropertyValueString) Type() string

Directories

Path Synopsis
cmd
internal

Jump to

Keyboard shortcuts

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