Documentation
¶
Overview ¶
pca9685.go
Index ¶
- Constants
- type Channel
- type Config
- type I2C
- type I2CAdapterD2r2
- type I2CAdapterPeriph
- type LogLevel
- type Logger
- type PCA9685
- func (pca *PCA9685) Close() error
- func (pca *PCA9685) DisableChannels(channels ...int) error
- func (pca *PCA9685) DumpState() string
- func (pca *PCA9685) EnableAllCall() error
- func (pca *PCA9685) EnableChannels(channels ...int) error
- func (pca *PCA9685) FadeChannel(ctx context.Context, channel int, start, end uint16, duration time.Duration) error
- func (pca *PCA9685) GetChannelState(channel int) (enabled bool, on, off uint16, err error)
- func (pca *PCA9685) Reset() error
- func (pca *PCA9685) SetAllPWM(ctx context.Context, on, off uint16) error
- func (pca *PCA9685) SetMultiPWM(ctx context.Context, settings map[int]struct{ ... }) error
- func (pca *PCA9685) SetPWM(ctx context.Context, channel int, on, off uint16) error
- func (pca *PCA9685) SetPWMFreq(freq float64) error
- type Pump
- type PumpOption
- type RGBCalibration
- type RGBLed
- func (l *RGBLed) GetBrightness() float64
- func (l *RGBLed) GetCalibration() RGBCalibration
- func (l *RGBLed) Off(ctx context.Context) error
- func (l *RGBLed) On(ctx context.Context) error
- func (l *RGBLed) SetBrightness(brightness float64) error
- func (l *RGBLed) SetCalibration(cal RGBCalibration)
- func (l *RGBLed) SetColor(ctx context.Context, r, g, b uint8) error
- func (l *RGBLed) SetColorStdlib(ctx context.Context, c color.Color) error
- type TestI2C
Constants ¶
const ( // Регистр MODE1 RegMode1 = 0x00 Mode1Sleep = 0x10 Mode1AutoInc = 0x20 Mode1Restart = 0x80 Mode1AllCall = 0x01 // Регистр MODE2 RegMode2 = 0x01 Mode2OutDrv = 0x04 Mode2Invrt = 0x10 Mode2OutNe = 0x01 // Регистр для каналов LED RegLed0 = 0x06 RegAllLed = 0xFA RegPrescale = 0xFE // Константы PwmResolution = 4096 MinFrequency = 24 MaxFrequency = 1526 OscClock = 25000000 // 25 МГц )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Channel ¶
type Channel struct {
// contains filtered or unexported fields
}
Channel представляет один PWM канал.
type Config ¶
type Config struct { InitialFreq float64 // Начальная частота PWM (от 24 до 1526 Гц) InvertLogic bool // Инвертировать выходную логику OpenDrain bool // Использовать open-drain выходы Context context.Context // Контекст для отмены операций Logger Logger // Логгер. Если nil, будет использован стандартный. LogLevel LogLevel // Уровень логирования. }
Config содержит настройки для инициализации PCA9685.
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig возвращает конфигурацию по умолчанию.
type I2C ¶
type I2C interface { WriteReg(reg uint8, data []byte) error ReadReg(reg uint8, data []byte) error Close() error }
I2C – минимальный интерфейс для работы с I²C устройствами.
type I2CAdapterD2r2 ¶
type I2CAdapterD2r2 struct {
// contains filtered or unexported fields
}
I2CAdapterD2r2 оборачивает объект *i2c.I2C из библиотеки d2r2/go-i2c.
func NewI2CAdapterD2r2 ¶
func NewI2CAdapterD2r2(dev *i2c.I2C) *I2CAdapterD2r2
NewI2CAdapterD2r2 создаёт новый адаптер для d2r2/go-i2c.
func (*I2CAdapterD2r2) Close ¶
func (a *I2CAdapterD2r2) Close() error
type I2CAdapterPeriph ¶
type I2CAdapterPeriph struct {
// contains filtered or unexported fields
}
I2CAdapterPeriph реализует работу с I2C через periph.io.
func NewI2CAdapterPeriph ¶
func NewI2CAdapterPeriph(dev *periph_i2c.Dev) *I2CAdapterPeriph
NewI2CAdapterPeriph создаёт новый адаптер для periph.io.
func (*I2CAdapterPeriph) Close ¶
func (a *I2CAdapterPeriph) Close() error
type Logger ¶
type Logger interface { Basic(msg string, args ...interface{}) Detailed(msg string, args ...interface{}) Error(msg string, args ...interface{}) }
Logger – минимальный интерфейс для логирования.
func NewDefaultLogger ¶
NewDefaultLogger создаёт новый логгер с указанным уровнем.
type PCA9685 ¶
type PCA9685 struct { Freq float64 // contains filtered or unexported fields }
PCA9685 представляет контроллер PCA9685.
func (*PCA9685) DisableChannels ¶
DisableChannels выключает указанные каналы.
func (*PCA9685) DumpState ¶
DumpState возвращает строку с текущим состоянием контроллера (частота и состояние каналов).
func (*PCA9685) EnableAllCall ¶
EnableAllCall включает режим All Call.
func (*PCA9685) EnableChannels ¶
EnableChannels включает указанные каналы.
func (*PCA9685) FadeChannel ¶
func (pca *PCA9685) FadeChannel(ctx context.Context, channel int, start, end uint16, duration time.Duration) error
FadeChannel плавно изменяет значение PWM для указанного канала от start до end за duration.
func (*PCA9685) GetChannelState ¶
GetChannelState возвращает состояние канала: включён ли, и текущие значения on/off.
func (*PCA9685) SetMultiPWM ¶
func (pca *PCA9685) SetMultiPWM(ctx context.Context, settings map[int]struct{ On, Off uint16 }) error
SetMultiPWM устанавливает значения PWM для нескольких каналов.
func (*PCA9685) SetPWMFreq ¶
SetPWMFreq устанавливает частоту PWM в герцах (от 24 до 1526 Гц).
type Pump ¶
Pump представляет управление насосом.
func NewPump ¶
func NewPump(pca *PCA9685, channel int, opts ...PumpOption) (*Pump, error)
NewPump создает новый контроллер насоса. При создании насоса проверяется корректность номера канала и опционально применяются опции (например, установка ограничений скорости).
func (*Pump) GetCurrentSpeed ¶
GetCurrentSpeed возвращает текущую скорость насоса в процентах.
func (*Pump) SetSpeedLimits ¶
SetSpeedLimits устанавливает новые ограничения скорости.
type PumpOption ¶
type PumpOption func(*Pump)
PumpOption определяет опцию конфигурации насоса.
func WithSpeedLimits ¶
func WithSpeedLimits(min, max uint16) PumpOption
WithSpeedLimits устанавливает минимальную и максимальную скорости насоса.
type RGBCalibration ¶
type RGBCalibration struct {
RedMin, RedMax uint16
GreenMin, GreenMax uint16
BlueMin, BlueMax uint16
}
RGBCalibration содержит калибровочные данные для RGB светодиода.
func DefaultRGBCalibration ¶
func DefaultRGBCalibration() RGBCalibration
DefaultRGBCalibration возвращает калибровку по умолчанию.
type RGBLed ¶
type RGBLed struct {
// contains filtered or unexported fields
}
RGBLed представляет RGB светодиод, управляемый через контроллер PCA9685.
func (*RGBLed) GetBrightness ¶
GetBrightness возвращает текущую яркость.
func (*RGBLed) GetCalibration ¶
func (l *RGBLed) GetCalibration() RGBCalibration
GetCalibration возвращает текущие калибровочные данные.
func (*RGBLed) SetBrightness ¶
SetBrightness устанавливает яркость (от 0.0 до 1.0).
func (*RGBLed) SetCalibration ¶
func (l *RGBLed) SetCalibration(cal RGBCalibration)
SetCalibration устанавливает калибровочные данные для светодиода.
type TestI2C ¶
type TestI2C struct {
// contains filtered or unexported fields
}
TestI2C представляет адаптер-эмулятор I2C для MacOS/Windows или тестового устройства.