I want to operate my window coverings with my smartphone. Now every time I change the position on my phone a method
func main() {
OnUpdate(func(tPos int) {
wc(tPos,cPos)
cPos = tPos
}
}
is called where tPos is an integer between 0 and 100 which is is target position. There also is a variable for the current position cPos. OnUpdate should call a function which either open or closes the window covering depending of the order relation between cPos and tPos. This function looks like this.
func wc(tPos int, cPos int){
switch{
case tPos == 0:
log.Println("close")
case tPos == 100:
log.Println("open")
case tPos > cPos:
t := time.Duration( (tPos - cPos)*10*openTime)
log.Println("open")
time.Sleep( t * time.Millisecond)
log.Println("stop")
case tPos < cPos:
t := time.Duration( (cPos - tPos)*10*closeTime)
log.Println("close")
time.Sleep( t * time.Millisecond)
log.Println("stop")
}
}
My problem now is that there should be some delay. I want that after OnUpdate is called there is a timer for like 3 seconds and then wc is called unless OnUpdate is called again during that 3 seconds.
But I don't know how to do this. Can someone tell me what is a good way to do that?