~sungo/argon

7b72493b5fe86d0bffdffeb68bacab1a89fc64b0 — sungo 2 months ago 929d4d0
a really dumb demo app for the fan
1 files changed, 66 insertions(+), 0 deletions(-)

A cmd/argon/main.go
A cmd/argon/main.go => cmd/argon/main.go +66 -0
@@ 0,0 1,66 @@
package main

// Code originally developed by sungo (https://sungo.io)
// Distributed under the terms of the 0BSD license https://opensource.org/licenses/0BSD

import (
	"fmt"
	"os"
	"os/signal"
	"syscall"
	"time"

	argonFan "git.sungo.io/sungo/argon/fan"
)

const (
	Bus     = 1
	Address = 0x1a // This is cribbed from the argon python script
)

func main() {

	fan, err := argonFan.New(Address, Bus)
	if err != nil {
		panic(err)
	}
	defer fan.SafeClose()

	sigc := make(chan os.Signal, 1)
	signal.Notify(
		sigc,
		syscall.SIGHUP,
		syscall.SIGINT,
		syscall.SIGTERM,
		syscall.SIGQUIT,
	)
	go func() {
		<-sigc
		fmt.Println("CAUGHT SIGNAL - Shutting down")
		fan.SafeClose()
		os.Exit(1)
	}()

	fmt.Println("Changing fan speeds")
	for {
		fmt.Println("100")
		fan.SetSpeed(100)
		time.Sleep(5 * time.Second)

		fmt.Println("0")
		fan.SetSpeed(0)
		time.Sleep(5 * time.Second)

		fmt.Println("25")
		fan.SetSpeed(25)
		time.Sleep(5 * time.Second)

		fmt.Println("10")
		fan.SetSpeed(10)
		time.Sleep(5 * time.Second)

		fmt.Println("50")
		fan.SetSpeed(50)
		time.Sleep(5 * time.Second)
	}
}