For many of my data fields, I don't need to recompute the underlying metrics every second. For some, every 5 seconds is more than fine. So I'm trying this technique.
class DeviceView extends Toybox.WatchUi.DataField {
const computeDelay = 5; // run compute logic every 5 seconds
var computeCount = 1; // track compute iterations to reduce compute execution to save battery and compute load
function compute(info) {
if (computeCount <= 1) { computeCount = computeDelay; } else { computeCount--; return; }
// compute logic
return;
}
}
Any potential issues with this? Seems to work fine.
I'm also thinking of doing the same with the code in onUpdate(). No need to repaint the screen every second either, right? Unless onShow() is called. Then you need to update the screen immediately. But when I do this, the screen blanks out for the duration of the delay, then paints for one second, then blanks out. I don't call dc.clear(). Any idea why the screen goes blank if onUpdate() is skipped?
class DeviceView extends Toybox.WatchUi.DataField {
const updateDelay = 5; // run compute logic every 5 seconds
var updateCount = 1; // track compute iterations to reduce compute execution to save battery and compute load
function onShow() {
updateCount = 1; // force onUpdate to run when DF shown
return;
}
function onUpdate(dc) {
if (updateCount <= 1) { updateCount = updateDelay; } else { updateCount--; return; }
// screen update logic
return;
}
}