From 9d4da68727f3904ae9871148e2c6c5921890cc82 Mon Sep 17 00:00:00 2001 From: dieghernan Date: Tue, 25 Apr 2017 11:20:53 +0200 Subject: [PATCH] v6.3 ready Fix Danish Still to review to see right format --- package.json | 28 +- src/c/main.c | 474 ++++++++------------------ src/c/num2words-br.c | 304 +++++++---------- src/c/num2words-br.h | 7 +- src/c/num2words-de.c | 257 +++++--------- src/c/num2words-de.h | 6 +- src/c/num2words-dk.c | 297 +++++++---------- src/c/num2words-dk.h | 6 +- src/c/num2words-en.c | 275 ++++++--------- src/c/num2words-en.h | 6 +- src/c/num2words-es.c | 274 ++++++--------- src/c/num2words-es.h | 6 +- src/pkjs/app.js | 775 ++++++++++++++++++++----------------------- src/pkjs/config.js | 2 +- 14 files changed, 1062 insertions(+), 1655 deletions(-) diff --git a/package.json b/package.json index fb0dc85..df45d06 100644 --- a/package.json +++ b/package.json @@ -50,16 +50,17 @@ "type": "font" }, { - "characterRegex": "[a-z .' A-Z 0-9 \u00e1\u00e9\u00ed\u00f3\u00fa\u00f6\u00fc\u00fb\u00ea \u00e5\u00f8]", + "characterRegex": "[a-z ' UV\u00f6\u00fc\u00e9\u00fb\u00ea \\-\u00e5\u00f8]", "file": "fonts/Gotham Light.otf", - "name": "FONT_GLIGHT_16", + "name": "FONT_GLIGHT_30", "targetPlatforms": null, + "trackingAdjust": -2, "type": "font" }, { "characterRegex": "[a-z ' UV\u00f6\u00fc\u00e9\u00fb\u00ea \\-\u00e5\u00f8]", "file": "fonts/Gotham Light.otf", - "name": "FONT_GLIGHT_39", + "name": "FONT_GLIGHT_34", "targetPlatforms": null, "trackingAdjust": -2, "type": "font" @@ -67,29 +68,30 @@ { "characterRegex": "[a-z ' UV\u00f6\u00fc\u00e9\u00fb\u00ea \\-\u00e5\u00f8]", "file": "fonts/Gotham Light.otf", - "name": "FONT_GLIGHT_34", + "name": "FONT_GLIGHT_39", "targetPlatforms": null, "trackingAdjust": -2, "type": "font" }, { - "characterRegex": "[a-z ' UV\u00f6\u00fc\u00e9\u00fb\u00ea \\-\u00e5\u00f8]", + "characterRegex": "[a-z .' A-Z 0-9 \u00e1\u00e9\u00ed\u00f3\u00fa\u00f6\u00fc\u00fb\u00ea \u00e5\u00f8]", "file": "fonts/Gotham Light.otf", - "name": "FONT_GLIGHT_30", + "name": "FONT_GLIGHT_16", "targetPlatforms": null, - "trackingAdjust": -2, "type": "font" }, { + "characterRegex": "[a-z ' UV\u00f6\u00fc\u00e9\u00fb\u00ea \\-\u00e5\u00f8]", "file": "fonts/Gotham Bold.otf", - "name": "FONT_GBOLD_16", + "name": "FONT_GBOLD_22", "targetPlatforms": null, + "trackingAdjust": -1, "type": "font" }, { "characterRegex": "[a-z ' UV\u00f6\u00fc\u00e9\u00fb\u00ea \\-\u00e5\u00f8]", "file": "fonts/Gotham Bold.otf", - "name": "FONT_GBOLD_39", + "name": "FONT_GBOLD_30", "targetPlatforms": null, "trackingAdjust": -1, "type": "font" @@ -105,17 +107,15 @@ { "characterRegex": "[a-z ' UV\u00f6\u00fc\u00e9\u00fb\u00ea \\-\u00e5\u00f8]", "file": "fonts/Gotham Bold.otf", - "name": "FONT_GBOLD_30", + "name": "FONT_GBOLD_39", "targetPlatforms": null, "trackingAdjust": -1, "type": "font" }, { - "characterRegex": "[a-z ' UV\u00f6\u00fc\u00e9\u00fb\u00ea \\-\u00e5\u00f8]", "file": "fonts/Gotham Bold.otf", - "name": "FONT_GBOLD_22", + "name": "FONT_GBOLD_16", "targetPlatforms": null, - "trackingAdjust": -1, "type": "font" }, { @@ -139,5 +139,5 @@ "watchface": true } }, - "version": "6.2.0" + "version": "6.3.0" } diff --git a/src/c/main.c b/src/c/main.c index e49dc32..7a8ee85 100644 --- a/src/c/main.c +++ b/src/c/main.c @@ -1,7 +1,6 @@ #include #include "main.h" #define BUFFER_SIZE 20 - //Include languages #include "num2words-es.h" #include "num2words-en.h" @@ -11,12 +10,7 @@ #include "num2words-it.h" #include "num2words-nn.h" #include "num2words-dk.h" - - -/////////////////////////// // 1. Define structures//// -/////////////////////////// - // Struct Line typedef struct { TextLayer *currentLayer; @@ -24,17 +18,13 @@ typedef struct { PropertyAnimation *currentAnimation; PropertyAnimation *nextAnimation; } Line; - Line line1; Line line2; Line line3; - -// Layers +// Layers static Window *s_main_window; Layer *back_layer; Layer *scroll; - - // Chars static char line1Str[2][BUFFER_SIZE]; static char line2Str[2][BUFFER_SIZE]; @@ -42,7 +32,6 @@ static char line3Str[2][BUFFER_SIZE]; // Weather information char tempstring[44], condstringday[44],condstringnight[44]; char textbefore1[BUFFER_SIZE], textbefore2[BUFFER_SIZE],textbefore3[BUFFER_SIZE]; - //Fonts static GFont FontCond; static GFont Bold; @@ -55,7 +44,6 @@ static GFont LightReduced2; static GFont FontWDay; static GFont FontDate; static GFont FontSymbol; - //Others PropertyAnimation *scroll_down; PropertyAnimation *scroll_up; @@ -63,21 +51,18 @@ static bool PoppedDownNow; static bool PoppedDownAtInit; GRect bounds; static int offsetpebble, s_loop,s_countdown; - -/////////////////////////// //////Init Configuration/// -/////////////////////////// //Init Clay ClaySettings settings; // Initialize the default settings -static void prv_default_settings() { +static void prv_default_settings() { settings.BackgroundColor = GColorOxfordBlue; settings.ForegroundColor = GColorWhite; settings.BackgroundColorNight=GColorWhite; settings.ForegroundColorNight=GColorOxfordBlue; settings.NightTheme=false; settings.WeatherUnit = false; - settings.LangKey=1; + settings.LangKey=1; settings.DateFormat=1; settings.IsNightNow=false; settings.HourSunrise =600; @@ -87,14 +72,8 @@ static void prv_default_settings() { settings.DisplayTemp=false; settings.BTOn=true; } -/////////////////////////// //////End Configuration/// -/////////////////////////// - -/////////////////////////// //////Lang Selector /// -/////////////////////////// - void writetimeto3words(int hour_i,int minute_i,int *linebold_i,char *line1_i, char *line2_i, char *line3_i, int lang_i){ if (lang_i==1){ //Spanish time_to_3words_ES(hour_i , minute_i,linebold_i ,line1_i, line2_i, line3_i); @@ -107,23 +86,21 @@ void writetimeto3words(int hour_i,int minute_i,int *linebold_i,char *line1_i, ch } else if (lang_i==4){ //French time_to_3words_FR(hour_i , minute_i,linebold_i ,line1_i, line2_i, line3_i); - } + } else if (lang_i==5){ //PortugueseBR - time_to_3words_BR(hour_i , minute_i,linebold_i ,line1_i, line2_i, line3_i); + time_to_3words_BR(hour_i , minute_i,linebold_i ,line1_i, line2_i, line3_i); } else if (lang_i==6){ //Italian - time_to_3words_IT(hour_i , minute_i,linebold_i ,line1_i, line2_i, line3_i); + time_to_3words_IT(hour_i , minute_i,linebold_i ,line1_i, line2_i, line3_i); } else if (lang_i==7){ //Norwegian - time_to_3words_NN(hour_i , minute_i,linebold_i ,line1_i, line2_i, line3_i); + time_to_3words_NN(hour_i , minute_i,linebold_i ,line1_i, line2_i, line3_i); } else if (lang_i==8){ //Danish - time_to_3words_DK(hour_i , minute_i,linebold_i ,line1_i, line2_i, line3_i); + time_to_3words_DK(hour_i , minute_i,linebold_i ,line1_i, line2_i, line3_i); } } - void popatinitlang(int min, int * leninit, int Lang){ - if (Lang==1){ // Spanish PopatInit_ES(min, leninit);} else if (Lang==2){ //English @@ -134,10 +111,10 @@ void popatinitlang(int min, int * leninit, int Lang){ } else if (Lang==4){ //French PopatInit_FR(min, leninit); - } + } else if (Lang==5){ //Portuguese PopatInit_BR(min, leninit); - } + } else if (Lang==6){ //Italian PopatInit_IT(min, leninit); } @@ -148,51 +125,49 @@ void popatinitlang(int min, int * leninit, int Lang){ PopatInit_DK(min, leninit); } } - void writedatelang(int week,int Mon,int Day, char* iterwd,char * iterdat, char * itermon, int Lang){ if (Lang==1){ //Spanish WriteDate_ES(week , Mon ,Day, iterwd ,iterdat,itermon); } else if (Lang==2){ //English - WriteDate_EN(week , Mon ,Day, iterwd ,iterdat,itermon); + WriteDate_EN(week , Mon ,Day, iterwd ,iterdat,itermon); } else if (Lang==3){ //German - WriteDate_DE(week , Mon ,Day, iterwd ,iterdat,itermon); + WriteDate_DE(week , Mon ,Day, iterwd ,iterdat,itermon); } else if (Lang==4){ //French - WriteDate_FR(week , Mon ,Day, iterwd ,iterdat,itermon); + WriteDate_FR(week , Mon ,Day, iterwd ,iterdat,itermon); + } + else if (Lang==5){ //Portuguese - BR + WriteDate_BR(week , Mon ,Day, iterwd ,iterdat,itermon); } - else if (Lang==5){ //Portuguese - BR - WriteDate_BR(week , Mon ,Day, iterwd ,iterdat,itermon); - } else if (Lang==6){ //Italian - WriteDate_IT(week , Mon ,Day, iterwd ,iterdat,itermon); - } + WriteDate_IT(week , Mon ,Day, iterwd ,iterdat,itermon); + } else if (Lang==7){ //Norwegian - WriteDate_NN(week , Mon ,Day, iterwd ,iterdat,itermon); - } + WriteDate_NN(week , Mon ,Day, iterwd ,iterdat,itermon); + } else if (Lang==8){ //Danish - WriteDate_DK(week , Mon ,Day, iterwd ,iterdat,itermon); - } + WriteDate_DK(week , Mon ,Day, iterwd ,iterdat,itermon); + } } - void animationslan(int minute_2,int* LenB1, int* LenN1, int *LenA1, int Lang_2){ //Different based on Language if (Lang_2==1){ //Spanish Animations_ES(minute_2, LenB1, LenN1, LenA1); } else if (Lang_2==2){ //English - Animations_EN(minute_2, LenB1, LenN1, LenA1); + Animations_EN(minute_2, LenB1, LenN1, LenA1); } else if (Lang_2==3){ //German - Animations_DE(minute_2, LenB1, LenN1, LenA1); + Animations_DE(minute_2, LenB1, LenN1, LenA1); } else if (Lang_2==4){ //French - Animations_FR(minute_2, LenB1, LenN1, LenA1); + Animations_FR(minute_2, LenB1, LenN1, LenA1); } else if (Lang_2==5){ //PortugueseBR Animations_BR(minute_2, LenB1, LenN1, LenA1); - } + } else if (Lang_2==6){ //Italian Animations_IT(minute_2, LenB1, LenN1, LenA1); } @@ -203,24 +178,17 @@ void animationslan(int minute_2,int* LenB1, int* LenN1, int *LenA1, int Lang_2){ Animations_DK(minute_2, LenB1, LenN1, LenA1); } } - -/////////////////////////// //////End Lang Selector/// -/////////////////////////// - -/////////////////////////// //////Define Function /// -/////////////////////////// -static int limit(int nline){ +static int limit(int nline){ int isround=PBL_IF_ROUND_ELSE(1, 0); - if (isround==1){ + if (isround==1){ if (nline==1){return 130;} else if (nline==2){return 160;} else return 150; } else return 123; } - // Callback for js request void request_watchjs(){ //Starting loop at 0 @@ -231,36 +199,31 @@ void request_watchjs(){ // Add a key-value pair dict_write_uint8(iter, 0, 0); // Send the message! - app_message_outbox_send(); + app_message_outbox_send(); } - static GColor ColorSelect(bool isactive, bool gpsstate, bool isnight, GColor ColorDay, GColor ColorNight){ if (isactive && isnight && gpsstate){ - return ColorNight; + return ColorNight; } else { return ColorDay; - } + } } -/////////////////////////// //////End Function /// -/////////////////////////// - -//////////////////////////// ////Init: Animations procs// -//////////////////////////// void makeScrollUp(struct tm *t){ GRect from = layer_get_bounds((Layer *)scroll); - GRect to = layer_get_bounds((Layer *)scroll); + GRect to = layer_get_bounds((Layer *)scroll); GRect rect = layer_get_bounds((Layer *)scroll); if(rect.origin.y == 21){ from.origin.y = 0; to.origin.y = -21; - } else { + } + else { from.origin.y = 21; to.origin.y = 0; } - scroll_down = property_animation_create_layer_frame((Layer *)scroll, &from, &to); + scroll_down = property_animation_create_layer_frame((Layer *)scroll, &from, &to); animation_set_duration(property_animation_get_animation(scroll_down), 800); animation_set_delay(property_animation_get_animation(scroll_down), (59000-1000*t->tm_sec)); animation_set_curve(property_animation_get_animation(scroll_down), AnimationCurveEaseOut); @@ -275,7 +238,8 @@ void makeScrollUpNow(){ if(rect.origin.y == 21){ from.origin.y = 0; to.origin.y = -21; - } else { + } + else { from.origin.y = 21; to.origin.y = 0; } @@ -292,7 +256,8 @@ void makeScrollDown(){ if(PoppedDownAtInit == true){ from.origin.y = -21; to.origin.y = 0; - } else { + } + else { from.origin.y = 0; to.origin.y = 21; } @@ -310,31 +275,26 @@ void animationStoppedHandler(struct Animation *animation, bool finished, void *c layer_set_frame(current, rect); } // Animate text line -void makeAnimationsForLayers(Line *line, TextLayer *current, TextLayer *next) { - +void makeAnimationsForLayers(Line *line, TextLayer *current, TextLayer *next) { if (line->nextAnimation != NULL) - property_animation_destroy(line->nextAnimation); + property_animation_destroy(line->nextAnimation); if (line->currentAnimation != NULL) - property_animation_destroy(line->currentAnimation); - + property_animation_destroy(line->currentAnimation); GRect rect = layer_get_frame((Layer *)next); rect.origin.x -= bounds.size.w; line->nextAnimation = property_animation_create_layer_frame((Layer *)next, NULL, &rect); animation_set_duration(property_animation_get_animation(line->nextAnimation), 400); animation_set_curve(property_animation_get_animation(line->nextAnimation), AnimationCurveEaseOut); - animation_schedule(property_animation_get_animation(line->nextAnimation)); - + animation_schedule(property_animation_get_animation(line->nextAnimation)); GRect rect2 = layer_get_frame((Layer *)current); rect2.origin.x -= bounds.size.w; line->currentAnimation = property_animation_create_layer_frame((Layer *)current, NULL, &rect2); animation_set_duration(property_animation_get_animation(line->currentAnimation), 400); animation_set_curve(property_animation_get_animation(line->currentAnimation), AnimationCurveEaseOut); - animation_set_handlers(property_animation_get_animation(line->currentAnimation), (AnimationHandlers) { .stopped = (AnimationStoppedHandler)animationStoppedHandler - }, - current); - + }, + current); animation_schedule(property_animation_get_animation(line->currentAnimation)); } // Pop down to center before initial display when only 2 lines of text @@ -343,21 +303,15 @@ void makePopDown(){ rect.origin.y = 21; layer_set_bounds(scroll, rect); } -//////////////////////////// ////End: Animations procs// -//////////////////////////// - -//////////////////////////// ////Init: Layer updating//// -//////////////////////////// //Vertical alignment static void verticalAlignTextLayer(TextLayer *layer, int inity) { GRect frame = layer_get_frame(text_layer_get_layer(layer)); GSize content = text_layer_get_content_size(layer); - // Adjust position of the layer so visually all the text are aligned to the bottom + // Adjust position of the layer so visually all the text are aligned to the bottom // This is neccesary cuz Pebble works aligning to the top - doesnt like how it looks int offsetv; - //Handle nulls, no need to change if (content.h==0){ offsetv=0; @@ -366,126 +320,103 @@ static void verticalAlignTextLayer(TextLayer *layer, int inity) { offsetv=39-content.h; } layer_set_frame(text_layer_get_layer(layer), - GRect(frame.origin.x, inity + offsetv, frame.size.w, frame.size.h)); + GRect(frame.origin.x, inity + offsetv, frame.size.w, frame.size.h)); } - void sizeandbold(TextLayer *linelayer, int linr, int linb) { if (linr==linb){text_layer_set_font(linelayer,Bold);} else {text_layer_set_font(linelayer,Light);} - int evlimit=limit(linr); - const char * textonlayer; - textonlayer=text_layer_get_text(linelayer); + textonlayer=text_layer_get_text(linelayer); char textget[BUFFER_SIZE]; snprintf(textget, sizeof(textget), "%s",textonlayer); GSize sizetext=text_layer_get_content_size(linelayer); int width=sizetext.w; - - -if (linr==linb){ - if (width>evlimit){ - text_layer_set_font(linelayer,BoldReduced1); - GSize sizetext2=text_layer_get_content_size(linelayer); - int width2=sizetext2.w; - - if (width2>evlimit ){ - text_layer_set_font(linelayer,BoldReduced2); - GSize sizetext3=text_layer_get_content_size(linelayer); - int width3=sizetext3.w; - if (width3>evlimit){ - text_layer_set_font(linelayer, BoldReduced3); + if (linr==linb){ + if (width>evlimit){ + text_layer_set_font(linelayer,BoldReduced1); + GSize sizetext2=text_layer_get_content_size(linelayer); + int width2=sizetext2.w; + if (width2>evlimit ){ + text_layer_set_font(linelayer,BoldReduced2); + GSize sizetext3=text_layer_get_content_size(linelayer); + int width3=sizetext3.w; + if (width3>evlimit){ + text_layer_set_font(linelayer, BoldReduced3); + } } - } + } } -} else { + else { if (width>evlimit){ - text_layer_set_font(linelayer,LightReduced1); - GSize sizetext2=text_layer_get_content_size(linelayer); - int width2=sizetext2.w; + text_layer_set_font(linelayer,LightReduced1); + GSize sizetext2=text_layer_get_content_size(linelayer); + int width2=sizetext2.w; if (width2>evlimit ){ - text_layer_set_font(linelayer,LightReduced2); - } + text_layer_set_font(linelayer,LightReduced2); + } } } - int offsetline=0; if (linr==2){ offsetline=37; } else if (linr==3){ offsetline=74; - } - //Adjust vertical alignment - verticalAlignTextLayer(linelayer, offsetpebble+offsetline); - }; - + } + //Adjust vertical alignment + verticalAlignTextLayer(linelayer, offsetpebble+offsetline); +}; // Update text line void updateLineTo(Line *line, char lineStr[2][BUFFER_SIZE], char *value, int linref, int linbold) { TextLayer *next, *current; GRect rect = layer_get_frame((Layer *)line->currentLayer); current = (rect.origin.x == 0) ? line->currentLayer : line->nextLayer; - next = (current == line->currentLayer) ? line->nextLayer : line->currentLayer; - + next = (current == line->currentLayer) ? line->nextLayer : line->currentLayer; // Update correct text only if (current == line->currentLayer) { memset(lineStr[1], 0, BUFFER_SIZE); memcpy(lineStr[1], value, strlen(value)); text_layer_set_text(next, lineStr[1]); - } + } else { memset(lineStr[0], 0, BUFFER_SIZE); memcpy(lineStr[0], value, strlen(value)); text_layer_set_text(next, lineStr[0]); } - sizeandbold(next,linref,linbold); + sizeandbold(next,linref,linbold); makeAnimationsForLayers(line, current, next); } - bool checkupdate(char text1[BUFFER_SIZE],char text2[BUFFER_SIZE]){ - if (strcmp(text1,text2)==0){ - return false ; - } - else { - return true; - } + if (strcmp(text1,text2)==0){ + return false ; + } + else { + return true; + } } - -//////////////////////////// ////End: Layer updating//// -//////////////////////////// - -//////////////////////////// ////Init: Layer formatting// -//////////////////////////// // Configure line of text void configureLineLayer(TextLayer *textlayer) { - text_layer_set_text_color(textlayer, ColorSelect(settings.NightTheme, settings.GPSOn, settings.IsNightNow, settings.ForegroundColor, settings.ForegroundColorNight)); + text_layer_set_text_color(textlayer, ColorSelect(settings.NightTheme, settings.GPSOn, settings.IsNightNow, settings.ForegroundColor, settings.ForegroundColorNight)); text_layer_set_background_color(textlayer, GColorClear); text_layer_set_text_alignment(textlayer, GTextAlignmentCenter); } - -//////////////////////////// ////End: Layer formatting// -//////////////////////////// - -////////////////////////////////////// ///// Init: Updating time and date//// -///////////////////////////////////// // Update screen based on new time void display_time(struct tm *t, int atinit) { // The current time text will be stored in the following 3 strings char textLine1[BUFFER_SIZE]; char textLine2[BUFFER_SIZE]; char textLine3[BUFFER_SIZE]; - int LineToPutinBold=0; - + int LineToPutinBold=0; // Language settings - writetimeto3words(t->tm_hour, t->tm_min, &LineToPutinBold, textLine1, textLine2, textLine3,settings.LangKey); - + writetimeto3words(t->tm_hour, t->tm_min, &LineToPutinBold, textLine1, textLine2, textLine3,settings.LangKey); //Update lines if (checkupdate(textbefore1,textLine1)) { - updateLineTo(&line1, line1Str, textLine1,1,LineToPutinBold); + updateLineTo(&line1, line1Str, textLine1,1,LineToPutinBold); } if (checkupdate(textbefore2,textLine2)) { updateLineTo(&line2, line2Str, textLine2,2,LineToPutinBold); @@ -493,48 +424,39 @@ void display_time(struct tm *t, int atinit) { if (checkupdate(textbefore3,textLine3)) { updateLineTo(&line3, line3Str, textLine3,3,LineToPutinBold); } - // Save + // Save strcpy(textbefore1, textLine1); strcpy(textbefore2, textLine2); - strcpy(textbefore3, textLine3); - -} + strcpy(textbefore3, textLine3);} // Update graphics when timer ticks static void time_timer_tick(struct tm *t, TimeUnits units_changed) { if (units_changed & MINUTE_UNIT ) { - layer_mark_dirty(back_layer); + layer_mark_dirty(back_layer); } - - //BT: Evaluate reconnection bool CheckBT=connection_service_peek_pebble_app_connection(); if (!settings.BTOn && CheckBT ){ APP_LOG(APP_LOG_LEVEL_DEBUG, "BT reconnected"); settings.BTOn=true; // Update weather info - request_watchjs(); - } + request_watchjs(); + } //Update toggle settings.BTOn=CheckBT; - - - - APP_LOG(APP_LOG_LEVEL_DEBUG, "Tick at %d", t->tm_min); - s_loop=0; + APP_LOG(APP_LOG_LEVEL_DEBUG, "Tick at %d", t->tm_min); + s_loop=0; if (s_countdown==0){ //Reset s_countdown=settings.UpSlider; } else { - s_countdown=s_countdown-1; + s_countdown=s_countdown-1; } - APP_LOG(APP_LOG_LEVEL_DEBUG, "Countdown to update %d", s_countdown); - // Evaluate if is day or night int nowthehouris=t->tm_hour*100+t->tm_min; if (settings.HourSunrise<=nowthehouris && nowthehouris<=settings.HourSunset){ - settings.IsNightNow=false; + settings.IsNightNow=false; } else { settings.IsNightNow=true; @@ -542,32 +464,28 @@ static void time_timer_tick(struct tm *t, TimeUnits units_changed) { // Extra catch on sunrise and sunset if (nowthehouris==settings.HourSunrise || nowthehouris==settings.HourSunset){ s_countdown=1; - } + } if (settings.GPSOn && settings.NightTheme){ //Extra catch around 1159 to gather information of today if (nowthehouris==1159 && s_countdown>5) {s_countdown=1;}; // Change Color of background layer_mark_dirty(back_layer); window_set_background_color(s_main_window,ColorSelect(settings.NightTheme, settings.IsNightNow, settings.GPSOn,settings.BackgroundColor, settings.BackgroundColorNight)); - text_layer_set_text_color(line1.currentLayer, ColorSelect(settings.NightTheme, settings.GPSOn, settings.IsNightNow, settings.ForegroundColor, settings.ForegroundColorNight)); - text_layer_set_text_color(line1.nextLayer, ColorSelect(settings.NightTheme, settings.GPSOn, settings.IsNightNow, settings.ForegroundColor, settings.ForegroundColorNight)); - text_layer_set_text_color(line2.currentLayer,ColorSelect(settings.NightTheme, settings.GPSOn, settings.IsNightNow, settings.ForegroundColor, settings.ForegroundColorNight)); - text_layer_set_text_color(line2.nextLayer, ColorSelect(settings.NightTheme, settings.GPSOn, settings.IsNightNow, settings.ForegroundColor, settings.ForegroundColorNight)); - text_layer_set_text_color(line3.currentLayer, ColorSelect(settings.NightTheme, settings.GPSOn, settings.IsNightNow, settings.ForegroundColor, settings.ForegroundColorNight)); - text_layer_set_text_color(line3.nextLayer, ColorSelect(settings.NightTheme, settings.GPSOn, settings.IsNightNow, settings.ForegroundColor, settings.ForegroundColorNight)); + text_layer_set_text_color(line1.currentLayer, ColorSelect(settings.NightTheme, settings.GPSOn, settings.IsNightNow, settings.ForegroundColor, settings.ForegroundColorNight)); + text_layer_set_text_color(line1.nextLayer, ColorSelect(settings.NightTheme, settings.GPSOn, settings.IsNightNow, settings.ForegroundColor, settings.ForegroundColorNight)); + text_layer_set_text_color(line2.currentLayer,ColorSelect(settings.NightTheme, settings.GPSOn, settings.IsNightNow, settings.ForegroundColor, settings.ForegroundColorNight)); + text_layer_set_text_color(line2.nextLayer, ColorSelect(settings.NightTheme, settings.GPSOn, settings.IsNightNow, settings.ForegroundColor, settings.ForegroundColorNight)); + text_layer_set_text_color(line3.currentLayer, ColorSelect(settings.NightTheme, settings.GPSOn, settings.IsNightNow, settings.ForegroundColor, settings.ForegroundColorNight)); + text_layer_set_text_color(line3.nextLayer, ColorSelect(settings.NightTheme, settings.GPSOn, settings.IsNightNow, settings.ForegroundColor, settings.ForegroundColorNight)); } // Update text time display_time(t,0); - // Set Up and Down animations int LBef=0; int Lnow=0; int LAft=0; - // Animations animationslan(t->tm_min, &LBef, &Lnow, &LAft,settings.LangKey); - - // Recenter screen if last time was 3 lines, but new time is 2 lines // Don't do this if time was just initialized already centered if(LBef>0 && Lnow==0 ){ @@ -575,56 +493,43 @@ static void time_timer_tick(struct tm *t, TimeUnits units_changed) { makeScrollDown(); } } - // Prepare for next time being 3 lines, if current time is 2 lines if(Lnow==0 && LAft > 0 ){ makeScrollUp(t); } - if(s_countdown== 0 || s_countdown==5) { if (settings.DisplayTemp ){ APP_LOG(APP_LOG_LEVEL_DEBUG, "Update weather at %d", t->tm_min); - request_watchjs(); - } + request_watchjs(); + } } - if (!settings.GPSOn){ if (settings.DisplayTemp ){ if (settings.UpSlider>15){ if(s_countdown % 15 == 0){ APP_LOG(APP_LOG_LEVEL_DEBUG, "Attempt to request GPS on %d", t->tm_min); - request_watchjs(); + request_watchjs(); } - } + } } - } + } } // Proc to update Date and Month layer static void back_update_proc(Layer *layer, GContext *ctx) { - // Colors - graphics_context_set_text_color(ctx,ColorSelect(settings.NightTheme, settings.GPSOn, settings.IsNightNow, settings.ForegroundColor, settings.ForegroundColorNight)); - - - + graphics_context_set_text_color(ctx,ColorSelect(settings.NightTheme, settings.GPSOn, settings.IsNightNow, settings.ForegroundColor, settings.ForegroundColorNight)); GRect bounds2layer = layer_get_bounds(layer); - //Translate char WeekDay_END[BUFFER_SIZE]; char Date_END[BUFFER_SIZE]; char Month_END[BUFFER_SIZE]; - time_t now = time(NULL); struct tm *t = localtime(&now); - // Set language - writedatelang(t->tm_wday ,t->tm_mon, t->tm_mday, WeekDay_END, Date_END,Month_END,settings.LangKey); - //Draw day of the week GRect WDay_rect=GRect(bounds2layer.origin.x,bounds2layer.origin.y,bounds2layer.size.w,bounds2layer.size.h); graphics_draw_text(ctx, WeekDay_END, FontWDay, WDay_rect, GTextOverflowModeFill, GTextAlignmentCenter, NULL); - //Draw date char builddate[BUFFER_SIZE]; //Build based on config settings @@ -640,43 +545,38 @@ static void back_update_proc(Layer *layer, GContext *ctx) { } GRect Date=GRect(WDay_rect.origin.x,WDay_rect.origin.y+20,WDay_rect.size.w,WDay_rect.size.h); graphics_draw_text(ctx, builddate, FontDate, Date, GTextOverflowModeTrailingEllipsis, GTextAlignmentCenter, NULL); - int offsetx=PBL_IF_ROUND_ELSE(0, 10); int offsety=PBL_IF_ROUND_ELSE(0, 10); - - //Draw Rect for temp GRect temprect=GRect(WDay_rect.origin.x, WDay_rect.origin.y, WDay_rect.size.w/2-25-offsetx/3, - WDay_rect.size.h); + WDay_rect.size.h); //Draw Rect for cond GRect condrect=GRect(WDay_rect.size.w/2+25+offsetx, WDay_rect.origin.y+offsety, WDay_rect.size.w, WDay_rect.size.h); - //If Bluetooth off and some info was requested display warning if (!settings.BTOn){ if (settings.DisplayTemp){ - graphics_draw_text(ctx, "a", - FontSymbol, + FontSymbol, temprect, GTextOverflowModeWordWrap, GTextAlignmentRight, NULL ); - } + } } //If connected but GPS off then display warning else { if (!settings.GPSOn){ if (settings.DisplayTemp){ - graphics_draw_text(ctx, "b", - FontSymbol, + graphics_draw_text(ctx, "b", + FontSymbol, temprect, GTextOverflowModeWordWrap, GTextAlignmentRight, NULL ); - } + } } // If BT on and GPS on display according with preferences else{ @@ -692,18 +592,11 @@ static void back_update_proc(Layer *layer, GContext *ctx) { graphics_draw_text(ctx, condstringday, FontCond,condrect, GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, NULL); } } - } - } + } + } } // End build - - -////////////////////////////////////// ///// End: Updating time and date//// -///////////////////////////////////// - -///////////////////////////////////////// ////Init: Handle Settings and Weather//// -///////////////////////////////////////// // Read settings from persistent storage static void prv_load_settings() { // Load the default settings @@ -714,24 +607,14 @@ static void prv_load_settings() { // Save the settings to persistent storage static void prv_save_settings(int ChangeLang, int LangBefore) { persist_write_data(SETTINGS_KEY, &settings, sizeof(settings)); - - - time_t now = time(NULL); struct tm *t = localtime(&now); - - // Content of line 3 now int LenBeforeSave=0; popatinitlang(t->tm_min, &LenBeforeSave, LangBefore); - - - // Adjust animations to fit the change of language - study how long will be line 3 after change language - int LenAfterSave=0; + int LenAfterSave=0; popatinitlang(t->tm_min, &LenAfterSave, settings.LangKey); - - //Update text if language has changed //Adjust position using animations if (ChangeLang>0){ @@ -741,7 +624,6 @@ static void prv_save_settings(int ChangeLang, int LangBefore) { } // Display time display_time(t,1); - if (LenBeforeSave>0 && LenAfterSave == 0){ // Pop down if before were 3 lines and now 2 lines makeScrollDown(); @@ -752,42 +634,36 @@ static void prv_save_settings(int ChangeLang, int LangBefore) { static void prv_inbox_received_handler(DictionaryIterator *iter, void *context) { s_loop=s_loop+1; if (s_loop==1){ - //Clean vars + //Clean vars strcpy(tempstring, ""); strcpy(condstringday, ""); strcpy(condstringnight, ""); } - - // Background Color Tuple *bg_color_t = dict_find(iter, MESSAGE_KEY_BackgroundColor); if (bg_color_t) { settings.BackgroundColor = GColorFromHEX(bg_color_t->value->int32); } - Tuple *nbg_color_t = dict_find(iter, MESSAGE_KEY_BackgroundColorNight); if (nbg_color_t) { settings.BackgroundColorNight = GColorFromHEX(nbg_color_t->value->int32); } - // Foreground Color Tuple *fg_color_t = dict_find(iter, MESSAGE_KEY_ForegroundColor); if (fg_color_t) { settings.ForegroundColor = GColorFromHEX(fg_color_t->value->int32); - } + } Tuple *nfg_color_t = dict_find(iter, MESSAGE_KEY_ForegroundColorNight); if (nfg_color_t) { settings.ForegroundColorNight = GColorFromHEX(nfg_color_t->value->int32); - } + } // Get display handlers Tuple *frequpdate=dict_find(iter, MESSAGE_KEY_UpSlider); if (frequpdate){ settings.UpSlider=(int)frequpdate->value->int32; //Restart the counter s_countdown=settings.UpSlider; - } - Tuple *distemp_t=dict_find(iter,MESSAGE_KEY_DisplayTemp); if (distemp_t){ if (distemp_t->value->int32==0){ @@ -795,8 +671,6 @@ static void prv_inbox_received_handler(DictionaryIterator *iter, void *context) } else settings.DisplayTemp=true; } - - Tuple *disntheme_t=dict_find(iter,MESSAGE_KEY_NightTheme); if (disntheme_t){ if (disntheme_t->value->int32==0){ @@ -805,20 +679,19 @@ static void prv_inbox_received_handler(DictionaryIterator *iter, void *context) else { settings.NightTheme=true;} } - -//Control of data from http + //Control of data from http // Weather Cond Tuple *wcond_t=dict_find(iter, MESSAGE_KEY_WeatherCondDay); - if (wcond_t){ + if (wcond_t){ snprintf(condstringday , sizeof(condstringday), "%s", wcond_t->value->cstring); } Tuple *n_wcond_t=dict_find(iter, MESSAGE_KEY_WeatherCondNight); - if (n_wcond_t){ + if (n_wcond_t){ snprintf(condstringnight , sizeof(condstringnight), "%s", n_wcond_t->value->cstring); } // Weather Temp Tuple *wtemp_t=dict_find(iter, MESSAGE_KEY_WeatherTemp); - if (wtemp_t){ + if (wtemp_t){ snprintf(tempstring, sizeof(tempstring), "%s", wtemp_t->value->cstring); } //Hour Sunrise and Sunset @@ -829,23 +702,18 @@ static void prv_inbox_received_handler(DictionaryIterator *iter, void *context) Tuple *sunset_t=dict_find(iter, MESSAGE_KEY_HourSunset); if (sunset_t){ settings.HourSunset=(int)sunset_t->value->int32; - } - - + } //Control of data gathered for http APP_LOG(APP_LOG_LEVEL_DEBUG, "After loop %d temp is %s Cond is %s Sunrise is %d Sunset is %d", s_loop,tempstring,condstringday,settings.HourSunrise,settings.HourSunset); - if (strcmp(tempstring, "") !=0 && strcmp(condstringday, "") !=0 && strcmp(condstringnight, "")){ APP_LOG(APP_LOG_LEVEL_DEBUG,"GPS on at loop %d",s_loop); settings.GPSOn=true; - } + } else { APP_LOG(APP_LOG_LEVEL_DEBUG,"Missing info at loop %d, GPS off",s_loop); settings.GPSOn=false; } //End data gathered - - // Store language applied before refreshing int LangBefSave=settings.LangKey; // Language @@ -854,67 +722,44 @@ static void prv_inbox_received_handler(DictionaryIterator *iter, void *context) settings.LangKey=atoi(lang_t->value->cstring); }; int LangAftSave=settings.LangKey; - // Date format Tuple *dateformat_t=dict_find(iter,MESSAGE_KEY_DateFormat); if (dateformat_t){ settings.DateFormat=atoi(dateformat_t->value->cstring); } - //Update colors - window_set_background_color(s_main_window, ColorSelect(settings.NightTheme, settings.GPSOn, settings.IsNightNow, settings.BackgroundColor, settings.BackgroundColorNight)); + window_set_background_color(s_main_window, ColorSelect(settings.NightTheme, settings.GPSOn, settings.IsNightNow, settings.BackgroundColor, settings.BackgroundColorNight)); layer_mark_dirty(back_layer); - text_layer_set_text_color(line1.currentLayer, ColorSelect(settings.NightTheme, settings.GPSOn, settings.IsNightNow, settings.ForegroundColor, settings.ForegroundColorNight)); - text_layer_set_text_color(line1.nextLayer, ColorSelect(settings.NightTheme, settings.GPSOn, settings.IsNightNow, settings.ForegroundColor, settings.ForegroundColorNight)); - text_layer_set_text_color(line2.currentLayer,ColorSelect(settings.NightTheme, settings.GPSOn, settings.IsNightNow, settings.ForegroundColor, settings.ForegroundColorNight)); - text_layer_set_text_color(line2.nextLayer, ColorSelect(settings.NightTheme, settings.GPSOn, settings.IsNightNow, settings.ForegroundColor, settings.ForegroundColorNight)); - text_layer_set_text_color(line3.currentLayer, ColorSelect(settings.NightTheme, settings.GPSOn, settings.IsNightNow, settings.ForegroundColor, settings.ForegroundColorNight)); - text_layer_set_text_color(line3.nextLayer, ColorSelect(settings.NightTheme, settings.GPSOn, settings.IsNightNow, settings.ForegroundColor, settings.ForegroundColorNight)); - - + text_layer_set_text_color(line1.currentLayer, ColorSelect(settings.NightTheme, settings.GPSOn, settings.IsNightNow, settings.ForegroundColor, settings.ForegroundColorNight)); + text_layer_set_text_color(line1.nextLayer, ColorSelect(settings.NightTheme, settings.GPSOn, settings.IsNightNow, settings.ForegroundColor, settings.ForegroundColorNight)); + text_layer_set_text_color(line2.currentLayer,ColorSelect(settings.NightTheme, settings.GPSOn, settings.IsNightNow, settings.ForegroundColor, settings.ForegroundColorNight)); + text_layer_set_text_color(line2.nextLayer, ColorSelect(settings.NightTheme, settings.GPSOn, settings.IsNightNow, settings.ForegroundColor, settings.ForegroundColorNight)); + text_layer_set_text_color(line3.currentLayer, ColorSelect(settings.NightTheme, settings.GPSOn, settings.IsNightNow, settings.ForegroundColor, settings.ForegroundColorNight)); + text_layer_set_text_color(line3.nextLayer, ColorSelect(settings.NightTheme, settings.GPSOn, settings.IsNightNow, settings.ForegroundColor, settings.ForegroundColorNight)); // Mark if language has changed int LangChanged=0; if (LangAftSave != LangBefSave ) {LangChanged=1; } - // Update date // layer_set_update_proc(back_layer, back_update_proc); layer_mark_dirty(back_layer); - - - // Save the new settings to persistent storage prv_save_settings(LangChanged,LangBefSave); - - - } -///////////////////////////////////////// ////End: Handle Settings and Weather//// -///////////////////////////////////////// - -////////////////////////////////// ////Init: Creating Watchface///// -///////////////////////////////// //Build watchface static void prv_window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); - back_layer = layer_create(GRect(0,bounds.size.h-45,bounds.size.w, 45)); layer_set_update_proc(back_layer, back_update_proc); - layer_add_child(window_layer, back_layer); - - - // Configure text time on init - time_t now = time(NULL); - struct tm *t = localtime(&now); - display_time(t,1); + layer_add_child(window_layer, back_layer); } // Window Unload event static void prv_window_unload(Window *window) { - layer_destroy(back_layer); + layer_destroy(back_layer); window_destroy(s_main_window); text_layer_destroy(line1.currentLayer); text_layer_destroy(line1.nextLayer); @@ -922,7 +767,7 @@ static void prv_window_unload(Window *window) { text_layer_destroy(line2.nextLayer); text_layer_destroy(line3.currentLayer); text_layer_destroy(line3.nextLayer); - layer_destroy(scroll); + layer_destroy(scroll); fonts_unload_custom_font(FontCond); fonts_unload_custom_font(Bold); fonts_unload_custom_font(BoldReduced1); @@ -933,21 +778,17 @@ static void prv_window_unload(Window *window) { fonts_unload_custom_font(LightReduced2); fonts_unload_custom_font(FontWDay); fonts_unload_custom_font(FontDate); - fonts_unload_custom_font(FontSymbol); + fonts_unload_custom_font(FontSymbol); } - void main_window_push() { - s_main_window = window_create(); - - Layer *root = window_get_root_layer(s_main_window); - + s_main_window = window_create(); + Layer *root = window_get_root_layer(s_main_window); //Set bounds and offsets bounds = layer_get_bounds(root); offsetpebble= PBL_IF_ROUND_ELSE((bounds.size.h - 145) / 2,5); - // Create layers // Scroll - scroll = layer_create(bounds); + scroll = layer_create(bounds); // 1st line layer line1.currentLayer = text_layer_create(GRect(0, offsetpebble, bounds.size.w, 50)); line1.nextLayer = text_layer_create(GRect(bounds.size.w, offsetpebble, bounds.size.w, 50)); @@ -971,21 +812,19 @@ void main_window_push() { layer_add_child(scroll, (Layer *)line2.nextLayer); layer_add_child(scroll, (Layer *)line3.currentLayer); layer_add_child(scroll, (Layer *)line3.nextLayer); - + // Configure text time on init + time_t now = time(NULL); + struct tm *t = localtime(&now); + display_time(t,1); // Configure main window window_set_window_handlers(s_main_window, (WindowHandlers) { .load = prv_window_load, .unload = prv_window_unload, }); - - window_stack_push(s_main_window, true); } - - static void prv_init(void) { prv_load_settings(); - //Starting loop at 0 s_loop=0; s_countdown=settings.UpSlider; @@ -993,12 +832,9 @@ static void prv_init(void) { strcpy(tempstring, ""); strcpy(condstringday, ""); strcpy(condstringnight, ""); - - // Listen for AppMessages app_message_register_inbox_received(prv_inbox_received_handler); app_message_open(256, 256); - // Load fonts Bold=fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_GBOLD_39)); BoldReduced1=fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_GBOLD_34)); @@ -1011,31 +847,18 @@ static void prv_init(void) { FontWDay=fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_GBOLD_16)); FontDate=fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_GLIGHT_16)); FontSymbol =fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_SYMBOL_16)); - - main_window_push(); - - + main_window_push(); // Register for minute ticks - tick_timer_service_subscribe(MINUTE_UNIT, time_timer_tick); - - - + tick_timer_service_subscribe(MINUTE_UNIT, time_timer_tick); // initialize PoppedDown indicators - - time_t now = time(NULL); struct tm *t = localtime(&now); - PoppedDownNow = false; PoppedDownAtInit = false; // If initial display of time is only 2 lines of text, display centered // Based on languague on init - int LenInit_END=0; - + int LenInit_END=0; popatinitlang(t->tm_min, &LenInit_END, settings.LangKey); - - - // Check Line3 at init if(LenInit_END == 0 ){ makePopDown(); @@ -1046,15 +869,12 @@ static void prv_init(void) { } } static void prv_deinit(void) { - tick_timer_service_unsubscribe(); - app_message_deregister_callbacks(); //Destroy the callbacks for clean up + app_message_deregister_callbacks(); //Destroy the callbacks for clean up } int main(void) { prv_init(); app_event_loop(); prv_deinit(); } -////////////////////////////////// -////End: Creating Watchface///// -///////////////////////////////// \ No newline at end of file +////End: Creating Watchface///// \ No newline at end of file diff --git a/src/c/num2words-br.c b/src/c/num2words-br.c index 7e0eec2..d366740 100644 --- a/src/c/num2words-br.c +++ b/src/c/num2words-br.c @@ -3,196 +3,129 @@ #include "string.h" #include static const char* const HOUR_BR[] = { -"doze", -"uma", -"duas", -"três", -"quatro", -"cinco", -"seis", -"sete", -"oito", -"nove", -"dez", -"onze", -"doze", -"uma" + "doze", + "uma", + "duas", + "três", + "quatro", + "cinco", + "seis", + "sete", + "oito", + "nove", + "dez", + "onze", + "doze", + "uma" }; -static const char* const MIN_BR1[]={ -"horas", -"e um", -"e dois", -"e três", -"e quatro", -"e cinco", -"e seis", -"e sete", -"e oito", -"e nove", -"e dez", -"e onze", -"e doze", -"e treze", -"e catorze", -"quinze", -"dezasseis", -"dezassete", -"dezoito", -"dezanove", -"vinte", -"vinte", -"vinte", -"vinte", -"vinte", -"vinte", -"vinte", -"vinte", -"vinte", -"vinte", -"e meia", -"trinta", -"trinta", -"trinta", -"trinta", -"trinta", -"trinta", -"trinta", -"trinta", -"trinta", -"vinte", -"dezanove", -"dezoito", -"dezassete", -"dezasseis", -"quinze", -"catorze", -"treze", -"doze", -"onze", -"dez", -"nove", -"oito", -"sete", -"seis", -"cinco", -"quatro", -"três", -"dois", -"um" +static const char* const MIN_AUX_BR[]={ + "", + "", + "vinte", + "trinta" }; -const char* const MIN_BR2[]={ -"", -"", -"", -"", -"", -"", -"", -"", -"", -"", -"", -"", -"", -"", -"", -"", -"", -"", -"", -"", -"", -"e um", -"e dois", -"e três", -"e quatro", -"e cinco", -"e seis", -"e sete", -"e oito", -"e nove", -"", -"e um", -"e dois", -"e três", -"e quatro", -"e cinco", -"e seis", -"e sete", -"e oito", -"e nove", -"para as", -"para as", -"para as", -"para as", -"para as", -"para as", -"para as", -"para as", -"para as", -"para as", -"para as", -"para as", -"para as", -"para as", -"para as", -"para as", -"para as", -"para as", -"para as", -"para as" +static const char* const MIN_BR1[]={ + "horas", + "um", + "dois", + "três", + "quatro", + "cinco", + "seis", + "sete", + "oito", + "nove", + "dez", + "onze", + "doze", + "treze", + "catorze", + "quinze", + "dezasseis", + "dezassete", + "dezoito", + "dezanove", + "vinte" }; //Init_StrMonthDat: Create strings for Months and Days const char* const MONTHS_BR[] = { -"Jan", -"Fev", -"Mar", -"Abr", -"Mai", -"Jun", -"Jul", -"Ago", -"Set", -"Out", -"Nov", -"Dez" + "Jan", + "Fev", + "Mar", + "Abr", + "Mai", + "Jun", + "Jul", + "Ago", + "Set", + "Out", + "Nov", + "Dez" }; const char* const WEEKDAY_BR[] = { -"Dom", -"Seg", -"Ter", -"Qua", -"Qui", -"Sex", -"Sab" + "Dom", + "Seg", + "Ter", + "Qua", + "Qui", + "Sex", + "Sab" }; void time_to_3words_BR(int hours, int minutes, int *LineBold,char *line1, char *line2, char *line3){ - //hour - line1 - //shift 1 hour the label for this minutes - if ( minutes>39) {hours=(hours+1); - } + //shift 1 hour the label for this minutes + if ( minutes>39) {hours=(hours+1);} hours=hours % 12; - if (minutes<40){ + //Exceptions first + if (minutes<40){ + //hour - line1 strcpy(line1, HOUR_BR[hours]); - // Fix plural + // Fix plural for 1hour if (minutes==0 && hours==1){ strcpy(line2,"hora"); } - else { - strcpy(line2,MIN_BR1[minutes]); - } - strcpy(line3,MIN_BR2[minutes]); - *LineBold=1; - } + else if (minutes==20){ + strcpy(line2, "e vinte"); + strcpy(line3, ""); + } + else if (minutes==30){ + strcpy(line2,"e meia"); + strcpy(line3, ""); + } + else if (minutes==0){ + strcpy(line2, MIN_BR1[minutes]); + strcpy(line3, ""); + } + else if (minutes<=14){ + strcpy(line2, "e "); + strcat(line2, MIN_BR1[minutes]); + strcpy(line3, ""); + } + else if(minutes<20){ + strcpy(line2, MIN_BR1[minutes]); + strcpy(line3, ""); + } + else if (minutes<40){ + strcpy(line2, MIN_AUX_BR[minutes/10]); + strcpy(line3, "e "); + strcat(line3, MIN_BR1[minutes % 10]); + } + *LineBold=1; + } else { - strcpy(line1,MIN_BR1[minutes]); - strcpy(line2,MIN_BR2[minutes]); + strcpy(line1,MIN_BR1[60-minutes]); + strcpy(line2,"para as"); strcpy(line3, HOUR_BR[hours]); - *LineBold=3; - } + *LineBold=3; + } +} +int Len_BR(int min){ + if (min<=20 || min==30){ + return 0; + } + else return 10; } void PopatInit_BR(int minute, int *lenatinit){ -*lenatinit=strlen(MIN_BR2[minute]); + *lenatinit=Len_BR(minute); } void WriteDate_BR(int WD, int Mnth, int Dy, char *iterweekday, char *iterdate, char *itermonth ){ strcpy(iterweekday, WEEKDAY_BR[WD]); @@ -200,20 +133,17 @@ void WriteDate_BR(int WD, int Mnth, int Dy, char *iterweekday, char *iterdate, c strcpy(itermonth, MONTHS_BR[Mnth]); } void Animations_BR(int Minute, int *LenBefore, int *LenNow, int *LenAfter){ - //Len Before - if (Minute==0){ - *LenBefore=strlen(MIN_BR2[59]); - } -else { - *LenBefore=strlen(MIN_BR2[Minute-1]); - } -// Len Now -*LenNow=strlen(MIN_BR2[Minute]); -//Len After - if (Minute==59){ - *LenAfter=strlen(MIN_BR2[0]); - } -else { - *LenAfter=strlen(MIN_BR2[Minute+1]); + *LenNow=Len_BR(Minute); + if (Minute==0){ + *LenBefore=Len_BR(59); + } + else { + *LenBefore=Len_BR(Minute-1); + } + if (Minute==59){ + *LenAfter=Len_BR(0); + } + else { + *LenAfter=Len_BR(Minute+1); } } \ No newline at end of file diff --git a/src/c/num2words-br.h b/src/c/num2words-br.h index f5360c0..b62718f 100644 --- a/src/c/num2words-br.h +++ b/src/c/num2words-br.h @@ -1,12 +1,9 @@ #pragma once - - +#include "string.h" void time_to_3words_BR(int hours, int minutes,int *LineBold, char *line1, char *line2, char *line3); void PopatInit_BR(int minute, int *lenatinit); void WriteDate_BR(int WD, int Mnth, int Dy, char *iterweekday, char *iterdate, char *itermonth ); void Animations_BR(int Minute, int *LenBefore, int *LenNow, int *LenAfter); - extern const char* const MONTHS_BR[]; extern const char* const DAYS_BR[]; -extern const char* const WEEKDAY_BR[]; -extern const char* const MIN_BR2[]; \ No newline at end of file +extern const char* const WEEKDAY_BR[]; \ No newline at end of file diff --git a/src/c/num2words-de.c b/src/c/num2words-de.c index 6c568bc..7b92e35 100644 --- a/src/c/num2words-de.c +++ b/src/c/num2words-de.c @@ -20,181 +20,101 @@ static const char* const HOUR_DE[] = { "eins" }; static const char* const MIN_DE1[]={ -"Uhr", -"eins", -"zwei", -"drei", -"vier", -"fünf", -"sechs", -"sieben", -"acht", -"neun", -"zehn", -"elf", -"zwölf", -"dreizehn", -"vierzehn", -"Viertel", -"sechzehn", -"siebzehn", -"achtzehn", -"neunzehn", -"zwanzig", -"neun", -"acht", -"sieben", -"sechs", -"fünf", -"vier", -"drei", -"zwei", -"eins", -"halb", -"eins", -"zwei", -"drei", -"vier", -"fünf", -"sechs", -"sieben", -"acht", -"neun", -"zwanzig", -"neunzehn", -"achtzehn", -"siebzehn", -"sechzehn", -"Viertel", -"vierzehn", -"dreizehn", -"zwölf", -"elf", -"zehn", -"neun", -"acht", -"sieben", -"sechs", -"fünf", -"vier", -"drei", -"zwei", -"eins" -}; -const char* const MIN_DE2[]={ -"", -"nach", -"nach", -"nach", -"nach", -"nach", -"nach", -"nach", -"nach", -"nach", -"nach", -"nach", -"nach", -"nach", -"nach", -"nach", -"nach", -"nach", -"nach", -"nach", -"nach", -"vor halb", -"vor halb", -"vor halb", -"vor halb", -"vor halb", -"vor halb", -"vor halb", -"vor halb", -"vor halb", -"", -"nach halb", -"nach halb", -"nach halb", -"nach halb", -"nach halb", -"nach halb", -"nach halb", -"nach halb", -"nach halb", -"vor", -"vor", -"vor", -"vor", -"vor", -"vor", -"vor", -"vor", -"vor", -"vor", -"vor", -"vor", -"vor", -"vor", -"vor", -"vor", -"vor", -"vor", -"vor", -"vor" + "Uhr", + "eins", + "zwei", + "drei", + "vier", + "fünf", + "sechs", + "sieben", + "acht", + "neun", + "zehn", + "elf", + "zwölf", + "dreizehn", + "vierzehn", + "Viertel", + "sechzehn", + "siebzehn", + "achtzehn", + "neunzehn", + "zwanzig" }; -//Init_StrMonthDat: Create strings for Months and Days const char* const MONTHS_DE[] = { -"Jan.", -"Feb.", -"Mrz.", -"Apr.", -"Mai.", -"Jun.", -"Jul.", -"Aug.", -"Sep.", -"Okt.", -"Nov.", -"Dez.", + "Jan.", + "Feb.", + "Mrz.", + "Apr.", + "Mai.", + "Jun.", + "Jul.", + "Aug.", + "Sep.", + "Okt.", + "Nov.", + "Dez." }; const char* const WEEKDAY_DE[] = { -"So.", -"Mo.", -"Di.", -"Mi.", -"Do.", -"Fr.", -"Sa.", + "So.", + "Mo.", + "Di.", + "Mi.", + "Do.", + "Fr.", + "Sa." }; -//End_Weekday void time_to_3words_DE(int hours, int minutes, int *LineBold,char *line1, char *line2, char *line3){ //hour - line1 //shift 1 hour the label for this minutes - if ( minutes>20) {hours=(hours+1); - } + if ( minutes>20) {hours=(hours+1);} hours=hours % 12; + // Exceptions first if (minutes==0 ){ strcpy(line1, HOUR_DE[hours]); strcpy(line2,MIN_DE1[minutes]); - strcpy(line3,MIN_DE2[minutes]); + strcpy(line3,""); *LineBold=1; } - else if (minutes==30){ - strcpy(line1,MIN_DE1[minutes]); + else if (minutes==30){ + strcpy(line1,"halb"); strcpy(line2, HOUR_DE[hours]); - strcpy(line3,MIN_DE2[minutes]); - *LineBold=2; + strcpy(line3,""); + *LineBold=2; } else { - strcpy(line1,MIN_DE1[minutes]); - strcpy(line2,MIN_DE2[minutes]); - strcpy(line3, HOUR_DE[hours]); - *LineBold=3; + if (minutes<=20) { + strcpy(line1,MIN_DE1[minutes]); + strcpy(line2,"nach"); + strcpy(line3, HOUR_DE[hours]); + } + else if (minutes<=30) { + strcpy(line1,MIN_DE1[10-minutes%10]); + strcpy(line2,"vor halb"); + strcpy(line3, HOUR_DE[hours]); + } + else if (minutes<40) { + strcpy(line1,MIN_DE1[minutes%10]); + strcpy(line2,"nach halb"); + strcpy(line3, HOUR_DE[hours]); + } + else { + strcpy(line1,MIN_DE1[20-minutes%10]); + strcpy(line2,"vor"); + strcpy(line3, HOUR_DE[hours]); + } + *LineBold=3; + } +} +int Len_DE(int min){ + if (min==0 || min==30){ + return 0; } + else return 10; } void PopatInit_DE(int minute, int *lenatinit){ -*lenatinit=strlen(MIN_DE2[minute]); + *lenatinit=Len_DE(minute); } void WriteDate_DE(int WD, int Mnth, int Dy, char *iterweekday, char *iterdate, char *itermonth ){ strcpy(iterweekday, WEEKDAY_DE[WD]); @@ -202,20 +122,17 @@ void WriteDate_DE(int WD, int Mnth, int Dy, char *iterweekday, char *iterdate, c strcpy(itermonth, MONTHS_DE[Mnth]); } void Animations_DE(int Minute, int *LenBefore, int *LenNow, int *LenAfter){ - //Len Before - if (Minute==0){ - *LenBefore=strlen(MIN_DE2[59]); - } -else { - *LenBefore=strlen(MIN_DE2[Minute-1]); - } -// Len Now -*LenNow=strlen(MIN_DE2[Minute]); -//Len After - if (Minute==59){ - *LenAfter=strlen(MIN_DE2[0]); - } -else { - *LenAfter=strlen(MIN_DE2[Minute+1]); + *LenNow=Len_DE(Minute); + if (Minute==0){ + *LenBefore=Len_DE(59); + } + else { + *LenBefore=Len_DE(Minute-1); + } + if (Minute==59){ + *LenAfter=Len_DE(0); + } + else { + *LenAfter=Len_DE(Minute+1); } } \ No newline at end of file diff --git a/src/c/num2words-de.h b/src/c/num2words-de.h index dab4e0f..604d7da 100644 --- a/src/c/num2words-de.h +++ b/src/c/num2words-de.h @@ -1,13 +1,9 @@ #pragma once #include "string.h" - - void time_to_3words_DE(int hours, int minutes,int *LineBold, char *line1, char *line2, char *line3); void PopatInit_DE(int minute, int *lenatinit); void WriteDate_DE(int WD, int Mnth, int Dy, char *iterweekday, char *iterdate, char *itermonth ); void Animations_DE(int Minute, int *LenBefore, int *LenNow, int *LenAfter); - extern const char* const MONTHS_DE[]; extern const char* const DAYS_DE[]; -extern const char* const WEEKDAY_DE[]; -extern const char* const MIN_DE2[]; \ No newline at end of file +extern const char* const WEEKDAY_DE[]; \ No newline at end of file diff --git a/src/c/num2words-dk.c b/src/c/num2words-dk.c index f6d5e31..33a7809 100644 --- a/src/c/num2words-dk.c +++ b/src/c/num2words-dk.c @@ -3,191 +3,127 @@ #include "string.h" #include static const char* const HOUR_DK[] = { -"tolv", -"et", -"to", -"tre", -"fire", -"fem", -"seks", -"syv", -"otte", -"ni", -"ti", -"elleve", -"tolv", -"et" + "tolv", + "et", + "to", + "tre", + "fire", + "fem", + "seks", + "syv", + "otte", + "ni", + "ti", + "elleve", + "tolv", + "et" }; static const char* const MIN_DK1[]={ -"klokken", -"et", -"to", -"tre", -"fire", -"fem", -"seks", -"syv", -"otte", -"ni", -"ti", -"elleve", -"tolv", -"tretten", -"fjorten", -"kvart", -"seksten", -"sytten", -"atten", -"nitten", -"tyve", -"énog", -"toog", -"treog", -"fireog", -"femog", -"seksog", -"syvog", -"otteog", -"niog", -"halv", -"niog", -"otteog", -"syvog", -"seksog", -"femog", -"fireog", -"treog", -"toog", -"énog", -"tyve", -"nitten", -"atten", -"sytten", -"seksten", -"kvart", -"fjorten", -"tretten", -"tolv", -"elleve", -"ti", -"ni", -"otte", -"syv", -"seks", -"fem", -"fire", -"tre", -"to", -"et" -}; -const char* const MIN_DK2[]={ -"", -"over", -"over", -"over", -"over", -"over", -"over", -"over", -"over", -"over", -"over", -"over", -"over", -"over", -"over", -"over", -"over", -"over", -"over", -"over", -"over", -"tyve over", -"tyve over", -"tyve over", -"tyve over", -"tyve over", -"tyve over", -"tyve over", -"tyve over", -"tyve over", -"", -"tyve i", -"tyve i", -"tyve i", -"tyve i", -"tyve i", -"tyve i", -"tyve i", -"tyve i", -"tyve i", -"i", -"i", -"i", -"i", -"i", -"i", -"i", -"i", -"i", -"i", -"i", -"i", -"i", -"i", -"i", -"i", -"i", -"i", -"i", -"i" + "klokken", + "et", + "to", + "tre", + "fire", + "fem", + "seks", + "syv", + "otte", + "ni", + "ti", + "elleve", + "tolv", + "tretten", + "fjorten", + "kvart", + "seksten", + "sytten", + "atten", + "nitten", + "tyve", + "énog", + "toog", + "treog", + "fireog", + "femog", + "seksog", + "syvog", + "otteog", + "niog" }; //Init_StrMonthDat: Create strings for Months and Days const char* const MONTHS_DK[] = { -"Jan.", -"Feb.", -"Mar.", -"Apr.", -"Maj.", -"Jun.", -"Jul.", -"Aug.", -"Sep.", -"Okt.", -"Nov.", -"Dec." + "Jan.", + "Feb.", + "Mar.", + "Apr.", + "Maj.", + "Jun.", + "Jul.", + "Aug.", + "Sep.", + "Okt.", + "Nov.", + "Dec." }; const char* const WEEKDAY_DK[] = { -"Sø.", -"Ma.", -"Ti.", -"On.", -"To.", -"Fr.", -"Lø." + "Sø.", + "Ma.", + "Ti.", + "On.", + "To.", + "Fr.", + "Lø." }; //End_Weekday void time_to_3words_DK(int hours, int minutes, int *LineBold,char *line1, char *line2, char *line3){ //hour - line1 //shift 1 hour the label for this minutes - if ( minutes>15) {hours=(hours+1); - } + if ( minutes>=30) {hours=(hours+1);} hours=hours % 12; - if (minutes==0 || minutes==30){ - strcpy(line1,MIN_DK1[minutes]); + // Exceptions first + if (minutes==0 || minutes==30){ + if (minutes==0){ + strcpy(line1, MIN_DK1[0]); + } + else { + strcpy(line1,"halv"); + } strcpy(line2,HOUR_DK[hours]); - strcpy(line3,MIN_DK2[minutes]); - *LineBold=2; + strcpy(line3, ""); + *LineBold=2; } else { - strcpy(line1,MIN_DK1[minutes]); - strcpy(line2,MIN_DK2[minutes]); - strcpy(line3, HOUR_DK[hours]); - *LineBold=3; + if (minutes<=20){ + strcpy(line1, MIN_DK1[minutes]); + strcpy(line2, "over"); + strcpy(line3,HOUR_DK[hours]); + } + else if (minutes<=30){ + strcpy(line1, MIN_DK1[minutes]); + strcpy(line2, "tyve over"); + strcpy(line3,HOUR_DK[hours]); + } + else if (minutes<40){ + strcpy(line1, MIN_DK1[60-minutes]); + strcpy(line2, "tyve i"); + strcpy(line3,HOUR_DK[hours]); + } + else { + strcpy(line1, MIN_DK1[60-minutes]); + strcpy(line2, "i"); + strcpy(line3,HOUR_DK[hours]); + } + *LineBold=3; } } +int Len_DK(int min){ + if (min==0 || min==30){ + return 0; + } + else return 10; +} void PopatInit_DK(int minute, int *lenatinit){ -*lenatinit=strlen(MIN_DK2[minute]); + *lenatinit=Len_DK(minute); } void WriteDate_DK(int WD, int Mnth, int Dy, char *iterweekday, char *iterdate, char *itermonth ){ strcpy(iterweekday, WEEKDAY_DK[WD]); @@ -195,20 +131,17 @@ void WriteDate_DK(int WD, int Mnth, int Dy, char *iterweekday, char *iterdate, c strcpy(itermonth, MONTHS_DK[Mnth]); } void Animations_DK(int Minute, int *LenBefore, int *LenNow, int *LenAfter){ - //Len Before - if (Minute==0){ - *LenBefore=strlen(MIN_DK2[59]); - } -else { - *LenBefore=strlen(MIN_DK2[Minute-1]); - } -// Len Now -*LenNow=strlen(MIN_DK2[Minute]); -//Len After - if (Minute==59){ - *LenAfter=strlen(MIN_DK2[0]); - } -else { - *LenAfter=strlen(MIN_DK2[Minute+1]); + *LenNow=Len_DK(Minute); + if (Minute==0){ + *LenBefore=Len_DK(59); + } + else { + *LenBefore=Len_DK(Minute-1); + } + if (Minute==59){ + *LenAfter=Len_DK(0); } -} \ No newline at end of file + else { + *LenAfter=Len_DK(Minute+1); + } +} diff --git a/src/c/num2words-dk.h b/src/c/num2words-dk.h index 845b918..4791f57 100644 --- a/src/c/num2words-dk.h +++ b/src/c/num2words-dk.h @@ -1,13 +1,9 @@ #pragma once #include "string.h" - - void time_to_3words_DK(int hours, int minutes,int *LineBold, char *line1, char *line2, char *line3); void PopatInit_DK(int minute, int *lenatinit); void WriteDate_DK(int WD, int Mnth, int Dy, char *iterweekday, char *iterdate, char *itermonth ); void Animations_DK(int Minute, int *LenBefore, int *LenNow, int *LenAfter); - extern const char* const MONTHS_DK[]; extern const char* const DAYS_DK[]; -extern const char* const WEEKDAY_DK[]; -extern const char* const MIN_DK2[]; +extern const char* const WEEKDAY_DK[]; \ No newline at end of file diff --git a/src/c/num2words-en.c b/src/c/num2words-en.c index a7fbc22..0d05993 100644 --- a/src/c/num2words-en.c +++ b/src/c/num2words-en.c @@ -18,176 +18,110 @@ static const char* const HOUR_EN[] = { "twelve", "one" }; -static const char* const MIN_EN1[]={ -"o'clock", -"one", -"two", -"three", -"four", -"five", -"six", -"seven", -"eight", -"nine", -"ten", -"eleven", -"twelve", -"thir", -"four", -"quarter", -"sixteen", -"seven", -"eight", -"nine", -"twenty", -"twenty", -"twenty", -"twenty", -"twenty", -"twenty", -"twenty", -"twenty", -"twenty", -"twenty", -"half", -"thirty", -"thirty", -"thirty", -"thirty", -"thirty", -"thirty", -"thirty", -"thirty", -"thirty", -"twenty", -"fourty", -"fourty", -"fourty", -"fourty", -"quarter", -"fourty", -"fourty", -"fourty", -"fourty", -"ten", -"fifty", -"fifty", -"fifty", -"fifty", -"five", -"fifty", -"fifty", -"fifty", -"fifty" +static const char* const MIN_AUX_EN[]={ + "", + "teen", + "twenty", + "thirty", + "fourty", + "fifty" }; -const char* const MIN_EN2[]={ -"", -"", -"", -"", -"", -"", -"", -"", -"", -"", -"", -"", -"", -"teen", -"teen", -"past", -"", -"teen", -"teen", -"teen", -"", -"one", -"two", -"three", -"four", -"five", -"six", -"seven", -"eight", -"nine", -"past", -"one", -"two", -"three", -"four", -"five", -"six", -"seven", -"eight", -"nine", -"to", -"one", -"two", -"three", -"four", -"to", -"six", -"seven", -"eight", -"nine", -"to", -"one", -"two", -"three", -"four", -"to", -"six", -"seven", -"eight", -"nine" +static const char* const MIN_EN1[]={ + "o'clock", + "one", + "two", + "three", + "four", + "five", + "six", + "seven", + "eight", + "nine", + "ten", + "eleven", + "twelve", + "thir", + "four", + "quarter", + "sixteen" }; //Init_StrMonthDat: Create strings for Months and Days const char* const MONTHS_EN[] = { -"Jan", -"Feb", -"Mar", -"Apr", -"May", -"Jun", -"Jul", -"Aug", -"Sep", -"Oct", -"Nov", -"Dec", + "Jan", + "Feb", + "Mar", + "Apr", + "May", + "Jun", + "Jul", + "Aug", + "Sep", + "Oct", + "Nov", + "Dec" }; const char* const WEEKDAY_EN[] = { -"Sun", -"Mon", -"Tue", -"Wed", -"Thu", -"Fri", -"Sat", + "Sun", + "Mon", + "Tue", + "Wed", + "Thu", + "Fri", + "Sat" }; -//End_Weekday void time_to_3words_EN(int hours, int minutes, int *LineBold,char *line1, char *line2, char *line3){ //hour - line1 - //shift 1 hour the label for this minutes - if ( minutes>35 && minutes % 5 == 0) {hours=(hours+1); - } + //shift 1 hour the label for this minutes + if ( minutes>35 && minutes % 5 == 0) {hours=(hours+1);} hours=hours % 12; -if (minutes==15 || minutes==30 || minutes == 40 || minutes == 45 || minutes==50 || minutes==55 ){ - strcpy(line1,MIN_EN1[minutes]); - strcpy(line2,MIN_EN2[minutes]); - strcpy(line3, HOUR_EN[hours]); - *LineBold=3; + //Exceptions first + if (minutes==15 || minutes==30 || minutes == 40 || minutes == 45 || minutes==50 || minutes==55 ){ + if (minutes<=30){ + if (minutes==15){ + strcpy(line1, MIN_EN1[minutes]); + } + else { + strcpy(line1, "half"); + } + strcpy(line2,"past"); + } + else { + if (minutes==40){ + strcpy(line1, MIN_AUX_EN[2]); + } + else { + strcpy(line1, MIN_EN1[60-minutes]); + } + strcpy(line2,"to"); + } + strcpy(line3, HOUR_EN[hours]); + *LineBold=3; + } + else { + strcpy(line1, HOUR_EN[hours]); + if (minutes<13 || minutes==16){ + strcpy(line2, MIN_EN1[minutes]); + strcpy(line3, ""); + } + else if (minutes<20){ + strcpy(line2, MIN_EN1[minutes % 10]); + strcpy(line3, MIN_AUX_EN[minutes/10]); + } + else { + strcpy(line2, MIN_AUX_EN[minutes/10]); + strcpy(line3, MIN_EN1[minutes % 10]); + } + *LineBold=1; + } } -else { - strcpy(line1, HOUR_EN[hours]); - strcpy(line2,MIN_EN1[minutes]); - strcpy(line3,MIN_EN2[minutes]); - *LineBold=1; -} +int Len_EN(int min){ + if (min<13 || min==16 || min==20){ + return 0; + } + else return 10; } void PopatInit_EN(int minute, int *lenatinit){ -*lenatinit=strlen(MIN_EN2[minute]); + *lenatinit=Len_EN(minute); } void WriteDate_EN(int WD, int Mnth, int Dy, char *iterweekday, char *iterdate, char *itermonth ){ strcpy(iterweekday, WEEKDAY_EN[WD]); @@ -195,20 +129,17 @@ void WriteDate_EN(int WD, int Mnth, int Dy, char *iterweekday, char *iterdate, c strcpy(itermonth, MONTHS_EN[Mnth]); } void Animations_EN(int Minute, int *LenBefore, int *LenNow, int *LenAfter){ - //Len Before - if (Minute==0){ - *LenBefore=strlen(MIN_EN2[59]); - } -else { - *LenBefore=strlen(MIN_EN2[Minute-1]); - } -// Len Now -*LenNow=strlen(MIN_EN2[Minute]); -//Len After - if (Minute==59){ - *LenAfter=strlen(MIN_EN2[0]); - } -else { - *LenAfter=strlen(MIN_EN2[Minute+1]); + *LenNow=Len_EN(Minute); + if (Minute==0){ + *LenBefore=Len_EN(59); + } + else { + *LenBefore=Len_EN(Minute-1); + } + if (Minute==59){ + *LenAfter=Len_EN(0); + } + else { + *LenAfter=Len_EN(Minute+1); } } \ No newline at end of file diff --git a/src/c/num2words-en.h b/src/c/num2words-en.h index 92e86b2..e39741a 100644 --- a/src/c/num2words-en.h +++ b/src/c/num2words-en.h @@ -1,13 +1,9 @@ #pragma once #include "string.h" - - void time_to_3words_EN(int hours, int minutes,int *LineBold, char *line1, char *line2, char *line3); void PopatInit_EN(int minute, int *lenatinit); void WriteDate_EN(int WD, int Mnth, int Dy, char *iterweekday, char *iterdate, char *itermonth ); void Animations_EN(int Minute, int *LenBefore, int *LenNow, int *LenAfter); - extern const char* const MONTHS_EN[]; extern const char* const DAYS_EN[]; -extern const char* const WEEKDAY_EN[]; -extern const char* const MIN_EN2[]; \ No newline at end of file +extern const char* const WEEKDAY_EN[]; \ No newline at end of file diff --git a/src/c/num2words-es.c b/src/c/num2words-es.c index 8f94d58..e4c64dc 100644 --- a/src/c/num2words-es.c +++ b/src/c/num2words-es.c @@ -18,173 +18,114 @@ static const char* const HOUR_ES[] = { "doce", "una" }; -static const char* const MIN_ES1[]={ -"en punto", -"y uno", -"y dos", -"y tres", -"y cuatro", -"y cinco", -"y seis", -"y siete", -"y ocho", -"y nueve", -"y diez", -"y once", -"y doce", -"y trece", -"y catorce", -"y cuarto", -"dieci", -"dieci", -"dieci", -"dieci", -"veinte", -"veinti", -"veinti", -"veinti", -"veinti", -"veinti", -"veinti", -"veinti", -"veinti", -"veinti", -"y media", -"treinta", -"treinta", -"treinta", -"treinta", -"treinta", -"treinta", -"treinta", -"treinta", -"treinta", -"menos", -"cuarenta", -"cuarenta", -"cuarenta", -"cuarenta", -"menos", -"cuarenta", -"cuarenta", -"cuarenta", -"cuarenta", -"menos", -"cincuenta", -"cincuenta", -"cincuenta", -"cincuenta", -"menos", -"cincuenta", -"cincuenta", -"cincuenta", -"cincuenta" -}; -const char* const MIN_ES2[]={ +static const char* const MIN_AUX_ES[]={ "", -"", -"", -"", -"", -"", -"", -"", -"", -"", -"", -"", -"", -"", -"", -"", -"seis", -"siete", -"ocho", -"nueve", -"", -"uno", -"dos", -"tres", -"cuatro", -"cinco", -"seis", -"siete", -"ocho", -"nueve", -"", -"y uno", -"y dos", -"y tres", -"y cuatro", -"y cinco", -"y seis", -"y siete", -"y ocho", -"y nueve", -"veinte ", -"y uno", -"y dos", -"y tres", -"y cuatro", -"cuarto ", -"y seis", -"y siete", -"y ocho", -"y nueve", -"diez ", -"y uno", -"y dos", -"y tres", -"y cuatro", -"cinco ", -"y seis", -"y siete", -"y ocho", -"y nueve", -"en punto" + "dieci", + "veinti", + "treinta", + "cuarenta", + "cincuenta" +}; +static const char* const MIN_ES1[]={ + "en punto", + "uno", + "dos", + "tres", + "cuatro", + "cinco", + "seis", + "siete", + "ocho", + "nueve", + "diez", + "once", + "doce", + "trece", + "catorce", + "cuarto" }; -//Init_StrMonthDat: Create strings for Months and Days const char* const MONTHS_ES[] = { -"Ene", -"Feb", -"Mar", -"Abr", -"May", -"Jun", -"Jul", -"Ago", -"Sep", -"Oct", -"Nov", -"Dic", + "Ene", + "Feb", + "Mar", + "Abr", + "May", + "Jun", + "Jul", + "Ago", + "Sep", + "Oct", + "Nov", + "Dic", }; const char* const WEEKDAY_ES[] = { -"Dom", -"Lun", -"Mar", -"Mie", -"Jue", -"Vie", -"Sab", + "Dom", + "Lun", + "Mar", + "Mie", + "Jue", + "Vie", + "Sab", }; -//End_Weekday void time_to_3words_ES(int hours, int minutes, int *LineBold,char *line1, char *line2, char *line3){ - //hour - line1 - //shift 1 hour the label for this minutes - if ( minutes>35 && minutes % 5 == 0) {hours=(hours+1); + //hour - line1 + //shift 1 hour the label for this minutes + if ( minutes>35 && minutes % 5 == 0) { + hours=(hours+1); } hours=hours % 12; strcpy(line1, HOUR_ES[hours]); - //minute + //minute //optimized for spanish - strcpy(line2,MIN_ES1[minutes]); - strcpy(line3,MIN_ES2[minutes]); + // First do exceptions + if (minutes==0 || minutes==20 || minutes==30 ){ + if (minutes==0){ + strcpy(line2, MIN_ES1[0]); + } + else if (minutes==20){ + strcpy(line2,"y veinte"); + } + else if (minutes==30){ + strcpy(line2,"y media"); + } + strcpy(line3,""); + } + else if (minutes>35 && minutes % 5 == 0){ + strcpy(line2,"menos"); + if (minutes==40){ + strcpy(line3,"veinte"); + } + else { + strcpy(line3,MIN_ES1[60-minutes]); + } + } + else if (minutes<16){ + strcpy(line2,"y "); + strcat(line2,MIN_ES1[minutes]); + strcpy(line3,""); + } + else if (minutes<60){ + strcpy(line2,MIN_AUX_ES[minutes/10]); + if (minutes<30){ + strcpy(line3,MIN_ES1[minutes%10]); + } + else{ + strcpy(line3,"y "); + strcat(line3,MIN_ES1[minutes % 10]); + } + } //line to mark bold - // in spanish the hour is always in the first line - *LineBold=1; + // in spanish the hour is always in the first line + *LineBold=1; +} +int Len_ES(int min){ + if (min<16 || min==20 || min==30){ + return 0; + } + else return 10; } void PopatInit_ES(int minute, int *lenatinit){ -*lenatinit=strlen(MIN_ES2[minute]); + *lenatinit=Len_ES(minute); } void WriteDate_ES(int WD, int Mnth, int Dy, char *iterweekday, char *iterdate, char *itermonth ){ strcpy(iterweekday, WEEKDAY_ES[WD]); @@ -192,20 +133,17 @@ void WriteDate_ES(int WD, int Mnth, int Dy, char *iterweekday, char *iterdate, c strcpy(itermonth, MONTHS_ES[Mnth]); } void Animations_ES(int Minute, int *LenBefore, int *LenNow, int *LenAfter){ - //Len Before - if (Minute==0){ - *LenBefore=strlen(MIN_ES2[59]); - } -else { - *LenBefore=strlen(MIN_ES2[Minute-1]); - } -// Len Now -*LenNow=strlen(MIN_ES2[Minute]); -//Len After - if (Minute==59){ - *LenAfter=strlen(MIN_ES2[0]); - } -else { - *LenAfter=strlen(MIN_ES2[Minute+1]); + *LenNow=Len_ES(Minute); + if (Minute==0){ + *LenBefore=Len_ES(59); + } + else { + *LenBefore=Len_ES(Minute-1); + } + if (Minute==59){ + *LenAfter=Len_ES(0); + } + else { + *LenAfter=Len_ES(Minute+1); } } \ No newline at end of file diff --git a/src/c/num2words-es.h b/src/c/num2words-es.h index 07cea29..2e728b0 100644 --- a/src/c/num2words-es.h +++ b/src/c/num2words-es.h @@ -1,13 +1,9 @@ #pragma once #include "string.h" - - void time_to_3words_ES(int hours, int minutes,int *LineBold, char *line1, char *line2, char *line3); void PopatInit_ES(int minute, int *lenatinit); void WriteDate_ES(int WD, int Mnth, int Dy, char *iterweekday, char *iterdate, char *itermonth ); void Animations_ES(int Minute, int *LenBefore, int *LenNow, int *LenAfter); - extern const char* const MONTHS_ES[]; extern const char* const DAYS_ES[]; -extern const char* const WEEKDAY_ES[]; -extern const char* const MIN_ES2[]; \ No newline at end of file +extern const char* const WEEKDAY_ES[]; \ No newline at end of file diff --git a/src/pkjs/app.js b/src/pkjs/app.js index f6b01fe..9608192 100644 --- a/src/pkjs/app.js +++ b/src/pkjs/app.js @@ -1,7 +1,6 @@ var Clay = require('pebble-clay'); var clayConfig = require('./config'); var clay = new Clay(clayConfig); - var xhrRequest = function (url, type, callback) { var xhr = new XMLHttpRequest(); xhr.onload = function () { @@ -22,350 +21,314 @@ function locationSuccessWU(pos){ var urlWU = "http://api.wunderground.com/api/"+ keyAPI + "/conditions/astronomy/q/"+ lat+","+lon+ - ".json"; - + ".json"; console.log("WUUrl= " + urlWU); - - xhrRequest(encodeURI(urlWU), 'GET', - function(responseText) { - // responseText contains a JSON object with weather info - var json = JSON.parse(responseText); - //Handle error in the response - localStorage.setItem("OKAPI", 0); - // Temperature - var tempf = Math.round(json.current_observation.temp_f)+"°" + units; - var tempc = Math.round(json.current_observation.temp_c)+"°" + units; - var tempwu=temptousewu(units,tempf,tempc); - // Condition - var condwu=json.current_observation.icon; - var condwuparsed=parsewu(condwu); - var condaywu=parseday(condwuparsed); - var condnightwu=parsenight(condwuparsed); - // Sunrise and Sunset - var sunrisewu=parseInt(json.sun_phase.sunrise.hour*100)+parseInt(json.sun_phase.sunrise.minute*1); - var sunsetwu=parseInt(json.sun_phase.sunset.hour*100)+parseInt(json.sun_phase.sunset.minute*1); - //if everything cached then is working - localStorage.setItem("OKAPI", 1); - console.log("OK API"); - - // Assemble dictionary - var dictionary = { - "WeatherTemp": tempwu, - "WeatherCondDay": condaywu, - "WeatherCondNight":condnightwu, - "HourSunset": sunsetwu, - "HourSunrise":sunrisewu - }; - - // Send to Pebble - Pebble.sendAppMessage(dictionary, - function(e) { - console.log("Weather from WU sent to Pebble successfully!"); - }, - function(e) { - console.log("Error sending WU info to Pebble!"); - } - ); - } - ); + xhrRequest(encodeURI(urlWU), 'GET', + function(responseText) { + // responseText contains a JSON object with weather info + var json = JSON.parse(responseText); + //Handle error in the response + localStorage.setItem("OKAPI", 0); + // Temperature + var tempf = Math.round(json.current_observation.temp_f)+"°" + units; + var tempc = Math.round(json.current_observation.temp_c)+"°" + units; + var tempwu=temptousewu(units,tempf,tempc); + // Condition + var condwu=json.current_observation.icon; + var condwuparsed=parsewu(condwu); + var condaywu=parseday(condwuparsed); + var condnightwu=parsenight(condwuparsed); + // Sunrise and Sunset + var sunrisewu=parseInt(json.sun_phase.sunrise.hour*100)+parseInt(json.sun_phase.sunrise.minute*1); + var sunsetwu=parseInt(json.sun_phase.sunset.hour*100)+parseInt(json.sun_phase.sunset.minute*1); + //if everything cached then is working + localStorage.setItem("OKAPI", 1); + console.log("OK API"); + // Assemble dictionary + var dictionary = { + "WeatherTemp": tempwu, + "WeatherCondDay": condaywu, + "WeatherCondNight":condnightwu, + "HourSunset": sunsetwu, + "HourSunrise":sunrisewu + }; + // Send to Pebble + Pebble.sendAppMessage(dictionary, + function(e) { + console.log("Weather from WU sent to Pebble successfully!"); + }, + function(e) { + console.log("Error sending WU info to Pebble!"); + } + ); + } + ); } - // Request for OWM function locationSuccessOWM(pos){ - //Request OWM + //Request OWM var lat=pos.coords.latitude; var lon= pos.coords.longitude; var settings = JSON.parse(localStorage.getItem('clay-settings')) || {}; - var keyAPI=localStorage.getItem('owmKey'); + var keyAPI=localStorage.getItem('owmKey'); var units = unitsToString(settings.WeatherUnit); var unitsOWM=unitsToStringOWM(settings.WeatherUnit); // Construct URL var urlOWM = "http://api.openweathermap.org/data/2.5/weather?lat=" + lat + "&lon=" + lon + '&appid=' + keyAPI+ - '&units='+unitsOWM; - + '&units='+unitsOWM; console.log("OWMUrl= " + urlOWM); - // Send request to OpenWeatherMap - xhrRequest(encodeURI(urlOWM), 'GET', - function(responseText) { - // responseText contains a JSON object with weather info - var json = JSON.parse(responseText); - //Handle error in the response - var error=json.cod; - if (error=="401"){ - console.log("error OWM desc:"+error); - localStorage.setItem("OKAPI", 0); - console.log("Error API"); - } - else { - localStorage.setItem("OKAPI", 1); - console.log("OK API"); - } - - // Temperature - var tempowm = Math.round(json.main.temp)+"°" + units; - // Conditions - var condowm = json.weather[0].id; - var condowmparsed=parseowm(condowm); - var condayowm=parseday(condowmparsed); - var condnightowm=parsenight(condowmparsed); - // Sunrise and Sunset - var auxsunowm =new Date(json.sys.sunrise*1000); - var sunriseowm=auxsunowm.getHours()*100+auxsunowm.getMinutes(); - var auxsetowm =new Date(json.sys.sunset*1000); - var sunsetowm=auxsetowm.getHours()*100+auxsetowm.getMinutes(); - - - // Assemble dictionary using our keys - var dictionary = { - "WeatherTemp": tempowm, - "WeatherCondDay": condayowm, - "WeatherCondNight":condnightowm, - "HourSunset": sunsetowm, - "HourSunrise":sunriseowm - }; - - // Send to Pebble - Pebble.sendAppMessage(dictionary, - function(e) { - console.log("Weather from OWM sent to Pebble successfully!"); - }, - function(e) { - console.log("Error sending OWM info to Pebble!"); - } - ); - } - ); + xhrRequest(encodeURI(urlOWM), 'GET', + function(responseText) { + // responseText contains a JSON object with weather info + var json = JSON.parse(responseText); + //Handle error in the response + var error=json.cod; + if (error=="401"){ + console.log("error OWM desc:"+error); + localStorage.setItem("OKAPI", 0); + console.log("Error API"); + } + else { + localStorage.setItem("OKAPI", 1); + console.log("OK API"); + } + // Temperature + var tempowm = Math.round(json.main.temp)+"°" + units; + // Conditions + var condowm = json.weather[0].id; + var condowmparsed=parseowm(condowm); + var condayowm=parseday(condowmparsed); + var condnightowm=parsenight(condowmparsed); + // Sunrise and Sunset + var auxsunowm =new Date(json.sys.sunrise*1000); + var sunriseowm=auxsunowm.getHours()*100+auxsunowm.getMinutes(); + var auxsetowm =new Date(json.sys.sunset*1000); + var sunsetowm=auxsetowm.getHours()*100+auxsetowm.getMinutes(); + // Assemble dictionary using our keys + var dictionary = { + "WeatherTemp": tempowm, + "WeatherCondDay": condayowm, + "WeatherCondNight":condnightowm, + "HourSunset": sunsetowm, + "HourSunrise":sunriseowm + }; + // Send to Pebble + Pebble.sendAppMessage(dictionary, + function(e) { + console.log("Weather from OWM sent to Pebble successfully!"); + }, + function(e) { + console.log("Error sending OWM info to Pebble!"); + } + ); + } + ); } - - - function locationSuccessYahoo(pos) { - var settings = JSON.parse(localStorage.getItem('clay-settings')) || {}; - var units = unitsToString(settings.WeatherUnit); - + var units = unitsToString(settings.WeatherUnit); // Construct URL - - //Get JSON from Yahoo Weather - var urlyahoo = 'https://query.yahooapis.com/v1/public/yql?q=select astronomy,item.condition ' + + //Get JSON from Yahoo Weather + var urlyahoo = 'https://query.yahooapis.com/v1/public/yql?q=select astronomy,item.condition ' + 'from weather.forecast(1) where woeid in ' + '(select woeid from geo.places(1) where ' + 'text=\'(' + pos.coords.latitude + ',' + pos.coords.longitude + ')\') and ' + - 'u=\'' + units + '\'&format=json'; - - console.log("Url is " + urlyahoo); - - + 'u=\'' + units + '\'&format=json'; + console.log("Url is " + urlyahoo); // Send request to Yahoo - xhrRequest(encodeURI(urlyahoo), 'GET', - function(responseText) { - // responseText contains a JSON object with weather info - var json = JSON.parse(responseText); - var temperature = Math.round(json.query.results.channel.item.condition.temp) +"°" + units; - // Conditions item.condition.code - var conditions = Math.round(json.query.results.channel.item.condition.code); - var condparsed=parseyahoo(conditions); - - var conday=parseday(condparsed); - var condnight=parsenight(condparsed); - - // Sunrise - var risebase=json.query.results.channel.astronomy.sunrise; - var sunrisehhmm=gettime(risebase); - - //Sunset - var setbase=json.query.results.channel.astronomy.sunset; - var sunsethhmm=gettime(setbase); - - // Assemble dictionary using our keys - var dictionary = { - "WeatherTemp": temperature, - "WeatherCondDay": conday, - "WeatherCondNight":condnight, - "HourSunset": sunsethhmm, - "HourSunrise":sunrisehhmm - }; - // Send to Pebble - Pebble.sendAppMessage(dictionary, - function(e) { - console.log("Weather info sent to Pebble successfully!"); - }, - function(e) { - console.log("Error sending weather info to Pebble!"); - } - ); - } - ); + xhrRequest(encodeURI(urlyahoo), 'GET', + function(responseText) { + // responseText contains a JSON object with weather info + var json = JSON.parse(responseText); + var temperature = Math.round(json.query.results.channel.item.condition.temp) +"°" + units; + // Conditions item.condition.code + var conditions = Math.round(json.query.results.channel.item.condition.code); + var condparsed=parseyahoo(conditions); + var conday=parseday(condparsed); + var condnight=parsenight(condparsed); + // Sunrise + var risebase=json.query.results.channel.astronomy.sunrise; + var sunrisehhmm=gettime(risebase); + //Sunset + var setbase=json.query.results.channel.astronomy.sunset; + var sunsethhmm=gettime(setbase); + // Assemble dictionary using our keys + var dictionary = { + "WeatherTemp": temperature, + "WeatherCondDay": conday, + "WeatherCondNight":condnight, + "HourSunset": sunsethhmm, + "HourSunrise":sunrisehhmm + }; + // Send to Pebble + Pebble.sendAppMessage(dictionary, + function(e) { + console.log("Weather info sent to Pebble successfully!"); + }, + function(e) { + console.log("Error sending weather info to Pebble!"); + } + ); + } + ); } function locationError(err) { - console.log("Error requesting location!"); + console.log("Error requesting location!"); } function getWeatherAtInit() { var settings = JSON.parse(localStorage.getItem('clay-settings')) || {}; var weatherprov=settings.WeatherProv; - if (weatherprov=="yahoo"){ console.log("Requesting weather from Yahoo"); - navigator.geolocation.getCurrentPosition( - locationSuccessYahoo, - locationError, - {timeout: 5000, maximumAge: 60000} - ); + navigator.geolocation.getCurrentPosition( + locationSuccessYahoo, + locationError, + {timeout: 5000, maximumAge: 60000} + ); } else if(weatherprov=="owm") { console.log("Ready from OWM"); navigator.geolocation.getCurrentPosition( - locationSuccessOWM, - locationError, - {timeout: 5000, maximumAge: 60000} - ); + locationSuccessOWM, + locationError, + {timeout: 5000, maximumAge: 60000} + ); } else if (weatherprov=="wu"){ console.log("Ready from WU"); - navigator.geolocation.getCurrentPosition( - locationSuccessWU, - locationError, - {timeout: 5000, maximumAge: 60000} - ); - } - + navigator.geolocation.getCurrentPosition( + locationSuccessWU, + locationError, + {timeout: 5000, maximumAge: 60000} + ); + } else { console.log("Requesting weather from Yahoo"); - navigator.geolocation.getCurrentPosition( - locationSuccessYahoo, - locationError, - {timeout: 5000, maximumAge: 60000} - ); + navigator.geolocation.getCurrentPosition( + locationSuccessYahoo, + locationError, + {timeout: 5000, maximumAge: 60000} + ); } } function getWeatherNow() { - // Get keys from pmkey + // Get keys from pmkey var settings = JSON.parse(localStorage.getItem('clay-settings')) || {}; var email=settings.EmailPMKEY; var pin=settings.PINPMKEY; - if (email!==undefined && pin!==undefined){ - //Request API from pmkey.xyz - var urlpmk='https://pmkey.xyz/search/?email='+email+"&pin="+pin; - console.log("Url PMKEY is "+ urlpmk); - var keys=parseInt(localStorage.getItem("OKAPI")); - console.log("Flag keys is "+keys); - if (keys===0){ - xhrRequest(encodeURI(urlpmk),'GET', - function(responseText){ - var jsonpmk=JSON.parse(responseText); - var wuKey=jsonpmk.keys.weather.wu; - var owmKey=jsonpmk.keys.weather.owm; - console.log("Success retrieving keys from pmkey.xyz. wu="+wuKey+" owm="+owmKey); - localStorage.setItem("wuKey", wuKey); - localStorage.setItem("owmKey", owmKey); - } - ); - } + if (email!==undefined && pin!==undefined){ + //Request API from pmkey.xyz + var urlpmk='https://pmkey.xyz/search/?email='+email+"&pin="+pin; + console.log("Url PMKEY is "+ urlpmk); + var keys=parseInt(localStorage.getItem("OKAPI")); + console.log("Flag keys is "+keys); + if (keys===0){ + xhrRequest(encodeURI(urlpmk),'GET', + function(responseText){ + var jsonpmk=JSON.parse(responseText); + var wuKey=jsonpmk.keys.weather.wu; + var owmKey=jsonpmk.keys.weather.owm; + console.log("Success retrieving keys from pmkey.xyz. wu="+wuKey+" owm="+owmKey); + localStorage.setItem("wuKey", wuKey); + localStorage.setItem("owmKey", owmKey); + } + ); + } } - var weatherprov=settings.WeatherProv; if (weatherprov=="yahoo"){ console.log("Requesting weather from Yahoo"); - navigator.geolocation.getCurrentPosition( - locationSuccessYahoo, - locationError, - {timeout: 5000, maximumAge: 60000} - ); + navigator.geolocation.getCurrentPosition( + locationSuccessYahoo, + locationError, + {timeout: 5000, maximumAge: 60000} + ); } else if(weatherprov=="owm") { console.log("Ready from OWM"); navigator.geolocation.getCurrentPosition( - locationSuccessOWM, - locationError, + locationSuccessOWM, + locationError, {timeout: 5000, maximumAge: 60000} - ); + ); } else if (weatherprov=="wu"){ console.log("Ready from WU"); - navigator.geolocation.getCurrentPosition( - locationSuccessWU, - locationError, - {timeout: 5000, maximumAge: 60000} - ); - } - else { + navigator.geolocation.getCurrentPosition( + locationSuccessWU, + locationError, + {timeout: 5000, maximumAge: 60000} + ); + } + else { console.log("Requesting weather from Yahoo"); - navigator.geolocation.getCurrentPosition( - locationSuccessYahoo, - locationError, - {timeout: 5000, maximumAge: 60000} - ); + navigator.geolocation.getCurrentPosition( + locationSuccessYahoo, + locationError, + {timeout: 5000, maximumAge: 60000} + ); } } - // Events to answer // Listen for when the watchface is opened -Pebble.addEventListener('ready', - function(e) { - console.log("PebbleKit JS ready!"); - localStorage.setItem("OKAPI", 0); - - var settings = JSON.parse(localStorage.getItem('clay-settings')) || {}; - var distemp = settings.DisplayTemp; - console.log("Distemp Clay is "+distemp); - - if (distemp){ - // Get the initial weather if requested - console.log("Request weather at init"); - getWeatherAtInit(); - } - else { - console.log("Weather not requested"); - // Assemble dictionary using our keys - var dictionary = { - "WeatherTemp": "", - "WeatherCondDay": "", - "WeatherCondNight":"", - "HourSunset": 700, - "HourSunrise":1700 - }; - // Send to Pebble - Pebble.sendAppMessage(dictionary, - function(e) { - console.log("Sending default keys"); - }, - function(e) { - console.log("Error sending default keys"); - } - ); - } - } -); - +Pebble.addEventListener('ready', + function(e) { + console.log("PebbleKit JS ready!"); + localStorage.setItem("OKAPI", 0); + var settings = JSON.parse(localStorage.getItem('clay-settings')) || {}; + var distemp = settings.DisplayTemp; + console.log("Distemp Clay is "+distemp); + if (distemp){ + // Get the initial weather if requested + console.log("Request weather at init"); + getWeatherAtInit(); + } + else { + console.log("Weather not requested"); + // Assemble dictionary using our keys + var dictionary = { + "WeatherTemp": "", + "WeatherCondDay": "", + "WeatherCondNight":"", + "HourSunset": 1730, + "HourSunrise":730 + }; + // Send to Pebble + Pebble.sendAppMessage(dictionary, + function(e) { + console.log("Sending default keys"); + }, + function(e) { + console.log("Error sending default keys"); + } + ); + } + } + ); // Listen for when an AppMessage is received Pebble.addEventListener('appmessage', - function(e) { - console.log("AppMessage received!"); - getWeatherNow(); - } -); - + function(e) { + console.log("AppMessage received!"); + getWeatherNow(); + } + ); Pebble.addEventListener('webviewclosed', - function(e) { - console.log("Updating config!"); - getWeatherNow(); - } -); - + function(e) { + console.log("Updating config!"); + getWeatherNow(); + } + ); // Functions - - function temptousewu(unit,tempf,tempc){ if (unit=="f"){ return tempf; } - else return tempc; + else + return tempc; } - - function unitsToStringOWM(unit) { if (unit) { return 'imperial'; @@ -378,15 +341,12 @@ function unitsToString(unit) { } return 'c'; } - - function unitsToString(unit) { if (unit) { return 'f'; } return 'c'; } - function gettime(timetoparse){ var arrayrise = timetoparse.split(" "); var aamm=arrayrise[1]; @@ -396,11 +356,11 @@ function gettime(timetoparse){ var mm=parseInt(arrayhhmm[1]); if (aamm=='am'){ if (hh==12){ - return mm; + return mm; } else { return (hh*100)+mm; - } + } } else { if (hh==12){ @@ -408,139 +368,137 @@ function gettime(timetoparse){ } else { return ((hh+12)*100)+mm; - } + } } -} - +} // Function to translate Yahoo function parseyahoo(condcode){ if (condcode===0) return 0; //Condcode is tornado - icon is tornado -else if (condcode==1) return 1; //Condcode is tropical storm - icon is day-storm-showers -else if (condcode==2) return 2; //Condcode is hurricane - icon is hurricane -else if (condcode==3) return 3; //Condcode is severe thunderstorms - icon is thunderstorm -else if (condcode==4) return 3; //Condcode is thunderstorms - icon is thunderstorm -else if (condcode==5) return 4; //Condcode is mixed rain and snow - icon is rain-mix -else if (condcode==6) return 4; //Condcode is mixed rain and sleet - icon is rain-mix -else if (condcode==7) return 4; //Condcode is mixed snow and sleet - icon is rain-mix -else if (condcode==8) return 5; //Condcode is freezing drizzle - icon is hail -else if (condcode==9) return 6; //Condcode is drizzle - icon is showers -else if (condcode==10) return 5; //Condcode is freezing rain - icon is hail -else if (condcode==11) return 6; //Condcode is showers - icon is showers -else if (condcode==12) return 23; //Condcode is showers - icon is day-rain-mix -else if (condcode==13) return 7; //Condcode is snow flurries - icon is snowflake-cold -else if (condcode==14) return 7; //Condcode is light snow showers - icon is snowflake-cold -else if (condcode==15) return 7; //Condcode is blowing snow - icon is snowflake-cold -else if (condcode==16) return 7; //Condcode is snow - icon is snowflake-cold -else if (condcode==17) return 5; //Condcode is hail - icon is hail -else if (condcode==18) return 4; //Condcode is sleet - icon is rain-mix -else if (condcode==19) return 8; //Condcode is dust - icon is dust -else if (condcode==20) return 9; //Condcode is foggy - icon is fog -else if (condcode==21) return 8; //Condcode is haze - icon is dust -else if (condcode==22) return 12; //Condcode is smoky - icon is smoke -else if (condcode==23) return 11; //Condcode is blustery - icon is strong-wind -else if (condcode==24) return 10; //Condcode is windy - icon is windy -else if (condcode==25) return 7; //Condcode is cold - icon is snowflake-cold -else if (condcode==26) return 13; //Condcode is cloudy - icon is cloudy -else if (condcode==27) return 15; //Condcode is mostly cloudy (night) - icon is night-alt-cloudy -else if (condcode==28) return 14; //Condcode is mostly cloudy (day) - icon is day-cloudy -else if (condcode==29) return 15; //Condcode is partly cloudy (night) - icon is night-alt-cloudy -else if (condcode==30) return 14; //Condcode is partly cloudy (day) - icon is day-cloudy -else if (condcode==31) return 16; //Condcode is clear (night) - icon is night-clear -else if (condcode==32) return 17; //Condcode is sunny - icon is sunny -else if (condcode==33) return 18; //Condcode is fair (night) - icon is night-alt-partly-cloudy -else if (condcode==34) return 19; //Condcode is fair (day) - icon is sunny-overcast -else if (condcode==35) return 4; //Condcode is mixed rain and hail - icon is rain-mix -else if (condcode==36) return 25; //Condcode is hot - icon is thermometer -else if (condcode==37) return 1; //Condcode is isolated thunderstorms - icon is day-storm-showers -else if (condcode==38) return 1; //Condcode is scattered thunderstorms - icon is day-storm-showers -else if (condcode==39) return 1; //Condcode is scattered thunderstorms - icon is day-storm-showers -else if (condcode==40) return 6; //Condcode is scattered showers - icon is showers -else if (condcode==41) return 7; //Condcode is heavy snow - icon is snowflake-cold -else if (condcode==42) return 7; //Condcode is scattered snow showers - icon is snowflake-cold -else if (condcode==43) return 7; //Condcode is heavy snow - icon is snowflake-cold -else if (condcode==44) return 19; //Condcode is partly cloudy - icon is sunny-overcast -else if (condcode==45) return 1; //Condcode is thundershowers - icon is day-storm-showers -else if (condcode==46) return 7; //Condcode is snow showers - icon is snowflake-cold -else if (condcode==47) return 1; //Condcode is isolated thundershowers - icon is day-storm-showers -else return 26; + else if (condcode==1) return 1; //Condcode is tropical storm - icon is day-storm-showers + else if (condcode==2) return 2; //Condcode is hurricane - icon is hurricane + else if (condcode==3) return 3; //Condcode is severe thunderstorms - icon is thunderstorm + else if (condcode==4) return 3; //Condcode is thunderstorms - icon is thunderstorm + else if (condcode==5) return 4; //Condcode is mixed rain and snow - icon is rain-mix + else if (condcode==6) return 4; //Condcode is mixed rain and sleet - icon is rain-mix + else if (condcode==7) return 4; //Condcode is mixed snow and sleet - icon is rain-mix + else if (condcode==8) return 5; //Condcode is freezing drizzle - icon is hail + else if (condcode==9) return 6; //Condcode is drizzle - icon is showers + else if (condcode==10) return 5; //Condcode is freezing rain - icon is hail + else if (condcode==11) return 6; //Condcode is showers - icon is showers + else if (condcode==12) return 23; //Condcode is showers - icon is day-rain-mix + else if (condcode==13) return 7; //Condcode is snow flurries - icon is snowflake-cold + else if (condcode==14) return 7; //Condcode is light snow showers - icon is snowflake-cold + else if (condcode==15) return 7; //Condcode is blowing snow - icon is snowflake-cold + else if (condcode==16) return 7; //Condcode is snow - icon is snowflake-cold + else if (condcode==17) return 5; //Condcode is hail - icon is hail + else if (condcode==18) return 4; //Condcode is sleet - icon is rain-mix + else if (condcode==19) return 8; //Condcode is dust - icon is dust + else if (condcode==20) return 9; //Condcode is foggy - icon is fog + else if (condcode==21) return 8; //Condcode is haze - icon is dust + else if (condcode==22) return 12; //Condcode is smoky - icon is smoke + else if (condcode==23) return 11; //Condcode is blustery - icon is strong-wind + else if (condcode==24) return 10; //Condcode is windy - icon is windy + else if (condcode==25) return 7; //Condcode is cold - icon is snowflake-cold + else if (condcode==26) return 13; //Condcode is cloudy - icon is cloudy + else if (condcode==27) return 15; //Condcode is mostly cloudy (night) - icon is night-alt-cloudy + else if (condcode==28) return 14; //Condcode is mostly cloudy (day) - icon is day-cloudy + else if (condcode==29) return 15; //Condcode is partly cloudy (night) - icon is night-alt-cloudy + else if (condcode==30) return 14; //Condcode is partly cloudy (day) - icon is day-cloudy + else if (condcode==31) return 16; //Condcode is clear (night) - icon is night-clear + else if (condcode==32) return 17; //Condcode is sunny - icon is sunny + else if (condcode==33) return 18; //Condcode is fair (night) - icon is night-alt-partly-cloudy + else if (condcode==34) return 19; //Condcode is fair (day) - icon is sunny-overcast + else if (condcode==35) return 4; //Condcode is mixed rain and hail - icon is rain-mix + else if (condcode==36) return 25; //Condcode is hot - icon is thermometer + else if (condcode==37) return 1; //Condcode is isolated thunderstorms - icon is day-storm-showers + else if (condcode==38) return 1; //Condcode is scattered thunderstorms - icon is day-storm-showers + else if (condcode==39) return 1; //Condcode is scattered thunderstorms - icon is day-storm-showers + else if (condcode==40) return 6; //Condcode is scattered showers - icon is showers + else if (condcode==41) return 7; //Condcode is heavy snow - icon is snowflake-cold + else if (condcode==42) return 7; //Condcode is scattered snow showers - icon is snowflake-cold + else if (condcode==43) return 7; //Condcode is heavy snow - icon is snowflake-cold + else if (condcode==44) return 19; //Condcode is partly cloudy - icon is sunny-overcast + else if (condcode==45) return 1; //Condcode is thundershowers - icon is day-storm-showers + else if (condcode==46) return 7; //Condcode is snow showers - icon is snowflake-cold + else if (condcode==47) return 1; //Condcode is isolated thundershowers - icon is day-storm-showers + else return 26; } - -// Function to return condition values from OWM +// Function to return condition values from OWM function parseowm(condcode){ -if (condcode==200) return 1; //Condcode is thunderstorm with light rain - icon is day-storm-showers -else if (condcode==201) return 3; //Condcode is thunderstorm with rain - icon is thunderstorm -else if (condcode==202) return 3; //Condcode is thunderstorm with heavy rain - icon is thunderstorm -else if (condcode==210) return 1; //Condcode is light thunderstorm - icon is day-storm-showers -else if (condcode==211) return 3; //Condcode is thunderstorm - icon is thunderstorm -else if (condcode==212) return 3; //Condcode is heavy thunderstorm - icon is thunderstorm -else if (condcode==221) return 1; //Condcode is ragged thunderstorm - icon is day-storm-showers -else if (condcode==230) return 1; //Condcode is thunderstorm with light drizzle - icon is day-storm-showers -else if (condcode==231) return 1; //Condcode is thunderstorm with drizzle - icon is day-storm-showers -else if (condcode==232) return 3; //Condcode is thunderstorm with heavy drizzle - icon is thunderstorm -else if (condcode==300) return 23; //Condcode is light intensity drizzle - icon is day-rain-mix -else if (condcode==301) return 5; //Condcode is drizzle - icon is hail -else if (condcode==302) return 5; //Condcode is heavy intensity drizzle - icon is hail -else if (condcode==310) return 23; //Condcode is light intensity drizzle rain - icon is day-rain-mix -else if (condcode==311) return 5; //Condcode is drizzle rain - icon is hail -else if (condcode==312) return 5; //Condcode is heavy intensity drizzle rain - icon is hail -else if (condcode==313) return 5; //Condcode is shower rain and drizzle - icon is hail -else if (condcode==314) return 5; //Condcode is heavy shower rain and drizzle - icon is hail -else if (condcode==321) return 5; //Condcode is shower drizzle - icon is hail -else if (condcode==500) return 23; //Condcode is light rain - icon is day-rain-mix -else if (condcode==501) return 6; //Condcode is moderate rain - icon is showers -else if (condcode==502) return 6; //Condcode is heavy intensity rain - icon is showers -else if (condcode==503) return 6; //Condcode is very heavy rain - icon is showers -else if (condcode==504) return 6; //Condcode is extreme rain - icon is showers -else if (condcode==511) return 5; //Condcode is freezing rain - icon is hail -else if (condcode==520) return 23; //Condcode is light intensity shower rain - icon is day-rain-mix -else if (condcode==521) return 6; //Condcode is shower rain - icon is showers -else if (condcode==522) return 6; //Condcode is heavy intensity shower rain - icon is showers -else if (condcode==531) return 6; //Condcode is ragged shower rain - icon is showers -else if (condcode==600) return 7; //Condcode is light snow - icon is snowflake-cold -else if (condcode==601) return 7; //Condcode is snow - icon is snowflake-cold -else if (condcode==602) return 7; //Condcode is heavy snow - icon is snowflake-cold -else if (condcode==611) return 4; //Condcode is sleet - icon is rain-mix -else if (condcode==612) return 4; //Condcode is shower sleet - icon is rain-mix -else if (condcode==615) return 4; //Condcode is light rain and snow - icon is rain-mix -else if (condcode==616) return 7; //Condcode is rain and snow - icon is snowflake-cold -else if (condcode==620) return 4; //Condcode is light shower snow - icon is rain-mix -else if (condcode==621) return 7; //Condcode is shower snow - icon is snowflake-cold -else if (condcode==622) return 7; //Condcode is heavy shower snow - icon is snowflake-cold -else if (condcode==701) return 9; //Condcode is mist - icon is fog -else if (condcode==711) return 12; //Condcode is smoke - icon is smoke -else if (condcode==721) return 10; //Condcode is haze - icon is windy -else if (condcode==731) return 8; //Condcode is sand, dust whirls - icon is dust -else if (condcode==741) return 9; //Condcode is fog - icon is fog -else if (condcode==751) return 8; //Condcode is sand - icon is dust -else if (condcode==761) return 8; //Condcode is dust - icon is dust -else if (condcode==762) return 8; //Condcode is volcanic ash - icon is dust -else if (condcode==771) return 1; //Condcode is squalls - icon is day-storm-showers -else if (condcode==781) return 0; //Condcode is tornado - icon is tornado -else if (condcode==800) return 17; //Condcode is clear sky - icon is sunny -else if (condcode==801) return 19; //Condcode is few clouds - icon is sunny-overcast -else if (condcode==802) return 14; //Condcode is scattered clouds - icon is day-cloudy -else if (condcode==803) return 13; //Condcode is broken clouds - icon is cloudy -else if (condcode==804) return 13; //Condcode is overcast clouds - icon is cloudy -else if (condcode==900) return 0; //Condcode is tornado - icon is tornado -else if (condcode==901) return 1; //Condcode is tropical storm - icon is day-storm-showers -else if (condcode==902) return 2; //Condcode is hurricane - icon is hurricane -else if (condcode==903) return 7; //Condcode is cold - icon is snowflake-cold -else if (condcode==904) return 25; //Condcode is hot - icon is thermometer -else if (condcode==905) return 11; //Condcode is windy - icon is strong-wind -else if (condcode==906) return 5; //Condcode is hail - icon is hail -else if (condcode==951) return 17; //Condcode is calm - icon is sunny -else if (condcode==952) return 10; //Condcode is light breeze - icon is windy -else if (condcode==953) return 10; //Condcode is gentle breeze - icon is windy -else if (condcode==954) return 10; //Condcode is moderate breeze - icon is windy -else if (condcode==955) return 11; //Condcode is fresh breeze - icon is strong-wind -else if (condcode==956) return 11; //Condcode is strong breeze - icon is strong-wind -else if (condcode==957) return 11; //Condcode is high wind, near gale - icon is strong-wind -else if (condcode==958) return 11; //Condcode is gale - icon is strong-wind -else if (condcode==959) return 11; //Condcode is severe gale - icon is strong-wind -else if (condcode==960) return 1; //Condcode is storm - icon is day-storm-showers -else if (condcode==961) return 1; //Condcode is violent storm - icon is day-storm-showers -else if (condcode==962) return 2; //Condcode is hurricane - icon is hurricane -else return 26; + if (condcode==200) return 1; //Condcode is thunderstorm with light rain - icon is day-storm-showers + else if (condcode==201) return 3; //Condcode is thunderstorm with rain - icon is thunderstorm + else if (condcode==202) return 3; //Condcode is thunderstorm with heavy rain - icon is thunderstorm + else if (condcode==210) return 1; //Condcode is light thunderstorm - icon is day-storm-showers + else if (condcode==211) return 3; //Condcode is thunderstorm - icon is thunderstorm + else if (condcode==212) return 3; //Condcode is heavy thunderstorm - icon is thunderstorm + else if (condcode==221) return 1; //Condcode is ragged thunderstorm - icon is day-storm-showers + else if (condcode==230) return 1; //Condcode is thunderstorm with light drizzle - icon is day-storm-showers + else if (condcode==231) return 1; //Condcode is thunderstorm with drizzle - icon is day-storm-showers + else if (condcode==232) return 3; //Condcode is thunderstorm with heavy drizzle - icon is thunderstorm + else if (condcode==300) return 23; //Condcode is light intensity drizzle - icon is day-rain-mix + else if (condcode==301) return 5; //Condcode is drizzle - icon is hail + else if (condcode==302) return 5; //Condcode is heavy intensity drizzle - icon is hail + else if (condcode==310) return 23; //Condcode is light intensity drizzle rain - icon is day-rain-mix + else if (condcode==311) return 5; //Condcode is drizzle rain - icon is hail + else if (condcode==312) return 5; //Condcode is heavy intensity drizzle rain - icon is hail + else if (condcode==313) return 5; //Condcode is shower rain and drizzle - icon is hail + else if (condcode==314) return 5; //Condcode is heavy shower rain and drizzle - icon is hail + else if (condcode==321) return 5; //Condcode is shower drizzle - icon is hail + else if (condcode==500) return 23; //Condcode is light rain - icon is day-rain-mix + else if (condcode==501) return 6; //Condcode is moderate rain - icon is showers + else if (condcode==502) return 6; //Condcode is heavy intensity rain - icon is showers + else if (condcode==503) return 6; //Condcode is very heavy rain - icon is showers + else if (condcode==504) return 6; //Condcode is extreme rain - icon is showers + else if (condcode==511) return 5; //Condcode is freezing rain - icon is hail + else if (condcode==520) return 23; //Condcode is light intensity shower rain - icon is day-rain-mix + else if (condcode==521) return 6; //Condcode is shower rain - icon is showers + else if (condcode==522) return 6; //Condcode is heavy intensity shower rain - icon is showers + else if (condcode==531) return 6; //Condcode is ragged shower rain - icon is showers + else if (condcode==600) return 7; //Condcode is light snow - icon is snowflake-cold + else if (condcode==601) return 7; //Condcode is snow - icon is snowflake-cold + else if (condcode==602) return 7; //Condcode is heavy snow - icon is snowflake-cold + else if (condcode==611) return 4; //Condcode is sleet - icon is rain-mix + else if (condcode==612) return 4; //Condcode is shower sleet - icon is rain-mix + else if (condcode==615) return 4; //Condcode is light rain and snow - icon is rain-mix + else if (condcode==616) return 7; //Condcode is rain and snow - icon is snowflake-cold + else if (condcode==620) return 4; //Condcode is light shower snow - icon is rain-mix + else if (condcode==621) return 7; //Condcode is shower snow - icon is snowflake-cold + else if (condcode==622) return 7; //Condcode is heavy shower snow - icon is snowflake-cold + else if (condcode==701) return 9; //Condcode is mist - icon is fog + else if (condcode==711) return 12; //Condcode is smoke - icon is smoke + else if (condcode==721) return 10; //Condcode is haze - icon is windy + else if (condcode==731) return 8; //Condcode is sand, dust whirls - icon is dust + else if (condcode==741) return 9; //Condcode is fog - icon is fog + else if (condcode==751) return 8; //Condcode is sand - icon is dust + else if (condcode==761) return 8; //Condcode is dust - icon is dust + else if (condcode==762) return 8; //Condcode is volcanic ash - icon is dust + else if (condcode==771) return 1; //Condcode is squalls - icon is day-storm-showers + else if (condcode==781) return 0; //Condcode is tornado - icon is tornado + else if (condcode==800) return 17; //Condcode is clear sky - icon is sunny + else if (condcode==801) return 19; //Condcode is few clouds - icon is sunny-overcast + else if (condcode==802) return 14; //Condcode is scattered clouds - icon is day-cloudy + else if (condcode==803) return 13; //Condcode is broken clouds - icon is cloudy + else if (condcode==804) return 13; //Condcode is overcast clouds - icon is cloudy + else if (condcode==900) return 0; //Condcode is tornado - icon is tornado + else if (condcode==901) return 1; //Condcode is tropical storm - icon is day-storm-showers + else if (condcode==902) return 2; //Condcode is hurricane - icon is hurricane + else if (condcode==903) return 7; //Condcode is cold - icon is snowflake-cold + else if (condcode==904) return 25; //Condcode is hot - icon is thermometer + else if (condcode==905) return 11; //Condcode is windy - icon is strong-wind + else if (condcode==906) return 5; //Condcode is hail - icon is hail + else if (condcode==951) return 17; //Condcode is calm - icon is sunny + else if (condcode==952) return 10; //Condcode is light breeze - icon is windy + else if (condcode==953) return 10; //Condcode is gentle breeze - icon is windy + else if (condcode==954) return 10; //Condcode is moderate breeze - icon is windy + else if (condcode==955) return 11; //Condcode is fresh breeze - icon is strong-wind + else if (condcode==956) return 11; //Condcode is strong breeze - icon is strong-wind + else if (condcode==957) return 11; //Condcode is high wind, near gale - icon is strong-wind + else if (condcode==958) return 11; //Condcode is gale - icon is strong-wind + else if (condcode==959) return 11; //Condcode is severe gale - icon is strong-wind + else if (condcode==960) return 1; //Condcode is storm - icon is day-storm-showers + else if (condcode==961) return 1; //Condcode is violent storm - icon is day-storm-showers + else if (condcode==962) return 2; //Condcode is hurricane - icon is hurricane + else return 26; } // Function to translate wu function parsewu(condcode){ @@ -571,7 +529,7 @@ function parsewu(condcode){ else if (condcode=='unknown') return 26; //Condcode is Unknown - icon is na else if (condcode=='cloudy') return 13; //Condcode is Overcast - icon is cloudy else if (condcode=='partlycloudy') return 19; //Condcode is Scattered Clouds - icon is sunny-overcast - else return 26; + else return 26; } function parseday(condnum){ if (condnum===0) return "a"; //tornado @@ -629,6 +587,5 @@ function parsenight(condnum){ else if (condnum===23) return "y"; //night-alt-rain-mix else if (condnum===24) return "y"; //night-alt-rain-mix else if (condnum===25) return "z"; //thermometer - else if (condnum===26) return "0"; //na -} - + else if (condnum===26) return "0"; //na +} \ No newline at end of file diff --git a/src/pkjs/config.js b/src/pkjs/config.js index c2e6f98..e6c733d 100644 --- a/src/pkjs/config.js +++ b/src/pkjs/config.js @@ -186,7 +186,7 @@ module.exports = [ }, { "type": "heading", - "defaultValue": "Version v6.2 ", + "defaultValue": "Version v6.3 ", "size":6 } , {