Last active
October 11, 2016 21:11
-
-
Save asukakenji/07f8761a67427b6a91bea9303bbe3eab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (bt *BlinkyTape) playPattern(p Pattern, delay time.Duration) { | |
bt.clear() | |
L: | |
for _, frame := range p { | |
bt.setFrame(frame) | |
if err := bt.render(); err != nil { | |
log.Fatalf("render error: %s\n", err) | |
} | |
timer := timer.NewTimer(delay) | |
timer.Start() | |
stop := bt.stop | |
pause := bt.pause | |
resume := nil | |
timerC := nil | |
select { | |
case <-stop: | |
stop <- struct{}{} | |
break L | |
case <-pause: | |
if paused := timer.Pause(); paused != false { | |
// stop = bt.stop | |
pause = nil | |
resume = bt.resume | |
timerC = nil | |
} | |
case <-resume: | |
if started := timer.Start(); started != false { | |
// stop = bt.stop | |
pause = nil | |
resume = nil | |
timerC = timer.C | |
} | |
case <-timerC: | |
continue L | |
} | |
} | |
bt.next <- struct{}{} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment