device

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package device provides device profile abstraction for different USB display panels.

Each supported device type implements the DeviceProfile interface, which defines the device's properties (resolution, color format) and protocol (command building).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatVIDPID

func FormatVIDPID(vendorID, productID uint16) string

FormatVIDPID formats a VID/PID pair as a string.

func GenerateProfile

func GenerateProfile(spec DeviceSpec) (string, error)

GenerateProfile generates Go source code for a device profile.

func IsKnownDevice

func IsKnownDevice(vendorID, productID uint16) bool

IsKnownDevice returns true if the VID/PID matches a known device profile.

func KnownVIDPIDs

func KnownVIDPIDs() [][2]uint16

KnownVIDPIDs returns all known VID/PID pairs from registered profiles.

func Register

func Register(profile DeviceProfile)

Register adds a device profile to the registry. This is typically called during package initialization.

Types

type ByteOrder

type ByteOrder int

ByteOrder represents the byte order for multi-byte pixel values.

const (
	// BigEndian means most significant byte first.
	BigEndian ByteOrder = iota
	// LittleEndian means least significant byte first.
	LittleEndian
)

func (ByteOrder) String

func (b ByteOrder) String() string

type ColorFormat

type ColorFormat int

ColorFormat represents the pixel color format used by the device.

const (
	// RGB565 is 16-bit color (5 bits red, 6 bits green, 5 bits blue).
	RGB565 ColorFormat = iota
	// RGB888 is 24-bit color (8 bits per channel).
	RGB888
)

func (ColorFormat) BytesPerPixel

func (c ColorFormat) BytesPerPixel() int

BytesPerPixel returns the number of bytes per pixel for this color format.

func (ColorFormat) String

func (c ColorFormat) String() string

type DeviceProfile

type DeviceProfile interface {

	// ID returns the unique identifier for this profile (e.g., "qtkeji", "ax206").
	ID() string

	// Name returns the human-readable name of the device.
	Name() string

	// Description returns a brief description of the device.
	Description() string

	// Matches returns true if this profile supports the given VID/PID.
	Matches(vendorID, productID uint16) bool

	// VendorIDs returns all vendor IDs this profile supports.
	VendorIDs() []uint16

	// ProductIDs returns all product IDs this profile supports.
	ProductIDs() []uint16

	// Width returns the display width in pixels.
	Width() int

	// Height returns the display height in pixels.
	Height() int

	// ColorFormat returns the pixel color format.
	ColorFormat() ColorFormat

	// ByteOrder returns the byte order for pixel data.
	ByteOrder() ByteOrder

	// BufferSize returns the total frame buffer size in bytes.
	BufferSize() int

	// MaxBrightness returns the maximum brightness level (0 = no backlight control).
	MaxBrightness() int

	// ProtocolType returns the USB protocol type used by this device.
	ProtocolType() ProtocolType

	// BlitCommand builds the command bytes for sending image data to the display.
	// Parameters specify the destination rectangle and data length.
	BlitCommand(x, y, w, h int, dataLen int) []byte

	// BacklightCommand builds the command bytes for setting backlight brightness.
	BacklightCommand(level int) []byte

	// ParseResponse validates a response from the device.
	// Returns nil if the response indicates success, error otherwise.
	ParseResponse(data []byte) error

	// ConvertImage converts a Go image to the device's native pixel format.
	// The returned byte slice is ready to be sent to the device.
	ConvertImage(img image.Image) []byte
}

DeviceProfile defines the interface for a USB display device profile.

Each supported device type implements this interface to provide: - Device identification (VID/PID matching) - Display properties (resolution, color format) - Protocol implementation (command building, image conversion)

func All

func All() []DeviceProfile

All returns all registered device profiles.

func FindByID

func FindByID(id string) DeviceProfile

FindByID finds a profile by its unique ID. Returns nil if no matching profile is found.

func FindByVIDPID

func FindByVIDPID(vendorID, productID uint16) DeviceProfile

FindByVIDPID finds a profile that matches the given vendor and product ID. Returns nil if no matching profile is found.

func MustFindByVIDPID

func MustFindByVIDPID(vendorID, productID uint16) DeviceProfile

MustFindByVIDPID finds a profile or returns a generic fallback. This never returns nil - if no specific profile matches, a GenericProfile is returned.

type DeviceSpec

type DeviceSpec struct {
	ID            string
	Name          string
	Description   string
	VendorID      uint16
	ProductID     uint16
	Width         int
	Height        int
	ColorFormat   ColorFormat
	ByteOrder     ByteOrder
	MaxBrightness int
	ProtocolType  ProtocolType
}

DeviceSpec contains the specification for generating a device profile.

func (*DeviceSpec) BufferSize

func (s *DeviceSpec) BufferSize() int

BufferSize calculates the buffer size for the display.

func (*DeviceSpec) ByteOrderStr

func (s *DeviceSpec) ByteOrderStr() string

ByteOrderStr returns the ByteOrder as a Go constant string.

func (*DeviceSpec) ColorFormatStr

func (s *DeviceSpec) ColorFormatStr() string

ColorFormatStr returns the ColorFormat as a Go constant string.

func (*DeviceSpec) ProtocolTypeStr

func (s *DeviceSpec) ProtocolTypeStr() string

ProtocolTypeStr returns the ProtocolType as a Go constant string.

func (*DeviceSpec) StructName

func (s *DeviceSpec) StructName() string

StructName returns the Go struct name for this device.

func (*DeviceSpec) Validate

func (s *DeviceSpec) Validate() error

Validate checks if the spec has all required fields.

type GenericProfile

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

GenericProfile is a fallback profile for unknown USB display devices.

It uses the same protocol as QTKeJi devices, which is the most common. This allows basic functionality even for unrecognized devices.

func NewGenericProfile

func NewGenericProfile(vendorID, productID uint16) *GenericProfile

NewGenericProfile creates a generic profile for an unknown device.

func NewGenericProfileWithSize

func NewGenericProfileWithSize(vendorID, productID uint16, width, height int) *GenericProfile

NewGenericProfileWithSize creates a generic profile with custom dimensions.

func (*GenericProfile) BacklightCommand

func (p *GenericProfile) BacklightCommand(level int) []byte

BacklightCommand builds the SCSI CBW for setting backlight brightness.

func (*GenericProfile) BlitCommand

func (p *GenericProfile) BlitCommand(x, y, w, h int, dataLen int) []byte

BlitCommand builds the SCSI CBW for sending image data. Uses QTKeJi-compatible protocol as a reasonable default.

func (*GenericProfile) BufferSize

func (p *GenericProfile) BufferSize() int

BufferSize returns the total frame buffer size in bytes.

func (*GenericProfile) ByteOrder

func (p *GenericProfile) ByteOrder() ByteOrder

ByteOrder returns the byte order for pixel data.

func (*GenericProfile) ColorFormat

func (p *GenericProfile) ColorFormat() ColorFormat

ColorFormat returns the pixel color format.

func (*GenericProfile) ConvertImage

func (p *GenericProfile) ConvertImage(img image.Image) []byte

ConvertImage converts a Go image to the device's native pixel format.

func (*GenericProfile) Description

func (p *GenericProfile) Description() string

Description returns a brief description.

func (*GenericProfile) Height

func (p *GenericProfile) Height() int

Height returns the display height in pixels.

func (*GenericProfile) ID

func (p *GenericProfile) ID() string

ID returns the unique identifier for this profile.

func (*GenericProfile) Matches

func (p *GenericProfile) Matches(vendorID, productID uint16) bool

Matches returns true if this profile supports the given VID/PID. Generic profile matches only its specific VID/PID, not as a catch-all.

func (*GenericProfile) MaxBrightness

func (p *GenericProfile) MaxBrightness() int

MaxBrightness returns the maximum brightness level.

func (*GenericProfile) Name

func (p *GenericProfile) Name() string

Name returns the human-readable device name.

func (*GenericProfile) ParseResponse

func (p *GenericProfile) ParseResponse(data []byte) error

ParseResponse validates a CSW response from the device.

func (*GenericProfile) ProductIDs

func (p *GenericProfile) ProductIDs() []uint16

ProductIDs returns all product IDs this profile supports.

func (*GenericProfile) ProtocolType

func (p *GenericProfile) ProtocolType() ProtocolType

ProtocolType returns the USB protocol type.

func (*GenericProfile) VendorIDs

func (p *GenericProfile) VendorIDs() []uint16

VendorIDs returns all vendor IDs this profile supports.

func (*GenericProfile) Width

func (p *GenericProfile) Width() int

Width returns the display width in pixels.

type ProfileInfo

type ProfileInfo struct {
	ID          string
	Name        string
	Description string
	Width       int
	Height      int
	ColorFormat ColorFormat
	ByteOrder   ByteOrder
	VendorIDs   []uint16
	ProductIDs  []uint16
}

ProfileInfo contains basic information about a device profile for display purposes.

func GetInfo

func GetInfo(p DeviceProfile) ProfileInfo

GetInfo extracts displayable information from a DeviceProfile.

func ListProfiles

func ListProfiles() []ProfileInfo

ListProfiles returns information about all registered profiles.

type ProtocolType

type ProtocolType int

ProtocolType represents the USB protocol used by the device.

const (
	// ProtocolSCSI uses SCSI Command Block Wrapper for commands.
	ProtocolSCSI ProtocolType = iota
	// ProtocolBulk uses raw bulk transfers.
	ProtocolBulk
)

func (ProtocolType) String

func (p ProtocolType) String() string

type QTKeJiProfile

type QTKeJiProfile struct{}

QTKeJiProfile implements DeviceProfile for QTKeJi/AIDA64 USB displays.

These are 480x320 displays commonly sold as "AIDA64-compatible" USB sensor panels. They use SCSI-style vendor commands with RGB565 big-endian pixel format.

Known VID/PID pairs:

  • 1908:0102 (most common)
  • 1908:0103 (variant)

func (*QTKeJiProfile) BacklightCommand

func (p *QTKeJiProfile) BacklightCommand(level int) []byte

BacklightCommand builds the SCSI CBW for setting backlight brightness.

QTKeJi/AIDA64 Protocol:

  • cmd[0] = 0xCD (vendor prefix)
  • cmd[5] = 0x06 (BLIT/display operation)
  • cmd[6] = 0x01 (set property subcommand)
  • cmd[7] = 0x01 (property enabled)
  • cmd[8] = 0x00
  • cmd[9] = brightness level (0-7)
  • cmd[10] = 0x00

func (*QTKeJiProfile) BlitCommand

func (p *QTKeJiProfile) BlitCommand(x, y, w, h int, dataLen int) []byte

BlitCommand builds the SCSI CBW for sending image data.

QTKeJi/AIDA64 Protocol:

  • cmd[0] = 0xCD (vendor prefix)
  • cmd[5] = 0x06 (BLIT operation type)
  • cmd[6] = 0x12 (write image subcommand)
  • cmd[7-10] = 0 (reserved)
  • cmd[11-12] = width - 1 (little-endian)
  • cmd[13-14] = height - 1 (little-endian)

func (*QTKeJiProfile) BufferSize

func (p *QTKeJiProfile) BufferSize() int

BufferSize returns the total frame buffer size in bytes.

func (*QTKeJiProfile) ByteOrder

func (p *QTKeJiProfile) ByteOrder() ByteOrder

ByteOrder returns the byte order for pixel data.

func (*QTKeJiProfile) ColorFormat

func (p *QTKeJiProfile) ColorFormat() ColorFormat

ColorFormat returns the pixel color format.

func (*QTKeJiProfile) ConvertImage

func (p *QTKeJiProfile) ConvertImage(img image.Image) []byte

ConvertImage converts a Go image to the device's native pixel format.

func (*QTKeJiProfile) CreateSolidColorBuffer

func (p *QTKeJiProfile) CreateSolidColorBuffer(r, g, b uint8) []byte

CreateSolidColorBuffer creates an RGB565 buffer filled with a single color.

func (*QTKeJiProfile) CreateTestPatternBuffer

func (p *QTKeJiProfile) CreateTestPatternBuffer() []byte

CreateTestPatternBuffer creates a 4-color quadrant test pattern.

func (*QTKeJiProfile) Description

func (p *QTKeJiProfile) Description() string

Description returns a brief description.

func (*QTKeJiProfile) Height

func (p *QTKeJiProfile) Height() int

Height returns the display height in pixels.

func (*QTKeJiProfile) ID

func (p *QTKeJiProfile) ID() string

ID returns the unique identifier for this profile.

func (*QTKeJiProfile) Matches

func (p *QTKeJiProfile) Matches(vendorID, productID uint16) bool

Matches returns true if this profile supports the given VID/PID.

func (*QTKeJiProfile) MaxBrightness

func (p *QTKeJiProfile) MaxBrightness() int

MaxBrightness returns the maximum brightness level.

func (*QTKeJiProfile) Name

func (p *QTKeJiProfile) Name() string

Name returns the human-readable device name.

func (*QTKeJiProfile) ParseResponse

func (p *QTKeJiProfile) ParseResponse(data []byte) error

ParseResponse validates a CSW response from the device.

func (*QTKeJiProfile) ProductIDs

func (p *QTKeJiProfile) ProductIDs() []uint16

ProductIDs returns all product IDs this profile supports.

func (*QTKeJiProfile) ProtocolType

func (p *QTKeJiProfile) ProtocolType() ProtocolType

ProtocolType returns the USB protocol type.

func (*QTKeJiProfile) VendorIDs

func (p *QTKeJiProfile) VendorIDs() []uint16

VendorIDs returns all vendor IDs this profile supports.

func (*QTKeJiProfile) Width

func (p *QTKeJiProfile) Width() int

Width returns the display width in pixels.

Jump to

Keyboard shortcuts

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