From 804f308af17af8695f83c673026508f88adf5c2a Mon Sep 17 00:00:00 2001 From: adrian w kirk Date: Sat, 8 Oct 2022 21:46:00 +0100 Subject: [PATCH] sliding clock: changed styling from member variables to instance variables --- apps/slidingtext/slidingtext.js | 67 ++++++++++---------- apps/slidingtext/slidingtext.locale.de.js | 34 +++++----- apps/slidingtext/slidingtext.locale.dgt.js | 48 +++++++-------- apps/slidingtext/slidingtext.locale.en2.js | 72 +++++++++++----------- apps/slidingtext/slidingtext.locale.es.js | 34 +++++----- apps/slidingtext/slidingtext.locale.fr.js | 44 ++++++------- apps/slidingtext/slidingtext.locale.jp.js | 20 +++--- 7 files changed, 164 insertions(+), 155 deletions(-) diff --git a/apps/slidingtext/slidingtext.js b/apps/slidingtext/slidingtext.js index 6ea0cfd65..a7d0ba05f 100644 --- a/apps/slidingtext/slidingtext.js +++ b/apps/slidingtext/slidingtext.js @@ -448,6 +448,8 @@ function initComplete(){ speeds = null; rotations = null; heights = null; + const mem = process.memory(true); + console.log("init complete memory:" + mem.usage / mem.total); } function create_row(row_type, row_no){ @@ -547,7 +549,9 @@ function drawClock(){ } reset_commands(); date = display_time(date); - console.log("draw_clock:" + last_draw_time.toISOString() + " display:" + date.toISOString()); + const mem = process.memory(false); + console.log("draw_clock:" + last_draw_time.toISOString() + " display:" + date.toISOString() + + " memory:" + mem.usage / mem.total); const rows = date_formatter.formatDate(date); for (var i = 0; i < rows.length; i++) { @@ -622,34 +626,6 @@ const Locale = require('locale'); */ class DigitDateTimeFormatter { constructor() { - this.row_types = { - large: { - scroll_off: ['left', 'right', 'down'], - scroll_in: ['left', 'right', 'up'], - size: 'vlarge' - }, - small: { - angle_to_horizontal: 90, - scroll_off: ['down'], - scroll_in: ['up'], - size: 'vvsmall' - } - }; - - this.row_defs = [ - { - type: 'large', - row_direction: [0.0,1.0], - init_coords: [0.1,0.35], - rows: 1 - }, - { - type: 'small', - row_direction: [1.0,0], - init_coords: [0.85,0.99], - rows: 2 - } - ]; } format00(num){ @@ -670,9 +646,38 @@ class DigitDateTimeFormatter { return [time_txt, date_txt, month_txt]; } - defaultRowTypes(){ return this.row_types; } + defaultRowTypes(){ + return { + large: { + scroll_off: ['left', 'right', 'down'], + scroll_in: ['left', 'right', 'up'], + size: 'vlarge' + }, + small: { + angle_to_horizontal: 90, + scroll_off: ['down'], + scroll_in: ['up'], + size: 'vvsmall' + } + }; + } - defaultRowDefs() { return this.row_defs; } + defaultRowDefs() { + return [ + { + type: 'large', + row_direction: [0.0,1.0], + init_coords: [0.1,0.35], + rows: 1 + }, + { + type: 'small', + row_direction: [1.0,0], + init_coords: [0.85,0.99], + rows: 2 + } + ]; + } } var date_formatter; diff --git a/apps/slidingtext/slidingtext.locale.de.js b/apps/slidingtext/slidingtext.locale.de.js index e2b58bdb5..e18529aee 100644 --- a/apps/slidingtext/slidingtext.locale.de.js +++ b/apps/slidingtext/slidingtext.locale.de.js @@ -70,21 +70,6 @@ function germanMinsToText(mins) { class GermanDateFormatter extends DateFormatter { constructor() { super(); - this.row_types = { }; - this.row_defs = [ - { - type: 'large', - init_coords: [0.05,0.1], - row_direction: [0.0,1.0], - rows: 1 - }, - { - type: 'medium', - init_coords: [0.05,0.4], - row_direction: [0.0,1.0], - rows: 3 - } - ]; } formatDate(date){ const mins = date.getMinutes(); @@ -108,9 +93,24 @@ class GermanDateFormatter extends DateFormatter { return [hours, "UHR", mins_txt[0],mins_txt[1]]; } } - defaultRowTypes(){ return this.row_types;} + defaultRowTypes(){ return {};} - defaultRowDefs(){ return this.row_defs; } + defaultRowDefs(){ + return [ + { + type: 'large', + init_coords: [0.05,0.1], + row_direction: [0.0,1.0], + rows: 1 + }, + { + type: 'medium', + init_coords: [0.05,0.4], + row_direction: [0.0,1.0], + rows: 3 + } + ]; + } } module.exports = GermanDateFormatter; diff --git a/apps/slidingtext/slidingtext.locale.dgt.js b/apps/slidingtext/slidingtext.locale.dgt.js index 7946efa4d..446a4cd50 100644 --- a/apps/slidingtext/slidingtext.locale.dgt.js +++ b/apps/slidingtext/slidingtext.locale.dgt.js @@ -1,8 +1,27 @@ const Locale = require('locale'); class DigitDateTimeFormatter { - constructor() { - this.row_types = { + constructor() {} + + format00(num){ + const value = (num | 0); + if(value > 99 || value < 0) + throw "must be between in range 0-99"; + if(value < 10) + return "0" + value.toString(); + else + return value.toString(); + } + + formatDate(now){ + const hours = now.getHours() ; + const time_txt = this.format00(hours) + ":" + this.format00(now.getMinutes()); + const date_txt = Locale.dow(now,1) + " " + this.format00(now.getDate()); + return [time_txt[0], time_txt[1],time_txt[2], time_txt[3],time_txt[4],date_txt]; + } + + defaultRowTypes(){ + return { large: { scroll_off: ['down'], scroll_in: ['up'], @@ -15,8 +34,10 @@ class DigitDateTimeFormatter { scroll_in: ['right'], } }; + } - this.row_defs = [ + defaultRowDefs() { + return [ { type: 'large', row_direction: [0.7,0.0], @@ -37,27 +58,6 @@ class DigitDateTimeFormatter { } ]; } - - format00(num){ - const value = (num | 0); - if(value > 99 || value < 0) - throw "must be between in range 0-99"; - if(value < 10) - return "0" + value.toString(); - else - return value.toString(); - } - - formatDate(now){ - const hours = now.getHours() ; - const time_txt = this.format00(hours) + ":" + this.format00(now.getMinutes()); - const date_txt = Locale.dow(now,1) + " " + this.format00(now.getDate()); - return [time_txt[0], time_txt[1],time_txt[2], time_txt[3],time_txt[4],date_txt]; - } - - defaultRowTypes(){ return this.row_types; } - - defaultRowDefs() { return this.row_defs; } } module.exports = DigitDateTimeFormatter; \ No newline at end of file diff --git a/apps/slidingtext/slidingtext.locale.en2.js b/apps/slidingtext/slidingtext.locale.en2.js index 3e06659a7..ac2ae02ff 100644 --- a/apps/slidingtext/slidingtext.locale.en2.js +++ b/apps/slidingtext/slidingtext.locale.en2.js @@ -7,39 +7,6 @@ const numberToText = require("slidingtext.utils.en.js").numberToText; class EnglishTraditionalDateFormatter extends DateFormatter { constructor() { super(); - this.row_types = { - small: { - speed: 'medium', - scroll_off: ['left','right'], - scroll_in: ['left','right'], - }, - large: { - speed: 'medium', - color: 'major', - scroll_off: ['left','right'], - scroll_in: ['left','right'] - } - }; - this.row_defs = [ - { - type: 'large', - init_coords: [0.05,0.1], - row_direction: [0.0,1.0], - rows: 1 - }, - { - type: 'small', - init_coords: [0.05,0.35], - row_direction: [0.0,1.0], - rows: 3 - }, - { - type: 'large', - init_coords: [0.05,0.75], - row_direction: [0.0,1.0], - rows: 1 - } - ]; } formatDate(date){ const day_of_week = dayOfWeekShort(date); @@ -85,9 +52,44 @@ class EnglishTraditionalDateFormatter extends DateFormatter { } } } - defaultRowTypes(){ return this.row_types;} + defaultRowTypes(){ + return { + small: { + speed: 'medium', + scroll_off: ['left','right'], + scroll_in: ['left','right'], + }, + large: { + speed: 'medium', + color: 'major', + scroll_off: ['left','right'], + scroll_in: ['left','right'] + } + }; + } - defaultRowDefs(){ return this.row_defs; } + defaultRowDefs(){ + return [ + { + type: 'large', + init_coords: [0.05,0.1], + row_direction: [0.0,1.0], + rows: 1 + }, + { + type: 'small', + init_coords: [0.05,0.35], + row_direction: [0.0,1.0], + rows: 3 + }, + { + type: 'large', + init_coords: [0.05,0.75], + row_direction: [0.0,1.0], + rows: 1 + } + ]; + } } module.exports = EnglishTraditionalDateFormatter; \ No newline at end of file diff --git a/apps/slidingtext/slidingtext.locale.es.js b/apps/slidingtext/slidingtext.locale.es.js index 39e4df288..041497e04 100644 --- a/apps/slidingtext/slidingtext.locale.es.js +++ b/apps/slidingtext/slidingtext.locale.es.js @@ -47,21 +47,6 @@ function spanishMinsToText(mins){ class SpanishDateFormatter extends DateFormatter { constructor() { super(); - this.row_types = { }; - this.row_defs = [ - { - type: 'large', - init_coords: [0.05,0.1], - row_direction: [0.0,1.0], - rows: 1 - }, - { - type: 'medium', - init_coords: [0.05,0.4], - row_direction: [0.0,1.0], - rows: 3 - } - ]; } formatDate(date){ const mins = date.getMinutes(); @@ -88,9 +73,24 @@ class SpanishDateFormatter extends DateFormatter { return [hours, "Y", mins_txt[0],mins_txt[1]]; } } - defaultRowTypes(){ return this.row_types;} + defaultRowTypes(){ return {};} - defaultRowDefs(){ return this.row_defs; } + defaultRowDefs(){ + return [ + { + type: 'large', + init_coords: [0.05,0.1], + row_direction: [0.0,1.0], + rows: 1 + }, + { + type: 'medium', + init_coords: [0.05,0.4], + row_direction: [0.0,1.0], + rows: 3 + } + ]; + } } module.exports = SpanishDateFormatter; diff --git a/apps/slidingtext/slidingtext.locale.fr.js b/apps/slidingtext/slidingtext.locale.fr.js index f239af222..6da0e232d 100644 --- a/apps/slidingtext/slidingtext.locale.fr.js +++ b/apps/slidingtext/slidingtext.locale.fr.js @@ -31,25 +31,6 @@ function frenchHeures(hours){ class FrenchDateFormatter extends DateFormatter { constructor() { super(); - this.row_types = { - small: { - speed: 'vslow' - } - }; - this.row_defs = [ - { - type: 'large', - init_coords: [0.05,0.1], - row_direction: [0.0,1.0], - rows: 1 - }, - { - type: 'small', - init_coords: [0.05,0.4], - row_direction: [0.0,1.0], - rows: 3 - } - ]; } formatDate(date){ var hours = frenchHoursToText(date.getHours()); @@ -85,9 +66,30 @@ class FrenchDateFormatter extends DateFormatter { return [ hours, heures , mins_txt ]; } } - defaultRowTypes(){ return this.row_types;} + defaultRowTypes(){ + return { + small: { + speed: 'vslow' + } + }; + } - defaultRowDefs(){ return this.row_defs; } + defaultRowDefs(){ + return [ + { + type: 'large', + init_coords: [0.05,0.1], + row_direction: [0.0,1.0], + rows: 1 + }, + { + type: 'small', + init_coords: [0.05,0.4], + row_direction: [0.0,1.0], + rows: 3 + } + ]; + } } module.exports = FrenchDateFormatter; \ No newline at end of file diff --git a/apps/slidingtext/slidingtext.locale.jp.js b/apps/slidingtext/slidingtext.locale.jp.js index b3d0a255a..b2f9106a2 100644 --- a/apps/slidingtext/slidingtext.locale.jp.js +++ b/apps/slidingtext/slidingtext.locale.jp.js @@ -61,8 +61,16 @@ function japaneseMinsToText(mins){ class JapaneseDateFormatter extends DateFormatter { constructor() { super(); - this.row_types = { }; - this.row_defs = [ + } + formatDate(date){ + const hours_txt = japaneseHoursToText(date.getHours()); + const mins_txt = japaneseMinsToText(date.getMinutes()); + return [hours_txt,"JI", mins_txt[0], mins_txt[1] ]; + } + defaultRowTypes(){ return {}; } + + defaultRowDefs(){ + return [ { type: 'large', init_coords: [0.05,0.1], @@ -77,14 +85,6 @@ class JapaneseDateFormatter extends DateFormatter { } ]; } - formatDate(date){ - const hours_txt = japaneseHoursToText(date.getHours()); - const mins_txt = japaneseMinsToText(date.getMinutes()); - return [hours_txt,"JI", mins_txt[0], mins_txt[1] ]; - } - defaultRowTypes(){ return this.row_types;} - - defaultRowDefs(){ return this.row_defs; } } module.exports = JapaneseDateFormatter; \ No newline at end of file