Documentation
¶
Index ¶
- func UnitRegister(unit UnitConfig)
- func UnitReset()
- type App
- type Bus
- type Channel
- type CompoundError
- type Config
- type ConfigFunc
- type Display
- type Error
- type Event
- type EventHandler
- type EventHandlerFunc
- type EventId
- type EventNS
- type FlagNS
- type Flags
- type GPIO
- type GPIOEdge
- type GPIOMode
- type GPIOPin
- type GPIOPull
- type GPIOState
- type I2C
- type LIRC
- type LIRCMode
- type LIRCType
- type Logger
- type MainCommandFunc
- type MainTestFunc
- type NewFunc
- type PWM
- type Platform
- type PlatformType
- type Publisher
- type RPCEvent
- type RPCEventType
- type RPCFlag
- type RPCServiceDiscovery
- type RPCServiceRecord
- type RPCServiceRegister
- type SPI
- type SPIMode
- type Timer
- type Unit
- type UnitConfig
- type UnitType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func UnitRegister ¶
func UnitRegister(unit UnitConfig)
Types ¶
type App ¶
type App interface { // Run the application and return the return code Run() int // WaitForSignal stalls the application until a signal is returned, // context is cancelled or deadline exceeded WaitForSignal(context.Context, ...os.Signal) error // Wait for interrupt signal with context // Flags returns the set of key/value configuration parameters Flags() Flags // Emit events Emit(Event) // Return unit instances UnitInstance(string) Unit // Return singular unit for name Log() Logger // Return logger unit Timer() Timer // Return timer unit Bus() Bus // Return event bus unit Platform() Platform // Return hardware platform unit Display() Display // Return display I2C() I2C // Return I2C interface }
App encapsulates the lifecycle of a running application which is created through the 'app' package and run by calling the Run method. A running application has access to unit instances (for example, logger, timer and event bus).
type Bus ¶
type Bus interface { Unit // Emit an event on the bus Emit(Event) // NewHandler registers an event handler for an event name NewHandler(EventHandler) error // DefaultHandler registers a default handler for an event namespace DefaultHandler(EventNS, EventHandlerFunc) error }
Bus unit - handles events
type Channel ¶ added in v2.0.2
type Channel chan struct{}
Channel is an arbitary communication channel
type CompoundError ¶ added in v2.0.2
type CompoundError struct {
// contains filtered or unexported fields
}
CompoundError represents a set of errors
func NewCompoundError ¶ added in v2.0.2
func NewCompoundError(errs ...error) *CompoundError
func (*CompoundError) Add ¶ added in v2.0.2
func (this *CompoundError) Add(err error) error
func (*CompoundError) Error ¶ added in v2.0.2
func (this *CompoundError) Error() string
func (*CompoundError) ErrorOrSelf ¶ added in v2.0.2
func (this *CompoundError) ErrorOrSelf() error
func (*CompoundError) Is ¶ added in v2.0.2
func (this *CompoundError) Is(other error) bool
type Config ¶
type Config interface { Name() string // Returns name of the unit New(Logger) (Unit, error) // Opens the driver from configuration, or returns error }
Unit configuration interface
type ConfigFunc ¶
type Display ¶ added in v2.0.2
type Display interface { // Return display number DisplayId() uint // Return name of the display Name() string // Return display size for nominated display number, or (0,0) if display does not exist Size() (uint32, uint32) // Return the PPI (pixels-per-inch) for the display, or return zero if unknown PixelsPerInch() uint32 // Implements gopi.Unit Unit }
Display implements a pixel-based display device. Displays are always numbered from zero onwards
type Error ¶
type Error uint
Error represents a gopi error
const ( ErrNone Error = iota // No error condition ErrNotImplemented // Method or feature not implemented ErrBadParameter // Error with parameter passed to method ErrNotFound // Missing object ErrHelp // Help requested from command line ErrInternalAppError // Internal application error ErrSignalCaught // Signal caught ErrUnexpectedResponse // Unexpected Response ErrDuplicateItem // Duplicate Item ErrMax = ErrDuplicateItem )
func (Error) WithPrefix ¶
type Event ¶
type Event interface { Source() Unit // Source of the event Name() string // Name of the event NS() EventNS // Namespace for the event Value() interface{} // Any value associated with the event }
Event emitted on the event bus
var (
NullEvent Event
)
type EventHandler ¶
type EventHandler struct { // The name of the event Name string // The handler function for the event Handler EventHandlerFunc // The namespace of the event, usually 0 EventNS EventNS // The timeout value for the handler, usually 0 Timeout time.Duration }
EventHandler defines how an emitted event is handled in the application
type EventHandlerFunc ¶ added in v2.0.2
EventHandlerFunc is the handler for an emitted event, which should cancel when context.Done() signal is received
type EventNS ¶
type EventNS uint
EventNS is the namespace in which events are emitted, usually EVENT_NS_DEFAULT
const ( EVENT_NS_DEFAULT EventNS = iota // Default event namespace EVENT_NS_MAX = EVENT_NS_DEFAULT )
type Flags ¶
type Flags interface { Name() string // Return name of tool Parse([]string) error // Parse command-line flags Parsed() bool // Returns true if Parsed() has been called Args() []string // Return command-line arguments HasFlag(string, FlagNS) bool // HasFlag returns true if a flag exists Usage(io.Writer) // Write out usage for the application Version(io.Writer) // Write out version for the application // Define flags in default namespace FlagBool(name string, value bool, usage string) *bool FlagString(name, value, usage string) *string FlagDuration(name string, value time.Duration, usage string) *time.Duration FlagInt(name string, value int, usage string) *int FlagUint(name string, value uint, usage string) *uint FlagFloat64(name string, value float64, usage string) *float64 // Get flag values GetBool(string, FlagNS) bool GetString(string, FlagNS) string GetDuration(string, FlagNS) time.Duration GetInt(string, FlagNS) int GetUint(string, FlagNS) uint GetFloat64(string, FlagNS) float64 // Set flag values SetBool(string, FlagNS, bool) SetString(string, FlagNS, string) SetDuration(string, FlagNS, time.Duration) SetInt(string, FlagNS, int) SetUint(string, FlagNS, uint) SetFloat64(string, FlagNS, float64) }
Flags encapsulates a set of key/value pairs in several namespaces with parsing of command-line flags in the default namespace
type GPIO ¶ added in v2.0.2
type GPIO interface { // Return number of physical pins, or 0 if if cannot be returned // or nothing is known about physical pins NumberOfPhysicalPins() uint // Return array of available logical pins or nil if nothing is // known about pins Pins() []GPIOPin // Return logical pin for physical pin number. Returns // GPIO_PIN_NONE where there is no logical pin at that position // or we don't now about the physical pins PhysicalPin(uint) GPIOPin // Return physical pin number for logical pin. Returns 0 where there // is no physical pin for this logical pin, or we don't know anything // about the layout PhysicalPinForPin(GPIOPin) uint // Read pin state ReadPin(GPIOPin) GPIOState // Write pin state WritePin(GPIOPin, GPIOState) // Get pin mode GetPinMode(GPIOPin) GPIOMode // Set pin mode SetPinMode(GPIOPin, GPIOMode) // Set pull mode to pull down or pull up - will // return ErrNotImplemented if not supported SetPullMode(GPIOPin, GPIOPull) error // Start watching for rising and/or falling edge, // or stop watching when GPIO_EDGE_NONE is passed. // Will return ErrNotImplemented if not supported Watch(GPIOPin, GPIOEdge) error // Implements gopi.Unit Unit }
GPIO implements the GPIO interface for simple input and output
type GPIOPin ¶ added in v2.0.2
type GPIOPin uint8
GPIOPin is the logical GPIO pin
const ( // Invalid pin constant GPIO_PIN_NONE GPIOPin = 0xFF )
type GPIOPull ¶ added in v2.0.2
type GPIOPull uint8
GPIOPull is the GPIO Pin resistor configuration (pull up/down or floating)
type I2C ¶ added in v2.0.2
type I2C interface { // Set current slave address SetSlave(uint8) error // Get current slave address GetSlave() uint8 // Return true if a slave was detected at a particular address DetectSlave(uint8) (bool, error) // Read Byte (8-bits), Word (16-bits) & Block ([]byte) from registers ReadUint8(reg uint8) (uint8, error) ReadInt8(reg uint8) (int8, error) ReadUint16(reg uint8) (uint16, error) ReadInt16(reg uint8) (int16, error) ReadBlock(reg, length uint8) ([]byte, error) // Write Byte (8-bits) & Word (16-bits) to registers WriteUint8(reg, value uint8) error WriteInt8(reg uint8, value int8) error WriteUint16(reg uint8, value uint16) error WriteInt16(reg uint8, value int16) error // Implements gopi.Unit Unit }
I2C implements the I2C interface for sensors, etc.
type LIRC ¶ added in v2.0.2
type LIRC interface { // Get receive and send modes RcvMode() LIRCMode SendMode() LIRCMode SetRcvMode(mode LIRCMode) error SetSendMode(mode LIRCMode) error // Receive parameters GetRcvResolution() (uint32, error) SetRcvTimeout(micros uint32) error SetRcvTimeoutReports(enable bool) error SetRcvCarrierHz(value uint32) error SetRcvCarrierRangeHz(min uint32, max uint32) error // Send parameters SetSendCarrierHz(value uint32) error SetSendDutyCycle(value uint32) error // Send Pulse Mode, values are in milliseconds PulseSend(values []uint32) error // Implements gopi.Unit Unit }
LIRC implements the IR send & receive interface
type Logger ¶
type Logger interface { Unit // Name returns the name of the logger Name() string // Clone returns a new logger with a different name Clone(string) Logger // Error logs an error, and returns an error with the name prefixed Error(error) error // Debug will log a debug message when debugging is on Debug(args ...interface{}) // IsDebug returns true if debugging is enabled IsDebug() bool }
Abstract logging interface
type MainCommandFunc ¶
MainCommandFunc is the main handler for command line tool
type MainTestFunc ¶ added in v2.0.2
MainTestFunc is the main handler for a testing tool
type PWM ¶ added in v2.0.2
type PWM interface { // Return array of pins which are enabled for PWM Pins() []GPIOPin // Period Period(GPIOPin) (time.Duration, error) SetPeriod(time.Duration, ...GPIOPin) error // Duty Cycle between 0.0 and 1.0 (0.0 is always off, 1.0 is always on) DutyCycle(GPIOPin) (float32, error) SetDutyCycle(float32, ...GPIOPin) error // Implements gopi.Unit Unit }
PWM implements the PWM interface for actuators, motors, etc.
type Platform ¶ added in v2.0.2
type Platform interface { // Product returns product name Product() string // Type returns flags identifying platform type Type() PlatformType // SerialNumber returns unique serial number for host SerialNumber() string // Uptime returns uptime for host Uptime() time.Duration // LoadAverages returns 1, 5 and 15 minute load averages LoadAverages() (float64, float64, float64) // NumberOfDisplays returns the number of possible displays for this host NumberOfDisplays() uint // Implements gopi.Unit Unit }
type PlatformType ¶ added in v2.0.2
type PlatformType uint
const ( PLATFORM_NONE PlatformType = 0 PLATFORM_DARWIN PlatformType = (1 << iota) >> 1 PLATFORM_RPI PLATFORM_LINUX PLATFORM_MIN = PLATFORM_DARWIN PLATFORM_MAX = PLATFORM_LINUX )
func (PlatformType) FlagString ¶ added in v2.0.2
func (p PlatformType) FlagString() string
func (PlatformType) String ¶ added in v2.0.2
func (p PlatformType) String() string
type Publisher ¶ added in v2.0.2
type Publisher interface { // Emit sends values to be received by handlers Emit(queue uint, value interface{}) // Subscribe and handle messages which are emitted. This method call returns // when the receive loop has started as a goroutine, so is non-blocking. Subscribe(queue uint, capacity int, callback func(value interface{})) Channel // Unsubscribe from a channel. This method will return when the receive loop // has completed Unsubscribe(Channel) }
Publisher interface for Emit/Receive mechanism for arbitary messages
type RPCEvent ¶ added in v2.0.2
type RPCEvent interface { // Type of event Type() RPCEventType // Service record associated with event Service() RPCServiceRecord // Time-to-live value for event TTL() time.Duration Event }
type RPCEventType ¶ added in v2.0.2
type RPCEventType uint // RPCEventType is an enumeration of event types
const ( RPC_EVENT_NONE RPCEventType = iota RPC_EVENT_SERVER_STARTED // RPC Server started RPC_EVENT_SERVER_STOPPED // RPC Server stopped RPC_EVENT_SERVICE_ADDED // Service instance lookup (new) RPC_EVENT_SERVICE_UPDATED // Service instance lookup (updated) RPC_EVENT_SERVICE_REMOVED // Service instance lookup (removed) RPC_EVENT_SERVICE_EXPIRED // Service instance lookup (expired) RPC_EVENT_SERVICE_NAME // Service name discovered RPC_EVENT_SERVICE_RECORD // Service record lookup RPC_EVENT_CLIENT_CONNECTED RPC_EVENT_CLIENT_DISCONNECTED RPC_EVENT_MAX = RPC_EVENT_CLIENT_DISCONNECTED )
func (RPCEventType) String ¶ added in v2.0.2
func (t RPCEventType) String() string
type RPCFlag ¶ added in v2.0.2
type RPCFlag uint // RPCFlag is a set of flags modifying behavior
const ( RPC_FLAG_NONE RPCFlag = 0 RPC_FLAG_INET_UDP RPCFlag = (1 << iota) >> 1 // Use UDP protocol (TCP assumed otherwise) RPC_FLAG_INET_V4 // Use V4 addressing RPC_FLAG_INET_V6 // Use V6 addressing RPC_FLAG_SERVICE_FIRST // Use first service RPC_FLAG_SERVICE_ANY // Use any service RPC_FLAG_MIN = RPC_FLAG_INET_UDP RPC_FLAG_MAX = RPC_FLAG_SERVICE_ANY )
func (RPCFlag) FlagString ¶ added in v2.0.2
type RPCServiceDiscovery ¶ added in v2.0.2
type RPCServiceDiscovery interface { // Lookup service instances by name Lookup(ctx context.Context, service string) ([]RPCServiceRecord, error) // Return list of service names EnumerateServices(ctx context.Context) ([]string, error) }
RPCServiceDiscovery will lookup services and classes of service
type RPCServiceRecord ¶ added in v2.0.2
type RPCServiceRecord struct { Name string Service string Host string Port uint16 Addrs []net.IP Txt []string }
RPCServiceRecord defines a service which can be registered or discovered on the network
func (RPCServiceRecord) String ¶ added in v2.0.2
func (this RPCServiceRecord) String() string
type RPCServiceRegister ¶ added in v2.0.2
type RPCServiceRegister interface { // Register service record, and de-register when deadline is exceeded Register(ctx context.Context, record RPCServiceRecord) error }
RPCServiceRegister will register services
type SPI ¶ added in v2.0.2
type SPI interface { // Get SPI mode Mode() SPIMode // Get SPI speed MaxSpeedHz() uint32 // Get Bits Per Word BitsPerWord() uint8 // Set SPI mode SetMode(SPIMode) error // Set SPI speed SetMaxSpeedHz(uint32) error // Set Bits Per Word SetBitsPerWord(uint8) error // Read/Write Transfer(send []byte) ([]byte, error) // Read Read(len uint32) ([]byte, error) // Write Write(send []byte) error // Implements gopi.Unit Unit }
SPI implements the SPI interface for sensors, etc.
type SPIMode ¶ added in v2.0.2
type SPIMode uint8
SPIMode is the SPI Mode
const ( SPI_MODE_CPHA SPIMode = 0x01 SPI_MODE_CPOL SPIMode = 0x02 SPI_MODE_0 SPIMode = 0x00 SPI_MODE_1 SPIMode = (0x00 | SPI_MODE_CPHA) SPI_MODE_2 SPIMode = (SPI_MODE_CPOL | 0x00) SPI_MODE_3 SPIMode = (SPI_MODE_CPOL | SPI_MODE_CPHA) SPI_MODE_NONE SPIMode = 0xFF )
type Timer ¶
type Timer interface { Unit NewTicker(time.Duration) EventId // Create periodic event at interval NewTimer(time.Duration) EventId // Create one-shot event after interval Cancel(EventId) error // Cancel events }
Timer unit - sends out messages on the event bus
type Unit ¶
type Unit interface { Close() error // Close closes the driver and frees the underlying resources String() string // String returns a string representation of the unit }
Unit interface
type UnitConfig ¶
type UnitConfig struct { Name string // Unique name of the unit Type UnitType // Unit type Requires []string // Unit dependencies Config ConfigFunc New NewFunc // contains filtered or unexported fields }
func UnitWithDependencies ¶ added in v2.0.2
func UnitWithDependencies(unitNames ...string) ([]*UnitConfig, error)
UnitWithDependencies returns units with all dependencies satisfied in reverse order of when they need to be configured and initialized
func UnitsByName ¶
func UnitsByName(unitName string) []*UnitConfig
func UnitsByType ¶
func UnitsByType(unitType UnitType) []*UnitConfig
func (UnitConfig) String ¶
func (u UnitConfig) String() string