Skip to content
This repository has been archived by the owner on Nov 26, 2022. It is now read-only.

Commit

Permalink
v6.7
Browse files Browse the repository at this point in the history
Fuzzy mode fixed
  • Loading branch information
dieghernan committed May 2, 2017
1 parent d5eb82b commit e8f76eb
Show file tree
Hide file tree
Showing 19 changed files with 96 additions and 338 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"pebble-clay": "^1.0.1"
},
"keywords": [],
"name": "testwatch-clima",
"name": "testanim6",
"pebble": {
"capabilities": [
"location",
"configurable"
],
"displayName": "TextWatch Clima",
"displayName": "testanim6",
"enableMultiJS": true,
"messageKeys": [
"ForegroundColor",
Expand Down Expand Up @@ -149,5 +149,5 @@
"watchface": true
}
},
"version": "6.6.0"
"version": "6.7.0"
}
212 changes: 73 additions & 139 deletions src/c/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ static GFont FontSymbol;
//Others
PropertyAnimation *scroll_down;
PropertyAnimation *scroll_up;
static bool PoppedDownNow;
static bool PoppedDownAtInit;
static bool AtInit;
static bool PopUpNow=false;
GRect bounds;
static int offsetpebble, s_loop,s_countdown;
static int mast_hour, mast_min, mast_mon, mast_wday, mast_day;
//////Init Configuration///
//Init Clay
ClaySettings settings;
Expand Down Expand Up @@ -133,33 +134,6 @@ void writedatelang(int week,int Mon,int Day, char* iterwd,char * iterdat, char *
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);
}
else if (Lang_2==3){ //German
Animations_DE(minute_2, LenB1, LenN1, LenA1);
}
else if (Lang_2==4){ //French
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);
}
else if (Lang_2==7){ //Norwegian
Animations_NN(minute_2, LenB1, LenN1, LenA1);
}
else if (Lang_2==8){ //Danish
Animations_DK(minute_2, LenB1, LenN1, LenA1);
}
}
//////End Lang Selector///
//////Define Function ///
static int limit(int nline){
Expand Down Expand Up @@ -194,7 +168,7 @@ static GColor ColorSelect(bool isactive, bool gpsstate, bool isnight, GColor Col
}
//////End Function ///
////Init: Animations procs//
void makeScrollUp(struct tm *t){
void makeScrollUpNow(){
GRect from = layer_get_bounds((Layer *)scroll);
GRect to = layer_get_bounds((Layer *)scroll);
GRect rect = layer_get_bounds((Layer *)scroll);
Expand All @@ -208,35 +182,14 @@ void makeScrollUp(struct tm *t){
}
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);
animation_schedule(property_animation_get_animation(scroll_down));
// reset PoppedDown indicator
PoppedDownNow = false;
animation_schedule(property_animation_get_animation(scroll_down));
}
void makeScrollUpNow(){
void makeScrollDown(){
GRect from = 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 {
from.origin.y = 21;
to.origin.y = 0;
}
scroll_down = property_animation_create_layer_frame((Layer *)scroll, &from, &to);
animation_set_duration(property_animation_get_animation(scroll_down), 400);
animation_set_curve(property_animation_get_animation(scroll_down), AnimationCurveEaseOut);
animation_schedule(property_animation_get_animation(scroll_down));
// reset PoppedDown indicator
PoppedDownNow = false;
}
void makeScrollDown(){
GRect from = layer_get_bounds((Layer *)scroll);
GRect to = layer_get_bounds((Layer *)scroll);
if(PoppedDownAtInit == true){
from.origin.y = -21;
to.origin.y = 0;
}
Expand All @@ -248,7 +201,7 @@ void makeScrollDown(){
animation_set_duration(property_animation_get_animation(scroll_down), 800);
animation_set_delay(property_animation_get_animation(scroll_down), 600);
animation_set_curve(property_animation_get_animation(scroll_down), AnimationCurveEaseOut);
animation_schedule(property_animation_get_animation(scroll_down));
animation_schedule(property_animation_get_animation(scroll_down));
}
// Text Animation handler
void animationStoppedHandler(struct Animation *animation, bool finished, void *context) {
Expand All @@ -267,12 +220,19 @@ void makeAnimationsForLayers(Line *line, TextLayer *current, TextLayer *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);
if (PopUpNow){
animation_set_delay(property_animation_get_animation(line->nextAnimation), 1000);
}

animation_set_curve(property_animation_get_animation(line->nextAnimation), AnimationCurveEaseOut);
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);
if (PopUpNow){
animation_set_delay(property_animation_get_animation(line->currentAnimation), 1000);
}
animation_set_curve(property_animation_get_animation(line->currentAnimation), AnimationCurveEaseOut);
animation_set_handlers(property_animation_get_animation(line->currentAnimation), (AnimationHandlers) {
.stopped = (AnimationStoppedHandler)animationStoppedHandler},
Expand Down Expand Up @@ -402,14 +362,33 @@ void configureLineLayer(TextLayer *textlayer) {
////End: Layer formatting//
///// Init: Updating time and date////
// Update screen based on new time
void display_time(struct tm *t, int atinit) {
void display_animated(){
// 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;
// Language settings
writetimeto3words(t->tm_hour, t->tm_min, &LineToPutinBold, textLine1, textLine2, textLine3,settings.LangKey);
writetimeto3words(mast_hour, mast_min, &LineToPutinBold, textLine1, textLine2, textLine3,settings.LangKey);
// Set Up and Down animations
int LBef=strlen(textbefore3);
int Lnow=strlen(textLine3);
// Animations
if (AtInit){
if (Lnow==0){
makePopDown();
}
}
else if(LBef>0 && Lnow==0 ){
APP_LOG(APP_LOG_LEVEL_DEBUG, "Scroll Down LB %d SB %s LN %d SN %s", LBef,textbefore3,Lnow,textLine3);
makeScrollDown();
}
else if(LBef==0 && Lnow > 0 ){
APP_LOG(APP_LOG_LEVEL_DEBUG, "Scroll UP LB %d SB %s LN %d SN %s", LBef,textbefore3,Lnow,textLine3);
PopUpNow=true;
makeScrollUpNow();
}
AtInit=false;
//Update lines
if (checkupdate(textbefore1,textLine1)) {
updateLineTo(&line1, line1Str, textLine1,1,LineToPutinBold);
Expand All @@ -420,12 +399,41 @@ 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);
PopUpNow=false;
}
void timetoclock(bool isfuzzy){
time_t now = time(NULL);
struct tm *t = localtime(&now);
int minaux;
minaux=t->tm_min;
if (isfuzzy){
if (minaux >= 58){
mast_hour=t->tm_hour+1;
mast_min=0;
}
else {
mast_hour=t->tm_hour;
minaux=minaux+2;
minaux=minaux/5;
mast_min=5*minaux;
}
}
else {
mast_hour=t->tm_hour;
mast_min=t->tm_min;
}
mast_mon=t->tm_mon;
mast_day=t->tm_mday;
mast_wday=t->tm_wday;
display_animated();
}
// Update graphics when timer ticks
static void time_timer_tick(struct tm *t, TimeUnits units_changed) {
timetoclock(settings.FuzzyMode);
if (units_changed & MINUTE_UNIT ) {
layer_mark_dirty(back_layer);
}
Expand Down Expand Up @@ -468,25 +476,6 @@ static void time_timer_tick(struct tm *t, TimeUnits units_changed) {
layer_mark_dirty(back_layer);
TextColorFormatting();
}
// 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 ){
if(PoppedDownNow == false){
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);
Expand Down Expand Up @@ -520,10 +509,8 @@ static void back_update_proc(Layer *layer, GContext *ctx) {
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);
writedatelang(mast_wday,mast_mon,mast_day, 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);
Expand All @@ -543,7 +530,7 @@ 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);
int offsety=PBL_IF_ROUND_ELSE(5, 10);

int offsetconnect;
if (!settings.BTOn || !settings.GPSOn){
Expand Down Expand Up @@ -611,33 +598,8 @@ static void prv_load_settings() {
persist_read_data(SETTINGS_KEY, &settings, sizeof(settings));
}
// Save the settings to persistent storage
static void prv_save_settings(int ChangeLang, int LangBefore) {
static void prv_save_settings() {
persist_write_data(SETTINGS_KEY, &settings, sizeof(settings));
time_t now = time(NULL);
struct tm *t = localtime(&now);
// Content of line 3 now
int Del1=0;
int Del2=0;
int LenBeforeSave=0;
animationslan(t->tm_min, &Del1, &LenBeforeSave, &Del2,LangBefore);
// Adjust animations to fit the change of language - study how long will be line 3 after change language
int LenAfterSave=0;
animationslan(t->tm_min, &Del1, &LenAfterSave, &Del2,settings.LangKey);
//Update text if language has changed
//Adjust position using animations
if (ChangeLang>0){
if (LenBeforeSave==0 && LenAfterSave != 0){
// Scroll up if before were 2 lines and after 3 lines
makeScrollUpNow() ;
}
// Display time
display_time(t,1);
if (LenBeforeSave>0 && LenAfterSave == 0){
// Pop down if before were 3 lines and now 2 lines
makeScrollDown();
}
}
display_time(t,1);
}
// Handle the response from AppMessage
static void prv_inbox_received_handler(DictionaryIterator *iter, void *context) {
Expand Down Expand Up @@ -748,13 +710,11 @@ static void prv_inbox_received_handler(DictionaryIterator *iter, void *context)
}
//End data gathered
// Store language applied before refreshing
int LangBefSave=settings.LangKey;
// Language
Tuple *lang_t=dict_find(iter, MESSAGE_KEY_Lang);
if (lang_t){
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){
Expand All @@ -763,16 +723,9 @@ static void prv_inbox_received_handler(DictionaryIterator *iter, void *context)
//Update colors
TextColorFormatting();
layer_mark_dirty(back_layer);
// 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);
timetoclock(settings.FuzzyMode);
// Save the new settings to persistent storage
prv_save_settings(LangChanged,LangBefSave);
prv_save_settings();
}
////End: Handle Settings and Weather////
////Init: Creating Watchface/////
Expand Down Expand Up @@ -842,28 +795,9 @@ void main_window_push() {
layer_add_child(scroll, (Layer *)line3.currentLayer);
layer_add_child(scroll, (Layer *)line3.nextLayer);
TextColorFormatting();
text_layer_set_text(line1.currentLayer, "Loading...");
// Configure text time on init
time_t now = time(NULL);
struct tm *t = localtime(&now);
display_time(t,1);
// initialize PoppedDown indicators
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 Del1=0;
int Del2=0;
animationslan(t->tm_min, &Del1, &LenInit_END, &Del2, settings.LangKey);
// Check Line3 at init
if(LenInit_END == 0 ){
makePopDown();
// signal that this has been done, so an extra animation isn't triggered, and the down animation knows the right
// starting place
PoppedDownNow = true;
PoppedDownAtInit = true;
}
AtInit=true;
timetoclock(settings.FuzzyMode);
// Configure main window
window_set_window_handlers(s_main_window, (WindowHandlers) {
.load = prv_window_load,
Expand Down
Loading

0 comments on commit e8f76eb

Please sign in to comment.