105 lines
2.2 KiB
Go
105 lines
2.2 KiB
Go
package mk2driver
|
|
|
|
import "time"
|
|
|
|
type Led int
|
|
|
|
const (
|
|
LedMain Led = iota
|
|
LedAbsorption
|
|
LedBulk
|
|
LedFloat
|
|
LedInverter
|
|
LedOverload
|
|
LedLowBattery
|
|
LedTemperature
|
|
)
|
|
|
|
var LedNames = map[Led]string{
|
|
LedTemperature: "led_over_temp",
|
|
LedLowBattery: "led_bat_low",
|
|
LedOverload: "led_overload",
|
|
LedInverter: "led_inverter",
|
|
LedFloat: "led_float",
|
|
LedBulk: "led_bulk",
|
|
LedAbsorption: "led_absorb",
|
|
LedMain: "led_mains",
|
|
}
|
|
|
|
type LEDstate int
|
|
|
|
const (
|
|
LedOff LEDstate = iota
|
|
LedOn
|
|
LedBlink
|
|
)
|
|
|
|
var StateNames = map[LEDstate]string{
|
|
LedOff: "off",
|
|
LedOn: "on",
|
|
LedBlink: "blink",
|
|
}
|
|
|
|
type Mk2Info struct {
|
|
// Will be marked as false if an error is detected.
|
|
Valid bool
|
|
|
|
Version uint32
|
|
|
|
BatVoltage float64
|
|
// Positive current == charging
|
|
// Negative current == discharging
|
|
BatCurrent float64
|
|
|
|
// Input AC parameters
|
|
InVoltage float64
|
|
InCurrent float64
|
|
InFrequency float64
|
|
|
|
// Output AC parameters
|
|
OutVoltage float64
|
|
OutCurrent float64
|
|
OutFrequency float64
|
|
|
|
// Charge state 0.0 to 1.0
|
|
ChargeState float64
|
|
|
|
// List LEDs
|
|
LEDs map[Led]LEDstate
|
|
|
|
Errors []error
|
|
|
|
Timestamp time.Time
|
|
}
|
|
|
|
type Mk2 interface {
|
|
C() chan *Mk2Info
|
|
Close()
|
|
}
|
|
|
|
type PanelSwitchState byte
|
|
|
|
const (
|
|
// PanelSwitchChargerOnly enables charging only.
|
|
PanelSwitchChargerOnly PanelSwitchState = 0x01
|
|
// PanelSwitchInverterOnly enables inverter output and disables charging.
|
|
PanelSwitchInverterOnly PanelSwitchState = 0x02
|
|
// PanelSwitchOn enables both inverter and charger.
|
|
PanelSwitchOn PanelSwitchState = 0x03
|
|
// PanelSwitchOff disables inverter and charger.
|
|
PanelSwitchOff PanelSwitchState = 0x04
|
|
)
|
|
|
|
type SettingsWriter interface {
|
|
// WriteRAMVar writes a signed 16-bit value to a RAM variable id.
|
|
WriteRAMVar(id uint16, value int16) error
|
|
// WriteSetting writes a signed 16-bit value to a setting id.
|
|
WriteSetting(id uint16, value int16) error
|
|
// SetPanelState sends the MK2 "S" command using a virtual panel switch state.
|
|
// If currentLimitA is nil, the command does not update the AC current limit.
|
|
SetPanelState(switchState PanelSwitchState, currentLimitA *float64) error
|
|
// SetStandby configures the remote panel standby line.
|
|
// When enabled, the inverter is prevented from sleeping while switched off.
|
|
SetStandby(enabled bool) error
|
|
}
|