Time remaining imp.wakeup()

I have a imp.wakeup() timer I am using to control a process. I want to send the remaining time to be displayed. is there a way to see in the timer how long it has left? I have been working on this problem for a while any help would be appreciated.

I assume that this is in the device? If so, you can use hardware.millis() and set aside a variable to hold a millisecond value at the expected endpoint. You can then call a simple function to calculate the time remaining.

expectedEnd <- 0

function setProcesstime(t,onProcessEnd) {
  // t = time for process to run in seconds (float or integer)
  // onProcessEnd = function to be called at end of process
  expectedEnd = (t*1000).tointeger() + ::hardware.millis()

function getProcessTimeRemaining() {
  // return time remaining in seconds (as float)
  return (expectedEnd - ::hardware.millis())/1000.0

Do note that the onProcessEnd function may not be called at the exact millisecond you want. It’s only precise to 20ms and is also influenced by what else Squirrel is having to do at the time.

I really appreciate your help. This works perfectly. Thanks you!

This topic was automatically closed after 60 days. New replies are no longer allowed.