channel

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 29, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package channel defines the engine's workflow-level handles to external resources — hardware drivers (GPIO, ADC, UART, ...) and network protocols (MQTT, future HTTP). A channel mediates between nodes that read/write it and the underlying driver or transport. Nodes register against the channel during build; Setup configures the driver accordingly.

Index

Constants

View Source
const SubBufSize = 64

SubBufSize is the buffer size used in subscription channels. Events are dropped when this buffer size is exceeded.

Variables

This section is empty.

Functions

This section is empty.

Types

type ADC

type ADC struct {
	Driver  driver.ADCDriver
	Channel int
}

ADC is an analog input channel.

func (*ADC) Read

func (v *ADC) Read() (float64, error)

func (*ADC) Setup

func (*ADC) Setup() error

type Broadcaster

type Broadcaster[T any] struct {
	// contains filtered or unexported fields
}

Broadcaster is the fanout primitive for channels that emit events to trigger nodes. broadcast pushes non-blockingly and drops on full so a slow subscriber can never stall the producing driver thread.

func (*Broadcaster[T]) Subscribe

func (b *Broadcaster[T]) Subscribe() <-chan T

Subscribe appends a buffered channel to the fanout list and returns it; call during build, before the driver starts producing.

type Channel

type Channel interface {
	Setup() error // Setup configures the underlying driver according to the registered nodes. Called once during engine setup, after all nodes have registered.
}

Channel is the contract that all channel types must satisfy.

type DAC

type DAC struct {
	Driver  driver.DACDriver
	Channel int
}

DAC is a true analog output channel — sets a real voltage, in contrast with PWM which produces a switched square wave. Channels do not need per-channel acquisition, so Setup is a no-op.

func (*DAC) Setup

func (*DAC) Setup() error

func (*DAC) Write

func (v *DAC) Write(mV float64) error

Write writes the given voltage (millivolts) to the channel.

type GPIOInput

type GPIOInput struct {
	Broadcaster[bool]
	Driver     driver.GPIODriver
	Line       int
	Bias       driver.Bias
	DebounceMs int // Debounce time in milliseconds; 0 for no debounce
}

GPIOInput is a digital input pin channel.

func (*GPIOInput) Read

func (v *GPIOInput) Read() (bool, error)

Read samples the pin's current digital level synchronously.

func (*GPIOInput) Setup

func (v *GPIOInput) Setup() error

Setup configures the line in one call. With no subscribers registered the event handler is left nil and cdev allocates no event buffer for the pin. Otherwise broadcast is wired in as the cdev handler.

type GPIOOutput

type GPIOOutput struct {
	Driver driver.GPIODriver
	Line   int
}

GPIOOutput is a digital output pin.

func (*GPIOOutput) Setup

func (v *GPIOOutput) Setup() error

func (*GPIOOutput) Write

func (v *GPIOOutput) Write(value bool) error

type MQTT

type MQTT struct {
	Transport       transport.MQTTTransport
	Topic           string // the channel's topic (publish target / subscribe filter)
	PublishPrefix   string // prepended on every Publish; "" = pass-through
	SubscribePrefix string // prepended on every Subscribe; "" = pass-through
}

MQTT is a workflow-level MQTT channel: a topic endpoint on a bound broker.

func (*MQTT) Publish

func (m *MQTT) Publish(topic string, payload []byte, qos byte, retain bool) error

Publish prepends the configured PublishPrefix to topic and forwards to the transport. Topic must not be empty and must not contain MQTT wildcards (+, #).

func (*MQTT) Setup

func (*MQTT) Setup() error

func (*MQTT) Subscribe

func (m *MQTT) Subscribe(filter string, qos byte) (<-chan transport.MQTTMessage, error)

Subscribe prepends the configured SubscribePrefix to filter and forwards to the transport.

type PWM

type PWM struct {
	Driver    driver.PWMDriver
	Channel   int
	Frequency int // Pulse cycles per second (Hz) for this channel
}

PWM is a PWM output channel.

func (*PWM) Setup

func (v *PWM) Setup() error

func (*PWM) Write

func (v *PWM) Write(duty float64) error

type UART

type UART struct {
	Broadcaster[string]
	Driver driver.SerialDriver
}

UART is a serial port channel wrapping a SerialDriver and the fanout list of OnSerialReceive subscribers.

func (*UART) Flush

func (v *UART) Flush() error

Flush discards buffered input.

func (*UART) Read

func (v *UART) Read(ctx context.Context) (string, error)

Read blocks until one line arrives.

func (*UART) Setup

func (v *UART) Setup() error

Setup wires broadcast as the driver's permanent line callback when at least one subscriber is registered.

func (*UART) Write

func (v *UART) Write(data string) error

Write sends raw bytes; the caller is responsible for terminators.

Jump to

Keyboard shortcuts

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