keyboard

package
v0.0.0-...-5c20dc6 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2024 License: GPL-3.0 Imports: 11 Imported by: 5

Documentation

Index

Constants

View Source
const MacroMagicPrefix uint8 = 1

Variables

This section is empty.

Functions

func DefaultCPUReset

func DefaultCPUReset() error

func DefaultEnterBootloader

func DefaultEnterBootloader() error

Types

type Backlight

type Backlight struct {

	// BacklightDriver implementation to use; if nil, backlight is disabled.
	Driver BacklightDriver

	// Steps is the number of "on" states in between the off and on states.
	// The default zero value is treated the same as a value of 1.
	// A value 1 means that only on/off are supported; any value higher than that
	// will be used to automatically calculate equal "steps" in between the off
	// and fully on state.
	Steps uint8

	// Default backlight mode to use when not explicitly set
	DefaultMode BacklightMode

	// Default backlight level to use when not explicitly set
	DefaultLevel BacklightLevel

	// Whether or not backlight "breathing" is enabled
	SupportsBreathing bool

	// Whether or not to include "breathing" mode when iterating backlight steps
	IncludeBreathingInSteps bool
	// contains filtered or unexported fields
}

func (*Backlight) Configure

func (bl *Backlight) Configure()

func (*Backlight) ProcessKey

func (bl *Backlight) ProcessKey(key keycodes.Keycode, made bool)

func (*Backlight) Sync

func (bl *Backlight) Sync()

type BacklightColorStrip

type BacklightColorStrip struct {

	//
	ColorStrip ColorPixeler

	//
	Interval time.Duration

	// DoubleSyncHack is a temporary workaround for Macropad RP2040
	DoubleSyncHack bool
	// contains filtered or unexported fields
}

func (*BacklightColorStrip) Configure

func (bl *BacklightColorStrip) Configure()

func (*BacklightColorStrip) SetBacklight

func (bl *BacklightColorStrip) SetBacklight(mode BacklightMode, color hsv.Color)

func (*BacklightColorStrip) Task

func (bl *BacklightColorStrip) Task()

type BacklightDriver

type BacklightDriver interface {
	Configure()
	SetBacklight(mode BacklightMode, color hsv.Color)
	Task()
}

type BacklightLevel

type BacklightLevel uint8

type BacklightMode

type BacklightMode uint8
const (
	BacklightOff BacklightMode = iota
	BacklightOn
	BacklightBreathing
)

type BootloaderError

type BootloaderError int
const (
	ErrBootloaderNotSet BootloaderError = iota + 1
	ErrBootloaderNoDefault
)

func (BootloaderError) Error

func (err BootloaderError) Error() string

type ColorPixeler

type ColorPixeler interface {
	NumPixels() int
	GetPixel(pos int) (c color.RGBA)
	SetPixel(pos int, c color.RGBA)
	SyncPixels()
}

type ColorStrip

type ColorStrip struct {
	Writer ColorWriter
	Pixels []color.RGBA
}

func (*ColorStrip) GetPixel

func (ind *ColorStrip) GetPixel(pos int) (c color.RGBA)

func (*ColorStrip) NumPixels

func (ind *ColorStrip) NumPixels() int

func (*ColorStrip) SetPixel

func (ind *ColorStrip) SetPixel(pos int, c color.RGBA)

func (*ColorStrip) SyncPixels

func (ind *ColorStrip) SyncPixels()

type ColorWriter

type ColorWriter interface {
	WriteColors(values []color.RGBA) error
}

type ConsumerKey

type ConsumerKey uint16

type Encoder

type Encoder interface {
	Position() int
	SetPosition(int)
}

type EncoderPos

type EncoderPos struct {
	Encoder
	PosCW  Pos
	PosCCW Pos
}

type Encoders

type Encoders interface {
	EncodersTask()
}

type EncodersSubscriber

type EncodersSubscriber interface {
	EncoderChanged(index int, clockwise bool)
}

type EncodersSubscriberFunc

type EncodersSubscriberFunc func(index int, clockwise bool)

func (EncodersSubscriberFunc) EncoderChanged

func (fn EncodersSubscriberFunc) EncoderChanged(index int, clockwise bool)

type EnterBootloaderFunc

type EnterBootloaderFunc func() error

type Event

type Event struct {
	Pos  Pos
	Made bool
	Time uint32
}

type EventReceiver

type EventReceiver interface {
	// ReceiveEvent is called by the keyboard task loop for matrix state change
	// events. Return value of true indicates that the event is considered to be
	// handled and should not be propagated for handling by the keyboard, and a
	// return value of false indicates the event should be processed normally.
	ReceiveEvent(ev Event) (bool, error)
}

type EventReceiverFunc

type EventReceiverFunc func(ev Event) (bool, error)

func (EventReceiverFunc) ReceiveEvent

func (recv EventReceiverFunc) ReceiveEvent(ev Event) (bool, error)

type FsErr

type FsErr uint8
const (
	ErrNoFS FsErr = iota
	ErrNotAFile
)

func (FsErr) Error

func (err FsErr) Error() string

type Host

type Host interface {
	Send(report Report)
	LEDs() uint8
}

type KeyAction

type KeyAction interface {
	KeyAction(key keycodes.Keycode, made bool)
}

type KeyActionFunc

type KeyActionFunc func(key keycodes.Keycode, made bool)

func (KeyActionFunc) KeyAction

func (fn KeyActionFunc) KeyAction(key keycodes.Keycode, made bool)

type Keyboard

type Keyboard struct {
	// contains filtered or unexported fields
}

func New

func New(host Host, matrix *Matrix, keymap Keymap) *Keyboard

func (*Keyboard) ActiveLayer

func (kbd *Keyboard) ActiveLayer() uint8

func (*Keyboard) AddEventReceiver

func (kbd *Keyboard) AddEventReceiver(receiver EventReceiver)

func (*Keyboard) BacklightColor

func (kbd *Keyboard) BacklightColor() hsv.Color

func (*Keyboard) BacklightDriver

func (kbd *Keyboard) BacklightDriver() BacklightDriver

func (*Keyboard) BacklightEnabled

func (kbd *Keyboard) BacklightEnabled() bool

func (*Keyboard) BacklightMode

func (kbd *Keyboard) BacklightMode() BacklightMode

func (*Keyboard) BacklightUpdate

func (kbd *Keyboard) BacklightUpdate(mode BacklightMode, color hsv.Color, force bool)

func (*Keyboard) CLI

func (kbd *Keyboard) CLI() *console.Console

func (*Keyboard) CPUReset

func (kbd *Keyboard) CPUReset() error

func (*Keyboard) ClearKeycodes

func (kbd *Keyboard) ClearKeycodes()

func (*Keyboard) ConfigureFilesystem

func (kbd *Keyboard) ConfigureFilesystem() (err error)

func (*Keyboard) EnableConsole

func (kbd *Keyboard) EnableConsole(serialer Serialer, cmds ...console.Commands)

func (*Keyboard) EnterBootloader

func (kbd *Keyboard) EnterBootloader() error

func (*Keyboard) FS

func (kbd *Keyboard) FS() tinyfs.Filesystem

func (*Keyboard) GetLayerCount

func (kbd *Keyboard) GetLayerCount() uint8

func (*Keyboard) GetMatrixRowState

func (kbd *Keyboard) GetMatrixRowState(idx int) uint32

func (*Keyboard) LEDs

func (kbd *Keyboard) LEDs() LEDs

func (*Keyboard) LoadKeymapFromFile

func (kbd *Keyboard) LoadKeymapFromFile(filename string) (n int64, err error)

LoadKeymapFromFile updates the current in-memory keymap from the filesystem

func (*Keyboard) LoadMacrosFromFile

func (kbd *Keyboard) LoadMacrosFromFile(filename string) (n int64, err error)

LoadMacrosFromFile updates the current in-memory macros from the filesystem

func (*Keyboard) MacrosEnabled

func (kbd *Keyboard) MacrosEnabled() bool

func (*Keyboard) MapKey

func (kbd *Keyboard) MapKey(layer, row, col int) keycodes.Keycode

func (*Keyboard) MatrixCols

func (kbd *Keyboard) MatrixCols() uint8

func (*Keyboard) MatrixRows

func (kbd *Keyboard) MatrixRows() uint8

func (*Keyboard) Modifiers

func (kbd *Keyboard) Modifiers() KeyboardModifier

func (*Keyboard) ProcessKeycode

func (kbd *Keyboard) ProcessKeycode(key keycodes.Keycode, made bool)

func (*Keyboard) RTCInitialized

func (kbd *Keyboard) RTCInitialized() bool

func (*Keyboard) RTCSet

func (kbd *Keyboard) RTCSet(t time.Time) (err error)

func (*Keyboard) RTCTime

func (kbd *Keyboard) RTCTime() (time.Time, error)

func (*Keyboard) SaveKeymapToFile

func (kbd *Keyboard) SaveKeymapToFile(filename string) (n int64, err error)

SaveKeymapToFile write the current in-memory keymap to the filesystem

func (*Keyboard) SaveMacrosToFile

func (kbd *Keyboard) SaveMacrosToFile(filename string) (n int64, err error)

SaveMacrosToFile write the current in-memory macros to the filesystem

func (*Keyboard) SetActiveLayer

func (kbd *Keyboard) SetActiveLayer(index uint8)

func (*Keyboard) SetBacklight

func (kbd *Keyboard) SetBacklight(bl Backlight)

func (*Keyboard) SetCPUResetFunc

func (kbd *Keyboard) SetCPUResetFunc(fn EnterBootloaderFunc)

func (*Keyboard) SetEncoders

func (kbd *Keyboard) SetEncoders(encs []Encoder, subscriber EncodersSubscriber)

func (*Keyboard) SetEnterBootloaderFunc

func (kbd *Keyboard) SetEnterBootloaderFunc(fn EnterBootloaderFunc)

func (*Keyboard) SetFS

func (kbd *Keyboard) SetFS(fs tinyfs.Filesystem)

func (*Keyboard) SetKey

func (kbd *Keyboard) SetKey(layer, row, col int, kc keycodes.Keycode) bool

TODO: Keep track of "dirty" keys and implement keypress for saving

func (*Keyboard) SetKeyAction

func (kbd *Keyboard) SetKeyAction(action KeyAction)

func (*Keyboard) SetMacroDriver

func (kbd *Keyboard) SetMacroDriver(m MacrosDriver)

func (*Keyboard) SetRTC

func (kbd *Keyboard) SetRTC(dev RTC)

func (*Keyboard) Task

func (kbd *Keyboard) Task()

type KeyboardModifier

type KeyboardModifier byte
const (
	KbdModNone       KeyboardModifier = 0x0
	KbdModCtrlLeft   KeyboardModifier = 1 << 0
	KbdModShiftLeft  KeyboardModifier = 1 << 1
	KbdModAltLeft    KeyboardModifier = 1 << 2
	KbdModGuiLeft    KeyboardModifier = 1 << 3
	KbdModCtrlRight  KeyboardModifier = 1 << 4
	KbdModShiftRight KeyboardModifier = 1 << 5
	KbdModAltRight   KeyboardModifier = 1 << 6
	KbdModGuiRight   KeyboardModifier = 1 << 7
)

type KeycodeProcessor

type KeycodeProcessor interface {
	ProcessKeycode(kc keycodes.Keycode, made bool)
	ClearKeycodes()
	Modifiers() KeyboardModifier
}

type Keymap

type Keymap []Layer

func (Keymap) GetLayerCount

func (keymap Keymap) GetLayerCount() uint8

func (Keymap) GetMaxKeyCount

func (keymap Keymap) GetMaxKeyCount() int

func (Keymap) MapKey

func (keymap Keymap) MapKey(layer, row, col int) (kc keycodes.Keycode)

func (Keymap) NumCols

func (keymap Keymap) NumCols() int

func (Keymap) NumRows

func (keymap Keymap) NumRows() int

func (Keymap) ReadFrom

func (keymap Keymap) ReadFrom(r io.Reader) (n int64, err error)

func (Keymap) SetKey

func (keymap Keymap) SetKey(layer, row, col int, kc keycodes.Keycode) bool

func (Keymap) StoredSize

func (keymap Keymap) StoredSize() int

func (Keymap) WriteTo

func (keymap Keymap) WriteTo(w io.Writer) (n int64, err error)

func (Keymap) ZeroFill

func (keymap Keymap) ZeroFill()

type LED

type LED uint8
const (
	LEDNumLock    LED = 1
	LEDCapsLock   LED = 2
	LEDScrollLock LED = 3
)

type LEDs

type LEDs uint8

func (*LEDs) Get

func (l *LEDs) Get(led LED) bool

func (*LEDs) Set

func (l *LEDs) Set(led LED, on bool)

type Layer

type Layer [][]keycodes.Keycode

func (Layer) KeyAt

func (layer Layer) KeyAt(row, col int) keycodes.Keycode

type MacroCode

type MacroCode uint8
const (
	MacroCodeNone MacroCode = iota
	MacroCodeTap
	MacroCodeDown
	MacroCodeUp
	MacroCodeDelay
	MacroCodeVialExtTap
	MacroCodeVialExtDown
	MacroCodeVialExtUp
	MacroCodeSend
)

func (MacroCode) String

func (i MacroCode) String() string

type MacroError

type MacroError uint8
const (
	MacroErrInvalidNum MacroError = iota + 1
)

func (MacroError) Error

func (err MacroError) Error() string

type Macros

type Macros struct {
	// MacroDriver implementation to use; if nil, macros are disabled.
	Driver MacrosDriver
}

func (*Macros) Enabled

func (m *Macros) Enabled() bool

func (*Macros) ProcessKey

func (m *Macros) ProcessKey(key keycodes.Keycode, made bool)

type MacrosDriver

type MacrosDriver interface {
	Configure()
	Count() uint8
	RunMacro(macroNum uint8) (err error)
	Task(proc KeycodeProcessor)
	io.ReaderFrom
	io.WriterTo
	ZeroFill()
}

func NewDefaultMacroDriver

func NewDefaultMacroDriver(count uint8, bufferSize uint16) MacrosDriver

type Matrix

type Matrix struct {
	// contains filtered or unexported fields
}

func NewMatrix

func NewMatrix(r, c uint8, io RowReader) *Matrix

func (*Matrix) Cols

func (m *Matrix) Cols() uint8

func (*Matrix) EncoderCount

func (m *Matrix) EncoderCount() int

func (*Matrix) GetRow

func (m *Matrix) GetRow(row uint8) Row

func (*Matrix) Ghosting

func (m *Matrix) Ghosting() bool

func (*Matrix) HasGhostInRow

func (m *Matrix) HasGhostInRow(row uint8) bool

func (*Matrix) IsOn

func (m *Matrix) IsOn(row uint8, col uint8) bool

func (*Matrix) MapEncoder

func (m *Matrix) MapEncoder(idx int) (ccw Pos, cw Pos, ok bool)

func (*Matrix) Rows

func (m *Matrix) Rows() uint8

func (*Matrix) Scan

func (m *Matrix) Scan() (changed bool)

func (*Matrix) WithEncoders

func (m *Matrix) WithEncoders(encs ...EncoderPos) *Matrix

func (*Matrix) WithGhosting

func (m *Matrix) WithGhosting(hasGhosting bool) *Matrix

type MouseButton

type MouseButton byte
const (
	MouseBtnLeft   MouseButton = 0x01
	MouseBtnRight  MouseButton = 0x02
	MouseBtnMiddle MouseButton = 0x04
)

type MouseKeys

type MouseKeys struct {
	// contains filtered or unexported fields
}

func NewMouseKeys

func NewMouseKeys(config MouseKeysConfig) *MouseKeys

func (*MouseKeys) Break

func (mk *MouseKeys) Break(code keycodes.Keycode)

func (*MouseKeys) Make

func (mk *MouseKeys) Make(code keycodes.Keycode)

func (*MouseKeys) Task

func (mk *MouseKeys) Task(report *Report) bool

type MouseKeysConfig

type MouseKeysConfig struct {
	MoveDelta     uint16
	MoveMaxSpeed  uint16
	MoveTimeToMax uint16

	WheelDelta     uint16
	WheelMaxSpeed  uint16
	WheelTimeToMax uint16

	Delay    time.Duration
	Interval time.Duration
}

type Pos

type Pos struct {
	// Layer uint8 // TBD
	Row uint8
	Col uint8
}

type RTC

type RTC interface {
	// Init() error
	ReadTime() (t time.Time, err error)
	SetTime(t time.Time) (err error)
}

type RTCError

type RTCError int
const (
	ErrRTCNotSet RTCError = iota
	ErrRTCNoInit
	ErrRTCUpdating
)

func (RTCError) Error

func (err RTCError) Error() string

type Report

type Report [8]byte

func (*Report) Break

func (r *Report) Break(key keycodes.Keycode)

func (*Report) Keyboard

func (r *Report) Keyboard(mod KeyboardModifier, keys ...byte)

func (*Report) Make

func (r *Report) Make(key keycodes.Keycode)

func (*Report) Mouse

func (r *Report) Mouse(buttons MouseButton, x int8, y int8, v int8, h int8)

TODO: implement wheel, accel

func (*Report) String

func (r *Report) String() string

func (*Report) Type

func (r *Report) Type() ReportType

func (*Report) WriteDebug

func (r *Report) WriteDebug(w io.Writer)

type ReportType

type ReportType byte
const (
	RptKeyboard ReportType = 0x0
	RptMouse    ReportType = 0x2
	RptConsumer ReportType = 0x3
)

func (ReportType) String

func (t ReportType) String() string

type Row

type Row uint32

func (Row) IsOn

func (r Row) IsOn(col uint8) bool

type RowReader

type RowReader interface {
	ReadRow(rowIndex uint8) Row
}

type RowReaderFunc

type RowReaderFunc func(rowIndex uint8) Row

func (RowReaderFunc) ReadRow

func (fn RowReaderFunc) ReadRow(rowIndex uint8) Row

type Serialer

type Serialer interface {
	io.Writer
	io.ByteReader
	io.ByteWriter
	Buffered() int
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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