gpstrek - Cleanup and more settings preparation
parent
e9e6d9471a
commit
fce51291dd
|
|
@ -3,7 +3,12 @@
|
||||||
const STORAGE = require("Storage");
|
const STORAGE = require("Storage");
|
||||||
const BAT_FULL = require("Storage").readJSON("setting.json").batFullVoltage || 0.3144;
|
const BAT_FULL = require("Storage").readJSON("setting.json").batFullVoltage || 0.3144;
|
||||||
const SETTINGS = {
|
const SETTINGS = {
|
||||||
mapCompass: true
|
mapCompass: true,
|
||||||
|
mapScale:0.09,
|
||||||
|
mapRefresh:500,
|
||||||
|
refresh:100,
|
||||||
|
cacheMinFreeMem:1000,
|
||||||
|
cacheMaxEntries:0,
|
||||||
};
|
};
|
||||||
|
|
||||||
let init = function(){
|
let init = function(){
|
||||||
|
|
@ -30,13 +35,6 @@ let cleanup = function(){
|
||||||
delete global.maxScreens;
|
delete global.maxScreens;
|
||||||
};
|
};
|
||||||
|
|
||||||
let rotate = function(point, rotation, center){
|
|
||||||
return {
|
|
||||||
x: ((point.x - center.x) * Math.cos(rotation) - (point.y - center.y) * Math.sin(rotation)) + center.x,
|
|
||||||
y: ((point.y - center.y) * Math.cos(rotation) + (point.x - center.x) * Math.sin(rotation)) + center.y
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
init();
|
init();
|
||||||
scheduleDraw = true;
|
scheduleDraw = true;
|
||||||
|
|
||||||
|
|
@ -109,9 +107,14 @@ let getEntry = function(filename, offset, result){
|
||||||
result.fileLength = offset - result.fileOffset;
|
result.fileLength = offset - result.fileOffset;
|
||||||
cache[result.fileOffset] = result;
|
cache[result.fileOffset] = result;
|
||||||
cacheInsertion.push(result.fileOffset);
|
cacheInsertion.push(result.fileOffset);
|
||||||
if (process.memory(false).free < 1000){
|
if (SETTINGS.cacheMinFreeMem && process.memory(false).free < SETTINGS.cacheMinFreeMem){
|
||||||
if (cacheInsertion.length > 0) cache[cacheInsertion.shift()] = undefined;
|
if (cacheInsertion.length > 0) cache[cacheInsertion.shift()] = undefined;
|
||||||
}
|
}
|
||||||
|
if (SETTINGS.cacheMaxEntries){
|
||||||
|
while (cacheInsertion.length > SETTINGS.cacheMaxEntries){
|
||||||
|
cache[cacheInsertion.shift()] = undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
cache.filename = filename;
|
cache.filename = filename;
|
||||||
return offset;
|
return offset;
|
||||||
};
|
};
|
||||||
|
|
@ -198,8 +201,6 @@ XXX XXX
|
||||||
XXX
|
XXX
|
||||||
`);
|
`);
|
||||||
|
|
||||||
const mapScale = 0.09;
|
|
||||||
|
|
||||||
let isGpsCourse = function(){
|
let isGpsCourse = function(){
|
||||||
return WIDGETS.gpstrek.getState().currentPos && !isNaN(WIDGETS.gpstrek.getState().currentPos.course);
|
return WIDGETS.gpstrek.getState().currentPos && !isNaN(WIDGETS.gpstrek.getState().currentPos.course);
|
||||||
};
|
};
|
||||||
|
|
@ -227,13 +228,13 @@ let getMapSlice = function(){
|
||||||
if (!SETTINGS.mapCompass) compassHeight=0;
|
if (!SETTINGS.mapCompass) compassHeight=0;
|
||||||
if (compassHeight > g.getHeight()*0.1) compassHeight = g.getHeight()*0.1;
|
if (compassHeight > g.getHeight()*0.1) compassHeight = g.getHeight()*0.1;
|
||||||
|
|
||||||
if (Date.now() - lastDrawn > 500){
|
if (Date.now() - lastDrawn > SETTINGS.mapRefresh) {
|
||||||
graphics.clearRect(x,y,x+width,y+height);
|
graphics.clearRect(x,y,x+width,y+height);
|
||||||
lastDrawn = Date.now();
|
lastDrawn = Date.now();
|
||||||
let mapCenterX = x+(width-10)/2+compassHeight+5;
|
let mapCenterX = x+(width-10)/2+compassHeight+5;
|
||||||
let mapRot = require("graphics_utils").degreesToRadians(180-course);
|
let mapRot = require("graphics_utils").degreesToRadians(180-course);
|
||||||
let mapTrans = {
|
let mapTrans = {
|
||||||
scale: mapScale,
|
scale: SETTINGS.mapScale,
|
||||||
rotate: mapRot,
|
rotate: mapRot,
|
||||||
x: mapCenterX,
|
x: mapCenterX,
|
||||||
y: y+height*0.7
|
y: y+height*0.7
|
||||||
|
|
@ -308,8 +309,8 @@ let getMapSlice = function(){
|
||||||
if (WIDGETS.gpstrek.getState().currentPos.lat) {
|
if (WIDGETS.gpstrek.getState().currentPos.lat) {
|
||||||
current.x = startingPoint.x - current.x;
|
current.x = startingPoint.x - current.x;
|
||||||
current.y = (startingPoint.y - current.y)*-1;
|
current.y = (startingPoint.y - current.y)*-1;
|
||||||
current.x *= mapScale;
|
current.x *= SETTINGS.mapScale;
|
||||||
current.y *= mapScale;
|
current.y *= SETTINGS.mapScale;
|
||||||
current.x += mapCenterX;
|
current.x += mapCenterX;
|
||||||
current.y += y + height*0.7;
|
current.y += y + height*0.7;
|
||||||
|
|
||||||
|
|
@ -945,7 +946,7 @@ let drawInTimeout = function(){
|
||||||
drawTimeout = setTimeout(()=>{
|
drawTimeout = setTimeout(()=>{
|
||||||
drawTimeout = undefined;
|
drawTimeout = undefined;
|
||||||
draw();
|
draw();
|
||||||
},100);
|
},SETTINGS.refresh);
|
||||||
};
|
};
|
||||||
|
|
||||||
let switchNav = function(){
|
let switchNav = function(){
|
||||||
|
|
@ -1061,17 +1062,17 @@ let healthSlice = getDoubleLineSlice("Heart","Steps",()=>{
|
||||||
return !isNaN(WIDGETS.gpstrek.getState().steps)? WIDGETS.gpstrek.getState().steps: "---";
|
return !isNaN(WIDGETS.gpstrek.getState().steps)? WIDGETS.gpstrek.getState().steps: "---";
|
||||||
});
|
});
|
||||||
|
|
||||||
let system2Slice = getDoubleLineSlice("Bat","",()=>{
|
let system2Slice = getDoubleLineSlice("Bat","Storage",()=>{
|
||||||
return (Bangle.isCharging()?"+":"") + E.getBattery().toFixed(0)+"% " + (analogRead(D3)*4.2/BAT_FULL).toFixed(2) + "V";
|
return (Bangle.isCharging()?"+":"") + E.getBattery().toFixed(0)+"% " + (analogRead(D3)*4.2/BAT_FULL).toFixed(2) + "V";
|
||||||
},()=>{
|
},()=>{
|
||||||
return "";
|
return (STORAGE.getFree()/1024).toFixed(0)+"kB";
|
||||||
});
|
});
|
||||||
|
|
||||||
let systemSlice = getDoubleLineSlice("RAM","Storage",()=>{
|
let systemSlice = getDoubleLineSlice("RAM","WP Cache",()=>{
|
||||||
let ram = process.memory(false);
|
let ram = process.memory(false);
|
||||||
return ((ram.blocksize * ram.free)/1024).toFixed(0)+"kB";
|
return ((ram.blocksize * ram.free)/1024).toFixed(0)+"kB";
|
||||||
},()=>{
|
},()=>{
|
||||||
return (STORAGE.getFree()/1024).toFixed(0)+"kB";
|
return cacheInsertion.length?cacheInsertion.length:0;
|
||||||
});
|
});
|
||||||
|
|
||||||
let clear = function() {
|
let clear = function() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue