calculate sleep time for slideshow interval more accurately
This commit is contained in:
parent
5d9b028c29
commit
ff68336c1b
1 changed files with 4 additions and 4 deletions
|
@ -21,9 +21,10 @@ var previousImage string
|
||||||
func Start() {
|
func Start() {
|
||||||
loggo.Info("starting the image slideshow...", "interval: "+strconv.FormatFloat(config.Interval.Seconds(), 'f', 0, 64)+" seconds")
|
loggo.Info("starting the image slideshow...", "interval: "+strconv.FormatFloat(config.Interval.Seconds(), 'f', 0, 64)+" seconds")
|
||||||
var sleepTime time.Duration
|
var sleepTime time.Duration
|
||||||
var scaleTime time.Duration
|
var loopTime time.Duration
|
||||||
scaleImages := config.IsResolutionSet()
|
scaleImages := config.IsResolutionSet()
|
||||||
for {
|
for {
|
||||||
|
loopTimestamp := time.Now()
|
||||||
var image string
|
var image string
|
||||||
var palette []color.Color
|
var palette []color.Color
|
||||||
var data []byte
|
var data []byte
|
||||||
|
@ -34,18 +35,17 @@ func Start() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if scaleImages {
|
if scaleImages {
|
||||||
scaleTimestamp := time.Now()
|
|
||||||
tmp, error := scale(image)
|
tmp, error := scale(image)
|
||||||
if error != nil {
|
if error != nil {
|
||||||
loggo.Error("encountered an error scaling an image", "image: "+image, error.Error())
|
loggo.Error("encountered an error scaling an image", "image: "+image, error.Error())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
data = tmp
|
data = tmp
|
||||||
scaleTime = time.Since(scaleTimestamp)
|
|
||||||
palette, _ = getColorPaletteRaw(data)
|
palette, _ = getColorPaletteRaw(data)
|
||||||
} else {
|
} else {
|
||||||
palette, _ = getColorPalette(image)
|
palette, _ = getColorPalette(image)
|
||||||
}
|
}
|
||||||
|
loopTime = time.Since(loopTimestamp)
|
||||||
if sleepTime > 0 {
|
if sleepTime > 0 {
|
||||||
loggo.Debug("sleeping for " + strconv.FormatInt(sleepTime.Milliseconds(), 10) + "ms before next image will be displayed...")
|
loggo.Debug("sleeping for " + strconv.FormatInt(sleepTime.Milliseconds(), 10) + "ms before next image will be displayed...")
|
||||||
time.Sleep(sleepTime)
|
time.Sleep(sleepTime)
|
||||||
|
@ -64,7 +64,7 @@ func Start() {
|
||||||
}
|
}
|
||||||
loggo.Info("set new background image", "image: "+image)
|
loggo.Info("set new background image", "image: "+image)
|
||||||
}
|
}
|
||||||
sleepTime = config.Interval - scaleTime
|
sleepTime = config.Interval - loopTime
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue