lib

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 18, 2023 License: GPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

type Command struct {
	CommandLine  string
	OutputRegexp *regexp.Regexp
	// contains filtered or unexported fields
}

func NewCommand

func NewCommand(commandLine, outputRegexp string, timeout time.Duration) (*Command, error)

func (*Command) Run

func (c *Command) Run(stdin io.Reader, expand func(string) string) (string, error)

type CommandRunner

type CommandRunner interface {
	Run(stdin io.Reader, expand func(string) string) (string, error)
}

type Control

type Control struct {
	InitCommand CommandRunner
	SetCommand  CommandRunner
	ExitCommand CommandRunner
	Zones       map[string]*Zone
	// contains filtered or unexported fields
}

Control temperature

func NewControl

func NewControl(sensorReader SensorReader, config cfg.FanControl, simulate bool) (*Control, error)

NewControl creates a new fan controller from configuration

func (*Control) Exit

func (c *Control) Exit() error

Exit resets the fan to be controlled back by the motherboard (or set a specific speed)

func (*Control) Init

func (c *Control) Init() error

Init runs the fan initialization

func (*Control) Start

func (c *Control) Start()

Start the controller. The method will return after it has kicked off the necessary goroutines.

type Disk

type Disk struct {
	Name   string
	Device string
	// contains filtered or unexported fields
}

Disk activity and status

func NewDisk

func NewDisk(global *Global, name string, config cfg.Disk, diskStatuses map[string]DiskStatuser) (*Disk, error)

NewDisk creates a new disk activity and status monitor

func (*Disk) HasForceStandby

func (d *Disk) HasForceStandby() bool

HasForceStandby returns true when the disk should be set to standby mode after a period of inactivity

func (*Disk) HasTemperature

func (d *Disk) HasTemperature() bool

HasTemperature indicates if the disk accepts temperature readings.

func (*Disk) IsActive

func (d *Disk) IsActive() bool

IsActive returns true when the disk is not in standby or sleep mode

func (*Disk) IsIdle

func (d *Disk) IsIdle() bool

IsIdle returns true when the disk hasn't been reading or writing for a set amount of time

func (*Disk) LastActivity

func (d *Disk) LastActivity() time.Time

LastActivity returns the last time the disk has been reading or writing

func (*Disk) StartStandbyWatch

func (d *Disk) StartStandbyWatch()

func (*Disk) Temperature

func (d *Disk) Temperature() int

Temperature reads disk temperature (and keeps it in cache for about 1 minute)

func (*Disk) TemperatureAvailable

func (d *Disk) TemperatureAvailable() bool

TemperatureAvailable indicates if we can read the disk temperature now. In general it means the disk is not idle

type DiskPool

type DiskPool struct {
	Name  string
	Disks []string
	// contains filtered or unexported fields
}

func NewDiskPool

func NewDiskPool(global *Global, name string, disks []string) *DiskPool

func (*DiskPool) CountActive

func (p *DiskPool) CountActive() int

type DiskStatus

type DiskStatus struct {
	Name         string
	DiskActive   string
	DiskStandby  string
	DiskSleeping string
	File         string
	// contains filtered or unexported fields
}

func NewDiskStatus

func NewDiskStatus(name string, config cfg.DiskPowerStatus) (*DiskStatus, error)

func (*DiskStatus) Get

func (s *DiskStatus) Get(expandEnv func(string) string) enum.DiskStatus

func (*DiskStatus) Standby

func (s *DiskStatus) Standby(expandEnv func(string) string) error

type DiskStatuser

type DiskStatuser interface {
	Get(expandEnv func(string) string) enum.DiskStatus
	Standby(expandEnv func(string) string) error
}

type Diskstats

type Diskstats struct {
	// contains filtered or unexported fields
}

func NewDiskstats

func NewDiskstats(r io.Reader) (*Diskstats, error)

func (*Diskstats) IOActivityFrom

func (s *Diskstats) IOActivityFrom(previous *Diskstats, diskname string) (int64, int64)

func (*Diskstats) IOInProgress

func (s *Diskstats) IOInProgress(diskname string) int

func (*Diskstats) PartitionsIOActivityFrom

func (s *Diskstats) PartitionsIOActivityFrom(previous *Diskstats, diskname string) (int64, int64)

type Global

type Global struct {
	Disks              map[string]*Disk
	DiskPools          map[string]*DiskPool
	Templates          map[string]*Template
	Tasks              map[string]*Task
	Schedules          map[string]*Schedule
	DiskStatuses       map[string]DiskStatuser
	TemperatureSensors map[string]SensorGetter
	FanControl         *Control
	// contains filtered or unexported fields
}

func NewGlobal

func NewGlobal(config cfg.Config) (*Global, error)

func (*Global) GetDiskstats

func (g *Global) GetDiskstats() (*Diskstats, error)

func (*Global) GetSensorReader

func (g *Global) GetSensorReader(sensorName string) func() (int, error)

func (*Global) GetStartupTasks

func (g *Global) GetStartupTasks() []*Task

func (*Global) GetTimerTasks

func (g *Global) GetTimerTasks() []Timer

func (*Global) StartTimers

func (g *Global) StartTimers()

type Rule

type Rule struct {
	RunTimer        time.Duration
	TemperatureFrom int
	TemperatureTo   int
	FanFrom         int
	FanTo           int
	FanSet          int
	// contains filtered or unexported fields
}

Rule conversion from temperature to fan speed

func NewRule

func NewRule(config cfg.SensorRule) (Rule, error)

NewRule creates a new rule to convert a temperature into a fan speed

func (Rule) CalculateFanSpeed

func (r Rule) CalculateFanSpeed(temperature int) (int, time.Duration)

CalculateFanSpeed from the rule. If the temperature is out of range it will return a min, max or set speed The second value returned is a request to change the temperature reading timer

func (Rule) MatchTemperature

func (r Rule) MatchTemperature(temperature int) bool

MatchTemperature is true when this rule matches the input temperature

type Schedule

type Schedule struct {
	Task *Task
	When []string
	// contains filtered or unexported fields
}

func NewSchedule

func NewSchedule(global *Global, config cfg.Schedule) *Schedule

func (*Schedule) OnStartup

func (s *Schedule) OnStartup() bool

func (*Schedule) OnTimer

func (s *Schedule) OnTimer() time.Duration

type Sensor

type Sensor struct {
	Name         string
	Command      CommandRunner
	File         string
	AverageFiles []string
	// contains filtered or unexported fields
}

Sensor reads value from the hardware (command line or sysfs file)

func NewSensor

func NewSensor(name string, config cfg.Task, fileSystem fs.FS) (*Sensor, error)

NewSensor creates a new access to the hardware

func (*Sensor) Get

func (s *Sensor) Get(expandEnv func(string) string) (int, error)

Get an integer value from the sensor

type SensorGetter

type SensorGetter interface {
	Get(func(string) string) (int, error)
}

type SensorReader

type SensorReader func(sensorName string) func() (int, error)

SensorReader is a function that takes a name and returns a function to read the named sensor

type Task

type Task struct {
	Name          string
	Command       CommandRunner
	InputTemplate string
	// contains filtered or unexported fields
}

func NewTask

func NewTask(global *Global, name string, config cfg.Task, simulate bool) (*Task, error)

func (*Task) Execute

func (t *Task) Execute() error

type TemperatureSensor

type TemperatureSensor struct {
	DefaultTimer time.Duration
	RunTimer     time.Duration
	Name         string
	Rules        []Rule
	// contains filtered or unexported fields
}

func NewTemperatureSensor

func NewTemperatureSensor(config cfg.Sensor, name string, timer time.Duration, readTemperature func() (int, error), requestSpeed func(string, int, bool, bool)) (*TemperatureSensor, error)

func (*TemperatureSensor) Run

func (s *TemperatureSensor) Run()

Run reads temperature and requests a change in fan speed. This method runs in a infinite loop and should be called inside a goroutine.

type Template

type Template struct {
	Name string
	ID   string
	// contains filtered or unexported fields
}

func NewTemplate

func NewTemplate(global *Global, name string, config cfg.Template) *Template

type Timer

type Timer struct {
	// contains filtered or unexported fields
}

type Zone

type Zone struct {
	ID      int
	Name    string
	Sensors map[string]*TemperatureSensor
	// contains filtered or unexported fields
}

Zone fan control

func NewZone

func NewZone(sensorReader SensorReader, config cfg.FanZone, name string, setSpeed func(zoneID, speed int) error) (*Zone, error)

NewZone creates a new fan control zone

func (*Zone) RequestSpeed

func (z *Zone) RequestSpeed(name string, speed int, min, max bool)

func (*Zone) SetSpeed

func (z *Zone) SetSpeed(speed int)

func (*Zone) Start

func (z *Zone) Start()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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