2013-10-23 07:45:31 +08:00
|
|
|
package gobot
|
2013-10-24 13:00:03 +08:00
|
|
|
|
2022-11-27 23:06:09 +08:00
|
|
|
// DigitalPinOptioner is the interface to provide the possibility to change pin behavior for the next usage
|
|
|
|
type DigitalPinOptioner interface {
|
|
|
|
// SetLabel change the pins label
|
|
|
|
SetLabel(string) (changed bool)
|
|
|
|
// SetDirectionOutput sets the pins direction to output with the given initial value
|
|
|
|
SetDirectionOutput(initialState int) (changed bool)
|
|
|
|
// SetDirectionInput sets the pins direction to input
|
|
|
|
SetDirectionInput() (changed bool)
|
|
|
|
}
|
|
|
|
|
|
|
|
// DigitalPinOptionApplier is the interface to apply options to change pin behavior immediately
|
|
|
|
type DigitalPinOptionApplier interface {
|
|
|
|
// ApplyOptions apply all given options to the pin immediately
|
|
|
|
ApplyOptions(...func(DigitalPinOptioner) bool) error
|
|
|
|
}
|
|
|
|
|
2022-11-21 02:22:26 +08:00
|
|
|
// DigitalPinner is the interface for system gpio interactions
|
|
|
|
type DigitalPinner interface {
|
2022-11-27 23:06:09 +08:00
|
|
|
// Export exports the pin for use by the adaptor
|
2022-11-21 02:22:26 +08:00
|
|
|
Export() error
|
2022-11-27 23:06:09 +08:00
|
|
|
// Unexport releases the pin from the adaptor, so it is free for the operating system
|
2022-11-21 02:22:26 +08:00
|
|
|
Unexport() error
|
|
|
|
// Read reads the current value of the pin
|
|
|
|
Read() (int, error)
|
|
|
|
// Write writes to the pin
|
|
|
|
Write(int) error
|
2022-11-27 23:06:09 +08:00
|
|
|
// DigitalPinOptionApplier is the interface to change pin behavior immediately
|
|
|
|
DigitalPinOptionApplier
|
|
|
|
}
|
|
|
|
|
|
|
|
// DigitalPinValuer is the interface to get pin behavior for the next usage. The interface is and should be rarely used.
|
|
|
|
type DigitalPinValuer interface {
|
|
|
|
// DirectionBehavior gets the direction behavior when the pin is used the next time.
|
|
|
|
// This means its possibly not in this direction type at the moment.
|
|
|
|
DirectionBehavior() string
|
2022-11-21 02:22:26 +08:00
|
|
|
}
|
|
|
|
|
2022-11-27 23:06:09 +08:00
|
|
|
// DigitalPinnerProvider is the interface that an Adaptor should implement to allow clients to obtain
|
|
|
|
// access to any DigitalPin's available on that board. If the pin is initially acquired, it is an input.
|
|
|
|
// Pin direction and other options can be changed afterwards by pin.ApplyOptions() at any time.
|
2022-11-21 02:22:26 +08:00
|
|
|
type DigitalPinnerProvider interface {
|
2022-11-27 23:06:09 +08:00
|
|
|
DigitalPin(id string) (DigitalPinner, error)
|
2022-11-21 02:22:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// PWMPinner is the interface for system PWM interactions
|
|
|
|
type PWMPinner interface {
|
|
|
|
// Export exports the pin for use by the operating system
|
|
|
|
Export() error
|
|
|
|
// Unexport unexports the pin and releases the pin from the operating system
|
|
|
|
Unexport() error
|
|
|
|
// Enable enables/disables the PWM pin
|
|
|
|
// TODO: rename to "SetEnable(bool)" according to golang style and allow "Enable()" to be the getter function
|
|
|
|
Enable(bool) (err error)
|
|
|
|
// Polarity returns the polarity either normal or inverted
|
|
|
|
Polarity() (polarity string, err error)
|
|
|
|
// SetPolarity writes value to pwm polarity path
|
|
|
|
SetPolarity(value string) (err error)
|
|
|
|
// InvertPolarity sets the polarity to inverted if called with true
|
|
|
|
InvertPolarity(invert bool) (err error)
|
|
|
|
// Period returns the current PWM period for pin
|
|
|
|
Period() (period uint32, err error)
|
|
|
|
// SetPeriod sets the current PWM period for pin
|
|
|
|
SetPeriod(period uint32) (err error)
|
|
|
|
// DutyCycle returns the duty cycle for the pin
|
|
|
|
DutyCycle() (duty uint32, err error)
|
|
|
|
// SetDutyCycle writes the duty cycle to the pin
|
|
|
|
SetDutyCycle(duty uint32) (err error)
|
|
|
|
}
|
|
|
|
|
|
|
|
// PWMPinnerProvider is the interface that an Adaptor should implement to allow
|
|
|
|
// clients to obtain access to any PWMPin's available on that board.
|
|
|
|
type PWMPinnerProvider interface {
|
2022-11-27 23:06:09 +08:00
|
|
|
PWMPin(id string) (PWMPinner, error)
|
2022-11-21 02:22:26 +08:00
|
|
|
}
|
|
|
|
|
2014-12-31 21:15:52 +08:00
|
|
|
// Adaptor is the interface that describes an adaptor in gobot
|
2014-11-21 10:00:32 +08:00
|
|
|
type Adaptor interface {
|
2014-12-31 21:15:52 +08:00
|
|
|
// Name returns the label for the Adaptor
|
2014-07-04 10:52:31 +08:00
|
|
|
Name() string
|
2016-09-25 17:46:55 +08:00
|
|
|
// SetName sets the label for the Adaptor
|
|
|
|
SetName(n string)
|
2014-12-31 21:15:52 +08:00
|
|
|
// Connect initiates the Adaptor
|
2016-11-07 21:55:21 +08:00
|
|
|
Connect() error
|
2014-12-31 21:15:52 +08:00
|
|
|
// Finalize terminates the Adaptor
|
2016-11-07 21:55:21 +08:00
|
|
|
Finalize() error
|
2014-11-22 11:35:01 +08:00
|
|
|
}
|
|
|
|
|
2014-12-31 21:15:52 +08:00
|
|
|
// Porter is the interface that describes an adaptor's port
|
2014-11-22 11:35:01 +08:00
|
|
|
type Porter interface {
|
2014-11-21 10:00:32 +08:00
|
|
|
Port() string
|
2014-06-14 01:46:58 +08:00
|
|
|
}
|