Skip to content

Commit

Permalink
Merge pull request #6 from landgenoot/golang
Browse files Browse the repository at this point in the history
Always full refresh and add delay to allow rendering
  • Loading branch information
landgenoot authored Jul 18, 2023
2 parents 0d5e88d + 58b9f7d commit 7b9d411
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions kindle.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (
"time"
)

var refreshCount = 0

// Suspend device and use real time clock alarm to wake it up.
// If our wake up time is more or less 24 hours away, we can put it to
// sleep immediately. Otherwise, we will wait another 30 seconds, which enables us
Expand All @@ -31,12 +29,16 @@ func suspendToRam(duration int) {
log.Fatal(err2)
}

// Check if we are waken up manually, give us time to abort the process
// Delay sleep process otherwise it gets suspended during rendering.
sleepDelay := 1
// If sleep time < 24hrs, the button has been pressed, so give extra time to abort the process.
if duration < 3600*24-60 {
log.Println("Waiting 30 seconds before going back to sleep")
time.Sleep(30 * time.Second)
sleepDelay = 30
}

log.Printf("Waiting %d seconds before going back to sleep", sleepDelay)
time.Sleep(time.Duration(sleepDelay) * time.Second)

log.Println("Suspending to RAM")

cmd3 := exec.Command("sh", "-c", "echo \"mem\" > /sys/power/state")
Expand Down Expand Up @@ -80,15 +82,10 @@ func drawToScreen(imagePath string) {
if runtime.GOARCH != "arm" {
return // Skip if not on Kindle
}
flags := "-g"
if refreshCount%4 == 0 {
flags = "-fg" // full refresh after 4 refreshes
}
err := exec.Command("/usr/sbin/eips", flags, imagePath).Run()
err := exec.Command("/usr/sbin/eips", "-fg", imagePath).Run()
if err != nil {
log.Fatal(err)
}
refreshCount++
}

// Draw a small black box in the left bottom corner of the screen
Expand Down

0 comments on commit 7b9d411

Please sign in to comment.