devices

package
v0.0.0-...-c4bdd08 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2021 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CancelFunc = cancelFunc

CancelFunc - Call this to shutdown the app

View Source
var Context = contextDecl

Context - The global context object

Functions

func ClearControllers

func ClearControllers()

ClearControllers reset the map of controllers

func DeleteTemperatureControllerByID

func DeleteTemperatureControllerByID(id string) []*string

DeleteTemperatureControllerByID - Delete a temperature controller with the ID specified and return the probes that are now freed

func GpioInUse

func GpioInUse(identifier string) bool

GpioInUse - Returns true if the GPIO specified is in use already

func ShutdownAllSwitches

func ShutdownAllSwitches()

ShutdownAllSwitches - Turn off all switches that are configured, does not cover output control pins

Types

type HysteriaSettings

type HysteriaSettings struct {
	gorm.Model
	MaxTempRaw              physic.Temperature
	MinTempRaw              physic.Temperature
	MinTime                 int64 // In seconds
	Configured              bool
	TemperatureControllerID uint
}

HysteriaSettings are used for Hysteria mode

func (*HysteriaSettings) ApplySettings

func (h *HysteriaSettings) ApplySettings(newSettings *model.HysteriaSettingsInput) error

ApplySettings - Update the current hysteria settings

func (*HysteriaSettings) MaxTemp

func (h *HysteriaSettings) MaxTemp() string

MaxTemp -> For hysteria, this is the string for the max temp to turn off

func (*HysteriaSettings) MinTemp

func (h *HysteriaSettings) MinTemp() string

MinTemp -> For hysteria, this is the string for the min temp to turn on

type ManualSettings

type ManualSettings struct {
	gorm.Model
	DutyCycle               int64
	CycleTime               int64
	Configured              bool
	TemperatureControllerID uint
}

ManualSettings are used for manually controlling the output

func (*ManualSettings) ApplySettings

func (s *ManualSettings) ApplySettings(newSettings *model.ManualSettingsInput) error

ApplySettings - Update the current manual settings

type OutPin

type OutPin struct {
	gorm.Model

	Identifier   string
	FriendlyName string
	PinIO        gpio.PinIO `gorm:"-"`
	// contains filtered or unexported fields
}

OutPin represents a stored output pin with a friendly name

func (*OutPin) Read

func (op *OutPin) Read() *gpio.Level

Read - Read the current pin level, High or Low

type OutputControl

type OutputControl struct {
	gorm.Model
	HeatOutput *OutPin
	CoolOutput *OutPin
	DutyCycle  int64 `gorm:"-"`
	CycleTime  int64 `gorm:"-"`
}

OutputControl is a basic struct to handle heating outputs with a duty cyclke

func (*OutputControl) AfterDelete

func (o *OutputControl) AfterDelete(tx *gorm.DB)

AfterDelete - After deleting a switch, remove the output pin

func (*OutputControl) CalculateOutput

func (o *OutputControl) CalculateOutput()

CalculateOutput - Turn on and off the output pin for this output control depending on the duty cycle

func (*OutputControl) RegisterGpios

func (o *OutputControl) RegisterGpios()

RegisterGpios - Register the outpins with the master list

func (*OutputControl) Reset

func (o *OutputControl) Reset()

Reset - Reset the output pins

func (*OutputControl) RunControl

func (o *OutputControl) RunControl(quit chan struct{})

RunControl -> Run the output controller for a heating output

func (*OutputControl) UpdateGpios

func (o *OutputControl) UpdateGpios(parentName string, heatGpio string, coolGpio string) error

UpdateGpios - Update the heating and cooling outputs to their new pins

type PidSettings

type PidSettings struct {
	gorm.Model
	Proportional              float64
	Integral                  float64
	Derivative                float64
	CycleTime                 int64
	Delay                     int64
	Configured                bool
	TemperatureControllerID   uint
	TemperatureControllerType string
	Gpio                      string
}

PidSettings define the actual values for heating/cooling as persisted

func (*PidSettings) ApplySettings

func (s *PidSettings) ApplySettings(newSettings *model.PidSettingsInput) error

ApplySettings - Update the current pid settings

type Switch

type Switch struct {
	gorm.Model
	OutputID uint
	Output   *OutPin `gorm:"ForeignKey:OutputID"`
	Inverted bool
}

Switch - Represents a thin wrapper around an OutPin to define a switch

func AllSwitches

func AllSwitches() []*Switch

AllSwitches returns all the switches, loading from the Database if none are configured

func CreateSwitch

func CreateSwitch(identifier string, friendlyName string) (*Switch, error)

CreateSwitch - Create a new switch, checking for the GPIO/Name already existing

func DeleteSwitchByID

func DeleteSwitchByID(id string) (*Switch, error)

DeleteSwitchByID - Does what it says on the tin, clearing up the Outpin too

func FindSwitchByID

func FindSwitchByID(id string) *Switch

FindSwitchByID - Find a temperature controller by id, preloading everything

func (*Switch) AfterDelete

func (s *Switch) AfterDelete(tx *gorm.DB)

AfterDelete - After deleting a switch, remove the output pin

func (*Switch) Gpio

func (s *Switch) Gpio() string

Gpio - Get the GPIO

func (*Switch) Name

func (s *Switch) Name() string

Name - Get the Name

func (*Switch) Off

func (s *Switch) Off()

Off - Switch off the output pin, if it's inverted, the pin goes to on

func (*Switch) On

func (s *Switch) On()

On - Switch on the output pin, if it's inverted, the pin goes to off

func (*Switch) Reset

func (s *Switch) Reset()

Reset - Turn off the switch if configured

func (*Switch) Save

func (s *Switch) Save()

Save - Helper to save this object

func (*Switch) State

func (s *Switch) State() model.SwitchMode

State - Returns on if this switch is on

func (*Switch) UpdateIdentifier

func (s *Switch) UpdateIdentifier(identifier string) error

UpdateIdentifier - update the identifier (GPIO)

type TempProbeDetail

type TempProbeDetail struct {
	gorm.Model
	TemperatureControllerID uint
	PhysAddr                string
	FriendlyName            string
	ReadingRaw              physic.Temperature `gorm:"-"`
	Updated                 time.Time
}

TempProbeDetail is the persisted model for TemperatureProbe this is to simplify loading data so that TemperatureProbe represents the physical state and this represents the cached state

func (*TempProbeDetail) Reading

func (t *TempProbeDetail) Reading() string

Reading The current temperature reading for the probe

func (*TempProbeDetail) UpdateReading

func (t *TempProbeDetail) UpdateReading()

UpdateReading - Update the reading from the associated probe

func (*TempProbeDetail) UpdateTemperature

func (t *TempProbeDetail) UpdateTemperature(newTemp string) error

UpdateTemperature Set the temperature on the Temperature Probe from a string

type TemperatureController

type TemperatureController struct {
	gorm.Model
	Name             string
	LastReadings     []physic.Temperature `gorm:"-"`
	TempProbeDetails []*TempProbeDetail
	CoolSettings     PidSettings `gorm:"polymorphic:TemperatureController;polymorphicValue:coolSettings"`
	// CoolSettingsID					uint
	HeatSettings PidSettings `gorm:"polymorphic:TemperatureController;polymorphicValue:heatSettings"`
	// HeatSettingsID					uint
	HysteriaSettings HysteriaSettings
	// HysteriaSettingsID			uint
	ManualSettings          ManualSettings
	Mode                    model.ControllerMode // Mode of this controller
	DutyCycle               int64
	CalculatedDuty          int64
	SetPointRaw             *physic.Temperature
	PreviousCalculationTime time.Time `gorm:"-"`
	TotalDiff               float64   `gorm:"-"` // Always in Fahrenheit (internal calculation)

	OutputControl *OutputControl `gorm:"-"`
	Running       bool           `gorm:"-"`
	// contains filtered or unexported fields
}

TemperatureController defines a mapping of temperature probes to their control settings

func AllTemperatureControllers

func AllTemperatureControllers() []*TemperatureController

AllTemperatureControllers returns all the temperature controllers

func CreateTemperatureController

func CreateTemperatureController(name string, probe *TempProbeDetail) (*TemperatureController, error)

CreateTemperatureController Create a new PID controller for the Temperature probe name -> The name of the PID Controller probe -> The probe to associate with the controller If a PID controller exists with the same name, the probe will be added to it (or no-op if it is already assigned) If the passed in TemperatureProbe is associated with a different PID Controller, an error will be returned and no PID controller will be returned

func FindTemperatureControllerByID

func FindTemperatureControllerByID(id string) *TemperatureController

FindTemperatureControllerByID - Find a temperature controller by id, preloading everything

func FindTemperatureControllerByName

func FindTemperatureControllerByName(name string) *TemperatureController

FindTemperatureControllerByName returns the pid controller with a specific name

func FindTemperatureControllerForProbe

func FindTemperatureControllerForProbe(physAddr string) *TemperatureController

FindTemperatureControllerForProbe returns the pid controller associated with the TemperatureProbe

func (*TemperatureController) ApplySettings

ApplySettings - Update the current temperature controller settings

func (*TemperatureController) AverageTemperature

func (c *TemperatureController) AverageTemperature() physic.Temperature

AverageTemperature Calculate the average temperature for a temperature controller over all the probes

func (*TemperatureController) Calculate

func (c *TemperatureController) Calculate(averageTemperature physic.Temperature, now func() time.Time) int64

Calculate does the calculation for the probe

func (*TemperatureController) RemoveProbe

func (c *TemperatureController) RemoveProbe(physAddr string) error

RemoveProbe removes a temperature probe from this controller

func (*TemperatureController) RunControl

func (c *TemperatureController) RunControl()

RunControl -> Run the output controller for a heating output

func (*TemperatureController) SetPoint

func (c *TemperatureController) SetPoint() string

SetPoint -> Te target Setpoint for this controller

func (*TemperatureController) UpdateOutput

func (c *TemperatureController) UpdateOutput()

UpdateOutput updates the temperatures and decides how to control the outputs

func (*TemperatureController) UpdateSetPoint

func (c *TemperatureController) UpdateSetPoint(newValue string) error

UpdateSetPoint -> Update the current set point value, empty string will clear the value

Jump to

Keyboard shortcuts

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