sliding text clock: Updated the colour schemes to make blue and black more interesting

master
adrian w kirk 2022-09-30 14:07:43 +01:00
parent 643b0b92dc
commit bc407c57e7
3 changed files with 21 additions and 55 deletions

View File

@ -14,7 +14,7 @@ const color_schemes = [
{ {
name: "black", name: "black",
background : [0.0,0.0,0.0], background : [0.0,0.0,0.0],
main_bar: [1.0,1.0,1.0], main_bar: [1.0,0.0,0.0],
other_bars: [0.9,0.9,0.9], other_bars: [0.9,0.9,0.9],
}, },
{ {
@ -37,8 +37,8 @@ const color_schemes = [
}, },
{ {
name: "blue", name: "blue",
background : [0.4,0.7,1.0], background : [0.1,0.2,1.0],
main_bar: [1.0,1.0,1.0], main_bar: [1.0,1.0,0.0],
other_bars: [0.9,0.9,0.9] other_bars: [0.9,0.9,0.9]
} }
]; ];
@ -66,17 +66,12 @@ let command_stack_high_priority = [];
let command_stack_low_priority = []; let command_stack_low_priority = [];
function next_command(){ function next_command(){
command = command_stack_high_priority.pop(); var command = command_stack_high_priority.pop();
if(command == null){ if(command == null){
//console.log("Low priority command");
command = command_stack_low_priority.pop(); command = command_stack_low_priority.pop();
} else {
//console.log("High priority command");
} }
if(command != null){ if(command != null){
command.call(); command.call();
} else {
//console.log("no command");
} }
} }
@ -129,7 +124,6 @@ class ShiftText {
setColor(color){ this.color = color; } setColor(color){ this.color = color; }
setBgColor(bg_color){ this.bg_color = bg_color; } setBgColor(bg_color){ this.bg_color = bg_color; }
reset(hard_reset) { reset(hard_reset) {
//console.log("reset");
this.hide(); this.hide();
this.x = this.init_x; this.x = this.init_x;
this.y = this.init_y; this.y = this.init_y;
@ -162,14 +156,12 @@ class ShiftText {
this.x = x; this.x = x;
this.y = y; this.y = y;
this.txt = txt; this.txt = txt;
//console.log("setTextPosition: (" + x + "," + y + ") " + txt);
this.show(); this.show();
} }
setTextXPosition(txt,x){ setTextXPosition(txt,x){
this.hide(); this.hide();
this.x = x; this.x = x;
this.txt = txt; this.txt = txt;
//console.log("setTextXPosition: (" + x + ") " + txt);
this.show(); this.show();
} }
setTextYPosition(txt,y){ setTextYPosition(txt,y){
@ -181,7 +173,6 @@ class ShiftText {
moveTo(new_x,new_y){ moveTo(new_x,new_y){
this.tgt_x = new_x; this.tgt_x = new_x;
this.tgt_y = new_y; this.tgt_y = new_y;
//console.log("moveTo: (" + this.tgt_x + "," + this.tgt_y + ") ");
this._doMove(); this._doMove();
} }
moveToX(new_x){ moveToX(new_x){
@ -197,14 +188,12 @@ class ShiftText {
to_y = this.init_y; to_y = this.init_y;
this.setTextPosition(txt, this.init_x, g.getHeight() + 2*this.font_size); this.setTextPosition(txt, this.init_x, g.getHeight() + 2*this.font_size);
//console.log("scrollInFromBottom y:" + this.y + "->" + to_y + " -> " + txt)
this.moveTo(this.init_x,to_y); this.moveTo(this.init_x,to_y);
} }
scrollInFromLeft(txt,to_x){ scrollInFromLeft(txt,to_x){
if(to_x == null) if(to_x == null)
to_x = this.init_x; to_x = this.init_x;
//console.log("scrollInFromLeft x:" + this.x + "->" + to_x + " -> " + txt)
this.setTextPosition(txt, -txt.length * this.font_size - this.font_size, this.init_y); this.setTextPosition(txt, -txt.length * this.font_size - this.font_size, this.init_y);
this.moveTo(to_x,this.init_y); this.moveTo(to_x,this.init_y);
} }
@ -212,20 +201,16 @@ class ShiftText {
if(to_x == null) if(to_x == null)
to_x = this.init_x; to_x = this.init_x;
//console.log("scrollInFromRight x:" + this.x + "->" + to_x + " -> " + txt)
this.setTextPosition(txt, g.getWidth() + this.font_size, this.init_y); this.setTextPosition(txt, g.getWidth() + this.font_size, this.init_y);
this.moveTo(to_x,this.init_y); this.moveTo(to_x,this.init_y);
} }
scrollOffToLeft(){ scrollOffToLeft(){
//console.log("scrollOffToLeft");
this.moveTo(-this.txt.length * this.font_size, this.init_y); this.moveTo(-this.txt.length * this.font_size, this.init_y);
} }
scrollOffToRight(){ scrollOffToRight(){
//console.log("scrollOffToRight");
this.moveTo(g.getWidth() + this.font_size, this.init_y); this.moveTo(g.getWidth() + this.font_size, this.init_y);
} }
scrollOffToBottom(){ scrollOffToBottom(){
//console.log("scrollOffToBottom");
this.moveTo(this.init_x,g.getHeight() + this.font_size); this.moveTo(this.init_x,g.getHeight() + this.font_size);
} }
onFinished(finished_callback){ onFinished(finished_callback){
@ -270,7 +255,6 @@ class ShiftText {
if(!finished){ if(!finished){
this.timeoutId = setTimeout(this._doMove.bind(this), this.freq_millis); this.timeoutId = setTimeout(this._doMove.bind(this), this.freq_millis);
} else if(this.finished_callback != null){ } else if(this.finished_callback != null){
//console.log("finished - calling:" + this.finished_callback);
this.finished_callback.call(); this.finished_callback.call();
this.finished_callback = null; this.finished_callback = null;
} }
@ -321,18 +305,15 @@ function initDisplay(settings) {
mergeMaps(row_types,settings.row_types); mergeMaps(row_types,settings.row_types);
var row_defs = (settings.row_defs != null && settings.row_defs.length > 0)? var row_defs = (settings.row_defs != null && settings.row_defs.length > 0)?
settings.row_defs : date_formatter.defaultRowDefs(); settings.row_defs : date_formatter.defaultRowDefs();
console.log("row_defs " + JSON.stringify(row_defs));
row_displays = []; row_displays = [];
for(var i=0; i< row_defs.length; i++){ row_defs.forEach(row_def =>{
var row_def = row_defs[i]; var row_type = create_row_type(row_types[row_def.type],row_def);
var row_type_val = row_types[row_def.type]; // we now create the number of rows specified of that type
var row_type = create_row_type(row_type_val,row_def);
// we now create the number of row specified of that type
for(var j=0; j<row_def.rows; j++){ for(var j=0; j<row_def.rows; j++){
row_displays.push(create_row(row_type,j)); row_displays.push(create_row(row_type,j));
} }
} });
} }
function mergeMaps(map1,map2){ function mergeMaps(map1,map2){
@ -359,7 +340,7 @@ function mergeObjects(obj1, obj2){
const heights = { const heights = {
vvsmall: [20,15], vvsmall: [20,15],
vsmall: [23,18], vsmall: [22,17],
small: [25,20], small: [25,20],
msmall: [30,22], msmall: [30,22],
medium: [40,25], medium: [40,25],
@ -468,7 +449,6 @@ function nextColorTheme(){
if(color_scheme_index >= color_schemes.length){ if(color_scheme_index >= color_schemes.length){
color_scheme_index = 0; color_scheme_index = 0;
} }
//console.log("changing color scheme to " + color_schemes[color_scheme_index].name)
updateColorScheme(); updateColorScheme();
resetClock(true); resetClock(true);
drawClock(); drawClock();
@ -551,55 +531,43 @@ function drawClock(){
for (var i = 0; i < rows.length; i++) { for (var i = 0; i < rows.length; i++) {
display = row_displays[i]; display = row_displays[i];
var txt = rows[i]; var txt = rows[i];
//console.log(i + "->" + txt);
display_row(display,txt); display_row(display,txt);
} }
// If the dateformatter has not returned enough // If the dateformatter has not returned enough
// rows then treat the remaining rows as empty // rows then treat the remaining rows as empty
for (var j = i; j < row_displays.length; j++) { for (var j = i; j < row_displays.length; j++) {
display = row_displays[j]; display = row_displays[j];
//console.log(i + "->''(empty)");
display_row(display,''); display_row(display,'');
} }
next_command(); next_command();
//console.log(date);
} }
function display_row(display,txt){ function display_row(display,txt){
if(display == null) { if(display == null) {
console.log("no display for text:" + txt);
return; return;
} }
if(display.txt == null || display.txt === ''){ if(display.txt == null || display.txt === ''){
if(txt !== '') { if(txt !== '') {
command_stack_high_priority.unshift( command_stack_high_priority.unshift(()=>{
function () {
//console.log("move in new:" + txt);
display.onFinished(next_command); display.onFinished(next_command);
display.getRowContext().scroll_in(display,txt); display.getRowContext().scroll_in(display,txt);
} }
); );
} }
} else if(txt !== display.txt && display.txt != null){ } else if(txt !== display.txt && display.txt != null){
command_stack_high_priority.push( command_stack_high_priority.push(()=>{
function(){
//console.log("move out:" + txt);
display.onFinished(next_command); display.onFinished(next_command);
display.getRowContext().scroll_off(display); display.getRowContext().scroll_off(display);
} }
); );
command_stack_low_priority.push( command_stack_low_priority.push(() => {
function(){
//console.log("move in:" + txt);
display.onFinished(next_command); display.onFinished(next_command);
display.getRowContext().scroll_in(display,txt); display.getRowContext().scroll_in(display,txt);
} }
); );
} else { } else {
command_stack_high_priority.push( command_stack_high_priority.push(() => {
function(){
//console.log("move in2:" + txt);
display.setTextPosition(txt,display.init_x, display.init_y); display.setTextPosition(txt,display.init_x, display.init_y);
next_command(); next_command();
} }
@ -735,9 +703,7 @@ function loadSettings() {
enable_live_controls = true; enable_live_controls = true;
} }
function button3pressed() { function button3pressed() {
console.log("button3pressed enable_live_controls=" + enable_live_controls);
if (enable_live_controls) { if (enable_live_controls) {
nextColorTheme(); nextColorTheme();
resetClock(true); resetClock(true);
@ -759,7 +725,6 @@ function startTimers(){
var date = new Date(); var date = new Date();
var secs = date.getSeconds(); var secs = date.getSeconds();
var nextMinuteStart = 60 - secs; var nextMinuteStart = 60 - secs;
//console.log("scheduling clock draw in " + nextMinuteStart + " seconds");
setTimeout(scheduleDrawClock,nextMinuteStart * 1000); setTimeout(scheduleDrawClock,nextMinuteStart * 1000);
drawClock(); drawClock();
} }

View File

@ -109,13 +109,13 @@ class EnglishTraditionalDateFormatter extends DateFormatter {
var hours = hoursToText(hourOfDay); var hours = hoursToText(hourOfDay);
// Deal with the special times first // Deal with the special times first
if(mins === 0){ if(mins === 0){
return [hours,"", "O'","CLOCK", date_txt]; return [hours,"", "O'","CLOCK","", date_txt];
} else if(mins === 30){ } else if(mins === 30){
return ["","HALF", "PAST", "", hours]; return ["","HALF", "PAST", "", hours, date_txt];
} else if(mins === 15){ } else if(mins === 15){
return ["","QUARTER", "PAST", "", hours]; return ["","QUARTER", "PAST", "", hours, date_txt];
} else if(mins === 45) { } else if(mins === 45) {
return ["", "QUARTER", "TO", "", hours]; return ["", "QUARTER", "TO", "", hours, date_txt];
} }
var mins_txt; var mins_txt;
var from_to; var from_to;
@ -130,12 +130,12 @@ class EnglishTraditionalDateFormatter extends DateFormatter {
mins_txt = numberToText(mins_value); mins_txt = numberToText(mins_value);
} }
if(mins_txt[1] != '') { if(mins_txt[1] !== '') {
return ['', mins_txt[0], mins_txt[1], from_to, hours, date_txt]; return ['', mins_txt[0], mins_txt[1], from_to, hours, date_txt];
} else { } else {
if(mins_value % 5 == 0) { if(mins_value % 5 === 0) {
return ['', mins_txt[0], from_to, '', hours, date_txt]; return ['', mins_txt[0], from_to, '', hours, date_txt];
} else if(mins_value == 1){ } else if(mins_value === 1){
return ['', mins_txt[0], 'MINUTE', from_to, hours, date_txt]; return ['', mins_txt[0], 'MINUTE', from_to, hours, date_txt];
} else { } else {
return ['', mins_txt[0], 'MINUTES', from_to, hours, date_txt]; return ['', mins_txt[0], 'MINUTES', from_to, hours, date_txt];

View File

@ -13,6 +13,7 @@
date_formatter: 'en', date_formatter: 'en',
row_types: { row_types: {
large:{ large:{
size: 'medium',
angle_to_horizontal: 90, angle_to_horizontal: 90,
scroll_off: ['down'], scroll_off: ['down'],
scroll_in: ['up'], scroll_in: ['up'],