From d71bf76dd1ec2cc7344e5b88e9a107964d671dc4 Mon Sep 17 00:00:00 2001 From: awkirk Date: Sun, 2 Oct 2022 01:05:17 +0100 Subject: [PATCH] SLiding Clock: Added digital clock --- apps/slidingtext/slidingtext.js | 14 ++++-- apps/slidingtext/slidingtext.locale.dgt.js | 57 ++++++++++++++++++++++ apps/slidingtext/slidingtext.locale.en2.js | 3 +- apps/slidingtext/slidingtext.settings.js | 5 +- 4 files changed, 72 insertions(+), 7 deletions(-) create mode 100644 apps/slidingtext/slidingtext.locale.dgt.js diff --git a/apps/slidingtext/slidingtext.js b/apps/slidingtext/slidingtext.js index 1e271d2b1..5169a0b53 100644 --- a/apps/slidingtext/slidingtext.js +++ b/apps/slidingtext/slidingtext.js @@ -339,11 +339,12 @@ function mergeObjects(obj1, obj2){ const heights = { - vvsmall: [20,15], - vsmall: [22,17], + vvsmall: [15,13], + vsmall: [20,15], small: [25,20], msmall: [30,22], medium: [40,25], + mlarge: [45,35], large: [50,40], vlarge: [60,50] }; @@ -511,6 +512,7 @@ function display_time(date){ function drawClock(){ var date = new Date(); + date.setHours(12); // we don't want the time to be displayed // and then immediately be trigger another time @@ -652,8 +654,12 @@ function setDateformat(shortname){ console.log("setting date format:" + shortname); try { if (date_formatter == null || date_formatter.shortName() !== shortname) { - var date_formatter_class = require("slidingtext.locale." + shortname + ".js"); - date_formatter = new date_formatter_class(); + if(shortname === "default"){ + date_formatter = new DigitDateTimeFormatter(); + } else { + var date_formatter_class = require("slidingtext.locale." + shortname + ".js"); + date_formatter = new date_formatter_class(); + } } } catch(e){ console.log("Failed to load " + shortname); diff --git a/apps/slidingtext/slidingtext.locale.dgt.js b/apps/slidingtext/slidingtext.locale.dgt.js new file mode 100644 index 000000000..6c2c56f92 --- /dev/null +++ b/apps/slidingtext/slidingtext.locale.dgt.js @@ -0,0 +1,57 @@ +const Locale = require('locale'); + +class DigitDateTimeFormatter { + constructor() { + this.row_types = { + large: { + scroll_off: ['down'], + scroll_in: ['up'], + size: 'large', + speed: 'vslow' + }, + small: { + angle_to_horizontal: 0, + scroll_off: ['left'], + scroll_in: ['right'], + } + }; + + this.row_defs = [ + { + type: 'large', + row_direction: [0.8,0.0], + init_coords: [0.1,0.35], + rows: 5 + }, + { + type: 'small', + row_direction: [0.0,1.0], + init_coords: [0.1,0.05], + rows: 1 + } + ]; + } + + format00(num){ + var 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){ + var hours = now.getHours() ; + var time_txt = this.format00(hours) + ":" + this.format00(now.getMinutes()); + var 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 2baf1de68..f3d5ad5a3 100644 --- a/apps/slidingtext/slidingtext.locale.en2.js +++ b/apps/slidingtext/slidingtext.locale.en2.js @@ -56,7 +56,7 @@ class EnglishTraditionalDateFormatter extends DateFormatter { speed: 'superslow', scroll_off: ['down'], scroll_in: ['up'], - size: 'vsmall', + size: 'vvsmall', angle_to_horizontal: 90 }, small: { @@ -69,6 +69,7 @@ class EnglishTraditionalDateFormatter extends DateFormatter { color: 'major', scroll_off: ['left'], scroll_in: ['left'], + size: 'mlarge', angle_to_horizontal: 0 } }; diff --git a/apps/slidingtext/slidingtext.settings.js b/apps/slidingtext/slidingtext.settings.js index d405afbc6..d8562ccb0 100644 --- a/apps/slidingtext/slidingtext.settings.js +++ b/apps/slidingtext/slidingtext.settings.js @@ -13,7 +13,7 @@ date_formatter: 'en', row_types: { large:{ - size: 'medium', + size: 'mlarge', angle_to_horizontal: 90, scroll_off: ['down'], scroll_in: ['up'], @@ -25,7 +25,7 @@ row_defs: [ { type: 'large', - init_coords: [0.05,0.95], + init_coords: [0.05,0.99], row_direction: [1.0,0.0], rows: 1 }, @@ -90,6 +90,7 @@ 'de': { date_formatter: 'de'}, 'es': { date_formatter: 'es'}, 'jp': { date_formatter: 'jp'}, + 'dgt': { date_formatter: 'dgt'}, } var locales = Object.keys(locale_mappings);