package main

import (
	"game-driver/logger"
	"game-driver/pkg/relay"
	"go.uber.org/zap"
	"os"
	"os/signal"
	"syscall"
	"time"
)

func main() {
	logger.DefaultLogger()
	defer logger.Sync()

	r, err := relay.New("/dev/ttyACM0")
	if err != nil {
		zap.S().Panicln(err)
	}
	defer r.Close()

	for i := 0; i < 4; i++ {
		func(num int) {
			r.On(num)
			defer r.Off(num)
			time.Sleep(1 * time.Second)
		}(i)
		time.Sleep(1 * time.Second)
	}

	r.OnAll()
	defer r.OffAll()

	sig := make(chan os.Signal, 1)
	signal.Notify(sig, os.Interrupt, syscall.SIGTERM)

	<-sig
	zap.S().Infoln("接收到关闭命令 - 正在关闭程序")
	zap.S().Infoln("关闭完成")
}
