homelabby/internal/printer/prt_qutie.go
Mikkel Georgsen 1156eff896 feat(04-03): PrinterDriver interface, MockDriver, PrtQutieDriver stub
- PrinterDriver interface: Connect/Print(bitmap,w,h)/Disconnect
- ImageToRawBitmap(): 1-bit packed row-major converter from image.Image
- MockDriver: saves PNG to SaveDir (/tmp default) for visual inspection
- PrtQutieDriver: stub returns ErrNoDevice — safe before hardware arrives
- ErrNoDevice, ErrNotConnected, ErrEmptyBitmap sentinel errors
2026-04-10 06:50:12 +00:00

64 lines
2 KiB
Go

package printer
import (
"go.bug.st/serial"
)
// PrtQutieDriver implements PrinterDriver for the PRT Qutie thermal printer.
//
// Protocol: UNKNOWN — reverse engineering required after hardware arrival 2026-04-13.
//
// TODO(hardware): Replace the stub Print() with real ESC/POS or PRT Qutie commands
// after capturing USB traffic with Wireshark on hardware arrival day.
// Reference: https://atctwo.net/posts/2024/07/16/thermal-printer.html
type PrtQutieDriver struct {
portPath string // resolved at Connect() time
port serial.Port
baudRate int
}
// NewPrtQutieDriver creates a stub driver. portPath is resolved at Connect() via
// USB Manager VID/PID enumeration. baudRate 0 defaults to 9600.
func NewPrtQutieDriver(baudRate int) *PrtQutieDriver {
if baudRate == 0 {
baudRate = 9600
}
return &PrtQutieDriver{baudRate: baudRate}
}
// Connect attempts to find and open the PRT Qutie serial port.
// Currently returns ErrNoDevice — real port resolution requires hardware.
//
// TODO(hardware): Resolve portPath via serial.GetPortsList() + system_profiler VID/PID
// cross-reference, then open the port with serial.Open().
func (d *PrtQutieDriver) Connect() error {
// Stub: return ErrNoDevice so callers can detect missing hardware gracefully.
// Real implementation: enumerate ports, match VID:PID 0525:a4a7, open port.
return ErrNoDevice
}
// Print sends label bitmap to the printer.
// Returns ErrNotConnected if Connect() has not been successfully called.
//
// TODO(hardware): Implement PRT Qutie print protocol — likely a binary
// command sequence (ESC/POS or proprietary). Capture with Wireshark.
func (d *PrtQutieDriver) Print(bitmap []byte, width, height int) error {
if d.port == nil {
return ErrNotConnected
}
// TODO(hardware): implement PRT Qutie print protocol
_ = bitmap
_ = width
_ = height
return nil
}
// Disconnect closes the serial port if open.
func (d *PrtQutieDriver) Disconnect() error {
if d.port != nil {
err := d.port.Close()
d.port = nil
return err
}
return nil
}