sliding clock: changed styling from member variables to instance variables

pull/2178/head
adrian w kirk 2022-10-08 21:46:00 +01:00
parent b9a7e76beb
commit 804f308af1
7 changed files with 164 additions and 155 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;