Skip to content

Commit

Permalink
Repeat times
Browse files Browse the repository at this point in the history
  • Loading branch information
hyorigo committed Oct 21, 2023
1 parent 30b0459 commit 84d255b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 14 deletions.
41 changes: 30 additions & 11 deletions exchange/play.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ func EncodePlayText(ps *schema.PatternSet) []string {

if r := ps.RepeatTimes; r == 0 {
ls = append(ls, "(Repeat Forever)")
} else if r == 1 {
ls = append(ls, "(Repeat Once)")
} else if r == 2 {
ls = append(ls, "(Repeat Twice)")
} else {
ls = append(ls, fmt.Sprintf("(Repeat: %d times)", r))
}
Expand All @@ -94,7 +98,7 @@ func EncodePlayText(ps *schema.PatternSet) []string {
lastLED blink1.LEDIndex
lastColor string
)
for _, st := range ps.Sequence {
for i, st := range ps.Sequence {
// color
hn, ok := util.ConvColorToNameOrHex(st.Color)
if ok {
Expand All @@ -112,21 +116,36 @@ func EncodePlayText(ps *schema.PatternSet) []string {

// fade time
switch f := st.FadeTime; {
case f < 10*time.Millisecond:
t = "now"
case f < time.Second:
t = fmt.Sprintf("%d msec", f.Milliseconds())
case f == time.Second:
t = "1 second"
default:
t = fmt.Sprintf("in %v", f)
t = fmt.Sprintf("%v seconds", f.Seconds())
}

// sentence format template
var sf string
if lastLED == st.LED && lastColor == hn {
sf = `Keep %s in %s %s`
// check state
instantly := st.FadeTime < 10*time.Millisecond
isMaintain := lastLED == st.LED && lastColor == hn

// sentence
var sent string
if isMaintain {
if instantly {
sent = fmt.Sprintf("Shift %s to %s instantly", l, hn)
} else {
sent = fmt.Sprintf("Maintain %s in %s for %s", l, hn, t)
}
} else {
ls = append(ls, "")
sf = `Turn %s into %s %s`
if instantly {
sent = fmt.Sprintf("Immediately transition %s to %s", l, hn)
} else {
sent = fmt.Sprintf("Transition %s to %s over %s", l, hn, t)
}
}
ls = append(ls, fmt.Sprintf(sf, l, hn, t))

// add index
ls = append(ls, strconv.Itoa(i+1)+". "+sent)

// for next run
lastLED, lastColor = st.LED, hn
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
bitbucket.org/neiku/hlog v0.1.2
bitbucket.org/neiku/winornot v0.0.3
github.com/1set/gut v0.0.0-20201117175203-a82363231997
github.com/b1ug/blink1-go v0.0.0-20231020113629-bad55546522d
github.com/b1ug/blink1-go v0.0.0-20231021124707-76fc26d11f94
github.com/b1ug/gid v0.0.0-20231001163456-b48caa2e0938
github.com/muesli/termenv v0.13.0
github.com/olekukonko/tablewriter v0.0.5
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ github.com/avast/retry-go v3.0.0+incompatible h1:4SOWQ7Qs+oroOTQOYnAHqelpCO0biHS
github.com/avast/retry-go v3.0.0+incompatible/go.mod h1:XtSnn+n/sHqQIpZ10K1qAevBhOOCWBLXXy3hyiqqBrY=
github.com/aymanbagabas/go-osc52 v1.0.3 h1:DTwqENW7X9arYimJrPeGZcV0ln14sGMt3pHZspWD+Mg=
github.com/aymanbagabas/go-osc52 v1.0.3/go.mod h1:zT8H+Rk4VSabYN90pWyugflM3ZhpTZNC7cASDfUCdT4=
github.com/b1ug/blink1-go v0.0.0-20231020113629-bad55546522d h1:/RZrpFgHay+8/u2sv/6seqTC1pe3fsGuhdfSzFZSUGc=
github.com/b1ug/blink1-go v0.0.0-20231020113629-bad55546522d/go.mod h1:lWnIARfxD/g8qPTSe69xatn3VIPknesbAOFuiqpGj7A=
github.com/b1ug/blink1-go v0.0.0-20231021124707-76fc26d11f94 h1:TdqY6qJLiT9bHedY7YRnL6q/DqoZFgETfdG4TvB8GBk=
github.com/b1ug/blink1-go v0.0.0-20231021124707-76fc26d11f94/go.mod h1:lWnIARfxD/g8qPTSe69xatn3VIPknesbAOFuiqpGj7A=
github.com/b1ug/gid v0.0.0-20231001163456-b48caa2e0938 h1:dmFHzMC2u+deomG4XrgjE6sKycNAtWKUHSRrnrTEzZM=
github.com/b1ug/gid v0.0.0-20231001163456-b48caa2e0938/go.mod h1:b9pd+IB3F4qVXRRUOWgux7TWqxceIEGo/mhoBcOp9RM=
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
Expand Down

0 comments on commit 84d255b

Please sign in to comment.