Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

display.poke() not turning on display

ANSWERED

Sense and Versa 3 devises.

I am trying to randomly update the background on my watchface everyday at midnight.  If the display is on at midnight everything works fine, but if the display is off, which I would assume it would be, in most cases, the background does not update.  I have tried to implement the display.poke() to force the display on so it will update but it does not seem to do anything, at least not in the simulator.  I have not installed it on an actual device to test yet.  Any help?  Here is the code in use. It is the } else { statement at the end that does not seem to work.  It does not log the console or anything almost like because the screen is off it does not initiate the script.

import document from "document";
import {display} from "display";
export function update() {
//Set watchface settings
  let watchFace = document.getElementById("watchFace");
  let today = new Date();
  let date = today.getDate();
  let hours = today.getHours();
  let mins = today.getMinutes();
  let secs = today.getSeconds();
  let imagecount = ["image1.png","image2.png","image3.png","image4.png","image5.png","image6.png",
"image7.png","image8.png","image9.png","image10.png","image11.png","image12.png","image13.png","image14.png","image15.png","image16.png"];
  let num = Math.floor(Math.random()* 16);
if (date >= 1 && date <= 31 && (hours == 0) && (mins == 0) && (secs <= 0)){
    if (display.on) {
        watchFace.href = "background/"+imagecount[num];
        console.log("display is on")
    } else {
        display.poke();
        console.log("display was off");
        watchFace.href = "background/"+imagecount[num];
    }
}
}
Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

Unless there's some context I'm not seeing, that code will run once when the clockface starts, and not again.

 

There are a few solutions. Presumably you have an ontick event listener function somewhere (eg, to update the displayed time). That listener will be executed whenever the display comes on, and every second or minute while it remains on. You could test the date in that function and update the background if a change is detected. Note that you won't want to base that test on the time.

 

An alternative would be to use setTimeout() to arrange for a function to be called after a period of time that you calculate. You could make this happen at midnight even if the display is off, and it wouldn't involve testing the date in every ontick(). But it would involve some maths!

Peter McLennan
Gondwana Software

View best answer in original post

Best Answer
4 REPLIES 4

Unless there's some context I'm not seeing, that code will run once when the clockface starts, and not again.

 

There are a few solutions. Presumably you have an ontick event listener function somewhere (eg, to update the displayed time). That listener will be executed whenever the display comes on, and every second or minute while it remains on. You could test the date in that function and update the background if a change is detected. Note that you won't want to base that test on the time.

 

An alternative would be to use setTimeout() to arrange for a function to be called after a period of time that you calculate. You could make this happen at midnight even if the display is off, and it wouldn't involve testing the date in every ontick(). But it would involve some maths!

Peter McLennan
Gondwana Software
Best Answer

Yes, I have the clock.ontick running in the index.js. The schedule.update is where the above code comes from.  Would I build the setTimeout() in the clock.ontick or in the schedule.js?

clock.ontick = (evt) => {
  updateClock();
  updateText();
  updateDistance();
  schedule.update();
};
Best Answer
0 Votes

I'd probably call schedule.update() at startup, and then configure a setTimeout() in there to call it again after the required interval. That way, you wouldn't need to call it at all from within your ontick handler, which is good for efficiency.

Peter McLennan
Gondwana Software
Best Answer

display.poke() is still not working but I ended up using the setInterval method to call the schedule every 15 minutes but to only run if (hours == 0 && (mins <= 15)). That is working like a charm.  Thanks for the poke in the right direction. Pun intended.

Best Answer