package main

import (
	"fmt"
	"time"

	"amuz.es/src/infra/cpu_ctrl/pid"
)

// 실제 CPU온도환경 모델링
func test_pid(P float64, I float64, D float64, L int) {
	pid := pid.New(P, I, D)
	pid.SetSetPoint(37.0)
	pid.SetSampleTime(time.Second)
	pid.SetWindupGuard(96.0)

	END := L

	feedback := 60.0

	minTemp := 28.0

	for i := 0; i < END; i++ {
		output := pid.Update((feedback * 1000.0) / 1000.0)
		adj := -output
		if adj < 4.0 {
			adj = 4.0
		} else if adj > 100.0 {
			adj = 100.0
		}

		adj_noob := int(adj)

		adj /= 10.0
		adj -= 1.1
		fmt.Printf("feedback: %0.17f output: %0.17f adj: %0.17f noob: 0x%x\n", feedback, output, adj, adj_noob)

		feedback -= adj

		if feedback < minTemp {
			feedback = minTemp
		}

		time.Sleep(time.Second)

	}
}
func main() {
	test_pid(1.5, 0.4, 2.0, 500)
}
