gpstrek - Simplyfy refreshing decision code
parent
69eaed2fad
commit
f9fb2d1289
|
|
@ -103,17 +103,14 @@ let matchFontSize = function(graphics, text, height, width){
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let getDoubleLineSlice = function(title1,title2,provider1,provider2,refreshTime){
|
let getDoubleLineSlice = function(title1,title2,provider1,provider2){
|
||||||
let lastDrawn = Date.now() - Math.random()*refreshTime;
|
|
||||||
let lastValue1 = 0;
|
let lastValue1 = 0;
|
||||||
let lastValue2 = 0;
|
let lastValue2 = 0;
|
||||||
return {
|
return {
|
||||||
refresh: function (){
|
refresh: function (){
|
||||||
let bigChange1 = (Math.abs(lastValue1 - provider1()) > 1);
|
let bigChange1 = (Math.abs(lastValue1 - provider1()) > 1);
|
||||||
let bigChange2 = (Math.abs(lastValue2 - provider2()) > 1);
|
let bigChange2 = (Math.abs(lastValue2 - provider2()) > 1);
|
||||||
let refresh = (Bangle.isLocked()?(refreshTime?refreshTime*5:10000):(refreshTime?refreshTime*2:1000));
|
return (bigChange1 || bigChange2);
|
||||||
let old = (Date.now() - lastDrawn) > refresh;
|
|
||||||
return (bigChange1 || bigChange2) && old;
|
|
||||||
},
|
},
|
||||||
draw: function (graphics, x, y, height, width){
|
draw: function (graphics, x, y, height, width){
|
||||||
lastDrawn = Date.now();
|
lastDrawn = Date.now();
|
||||||
|
|
@ -138,11 +135,9 @@ let getDoubleLineSlice = function(title1,title2,provider1,provider2,refreshTime)
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
let getMapSlice = function(refreshTime){
|
let getMapSlice = function(){
|
||||||
let lastDrawn = Date.now() - Math.random()*refreshTime;
|
|
||||||
return {
|
return {
|
||||||
draw: function (graphics, x, y, height, width){
|
draw: function (graphics, x, y, height, width){
|
||||||
lastDrawn = Date.now();
|
|
||||||
|
|
||||||
graphics.clearRect(x,y,x+width,y+height);
|
graphics.clearRect(x,y,x+width,y+height);
|
||||||
graphics.setClipRect(x,y,x+width,y+height);
|
graphics.setClipRect(x,y,x+width,y+height);
|
||||||
|
|
@ -199,13 +194,8 @@ let getMapSlice = function(refreshTime){
|
||||||
|
|
||||||
let getTargetSlice = function(targetDataSource){
|
let getTargetSlice = function(targetDataSource){
|
||||||
let nameIndex = 0;
|
let nameIndex = 0;
|
||||||
let lastDrawn = Date.now() - Math.random()*3000;
|
|
||||||
return {
|
return {
|
||||||
refresh: function (){
|
|
||||||
return Date.now() - lastDrawn > (Bangle.isLocked()?3000:10000);
|
|
||||||
},
|
|
||||||
draw: function (graphics, x, y, height, width){
|
draw: function (graphics, x, y, height, width){
|
||||||
lastDrawn = Date.now();
|
|
||||||
graphics.clearRect(x,y,x+width,y+height);
|
graphics.clearRect(x,y,x+width,y+height);
|
||||||
if (targetDataSource.icon){
|
if (targetDataSource.icon){
|
||||||
graphics.drawImage(targetDataSource.icon,x,y + (height - 16)/2);
|
graphics.drawImage(targetDataSource.icon,x,y + (height - 16)/2);
|
||||||
|
|
@ -288,15 +278,12 @@ let drawCompass = function(graphics, x, y, height, width, increment, start){
|
||||||
};
|
};
|
||||||
|
|
||||||
let getCompassSlice = function(compassDataSource){
|
let getCompassSlice = function(compassDataSource){
|
||||||
let lastDrawn = Date.now() - Math.random()*2000;
|
|
||||||
let lastDrawnValue = 0;
|
let lastDrawnValue = 0;
|
||||||
const buffers = 4;
|
const buffers = 4;
|
||||||
let buf = [];
|
let buf = [];
|
||||||
return {
|
return {
|
||||||
refresh : function (){
|
refresh : function (){
|
||||||
let bigChange = (Math.abs(lastDrawnValue - compassDataSource.getCourse()) > 2);
|
return (Math.abs(lastDrawnValue - compassDataSource.getCourse()) > 2);
|
||||||
let old = (Bangle.isLocked()?(Date.now() - lastDrawn > 2000):true);
|
|
||||||
return bigChange && old;
|
|
||||||
},
|
},
|
||||||
draw: function (graphics, x,y,height,width){
|
draw: function (graphics, x,y,height,width){
|
||||||
lastDrawn = Date.now();
|
lastDrawn = Date.now();
|
||||||
|
|
@ -893,7 +880,7 @@ let status2Slice = getDoubleLineSlice("Compass","GPS",()=>{
|
||||||
let course = "---°";
|
let course = "---°";
|
||||||
if (WIDGETS.gpstrek.getState().currentPos && WIDGETS.gpstrek.getState().currentPos.course) course = WIDGETS.gpstrek.getState().currentPos.course + "°";
|
if (WIDGETS.gpstrek.getState().currentPos && WIDGETS.gpstrek.getState().currentPos.course) course = WIDGETS.gpstrek.getState().currentPos.course + "°";
|
||||||
return course;
|
return course;
|
||||||
},200);
|
});
|
||||||
|
|
||||||
let healthSlice = getDoubleLineSlice("Heart","Steps",()=>{
|
let healthSlice = getDoubleLineSlice("Heart","Steps",()=>{
|
||||||
return WIDGETS.gpstrek.getState().bpm || "---";
|
return WIDGETS.gpstrek.getState().bpm || "---";
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue