Skip to content

Commit

Permalink
Merge pull request #30 from mwmahlberg/#39-remove-support-for-go-1.19
Browse files Browse the repository at this point in the history
#39-remove-support-for-go-1.19

fixes #29
  • Loading branch information
mwmahlberg authored Feb 18, 2025
2 parents fe2fc59 + f7fc814 commit e4ea985
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 38 deletions.
4 changes: 4 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# These are supported funding model platforms

github: mwmahlberg
buy_me_a_coffee: mwmahlberg
33 changes: 33 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go
---
name: Go

on:
push:
branches: ['**']
pull_request:
branches: ['master', 'develop']

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: ['1.20', '1.21.x', '1.22.x', '1.23.x', '1.24.x']
steps:
- uses: actions/checkout@v4.1.1
with:
fetch-tags: 'true'
fetch-depth: '20'

- name: Set up Go ${{ matrix.go-version }}
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}

- name: Build
run: go build -v ./...

- name: Build binary
run: GOOS=linux GOARCH=arm64 make
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# ArgonOne fan speed tools and control daemon

![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/mwmahlberg/argononefan/.github%2Fworkflows%2Fgo.yml?logo=GitHub&color=00aa00)
[![Bugs](https://sonarcloud.io/api/project_badges/measure?project=mwmahlberg_argononefan&metric=bugs)](https://sonarcloud.io/summary/new_code?id=mwmahlberg_argononefan)
[![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=mwmahlberg_argononefan&metric=reliability_rating)](https://sonarcloud.io/summary/new_code?id=mwmahlberg_argononefan)
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=mwmahlberg_argononefan&metric=sqale_rating)](https://sonarcloud.io/summary/new_code?id=mwmahlberg_argononefan)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=mwmahlberg_argononefan&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=mwmahlberg_argononefan)

![GitHub Tag](https://img.shields.io/github/v/tag/mwmahlberg/argononefan)
![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/mwmahlberg/argononefan)
[![Godoc](https://godoc.org/github.com/mwmahlberg/argononefan?status.svg)](http://godoc.org/github.com/mwmahlberg/argononefan)

![GitHub Issues or Pull Requests](https://img.shields.io/github/issues-raw/mwmahlberg/argononefan?style=flat)
![GitHub Issues or Pull Requests](https://img.shields.io/github/issues-pr-raw/mwmahlberg/argononefan)
![GitHub Issues or Pull Requests](https://img.shields.io/github/issues-pr-closed-raw/mwmahlberg/argononefan)
![GitHub Sponsors](https://img.shields.io/github/sponsors/mwmahlberg)

## Installation

TBD
Expand Down Expand Up @@ -127,3 +142,7 @@ shoulders of giants.

[wp:daemon]: https://en.wikipedia.org/wiki/Daemon_(computing) "Wikipedia page on 'daemon (computing)'"
[rpitips:cooling]: https://raspberrytips.com/raspberry-pi-temperature/ "Raspberry Pi Temperature: Limits monitoring, cooling and more"

---

[![SonarCloud](https://sonarcloud.io/images/project_badges/sonarcloud-orange.svg)](https://sonarcloud.io/summary/new_code?id=mwmahlberg_argononefan)
90 changes: 53 additions & 37 deletions cmd/argononefan/daemon_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,28 @@ func (d *daemonCmd) Run(
signalCtx, stop := signal.NotifyContext(context.Background(), syscall.SIGTERM, syscall.SIGINT)
defer stop()

go d.control(signalCtx, fan, tr, d.Thresholds, d.Hysteresis)
<-signalCtx.Done()
srv.Shutdown(nil)
errC := d.control(signalCtx, fan, tr, d.Thresholds, d.Hysteresis)

cmdloop:
for {
select {
case err := <-errC:
d.logger.Error("Error in control loop", "error", err)
case <-signalCtx.Done():
d.logger.Debug("Received stop signal")
d.logger.Debug("Shutting down Prometheus metrics server")
if err := srv.Shutdown(nil); err != nil {
d.logger.Error("shutting down Prometheus metrics server:", err)
}
// Without the label, the break would only break out of the select
break cmdloop
}
}

return nil
}

func (d *daemonCmd) control(ctx context.Context, fan *argononefan.Fan, tr *argononefan.ThermalReader, config *thresholds, hysteresis float32) {
func (d *daemonCmd) control(ctx context.Context, fan *argononefan.Fan, tr *argononefan.ThermalReader, config *thresholds, hysteresis float32) chan error {

var (
currentSpeed int = -1
Expand All @@ -116,47 +130,49 @@ func (d *daemonCmd) control(ctx context.Context, fan *argononefan.Fan, tr *argon
errC = make(chan error)
err error
)
go func() {
for {
select {
case <-tick.C:
if currentTemperature, err = tr.Celsius(); err != nil {
errC <- fmt.Errorf("reading temperature: %w", err)
}
targetSpeed := config.GetSpeed(currentTemperature)

for {
select {
case <-tick.C:
if currentTemperature, err = tr.Celsius(); err != nil {
errC <- fmt.Errorf("reading temperature: %w", err)
}
targetSpeed := config.GetSpeed(currentTemperature)
if targetSpeed < currentSpeed {
targetSpeed = config.GetSpeedWithHysteresis(currentTemperature, hysteresis)
}

if targetSpeed < currentSpeed {
targetSpeed = config.GetSpeedWithHysteresis(currentTemperature, hysteresis)
}
switch targetSpeed {

switch targetSpeed {
case currentSpeed:
d.logger.Debug("Temperature is still within the same threshold, no need to adjust fan speed")

case currentSpeed:
d.logger.Debug("Temperature is still within the same threshold, no need to adjust fan speed")
default:
d.logger.Debug("Found threshold", "threshold", config.GetThreshold(currentTemperature), "computed fanSpeed with hystersis", config.GetSpeedWithHysteresis(currentTemperature, hysteresis))

default:
d.logger.Debug("Found threshold", "threshold", config.GetThreshold(currentTemperature), "computed fanSpeed with hystersis", config.GetSpeedWithHysteresis(currentTemperature, hysteresis))
currentSpeed = targetSpeed
if err = fan.SetSpeed(targetSpeed); err != nil {
d.logger.Error("Setting fan speed", "error", err)
errC <- fmt.Errorf("setting fan speed: %w", err)
fanSpeedSetFailed.Inc()
continue
}

currentSpeed = targetSpeed
if err = fan.SetSpeed(targetSpeed); err != nil {
d.logger.Error("Setting fan speed", "error", err)
errC <- fmt.Errorf("setting fan speed: %w", err)
fanSpeedSetFailed.Inc()
continue
}
fanSpeed.Set(float64(targetSpeed))
fanSpeedSet.Inc()

fanSpeed.Set(float64(targetSpeed))
fanSpeedSet.Inc()
once.Do(func() {
d.logger.Info("Set initial fan speed based on readings", "temperature", currentTemperature, "speed", currentSpeed)
})
}

once.Do(func() {
d.logger.Info("Set initial fan speed based on readings", "temperature", currentTemperature, "speed", currentSpeed)
})
case <-ctx.Done():
d.logger.Debug("Received stop signal")
d.logger.Debug("Exiting goroutine...")
return
}

case <-ctx.Done():
d.logger.Debug("Received stop signal")
d.logger.Debug("Exiting goroutine...")
return
}
}
}()
return errC
}
3 changes: 2 additions & 1 deletion cmd/argononefan/thresholds.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ package main

import (
"fmt"
"slices"
"strconv"
"strings"
"sync"

"golang.org/x/exp/slices"

"github.com/alecthomas/kong"
"golang.org/x/exp/maps"
)
Expand Down

0 comments on commit e4ea985

Please sign in to comment.