Skip to content

Commit

Permalink
Merge v1.12.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mattrossman committed Mar 1, 2020
2 parents 754779c + 9cda596 commit 79a76c4
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 22 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ForecasWatch 2",
"author": "Matt Rossman",
"version": "1.11.0",
"version": "1.12.0",
"keywords": ["pebble-app"],
"private": true,
"dependencies": {},
Expand Down Expand Up @@ -68,7 +68,8 @@
"CLAY_SHOW_QT",
"CLAY_SHOW_BT",
"CLAY_SHOW_BT_DISCONNECT",
"CLAY_VIBE"
"CLAY_VIBE",
"CLAY_SHOW_AM_PM"
]
}
}
7 changes: 5 additions & 2 deletions src/c/appendix/app_message.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ static void inbox_received_callback(DictionaryIterator *iterator, void *context)
Tuple *clay_show_qt_tuple = dict_find(iterator, MESSAGE_KEY_CLAY_SHOW_QT);
Tuple *clay_show_bt_tuple = dict_find(iterator, MESSAGE_KEY_CLAY_SHOW_BT);
Tuple *clay_show_bt_disconnect_tuple = dict_find(iterator, MESSAGE_KEY_CLAY_SHOW_BT_DISCONNECT);
Tuple *clay_show_am_pm_tuple = dict_find(iterator, MESSAGE_KEY_CLAY_SHOW_AM_PM);

if(temp_trend_tuple && temp_trend_tuple && forecast_start_tuple && num_entries_tuple && city_tuple && sun_events_tuple) {
// Weather data received
Expand All @@ -54,7 +55,7 @@ static void inbox_received_callback(DictionaryIterator *iterator, void *context)
weather_status_layer_refresh();
}
if (clay_celsius_tuple && clay_axis_12h_tuple && clay_start_mon_tuple && clay_prev_week_tuple && clay_color_today_tuple
&& clay_show_qt_tuple && clay_show_bt_tuple && clay_show_bt_disconnect_tuple) {
&& clay_show_qt_tuple && clay_show_bt_tuple && clay_show_bt_disconnect_tuple && clay_show_am_pm_tuple) {
// Clay config data received
bool clay_celsius = (bool) (clay_celsius_tuple->value->int16);
bool time_lead_zero = (bool) (clay_time_lead_zero_tuple->value->int16);
Expand All @@ -64,6 +65,7 @@ static void inbox_received_callback(DictionaryIterator *iterator, void *context)
bool show_qt = (bool) (clay_show_qt_tuple->value->int16);
bool show_bt = (bool) (clay_show_bt_tuple->value->int16);
bool show_bt_disconnect = (bool) (clay_show_bt_disconnect_tuple->value->int16);
bool show_am_pm = (bool) (clay_show_am_pm_tuple->value->int16);
int16_t time_font = clay_time_font_tuple->value->int16;
GColor color_today = GColorFromHEX(clay_color_today_tuple->value->int32);
Config config = (Config) {
Expand All @@ -76,7 +78,8 @@ static void inbox_received_callback(DictionaryIterator *iterator, void *context)
.color_today = color_today,
.show_qt = show_qt,
.show_bt = show_bt,
.show_bt_disconnect = show_bt_disconnect
.show_bt_disconnect = show_bt_disconnect,
.show_am_pm = show_am_pm
};
persist_set_config(config);
main_window_refresh();
Expand Down
6 changes: 6 additions & 0 deletions src/c/appendix/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ void config_load() {
persist_get_config(g_config);
}

void config_refresh() {
free(g_config); // Clear out the old config
g_config = (Config*) malloc(sizeof(Config));
persist_get_config(g_config); // Then reload
}

void config_unload() {
free(g_config);
}
Expand Down
3 changes: 3 additions & 0 deletions src/c/appendix/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ typedef struct {
bool show_bt;
bool show_bt_disconnect;
bool vibe;
bool show_am_pm;
int16_t time_font;
GColor color_today;
} Config;
Expand All @@ -20,6 +21,8 @@ Config *g_config;

void config_load();

void config_refresh();

void config_unload();

int config_localize_temp(int temp_f);
Expand Down
5 changes: 3 additions & 2 deletions src/c/appendix/persist.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ void persist_init() {
.show_qt = true,
.show_bt = true,
.show_bt_disconnect = true,
.vibe = false
.vibe = false,
.show_am_pm = false
};
persist_set_config(config);
}
Expand Down Expand Up @@ -144,5 +145,5 @@ void persist_set_sun_event_times(time_t *data, const size_t size) {

void persist_set_config(Config config) {
persist_write_data(CONFIG, &config, sizeof(Config));
config_load(); // Refresh global config variable
config_refresh(); // Refresh global config variable
}
56 changes: 44 additions & 12 deletions src/c/layers/time_layer.c
Original file line number Diff line number Diff line change
@@ -1,21 +1,38 @@
#include "time_layer.h"
#include "c/appendix/config.h"

static Layer *s_container_layer;
// MT = Margin Top
#define MT_TIME 14
#define MT_AM_PM 7


static TextLayer *s_container_layer;
static TextLayer *s_time_layer;
static TextLayer *s_am_pm_layer;

void time_layer_create(Layer* parent_layer, GRect frame) {
s_container_layer = layer_create(frame);
s_container_layer = text_layer_create(frame);
s_time_layer = text_layer_create(GRect(0, 0, frame.size.w, frame.size.h));
// Improve the layout to be more like a watchface
s_am_pm_layer = text_layer_create(GRect(0, 0, 30, frame.size.h));

text_layer_set_background_color(s_container_layer, GColorClear);

// Main time formatting
text_layer_set_background_color(s_time_layer, GColorClear);
text_layer_set_text_color(s_time_layer, GColorWhite);
text_layer_set_text(s_time_layer, "00:00");
text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter);
text_layer_set_text_alignment(s_time_layer, GTextAlignmentLeft);

// Add it as a child layer to the Window's root layer
layer_add_child(s_container_layer, text_layer_get_layer(s_time_layer));
layer_add_child(parent_layer, s_container_layer);
// AM/PM formatting
text_layer_set_font(s_am_pm_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18));
text_layer_set_background_color(s_am_pm_layer, GColorClear);
text_layer_set_text_color(s_am_pm_layer, GColorWhite);
text_layer_set_text(s_am_pm_layer, "PM");
text_layer_set_text_alignment(s_am_pm_layer, GTextAlignmentLeft);

layer_add_child(text_layer_get_layer(s_container_layer), text_layer_get_layer(s_time_layer));
layer_add_child(text_layer_get_layer(s_time_layer), text_layer_get_layer(s_am_pm_layer));
layer_add_child(parent_layer, text_layer_get_layer(s_container_layer));

}

Expand All @@ -36,21 +53,36 @@ void time_layer_tick() {
static char s_buffer[8];
config_format_time(s_buffer, 8, tick_time);

// Display this time on the TextLayer
// Update the time and AM/PM indicator
text_layer_set_text(s_time_layer, s_buffer);
if (g_config->show_am_pm)
text_layer_set_text(s_am_pm_layer, tick_time->tm_hour < 12 ? "AM" : "PM");
}

void time_layer_refresh() {
time_layer_tick(); // Update time text

// Set up font and its positioning
text_layer_set_font(s_time_layer, config_time_font());
GRect bounds = layer_get_bounds(text_layer_get_layer(s_container_layer));
text_layer_move_frame(s_time_layer, GRect(0, 0, bounds.size.w, bounds.size.h)); // Reset for size calculation
GSize time_size = text_layer_get_content_size(s_time_layer);
GRect bounds = layer_get_bounds(s_container_layer);
text_layer_move_frame(s_time_layer, GRect(0, (49 - time_size.h) / 2, bounds.size.w, bounds.size.h));
GSize am_pm_size = text_layer_get_content_size(s_am_pm_layer);

// Calculate some landmarks
int content_w = time_size.w + (g_config->show_am_pm ? am_pm_size.w : 0);
int text_h = time_size.h - MT_TIME; // Remove top margin, approximately
int text_top = -MT_TIME + (bounds.size.h/2 - text_h/2);
int text_left = bounds.size.w / 2 - content_w / 2;

time_layer_tick();
// Update layer positions and visibility
text_layer_move_frame(s_time_layer, GRect(text_left, text_top, content_w, time_size.h));
if (g_config->show_am_pm)
text_layer_move_frame(s_am_pm_layer, GRect(time_size.w, MT_TIME - MT_AM_PM, 30, time_size.h));
layer_set_hidden(text_layer_get_layer(s_am_pm_layer), !g_config->show_am_pm);
}

void time_layer_destroy() {
text_layer_destroy(s_time_layer);
layer_destroy(s_container_layer);
text_layer_destroy(s_container_layer);
}
5 changes: 2 additions & 3 deletions src/c/windows/main_window.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

#define FORECAST_HEIGHT 51
#define WEATHER_STATUS_HEIGHT 14
#define TIME_HEIGHT 50
#define TIME_MARGIN_BOTTOM 5
#define TIME_HEIGHT 45
#define CALENDAR_HEIGHT 45
#define CALENDAR_STATUS_HEIGHT 13

Expand All @@ -29,7 +28,7 @@ static void main_window_load(Window *window) {
weather_status_layer_create(window_layer,
GRect(0, h - FORECAST_HEIGHT - WEATHER_STATUS_HEIGHT, w, WEATHER_STATUS_HEIGHT));
time_layer_create(window_layer,
GRect(0, h - FORECAST_HEIGHT - WEATHER_STATUS_HEIGHT - TIME_HEIGHT - TIME_MARGIN_BOTTOM,
GRect(0, h - FORECAST_HEIGHT - WEATHER_STATUS_HEIGHT - TIME_HEIGHT,
bounds.size.w, TIME_HEIGHT));
calendar_layer_create(window_layer,
GRect(0, CALENDAR_STATUS_HEIGHT, bounds.size.w, CALENDAR_HEIGHT));
Expand Down
5 changes: 5 additions & 0 deletions src/pkjs/clay/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ module.exports = [
"label": "Leading zero",
"messageKey": "timeLeadingZero",
},
{
"type": "toggle",
"label": "Show AM/PM",
"messageKey": "timeShowAmPm",
},
{
"type": "select",
"label": "Axis time format",
Expand Down
3 changes: 2 additions & 1 deletion src/pkjs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ function sendClaySettings() {
"CLAY_SHOW_QT": app.settings.showQt,
"CLAY_SHOW_BT": app.settings.btIcons === "connected" || app.settings.btIcons === "both",
"CLAY_SHOW_BT_DISCONNECT": app.settings.btIcons === "disconnected" || app.settings.btIcons === "both",
"CLAY_VIBE": app.settings.vibe
"CLAY_VIBE": app.settings.vibe,
"CLAY_SHOW_AM_PM": app.settings.timeShowAmPm,
}
Pebble.sendAppMessage(payload, function() {
console.log('Message sent successfully: ' + JSON.stringify(payload));
Expand Down

0 comments on commit 79a76c4

Please sign in to comment.