Sliding Clock: french minute text has to move faster across the screen

pull/2178/head
Adrian Kirk 2022-10-06 21:20:42 +01:00
parent 37c720f30c
commit 2cc7afe426
No known key found for this signature in database
GPG Key ID: 5A448EB0FC623526
8 changed files with 67 additions and 65 deletions

View File

@ -300,15 +300,15 @@ function initDisplay(settings) {
if(settings == null){
settings = {};
}
var row_type_overide = date_formatter.defaultRowTypes();
const row_type_overide = date_formatter.defaultRowTypes();
mergeMaps(row_types,row_type_overide);
mergeMaps(row_types,settings.row_types);
var row_defs = (settings.row_defs != null && settings.row_defs.length > 0)?
const row_defs = (settings.row_defs != null && settings.row_defs.length > 0)?
settings.row_defs : date_formatter.defaultRowDefs();
row_displays = [];
row_defs.forEach(row_def =>{
var row_type = create_row_type(row_types[row_def.type],row_def);
const row_type = create_row_type(row_types[row_def.type],row_def);
// we now create the number of rows specified of that type
for(var j=0; j<row_def.rows; j++){
row_displays.push(create_row(row_type,j));
@ -372,10 +372,10 @@ const SPACES = ' ';
* takes a json definition for a row type and creates an instance
*/
function create_row_type(row_type, row_def){
var speed = speeds[row_type.speed];
var rotation = rotations[row_type.angle_to_horizontal];
var height = heights[row_type.size];
var scroll_ins = [];
const speed = speeds[row_type.speed];
const rotation = rotations[row_type.angle_to_horizontal];
const height = heights[row_type.size];
const scroll_ins = [];
if(row_type.scroll_in.includes('left')){
scroll_ins.push((row_display,txt)=> row_display.scrollInFromLeft(txt));
}
@ -392,12 +392,12 @@ function create_row_type(row_type, row_def){
scroll_in = scroll_ins[0];
} else {
scroll_in = (row_display,txt) =>{
var idx = (Math.random() * scroll_ins.length) | 0;
const idx = (Math.random() * scroll_ins.length) | 0;
return scroll_ins[idx](row_display,txt);
};
}
var scroll_offs = [];
const scroll_offs = [];
if(row_type.scroll_off.includes('left')){
scroll_offs.push((row_display)=> row_display.scrollOffToLeft());
}
@ -421,7 +421,7 @@ function create_row_type(row_type, row_def){
var text_formatter = (txt)=>txt;
if(row_def.hasOwnProperty("alignment")){
var alignment = row_def.alignment;
const alignment = row_def.alignment;
if(alignment.startsWith("centre")){
const padding = parseInt(alignment.split("-")[1]);
if(padding > 0){
@ -433,7 +433,7 @@ function create_row_type(row_type, row_def){
}
}
var version = bangleVersion() - 1;
const version = bangleVersion() - 1;
return {
row_speed: speed,
row_height: height[version],
@ -475,7 +475,7 @@ function nextColorTheme(){
}
function updateColorScheme(){
var bgcolor = bg_color();
const bgcolor = bg_color();
for(var i=0; i<row_displays.length; i++){
row_displays[i].setColor(row_displays[i].getRowContext().fg_color());
row_displays[i].setBgColor(bgcolor);
@ -495,11 +495,11 @@ function resetClock(hard_reset){
// In this way the watch wakes by scrolling
// off the last time and scroll on the new time
var reset_time = last_draw_time;
var last_minute_millis = Date.now() - 60000;
const last_minute_millis = Date.now() - 60000;
if(reset_time.getTime() < last_minute_millis){
reset_time = display_time(new Date(last_minute_millis));
}
var rows = date_formatter.formatDate(reset_time);
const rows = date_formatter.formatDate(reset_time);
for (var i = 0; i < rows.length; i++) {
row_displays[i].hide();
row_displays[i].x = row_displays[i].init_x;
@ -651,7 +651,7 @@ class DigitDateTimeFormatter {
}
format00(num){
var value = (num | 0);
const value = (num | 0);
if(value > 99 || value < 0)
throw "must be between in range 0-99";
if(value < 10)
@ -661,10 +661,10 @@ class DigitDateTimeFormatter {
}
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());
var month_txt = Locale.month(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());
const month_txt = Locale.month(now);
return [time_txt, date_txt, month_txt];
}
@ -681,7 +681,7 @@ function setDateformat(shortname){
if(shortname === "default"){
date_formatter = new DigitDateTimeFormatter();
} else {
var date_formatter_class = require("slidingtext.locale." + shortname + ".js");
const date_formatter_class = require("slidingtext.locale." + shortname + ".js");
date_formatter = new date_formatter_class();
}
}
@ -700,7 +700,7 @@ const PREFERENCE_FILE = "slidingtext.settings.json";
*/
function loadSettings() {
try {
var settings = Object.assign({},
const settings = Object.assign({},
require('Storage').readJSON(PREFERENCE_FILE, true) || {});
if (settings.date_formatter == null) {
// for backward compatibility
@ -730,7 +730,6 @@ function loadSettings() {
initDisplay();
updateColorScheme();
}
enable_live_controls = true;
}
function button3pressed() {
@ -752,9 +751,9 @@ function clearTimers(){
}
function startTimers(){
var date = new Date();
var secs = date.getSeconds();
var nextMinuteStart = 60 - secs;
const date = new Date();
const secs = date.getSeconds();
const nextMinuteStart = 60 - secs;
setTimeout(scheduleDrawClock,nextMinuteStart * 1000);
drawClock();
}

View File

@ -1,4 +1,4 @@
var DateFormatter = require("slidingtext.dtfmt.js");
const DateFormatter = require("slidingtext.dtfmt.js");
const germanNumberStr = [ ["NULL",""], // 0
["EINS",""], // 1
@ -59,10 +59,10 @@ function germanMinsToText(mins) {
if (mins < 20) {
return germanNumberStr[mins];
} else {
var tens = (mins / 10 | 0);
var word1 = germanTensStr[tens];
var remainder = mins - tens * 10;
var word2 = germanUnit[remainder];
const tens = (mins / 10 | 0);
const word1 = germanTensStr[tens];
const remainder = mins - tens * 10;
const word2 = germanUnit[remainder];
return [word2, word1];
}
}
@ -87,13 +87,12 @@ class GermanDateFormatter extends DateFormatter {
];
}
formatDate(date){
var mins = date.getMinutes();
var hourOfDay = date.getHours();
const mins = date.getMinutes();
const hourOfDay = date.getHours();
var hours = germanHoursToText(hourOfDay);
//console.log('hourOfDay->' + hourOfDay + ' hours text->' + hours)
// Deal with the special times first
if(mins === 0){
var hours = germanHoursToText(hourOfDay);
return [hours,"UHR", "","",""];
} /*else if(mins == 30){
var hours = germanHoursToText(hourOfDay+1);
@ -105,7 +104,7 @@ class GermanDateFormatter extends DateFormatter {
var hours = germanHoursToText(hourOfDay+1);
return ["", "", "VIERTEL", "VOR",hours];
} */ else {
var mins_txt = germanMinsToText(mins);
const mins_txt = germanMinsToText(mins);
return [hours, "UHR", mins_txt[0],mins_txt[1]];
}
}

View File

@ -39,7 +39,7 @@ class DigitDateTimeFormatter {
}
format00(num){
var value = (num | 0);
const value = (num | 0);
if(value > 99 || value < 0)
throw "must be between in range 0-99";
if(value < 10)
@ -49,9 +49,9 @@ class DigitDateTimeFormatter {
}
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());
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];
}

View File

@ -1,4 +1,4 @@
var DateFormatter = require("slidingtext.dtfmt.js");
const DateFormatter = require("slidingtext.dtfmt.js");
const hoursToText = require("slidingtext.utils.en.js").hoursToText;
const numberToText = require("slidingtext.utils.en.js").numberToText;
const dayOfWeek = require("slidingtext.utils.en.js").dayOfWeek;

View File

@ -64,12 +64,12 @@ class SpanishDateFormatter extends DateFormatter {
];
}
formatDate(date){
var mins = date.getMinutes();
const mins = date.getMinutes();
var hourOfDay = date.getHours();
if(mins > 30){
hourOfDay += 1;
}
var hours = spanishHoursToText(hourOfDay);
const hours = spanishHoursToText(hourOfDay);
//console.log('hourOfDay->' + hourOfDay + ' hours text->' + hours)
// Deal with the special times first
if(mins === 0){
@ -81,10 +81,10 @@ class SpanishDateFormatter extends DateFormatter {
} else if(mins === 45) {
return [hours, "MENOS", "CUARTO",""];
} else if(mins > 30){
var mins_txt = spanishMinsToText(60-mins);
const mins_txt = spanishMinsToText(60-mins);
return [hours, "MENOS", mins_txt[0],mins_txt[1]];
} else {
var mins_txt = spanishMinsToText(mins);
const mins_txt = spanishMinsToText(mins);
return [hours, "Y", mins_txt[0],mins_txt[1]];
}
}

View File

@ -14,14 +14,14 @@ const frenchNumberStr = [ "ZERO", "UNE", "DEUX", "TROIS", "QUATRE",
function frenchHoursToText(hours){
hours = hours % 12;
if(hours == 0){
if(hours === 0){
hours = 12;
}
return frenchNumberStr[hours];
}
function frenchHeures(hours){
if(hours % 12 == 1){
if(hours % 12 === 1){
return 'HEURE';
} else {
return 'HEURES';
@ -31,7 +31,11 @@ function frenchHeures(hours){
class FrenchDateFormatter extends DateFormatter {
constructor() {
super();
this.row_types = { };
this.row_types = {
small: {
speed: 'vslow'
}
};
this.row_defs = [
{
type: 'large',
@ -50,27 +54,27 @@ class FrenchDateFormatter extends DateFormatter {
formatDate(date){
var hours = frenchHoursToText(date.getHours());
var heures = frenchHeures(date.getHours());
var mins = date.getMinutes();
if(mins == 0){
if(hours == 0){
const mins = date.getMinutes();
if(mins === 0){
if(hours === 0){
return ["MINUIT", "",""];
} else if(hours == 12){
} else if(hours === 12){
return ["MIDI", "",""];
} else {
return [hours, heures,""];
}
} else if(mins == 30){
} else if(mins === 30){
return [hours, heures,'ET DEMIE'];
} else if(mins == 15){
} else if(mins === 15){
return [hours, heures,'ET QUART'];
} else if(mins == 45){
} else if(mins === 45){
var next_hour = date.getHours() + 1;
hours = frenchHoursToText(next_hour);
heures = frenchHeures(next_hour);
return [hours, heures,"MOINS",'LET QUART'];
}
if(mins > 30){
var to_mins = 60-mins;
const to_mins = 60-mins;
var mins_txt = frenchNumberStr[to_mins];
next_hour = date.getHours() + 1;
hours = frenchHoursToText(next_hour);

View File

@ -1,4 +1,4 @@
var DateFormatter = require("slidingtext.dtfmt.js");
const DateFormatter = require("slidingtext.dtfmt.js");
/**
* Japanese date formatting
@ -40,9 +40,9 @@ function japaneseMinsToText(mins){
} else if(mins === 30)
return ["HAN",""];
else {
var units = mins % 10;
var mins_txt = japaneseMinuteStr[units];
var tens = mins /10 | 0;
const units = mins % 10;
const mins_txt = japaneseMinuteStr[units];
const tens = mins /10 | 0;
if(tens > 0){
var tens_txt = tensPrefixStr[tens];
var minutes_txt;
@ -78,8 +78,8 @@ class JapaneseDateFormatter extends DateFormatter {
];
}
formatDate(date){
var hours_txt = japaneseHoursToText(date.getHours());
var mins_txt = japaneseMinsToText(date.getMinutes());
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;}

View File

@ -1,13 +1,13 @@
(function(back) {
const PREFERENCE_FILE = "slidingtext.settings.json";
var settings = Object.assign({},
const settings = Object.assign({},
require('Storage').readJSON(PREFERENCE_FILE, true) || {});
// the screen controls are defaulted on for a bangle 1 and off for a bangle 2
if(settings.enable_live_controls == null){
settings.enable_live_controls = (g.getHeight()> 200);
}
console.log("loaded:" + JSON.stringify(settings));
var locale_mappings = {
const locale_mappings = {
'en' : { date_formatter: 'en' },
'en p': {
date_formatter: 'en',
@ -111,13 +111,13 @@
'jp': { date_formatter: 'jp'},
'dgt': { date_formatter: 'dgt'},
}
var locales = Object.keys(locale_mappings);
const locales = Object.keys(locale_mappings);
function writeSettings() {
if(settings.date_format == null){
settings.date_format = 'en';
}
var styling = locale_mappings[settings.date_format];
const styling = locale_mappings[settings.date_format];
if(styling.date_formatter != null)
settings.date_formatter = styling.date_formatter;
@ -144,7 +144,7 @@
wrap: true,
step: 1,
onchange: v => {
var write_value = (value_mapping == null)? values[v] : value_mapping(values[v]);
const write_value = (value_mapping == null)? values[v] : value_mapping(values[v]);
writer(write_value);
writeSettings();
}