sweepclock: Added a memory printout to the console so the memory usage can be followed when connected

pull/743/head
adrian w kirk 2021-05-16 20:04:32 +01:00
parent a2ba365a07
commit 193b880ffb
1 changed files with 182 additions and 166 deletions

View File

@ -1,8 +1,8 @@
/** /**
* Adrian Kirk 2021-03 * Adrian Kirk 2021-03
* Simple Clock showing 1 numeral for the hour * Simple Clock showing 1 numeral for the hour
* with a smooth sweep second. * with a smooth sweep second.
*/ */
const screen_center_x = g.getWidth()/2; const screen_center_x = g.getWidth()/2;
const screen_center_y = 10 + g.getHeight()/2; const screen_center_y = 10 + g.getHeight()/2;
@ -11,39 +11,39 @@ const TWO_PI = 2*Math.PI;
require("FontCopasetic40x58Numeric").add(Graphics); require("FontCopasetic40x58Numeric").add(Graphics);
const color_schemes = [ const color_schemes = [
{ {
name: "black", name: "black",
background : [0.0,0.0,0.0], background : [0.0,0.0,0.0],
second_hand: [1.0,0.0,0.0], second_hand: [1.0,0.0,0.0],
}, },
{ {
name: "red", name: "red",
background : [1.0,0.0,0.0], background : [1.0,0.0,0.0],
second_hand: [1.0,1.0,0.0], second_hand: [1.0,1.0,0.0],
}, },
{ {
name: "grey", name: "grey",
background : [0.5,0.5,0.5], background : [0.5,0.5,0.5],
second_hand: [0.0,0.0,0.0], second_hand: [0.0,0.0,0.0],
}, },
{ {
name: "purple", name: "purple",
background : [1.0,0.0,1.0], background : [1.0,0.0,1.0],
second_hand: [1.0,1.0,0.0], second_hand: [1.0,1.0,0.0],
}, },
{ {
name: "blue", name: "blue",
background : [0.4,0.7,1.0], background : [0.4,0.7,1.0],
second_hand: [0.5,0.5,0.5], second_hand: [0.5,0.5,0.5],
} }
]; ];
let color_scheme_index = 0; let color_scheme_index = 0;
var WHITE = [1.0,1.0,1.0]; const WHITE = [1.0,1.0,1.0];
function default_white(color){ function default_white(color){
if(color == null){ if(color == null){
return WHITE return WHITE;
} else { } else {
return color; return color;
} }
@ -51,24 +51,24 @@ function default_white(color){
class Hand { class Hand {
/** /**
* Pure virtual class for all Hand classes to extend. * Pure virtual class for all Hand classes to extend.
* a hand class will have 1 main function * a hand class will have 1 main function
* moveTo which will move the hand to the given angle. * moveTo which will move the hand to the given angle.
*/ */
moveTo(angle){} moveTo(angle){}
} }
class ThinHand extends Hand { class ThinHand extends Hand {
/** /**
* The thin hand is created from a simple line, so its easy and fast * The thin hand is created from a simple line, so its easy and fast
* to draw. * to draw.
*/ */
constructor(centerX, constructor(centerX,
centerY, centerY,
length, length,
tolerance, tolerance,
draw_test, draw_test,
color_theme){ color_theme){
super(); super();
this.centerX = centerX; this.centerX = centerX;
this.centerY = centerY; this.centerY = centerY;
@ -93,8 +93,8 @@ class ThinHand extends Hand {
// first test to see of the angle called is beyond the tolerance // first test to see of the angle called is beyond the tolerance
// for a redraw // for a redraw
if(Math.abs(angle - this.angle) > this.tolerance || if(Math.abs(angle - this.angle) > this.tolerance ||
// and then call the predicate to see if a redraw is needed // and then call the predicate to see if a redraw is needed
this.draw_test(this.angle,this.last_draw_time) ){ this.draw_test(this.angle,this.last_draw_time) ){
// rub out the old hand line // rub out the old hand line
var background = color_schemes[color_scheme_index].background; var background = color_schemes[color_scheme_index].background;
g.setColor(background[0],background[1],background[2]); g.setColor(background[0],background[1],background[2]);
@ -119,17 +119,17 @@ class ThinHand extends Hand {
class ThickHand extends Hand { class ThickHand extends Hand {
/** /**
* The thick hand is created from a filled polygone, so its slower to * The thick hand is created from a filled polygone, so its slower to
* draw so to be used sparingly with few redraws * draw so to be used sparingly with few redraws
*/ */
constructor(centerX, constructor(centerX,
centerY, centerY,
length, length,
tolerance, tolerance,
draw_test, draw_test,
color_theme, color_theme,
base_height, base_height,
thickness){ thickness){
super(); super();
this.centerX = centerX; this.centerX = centerX;
this.centerY = centerY; this.centerY = centerY;
@ -168,21 +168,21 @@ class ThickHand extends Hand {
var background = color_schemes[color_scheme_index].background; var background = color_schemes[color_scheme_index].background;
g.setColor(background[0],background[1],background[2]); g.setColor(background[0],background[1],background[2]);
g.fillPoly([this.last_x1, g.fillPoly([this.last_x1,
this.last_y1, this.last_y1,
this.last_x2, this.last_x2,
this.last_y2, this.last_y2,
this.last_x3, this.last_x3,
this.last_y3, this.last_y3,
this.last_x4, this.last_x4,
this.last_y4 this.last_y4
]); ]);
// bottom left // bottom left
var x1 = this.centerX + var x1 = this.centerX +
this.vertex_radius_base*Math.sin(angle - this.delta_base); this.vertex_radius_base*Math.sin(angle - this.delta_base);
var y1 = this.centerY - this.vertex_radius_base*Math.cos(angle - this.delta_base); var y1 = this.centerY - this.vertex_radius_base*Math.cos(angle - this.delta_base);
// bottom right // bottom right
var x2 = this.centerX + var x2 = this.centerX +
this.vertex_radius_base*Math.sin(angle + this.delta_base); this.vertex_radius_base*Math.sin(angle + this.delta_base);
var y2 = this.centerY - this.vertex_radius_base*Math.cos(angle + this.delta_base); var y2 = this.centerY - this.vertex_radius_base*Math.cos(angle + this.delta_base);
// top right // top right
var x3 = this.centerX + this.vertex_radius_top*Math.sin(angle + this.delta_top); var x3 = this.centerX + this.vertex_radius_top*Math.sin(angle + this.delta_top);
@ -193,10 +193,10 @@ class ThickHand extends Hand {
var hand_color = default_white(color_schemes[color_scheme_index][this.color_theme]); var hand_color = default_white(color_schemes[color_scheme_index][this.color_theme]);
g.setColor(hand_color[0],hand_color[1],hand_color[2]); g.setColor(hand_color[0],hand_color[1],hand_color[2]);
g.fillPoly([x1,y1, g.fillPoly([x1,y1,
x2,y2, x2,y2,
x3,y3, x3,y3,
x4,y4 x4,y4
]); ]);
this.last_x1 = x1; this.last_x1 = x1;
this.last_y1 = y1; this.last_y1 = y1;
this.last_x2 = x2; this.last_x2 = x2;
@ -216,7 +216,7 @@ class ThickHand extends Hand {
// The force draw is set to true to force all objects to redraw themselves // The force draw is set to true to force all objects to redraw themselves
let force_redraw = false; let force_redraw = false;
// The seconds hand is the main focus and is set to redraw on every cycle // The seconds hand is the main focus and is set to redraw on every cycle
let seconds_hand = new ThinHand(screen_center_x, let seconds_hand = new ThinHand(screen_center_x,
screen_center_y, screen_center_y,
95, 95,
0, 0,
@ -228,8 +228,8 @@ let seconds_hand = new ThinHand(screen_center_x,
// or when a force_redraw is called // or when a force_redraw is called
let minutes_hand_redraw = function(angle, last_draw_time){ let minutes_hand_redraw = function(angle, last_draw_time){
return force_redraw || (seconds_hand.angle > angle && return force_redraw || (seconds_hand.angle > angle &&
Math.abs(seconds_hand.angle - angle) <TWO_PI/25 && Math.abs(seconds_hand.angle - angle) <TWO_PI/25 &&
new Date().getTime() - last_draw_time.getTime() > 500); new Date().getTime() - last_draw_time.getTime() > 500);
}; };
let minutes_hand = new ThinHand(screen_center_x, let minutes_hand = new ThinHand(screen_center_x,
screen_center_y, screen_center_y,
@ -242,10 +242,10 @@ let minutes_hand = new ThinHand(screen_center_x,
// overlaps from its behind andle coverage to its ahead angle coverage. // overlaps from its behind andle coverage to its ahead angle coverage.
let hour_hand_redraw = function(angle_from, angle_to, last_draw_time){ let hour_hand_redraw = function(angle_from, angle_to, last_draw_time){
return force_redraw || (seconds_hand.angle >= angle_from && return force_redraw || (seconds_hand.angle >= angle_from &&
seconds_hand.angle <= angle_to && seconds_hand.angle <= angle_to &&
new Date().getTime() - last_draw_time.getTime() > 500); new Date().getTime() - last_draw_time.getTime() > 500);
}; };
let hours_hand = new ThickHand(screen_center_x, let hours_hand = new ThickHand(screen_center_x,
screen_center_y, screen_center_y,
40, 40,
TWO_PI/600, TWO_PI/600,
@ -269,8 +269,8 @@ var local = require('locale');
var last_date = null; var last_date = null;
var last_datestr = null; var last_datestr = null;
var last_coords = null; var last_coords = null;
var date_coords = [ const date_coords = [
{ name: "topright", coords:[180,30]}, { name: "topright", coords:[180,30]},
{ name: "bottomright", coords:[180,220]}, { name: "bottomright", coords:[180,220]},
{ name: "bottomleft", coords: [5,220]}, { name: "bottomleft", coords: [5,220]},
{ name: "topleft", coords:[5,30]}, { name: "topleft", coords:[5,30]},
@ -280,26 +280,26 @@ var date_coords = [
var date_coord_index = 0; var date_coord_index = 0;
function draw_date(date){ function draw_date(date){
if(force_redraw || last_date == null || last_date.getDate() != date.getDate()){ if(force_redraw || last_date == null || last_date.getDate() != date.getDate()){
//console.log("redrawing date"); //console.log("redrawing date");
g.setFontAlign(-1,-1,0); g.setFontAlign(-1,-1,0);
g.setFont("Vector",15); g.setFont("Vector",15);
if(last_coords != null && last_datestr != null) { if(last_coords != null && last_datestr != null) {
var background = color_schemes[color_scheme_index].background; var background = color_schemes[color_scheme_index].background;
g.setColor(background[0], background[1], background[2]); g.setColor(background[0], background[1], background[2]);
g.drawString(last_datestr, last_coords[0], last_coords[1]); g.drawString(last_datestr, last_coords[0], last_coords[1]);
} }
var coords = date_coords[date_coord_index].coords; var coords = date_coords[date_coord_index].coords;
if(coords != null) { if(coords != null) {
var date_format = local.dow(date,1) + " " + date.getDate(); var date_format = local.dow(date,1) + " " + date.getDate();
var numeral_color = default_white(color_schemes[color_scheme_index].numeral); var numeral_color = default_white(color_schemes[color_scheme_index].numeral);
g.setColor(numeral_color[0], numeral_color[1], numeral_color[2]); g.setColor(numeral_color[0], numeral_color[1], numeral_color[2]);
g.drawString(date_format, coords[0], coords[1]); g.drawString(date_format, coords[0], coords[1]);
last_date = date; last_date = date;
last_datestr = date_format; last_datestr = date_format;
last_coords = coords; last_coords = coords;
} }
} }
} }
function next_datecoords() { function next_datecoords() {
@ -354,17 +354,17 @@ function draw_hours(date){
} }
/** /**
* We want to be able to change the font so we set up * We want to be able to change the font so we set up
* pure virtual for all fonts implementtions to use * pure virtual for all fonts implementtions to use
*/ */
class NumeralFont { class NumeralFont {
/** /**
* The screen dimensions of what we are going to * The screen dimensions of what we are going to
* display for the given hour. * display for the given hour.
*/ */
getDimensions(hour){return [0,0];} getDimensions(hour){return [0,0];}
/** /**
* The characters that are going to be returned for * The characters that are going to be returned for
* the hour. * the hour.
*/ */
hour_txt(hour){ return ""; } hour_txt(hour){ return ""; }
@ -386,29 +386,34 @@ class NoFont extends NumeralFont{
getName(){return "NoFont";} getName(){return "NoFont";}
} }
const COPASET_DIM_20x58 = [20,58];
const COPASET_DIM_30x58 = [30,58];
const COPASET_DIM_40x58 = [40,58];
const COPASET_DIM_50x58 = [50,58];
class CopasetFont extends NumeralFont{ class CopasetFont extends NumeralFont{
constructor(){ constructor(){
super(); super();
} }
getDimensions(hour){ getDimensions(hour){
switch(hour){ switch(hour){
case 1: return [20,58]; case 1: return COPASET_DIM_20x58;
case 2: case 2:
case 3: case 3:
case 4: case 4:
case 5: case 5:
case 7: case 7:
return [30,58]; return COPASET_DIM_30x58;
case 6: case 6:
case 8: case 8:
case 9: case 9:
case 11: case 11:
case 12: case 12:
return [40,58]; return COPASET_DIM_40x58;
case 10: case 10:
return [50,58]; return COPASET_DIM_50x58;
default: default:
return [30,58]; return COPASET_DIM_30x58;
} }
} }
hour_txt(hour){ return hour.toString(); } hour_txt(hour){ return hour.toString(); }
@ -431,7 +436,13 @@ class CopasetFont extends NumeralFont{
getName(){return "Copaset";} getName(){return "Copaset";}
} }
const ROMAN_DIM_10x40 = [10,40];
const ROMAN_DIM_20x40 = [20,40];
const ROMAN_DIM_25x40 = [25,40];
const ROMAN_DIM_30x40 = [30,40];
const ROMAN_DIM_40x40 = [40,40];
const ROMAN_DIM_60x40 = [60,40];
const ROMAN_DIM_70x40 = [70,40];
class RomanNumeralFont extends NumeralFont{ class RomanNumeralFont extends NumeralFont{
constructor(){ constructor(){
super(); super();
@ -456,26 +467,26 @@ class RomanNumeralFont extends NumeralFont{
getDimensions(hour){ getDimensions(hour){
switch (hour){ switch (hour){
case 1: case 1:
return [10,40]; return ROMAN_DIM_10x40;
case 2: case 2:
return [25,40]; return ROMAN_DIM_25x40;
case 3: case 3:
case 4: case 4:
case 6: case 6:
case 9: case 9:
case 11: case 11:
case 12: case 12:
return [40,40]; return ROMAN_DIM_40x40;
case 5: case 5:
return [30,40]; return ROMAN_DIM_30x40;
case 7: case 7:
return [60,40]; return ROMAN_DIM_60x40;
case 8: case 8:
return [70,40]; return ROMAN_DIM_70x40;
case 10: case 10:
return [20,40]; return ROMAN_DIM_20x40;
default: default:
return [40,40]; return ROMAN_DIM_40x40;
} }
} }
hour_txt(hour){ return this.getText(hour); } hour_txt(hour){ return this.getText(hour); }
@ -487,9 +498,9 @@ class RomanNumeralFont extends NumeralFont{
getName(){return "Roman";} getName(){return "Roman";}
} }
// The problem with the trig inverse functions on // The problem with the trig inverse functions on
// a full circle is that the sector information will be lost // a full circle is that the sector information will be lost
// Choosing to use arcsin because you can get back the // Choosing to use arcsin because you can get back the
// sector with the help of the original coordinates // sector with the help of the original coordinates
function reifyasin(x,y,asin_angle){ function reifyasin(x,y,asin_angle){
if(x >= 0 && y >= 0){ if(x >= 0 && y >= 0){
@ -503,7 +514,7 @@ function reifyasin(x,y,asin_angle){
} }
} }
// rebase and angle so be between -pi and pi // rebase and angle so be between -pi and pi
// rather than 0 to 2PI // rather than 0 to 2PI
function rebaseNegative(angle){ function rebaseNegative(angle){
if(angle > Math.PI){ if(angle > Math.PI){
@ -524,10 +535,10 @@ function rebasePositive(angle){
} }
/** /**
* The Hour Scriber is responsible for drawing the numeral * The Hour Scriber is responsible for drawing the numeral
* on the screen at the requested angle. * on the screen at the requested angle.
* It allows for the font to be changed on the fly. * It allows for the font to be changed on the fly.
*/ */
class HourScriber { class HourScriber {
constructor(radius, numeral_font, draw_test){ constructor(radius, numeral_font, draw_test){
this.radius = radius; this.radius = radius;
@ -549,8 +560,8 @@ class HourScriber {
var background = color_schemes[color_scheme_index].background; var background = color_schemes[color_scheme_index].background;
g.setColor(background[0],background[1],background[2]); g.setColor(background[0],background[1],background[2]);
this.curr_numeral_font.draw(this.curr_hour_str, this.curr_numeral_font.draw(this.curr_hour_str,
this.curr_hour_x, this.curr_hour_x,
this.curr_hour_y); this.curr_hour_y);
//console.log("erasing old hour"); //console.log("erasing old hour");
var hours_frac = hours / 12; var hours_frac = hours / 12;
var angle = TWO_PI*hours_frac; var angle = TWO_PI*hours_frac;
@ -564,7 +575,7 @@ class HourScriber {
this.curr_hour_x = screen_center_x + delta_center_x; this.curr_hour_x = screen_center_x + delta_center_x;
this.curr_hour_y = screen_center_y - delta_center_y; this.curr_hour_y = screen_center_y - delta_center_y;
this.curr_hour_str = this.numeral_font.hour_txt(hours); this.curr_hour_str = this.numeral_font.hour_txt(hours);
// now work out the angle of the beginning and the end of the // now work out the angle of the beginning and the end of the
// text box so we know when to redraw // text box so we know when to redraw
// bottom left angle // bottom left angle
var x1 = delta_center_x; var x1 = delta_center_x;
@ -592,10 +603,10 @@ class HourScriber {
angle3 = rebaseNegative(angle3); angle3 = rebaseNegative(angle3);
angle3 = rebaseNegative(angle4); angle3 = rebaseNegative(angle4);
this.angle_from = rebasePositive( Math.min(angle1,angle2,angle3,angle4) ); this.angle_from = rebasePositive( Math.min(angle1,angle2,angle3,angle4) );
this.angle_to = rebasePositive( Math.max(angle1,angle2,angle3,angle4) ); this.angle_to = rebasePositive( Math.max(angle1,angle2,angle3,angle4) );
} else { } else {
this.angle_from = Math.min(angle1,angle2,angle3,angle4); this.angle_from = Math.min(angle1,angle2,angle3,angle4);
this.angle_to = Math.max(angle1,angle2,angle3,angle4); this.angle_to = Math.max(angle1,angle2,angle3,angle4);
} }
//console.log(angle1 + "/" + angle2 + " / " + angle3 + " / " + angle4); //console.log(angle1 + "/" + angle2 + " / " + angle3 + " / " + angle4);
//console.log( this.angle_from + " to " + this.angle_to); //console.log( this.angle_from + " to " + this.angle_to);
@ -604,7 +615,7 @@ class HourScriber {
changed = true; changed = true;
} }
if(changed || if(changed ||
this.draw_test(this.angle_from, this.angle_to, this.last_draw_time) ){ this.draw_test(this.angle_from, this.angle_to, this.last_draw_time) ){
var numeral_color = default_white(color_schemes[color_scheme_index].numeral); var numeral_color = default_white(color_schemes[color_scheme_index].numeral);
g.setColor(numeral_color[0],numeral_color[1],numeral_color[2]); g.setColor(numeral_color[0],numeral_color[1],numeral_color[2]);
this.numeral_font.draw(this.curr_hour_str,this.curr_hour_x,this.curr_hour_y); this.numeral_font.draw(this.curr_hour_str,this.curr_hour_x,this.curr_hour_y);
@ -617,43 +628,43 @@ class HourScriber {
let numeral_fonts = [new CopasetFont(), new RomanNumeralFont(), new NoFont()]; let numeral_fonts = [new CopasetFont(), new RomanNumeralFont(), new NoFont()];
let numeral_fonts_index = 0; let numeral_fonts_index = 0;
/** /**
* predicate for deciding when the digit has to be redrawn * predicate for deciding when the digit has to be redrawn
*/ */
let hour_numeral_redraw = function(angle_from, angle_to, last_draw_time){ let hour_numeral_redraw = function(angle_from, angle_to, last_draw_time){
var seconds_hand_angle = seconds_hand.angle; var seconds_hand_angle = seconds_hand.angle;
// we have to cope with the 12 problem where the // we have to cope with the 12 problem where the
// left side of the box has a value almost 2PI and the right // left side of the box has a value almost 2PI and the right
// side has a small positive value. The values are rebased so // side has a small positive value. The values are rebased so
// that they can be compared // that they can be compared
if(angle_from > angle_to && angle_from > 1.5*Math.PI){ if(angle_from > angle_to && angle_from > 1.5*Math.PI){
angle_from = angle_from - TWO_PI; angle_from = angle_from - TWO_PI;
if(seconds_hand_angle > Math.PI) if(seconds_hand_angle > Math.PI)
seconds_hand_angle = seconds_hand_angle - TWO_PI; seconds_hand_angle = seconds_hand_angle - TWO_PI;
} }
//console.log("initial:" + angle_from + "/" + angle_to + " seconds " + seconds_hand_angle); //console.log("initial:" + angle_from + "/" + angle_to + " seconds " + seconds_hand_angle);
var redraw = force_redraw || var redraw = force_redraw ||
(seconds_hand_angle >= angle_from && seconds_hand_angle <= angle_to) || (seconds_hand_angle >= angle_from && seconds_hand_angle <= angle_to) ||
(minutes_hand.last_draw_time.getTime() > last_draw_time.getTime()); (minutes_hand.last_draw_time.getTime() > last_draw_time.getTime());
if(redraw){ if(redraw){
//console.log(angle_from + "/" + angle_to + " seconds " + seconds_hand_angle); //console.log(angle_from + "/" + angle_to + " seconds " + seconds_hand_angle);
} }
return redraw; return redraw;
}; };
let hour_scriber = new HourScriber(70, let hour_scriber = new HourScriber(70,
numeral_fonts[numeral_fonts_index], numeral_fonts[numeral_fonts_index],
hour_numeral_redraw hour_numeral_redraw
); );
/** /**
* Called from button 1 to change the numerals that are * Called from button 1 to change the numerals that are
* displayed on the clock face * displayed on the clock face
*/ */
function next_font(){ function next_font(){
numeral_fonts_index = numeral_fonts_index + 1; numeral_fonts_index = numeral_fonts_index + 1;
if(numeral_fonts_index >= numeral_fonts.length){ if(numeral_fonts_index >= numeral_fonts.length){
numeral_fonts_index = 0; numeral_fonts_index = 0;
} }
hour_scriber.setNumeralFont( hour_scriber.setNumeralFont(
numeral_fonts[numeral_fonts_index]); numeral_fonts[numeral_fonts_index]);
force_redraw = true; force_redraw = true;
} }
@ -674,10 +685,10 @@ function draw_background(){
var background = color_schemes[color_scheme_index].background; var background = color_schemes[color_scheme_index].background;
g.setColor(background[0],background[1],background[2]); g.setColor(background[0],background[1],background[2]);
g.fillPoly([0,25, g.fillPoly([0,25,
0,240, 0,240,
240,240, 240,240,
240,25 240,25
]); ]);
} }
} }
@ -689,9 +700,9 @@ function next_colorscheme(){
} }
/** /**
* called from load_settings on startup to * called from load_settings on startup to
* set the color scheme to named value * set the color scheme to named value
*/ */
function set_colorscheme(colorscheme_name){ function set_colorscheme(colorscheme_name){
console.log("setting color scheme:" + colorscheme_name); console.log("setting color scheme:" + colorscheme_name);
for (var i=0; i < color_schemes.length; i++) { for (var i=0; i < color_schemes.length; i++) {
@ -705,9 +716,9 @@ function set_colorscheme(colorscheme_name){
} }
/** /**
* called from load_settings on startup * called from load_settings on startup
* to set the font to named value * to set the font to named value
*/ */
function set_font(font_name){ function set_font(font_name){
console.log("setting font:" + font_name); console.log("setting font:" + font_name);
for (var i=0; i < numeral_fonts.length; i++) { for (var i=0; i < numeral_fonts.length; i++) {
@ -722,8 +733,8 @@ function set_font(font_name){
} }
/** /**
* Called on startup to set the watch to the last preference settings * Called on startup to set the watch to the last preference settings
*/ */
function load_settings(){ function load_settings(){
try{ try{
var settings = require("Storage").readJSON("sweepclock.settings.json"); var settings = require("Storage").readJSON("sweepclock.settings.json");
@ -746,9 +757,15 @@ function load_settings(){
} }
} }
function print_memoryusage(){
var m = process.memory();
var pc = Math.round(m.usage*100/m.total);
console.log("memory usage: " + pc + "%");
}
/** /**
* Called on button press to save down the last preference settings * Called on button press to save down the last preference settings
*/ */
function save_settings(){ function save_settings(){
var settings = { var settings = {
font : numeral_fonts[numeral_fonts_index].getName(), font : numeral_fonts[numeral_fonts_index].getName(),
@ -757,6 +774,7 @@ function save_settings(){
}; };
console.log("saving:" + JSON.stringify(settings)); console.log("saving:" + JSON.stringify(settings));
require("Storage").writeJSON("sweepclock.settings.json",settings); require("Storage").writeJSON("sweepclock.settings.json",settings);
print_memoryusage();
} }
// Boiler plate code for setting up the clock, // Boiler plate code for setting up the clock,
@ -785,14 +803,12 @@ function scheduleDrawClock(){
} }
function reset_clock(){ function reset_clock(){
g.clear();
force_redraw = true; force_redraw = true;
} }
Bangle.on('lcdPower', (on) => { Bangle.on('lcdPower', (on) => {
if (on) { if (on) {
console.log("lcdPower: on"); console.log("lcdPower: on");
Bangle.drawWidgets();
reset_clock(); reset_clock();
startTimers(); startTimers();
} else { } else {
@ -821,7 +837,7 @@ startTimers();
setWatch(Bangle.showLauncher, BTN2,{repeat:false,edge:"falling"}); setWatch(Bangle.showLauncher, BTN2,{repeat:false,edge:"falling"});
function button1pressed(){ function button1pressed(){
next_font(); next_font();
save_settings(); save_settings();
} }