1234567891011121314151617181920212223242526272829 |
- package timer
- import (
- "github.com/robfig/cron"
- "smart_tunnel_edge/service"
- "smart_tunnel_edge/util/config"
- "time"
- )
- var commandQueue = make(chan []byte, 5)
- func TimeTasks() {
- c := cron.New()
- _ = c.AddFunc("0 */5 * * * ?", func() { //0/5 * * * * ?
- if config.Instance().Policy.Id == 3 { //如果当前策略是定时改变光照亮度
- endTime := config.Instance().Policy.EndTime
- startTime := config.Instance().Policy.StartTime
- currentTime := time.Now().Format("15:04")
- if currentTime == startTime {
- //开灯,将两条路亮度调高
- service.OperationLampSwitchJudge([]int8{1, 2}, service.MediumLightLevel, service.MediumPower)
- } else if currentTime == endTime {
- //关灯,将两条路亮度调低
- service.OperationLampSwitchJudge([]int8{1, 2}, service.LowLightLevel, service.LowPower)
- }
- }
- })
- c.Start()
- }
|