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

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

View File

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

View File

@ -39,7 +39,7 @@ class DigitDateTimeFormatter {
} }
format00(num){ format00(num){
var value = (num | 0); const value = (num | 0);
if(value > 99 || value < 0) if(value > 99 || value < 0)
throw "must be between in range 0-99"; throw "must be between in range 0-99";
if(value < 10) if(value < 10)
@ -49,9 +49,9 @@ class DigitDateTimeFormatter {
} }
formatDate(now){ formatDate(now){
var hours = now.getHours() ; const hours = now.getHours() ;
var time_txt = this.format00(hours) + ":" + this.format00(now.getMinutes()); const time_txt = this.format00(hours) + ":" + this.format00(now.getMinutes());
var date_txt = Locale.dow(now,1) + " " + this.format00(now.getDate()); 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]; 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 hoursToText = require("slidingtext.utils.en.js").hoursToText;
const numberToText = require("slidingtext.utils.en.js").numberToText; const numberToText = require("slidingtext.utils.en.js").numberToText;
const dayOfWeek = require("slidingtext.utils.en.js").dayOfWeek; const dayOfWeek = require("slidingtext.utils.en.js").dayOfWeek;

View File

@ -64,12 +64,12 @@ class SpanishDateFormatter extends DateFormatter {
]; ];
} }
formatDate(date){ formatDate(date){
var mins = date.getMinutes(); const mins = date.getMinutes();
var hourOfDay = date.getHours(); var hourOfDay = date.getHours();
if(mins > 30){ if(mins > 30){
hourOfDay += 1; hourOfDay += 1;
} }
var hours = spanishHoursToText(hourOfDay); const hours = spanishHoursToText(hourOfDay);
//console.log('hourOfDay->' + hourOfDay + ' hours text->' + hours) //console.log('hourOfDay->' + hourOfDay + ' hours text->' + hours)
// Deal with the special times first // Deal with the special times first
if(mins === 0){ if(mins === 0){
@ -81,10 +81,10 @@ class SpanishDateFormatter extends DateFormatter {
} else if(mins === 45) { } else if(mins === 45) {
return [hours, "MENOS", "CUARTO",""]; return [hours, "MENOS", "CUARTO",""];
} else if(mins > 30){ } 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]]; return [hours, "MENOS", mins_txt[0],mins_txt[1]];
} else { } else {
var mins_txt = spanishMinsToText(mins); const mins_txt = spanishMinsToText(mins);
return [hours, "Y", mins_txt[0],mins_txt[1]]; 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){ function frenchHoursToText(hours){
hours = hours % 12; hours = hours % 12;
if(hours == 0){ if(hours === 0){
hours = 12; hours = 12;
} }
return frenchNumberStr[hours]; return frenchNumberStr[hours];
} }
function frenchHeures(hours){ function frenchHeures(hours){
if(hours % 12 == 1){ if(hours % 12 === 1){
return 'HEURE'; return 'HEURE';
} else { } else {
return 'HEURES'; return 'HEURES';
@ -31,7 +31,11 @@ function frenchHeures(hours){
class FrenchDateFormatter extends DateFormatter { class FrenchDateFormatter extends DateFormatter {
constructor() { constructor() {
super(); super();
this.row_types = { }; this.row_types = {
small: {
speed: 'vslow'
}
};
this.row_defs = [ this.row_defs = [
{ {
type: 'large', type: 'large',
@ -50,27 +54,27 @@ class FrenchDateFormatter extends DateFormatter {
formatDate(date){ formatDate(date){
var hours = frenchHoursToText(date.getHours()); var hours = frenchHoursToText(date.getHours());
var heures = frenchHeures(date.getHours()); var heures = frenchHeures(date.getHours());
var mins = date.getMinutes(); const mins = date.getMinutes();
if(mins == 0){ if(mins === 0){
if(hours == 0){ if(hours === 0){
return ["MINUIT", "",""]; return ["MINUIT", "",""];
} else if(hours == 12){ } else if(hours === 12){
return ["MIDI", "",""]; return ["MIDI", "",""];
} else { } else {
return [hours, heures,""]; return [hours, heures,""];
} }
} else if(mins == 30){ } else if(mins === 30){
return [hours, heures,'ET DEMIE']; return [hours, heures,'ET DEMIE'];
} else if(mins == 15){ } else if(mins === 15){
return [hours, heures,'ET QUART']; return [hours, heures,'ET QUART'];
} else if(mins == 45){ } else if(mins === 45){
var next_hour = date.getHours() + 1; var next_hour = date.getHours() + 1;
hours = frenchHoursToText(next_hour); hours = frenchHoursToText(next_hour);
heures = frenchHeures(next_hour); heures = frenchHeures(next_hour);
return [hours, heures,"MOINS",'LET QUART']; return [hours, heures,"MOINS",'LET QUART'];
} }
if(mins > 30){ if(mins > 30){
var to_mins = 60-mins; const to_mins = 60-mins;
var mins_txt = frenchNumberStr[to_mins]; var mins_txt = frenchNumberStr[to_mins];
next_hour = date.getHours() + 1; next_hour = date.getHours() + 1;
hours = frenchHoursToText(next_hour); 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 * Japanese date formatting
@ -40,9 +40,9 @@ function japaneseMinsToText(mins){
} else if(mins === 30) } else if(mins === 30)
return ["HAN",""]; return ["HAN",""];
else { else {
var units = mins % 10; const units = mins % 10;
var mins_txt = japaneseMinuteStr[units]; const mins_txt = japaneseMinuteStr[units];
var tens = mins /10 | 0; const tens = mins /10 | 0;
if(tens > 0){ if(tens > 0){
var tens_txt = tensPrefixStr[tens]; var tens_txt = tensPrefixStr[tens];
var minutes_txt; var minutes_txt;
@ -78,8 +78,8 @@ class JapaneseDateFormatter extends DateFormatter {
]; ];
} }
formatDate(date){ formatDate(date){
var hours_txt = japaneseHoursToText(date.getHours()); const hours_txt = japaneseHoursToText(date.getHours());
var mins_txt = japaneseMinsToText(date.getMinutes()); const mins_txt = japaneseMinsToText(date.getMinutes());
return [hours_txt,"JI", mins_txt[0], mins_txt[1] ]; return [hours_txt,"JI", mins_txt[0], mins_txt[1] ];
} }
defaultRowTypes(){ return this.row_types;} defaultRowTypes(){ return this.row_types;}

View File

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