devices

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2025 License: BSD-2-Clause Imports: 4 Imported by: 0

README

devices

Some sensor type devices written in Go

Documentation

Overview

Package device provides a framework for managing hardware devices with support for messaging, periodic operations, and state management. Devices can be controlled via MQTT messages and can publish their state and data periodically.

Index

Constants

View Source
const (
	DeviceEventInitialized = "initialized"
	DeviceEventError       = "error"
	DeviceEventDataReady   = "data"
	DeviceEventRisingEdge  = "rising"
	DeviceEventFallingEdge = "falling"
)

Variables

View Source
var (
	ErrNotImplemented     = errors.New("method is not implemented")
	ErrTypeNotImplemented = errors.New("type is not implemented")
)

Functions

func IsMock

func IsMock() bool

func SetMock

func SetMock(v bool)

Types

type Device

type Device[T any] interface {
	Name() string
	Type() Type
	Open() error
	Close() error

	Get() (T, error)
	Set(v T) error

	TickHandler() *func(time.Time)
	StartTicker(period time.Duration, f *func(time.Time))
	RegisterEventHandler(f func(evt *DeviceEvent))
	HandleMsg(msg *messanger.Msg) error

	String() string
}

Device is a type-safe device contract for a single value type T. Implementations may be read-only by returning an error from Set.

type DeviceBase added in v0.0.2

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

func NewDeviceBase added in v0.0.2

func NewDeviceBase[T any](name string) *DeviceBase[T]

func (*DeviceBase[T]) Close added in v0.0.2

func (d *DeviceBase[T]) Close() error

func (*DeviceBase[T]) Get added in v0.0.2

func (d *DeviceBase[T]) Get() (T, error)

func (*DeviceBase[T]) HandleMsg added in v0.0.2

func (d *DeviceBase[T]) HandleMsg(msg *messanger.Msg) error

func (*DeviceBase[T]) Name added in v0.0.2

func (d *DeviceBase[T]) Name() string

func (*DeviceBase[T]) Open added in v0.0.2

func (d *DeviceBase[T]) Open() error

func (*DeviceBase[T]) RegisterEventHandler added in v0.0.2

func (d *DeviceBase[T]) RegisterEventHandler(f func(evt *DeviceEvent))

func (*DeviceBase[T]) Set added in v0.0.2

func (d *DeviceBase[T]) Set(v T) error

func (*DeviceBase[T]) StartTicker added in v0.0.2

func (d *DeviceBase[T]) StartTicker(period time.Duration, f *func(time.Time))

func (*DeviceBase[T]) String added in v0.0.2

func (d *DeviceBase[T]) String() string

func (*DeviceBase[T]) TickHandler added in v0.0.2

func (d *DeviceBase[T]) TickHandler() *func(time.Time)

func (*DeviceBase[T]) Type added in v0.0.2

func (d *DeviceBase[T]) Type() Type

type DeviceEvent added in v0.0.2

type DeviceEvent struct {
	Type    string
	Message string
	Time    time.Time
}

type DeviceState

type DeviceState uint8
const (
	StateUnknown DeviceState = iota
	StateInitializing
	StateRunning
	StateError
	StateStopped
)

type TimerHandler added in v0.0.2

type TimerHandler func(time.Time)

type Type

type Type uint8
const (
	TypeBool Type = iota
	TypeInt
	TypeFloat
	TypeString
	TypeBytes
	TypeJSON
	TypeAny
	TypeGPS
)

Directories

Path Synopsis
Package bme280 provides a driver for the BME280 temperature, humidity, and pressure sensor using I2C communication.
Package bme280 provides a driver for the BME280 temperature, humidity, and pressure sensor using I2C communication.
The drivers include GPIO (digital), analog (via ads1115), serial, I2C at this point.
The drivers include GPIO (digital), analog (via ads1115), serial, I2C at this point.
examples
blink command
bme280 command
gtu7 command
json command
oled command
relay command
switch command
vh400 command

Jump to

Keyboard shortcuts

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