package app import ( "my/go-controller/analog" "my/go-controller/digital" "my/go-controller/serial" "my/go-controller/task" "my/go-controller/timer" ) // 150 - примерно то же, что и 255 (должно быть те 1.25В где-то там же) // 100 - средненько const MAX_YARKOST int = 100 const MIN_YARKOST int = 0 const VREMYA_SVETA uint32 = 20000 var loopBlockTime task.TickType = task.MS_TO_TICKS(1000) var vklYarkBlockTime int = 10 var vyklYarkBlockTime task.TickType = task.MS_TO_TICKS(50) var yarkost int var kogdaVyklyuchit uint32 func initSvet() { yarkost = 0 kogdaVyklyuchit = 0 Vyklyuchit() } func DvizhEst() { kogdaVyklyuchit = timer.Millis() + VREMYA_SVETA if !Vklyucheno() { if DEBUG { serial.Println("Vkl svet") } PlavnoVklyuchit() } } func DvizhaNet() { if kogdaVyklyuchit > timer.Millis() { return } if Vklyucheno() { if DEBUG { serial.Println("Vykl") } PlavnoVyklyuchit() } } func PlavnoVklyuchit() { Enable() for yarkost = yarkost; yarkost <= MAX_YARKOST; yarkost++ { Yarkost(yarkost) if DEBUG { serial.Println(yarkost) } timer.Delay(vklYarkBlockTime) } Vklyuchit() } func PlavnoVyklyuchit() { var v int for yarkost = yarkost; yarkost >= MIN_YARKOST; yarkost-- { Yarkost(yarkost) if DEBUG { serial.Println(yarkost) } v = task.TaskNotifyTake(0, vyklYarkBlockTime) if v > 0 { DvizhEst() return } } Vyklyuchit() } func Vklyucheno() bool { return yarkost > 0 } func Vklyuchit() { Yarkost(MAX_YARKOST) Enable() } func Vyklyuchit() { Yarkost(MIN_YARKOST) Disable() } func Yarkost(i int) { // логика яркости инвертирована analog.Write(SVET_YARK_PIN, 255-i) } func Enable() { digital.Write(SVET_ONOFF_PIN, 1) } func Disable() { digital.Write(SVET_ONOFF_PIN, 0) } func TaskSveta() { var v int for { /* Block to wait for a notification. Here the RTOS task notification is being used as a counting semaphore. The task's notification value is incremented each time the ISR calls vTaskNotifyGiveFromISR(), and decremented each time the RTOS task calls ulTaskNotifyTake() - so in effect holds a count of the number of outstanding interrupts. The first parameter is set to pdFALSE, so the notification value is only decremented and not cleared to zero, and one deferred interrupt event is processed at a time. */ v = task.TaskNotifyTake(0, loopBlockTime) if v > 0 { DvizhEst() } else { DvizhaNet() } } }