scale

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package scale implements the logic for reading weight data from a serial-connected scale.

Index

Constants

View Source
const (
	// RetryDelay is the delay between connection retry attempts.
	RetryDelay = 3 * time.Second
	// SerialReadTimeout is the timeout for serial port reads.
	SerialReadTimeout = 5 * time.Second
	// BaudRate is the baud rate for serial communication.
	BaudRate = 9600
)

Communication constants for the scale reader

View Source
const (
	// ErrEOF is the error code for end-of-file received.
	ErrEOF = "ERR_EOF"
	// ErrTimeout is the error code for read timeout.
	ErrTimeout = "ERR_TIMEOUT"
	// ErrRead is the error code for read error.
	ErrRead = "ERR_READ"
	// ErrConnection is the error code for connection failure.
	ErrConnection = "ERR_SCALE_CONN"
)

Error codes for scale communication failures

Variables

View Source
var BrandCommands = map[string]string{
	"rhino":         "P",
	"rhino bar 8rs": "P",
}

BrandCommands maps scale brands to their weight request commands

View Source
var ErrorDescriptions = map[string]string{
	ErrEOF:        "EOF recibido. Posible desconexión.",
	ErrTimeout:    "Timeout de lectura.",
	ErrRead:       "Error de lectura.",
	ErrConnection: "No se pudo conectar al puerto serial.",
}

ErrorDescriptions maps error codes to human-readable descriptions

Functions

func GenerateSimulatedWeights

func GenerateSimulatedWeights() []float64

GenerateSimulatedWeights creates a sequence of realistic weight readings Returns 5 fluctuating values followed by a stable reading

func GetCommand

func GetCommand(brand string) string

GetCommand returns the command for a given brand Defaults to "P" if brand is unknown

Types

type Reader

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

Reader manages serial port communication with the scale

func NewReader

func NewReader(cfg *config.Config, broadcast chan<- string) *Reader

NewReader creates a new scale reader

func (*Reader) ClosePort

func (r *Reader) ClosePort()

ClosePort closes the serial port for config changes

func (*Reader) Start

func (r *Reader) Start(ctx context.Context)

Start begins the reading loop (blocking)

func (*Reader) Stop

func (r *Reader) Stop()

Stop signals the reader to stop

Jump to

Keyboard shortcuts

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