Skip to content

Commit

Permalink
Merge v1.11.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mattrossman committed Feb 29, 2020
2 parents 057c4f2 + b932d71 commit 754779c
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 96 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ForecasWatch 2",
"author": "Matt Rossman",
"version": "1.10.0",
"version": "1.11.0",
"keywords": ["pebble-app"],
"private": true,
"dependencies": {},
Expand Down
77 changes: 19 additions & 58 deletions src/c/appendix/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,67 +2,63 @@
#include "persist.h"
#include "math.h"

// NOTE: g_config is a global config variable

void config_load() {
g_config = (Config*) malloc(sizeof(Config));
persist_get_config(g_config);
}

void config_unload() {
free(g_config);
}

int config_localize_temp(int temp_f) {
// Convert temperatures as desired
Config *config = (Config*) malloc(sizeof(Config));
persist_get_config(config);
int result;
if (config->celsius)
if (g_config->celsius)
result = f_to_c(temp_f);
else
result = temp_f;
free(config);
return result;
}

int config_format_time(char *s, size_t maxsize, const struct tm * tm_p) {
Config *config = (Config*) malloc(sizeof(Config));
persist_get_config(config);
int res = strftime(s, maxsize, clock_is_24h_style() ? "%H:%M" : "%I:%M", tm_p);
if (!config->time_lead_zero) {
if (!g_config->time_lead_zero) {
// Remove leading zero if configured as such
if (s[0] == '0')
memmove(s, s+1, strlen(s));
}
free(config);
return res;
}

int config_axis_hour(int hour) {
Config *config = (Config*) malloc(sizeof(Config));
persist_get_config(config);
if (config->axis_12h) {
if (g_config->axis_12h) {
hour = hour % 12;
hour = hour == 0 ? 12 : hour;
}
else
hour = hour % 24;
free(config);
return hour;
}

int config_n_today() {
// Returns the index of the calendar box that holds today's date

Config *config = (Config*) malloc(sizeof(Config));
persist_get_config(config);

time_t today = time(NULL);
struct tm *tm_today = localtime(&today);
int wday = tm_today->tm_wday;
// Offset if user wants to start the week on monday
wday = config->start_mon ? (wday + 6) % 7 : wday;
wday = g_config->start_mon ? (wday + 6) % 7 : wday;
// Offset if user wants to show the previous week first
if (config->prev_week)
if (g_config->prev_week)
wday += 7;
free(config);
return wday;
}

GColor config_today_color() {
Config *config = (Config*) malloc(sizeof(Config));
persist_get_config(config);
GColor color = config->color_today;
free(config);
GColor color = g_config->color_today;
return color;
}

Expand All @@ -72,41 +68,6 @@ GFont config_time_font() {
FONT_KEY_LECO_42_NUMBERS,
FONT_KEY_BITHAM_42_MEDIUM_NUMBERS
};
Config *config = (Config*) malloc(sizeof(Config));
persist_get_config(config);
int16_t font_index = config->time_font;
free(config);
int16_t font_index = g_config->time_font;
return fonts_get_system_font(font_keys[font_index]);
}

bool config_show_qt() {
Config *config = (Config*) malloc(sizeof(Config));
persist_get_config(config);
bool show_qt = config->show_qt;
free(config);
return show_qt;
}

bool config_show_bt() {
Config *config = (Config*) malloc(sizeof(Config));
persist_get_config(config);
bool show_bt = config->show_bt;
free(config);
return show_bt;
}

bool config_show_bt_disconnect() {
Config *config = (Config*) malloc(sizeof(Config));
persist_get_config(config);
bool show_bt_disconnect = config->show_bt_disconnect;
free(config);
return show_bt_disconnect;
}

bool config_vibe() {
Config *config = (Config*) malloc(sizeof(Config));
persist_get_config(config);
bool vibe = config->vibe;
free(config);
return vibe;
}
16 changes: 7 additions & 9 deletions src/c/appendix/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ typedef struct {
GColor color_today;
} Config;

Config *g_config;

void config_load();

void config_unload();

int config_localize_temp(int temp_f);

int config_format_time(char *s, size_t maxsize, const struct tm * tm_p);
Expand All @@ -26,12 +32,4 @@ int config_n_today();

GColor config_today_color();

GFont config_time_font();

bool config_show_qt();

bool config_show_bt();

bool config_show_bt_disconnect();

bool config_vibe();
GFont config_time_font();
15 changes: 2 additions & 13 deletions src/c/appendix/persist.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
enum key {
TEMP_LO, TEMP_HI, TEMP_TREND, PRECIP_TREND, FORECAST_START, CITY, SUN_EVENT_START_TYPE, SUN_EVENT_TIMES, NUM_ENTRIES,
CURRENT_TEMP, BATTERY_LEVEL, CONFIG
};
}; // Deprecated: BATTERY_LEVEL

void persist_init() {
if (!persist_exists(TEMP_LO)) {
Expand Down Expand Up @@ -33,10 +33,6 @@ void persist_init() {
if (!persist_exists(CITY)) {
persist_write_string(CITY, "Koji");
}
if (!persist_exists(BATTERY_LEVEL)) {
BatteryChargeState charge = battery_state_service_peek();
persist_write_int(BATTERY_LEVEL, charge.charge_percent);
}
if (!persist_exists(SUN_EVENT_START_TYPE)) {
persist_write_int(SUN_EVENT_START_TYPE, 0);
}
Expand Down Expand Up @@ -102,10 +98,6 @@ int persist_get_sun_event_times(time_t *buffer, const size_t buffer_size) {
return persist_read_data(SUN_EVENT_TIMES, (void*) buffer, buffer_size * sizeof(time_t));
}

int persist_get_battery_level() {
return persist_read_int(BATTERY_LEVEL);
}

int persist_get_config(Config *config) {
return persist_read_data(CONFIG, config, sizeof(Config));
}
Expand Down Expand Up @@ -150,10 +142,7 @@ void persist_set_sun_event_times(time_t *data, const size_t size) {
persist_write_data(SUN_EVENT_TIMES, (void*) data, size * sizeof(time_t));
}

void persist_set_battery_level(int val) {
persist_write_int(BATTERY_LEVEL, val);
}

void persist_set_config(Config config) {
persist_write_data(CONFIG, &config, sizeof(Config));
config_load(); // Refresh global config variable
}
4 changes: 0 additions & 4 deletions src/c/appendix/persist.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ int persist_get_sun_event_start_type();

int persist_get_sun_event_times(time_t *buffer, const size_t buffer_size);

int persist_get_battery_level();

int persist_get_config(Config *config);

void persist_set_temp_lo(int val);
Expand All @@ -50,6 +48,4 @@ void persist_set_sun_event_start_type(int val);

void persist_set_sun_event_times(time_t *data, const size_t size);

void persist_set_battery_level(int val);

void persist_set_config(Config config);
6 changes: 3 additions & 3 deletions src/c/layers/battery_layer.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
static Layer *s_battery_layer;

static void battery_state_handler(BatteryChargeState charge) {
persist_set_battery_level(charge.charge_percent);
battery_layer_refresh();
}

Expand All @@ -28,7 +27,8 @@ static void battery_update_proc(Layer *layer, GContext *ctx) {
int w = bounds.size.w;
int h = bounds.size.h;
int battery_w = w - BATTERY_NUB_W;
int battery_level = persist_get_battery_level();
BatteryChargeState battery_state = battery_state_service_peek();
int battery_level = battery_state.charge_percent;

// Fill the battery level
GRect color_bounds = GRect(
Expand Down Expand Up @@ -63,4 +63,4 @@ void battery_layer_refresh() {
void battery_layer_destroy() {
battery_state_service_unsubscribe();
layer_destroy(s_battery_layer);
}
}
2 changes: 0 additions & 2 deletions src/c/layers/calendar_layer.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ static void calendar_update_proc(Layer *layer, GContext *ctx) {
}

void calendar_layer_create(Layer* parent_layer, GRect frame) {
APP_LOG(APP_LOG_LEVEL_INFO, "Creating calendar layer...");
s_calendar_layer = layer_create(frame);
GRect bounds = layer_get_bounds(s_calendar_layer);
int w = bounds.size.w;
Expand All @@ -47,7 +46,6 @@ void calendar_layer_create(Layer* parent_layer, GRect frame) {
layer_set_update_proc(s_calendar_layer, calendar_update_proc);
calendar_layer_refresh();
layer_add_child(parent_layer, s_calendar_layer);
// APP_LOG(APP_LOG_LEVEL_DEBUG, "The DOM 0 days from today is: %d", relative_day_of_month(0));
}

static int relative_day_of_month(int days_from_today) {
Expand Down
8 changes: 4 additions & 4 deletions src/c/layers/calendar_status_layer.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,20 @@ void calendar_status_layer_create(Layer* parent_layer, GRect frame) {
}

void bluetooth_icons_refresh(bool connected) {
bool show_bt = connected && config_show_bt();
bool show_bt_disconnect = !connected && config_show_bt_disconnect();
bool show_bt = connected && g_config->show_bt;
bool show_bt_disconnect = !connected && g_config->show_bt_disconnect;
layer_set_hidden(bitmap_layer_get_layer(s_bt_bitmap_layer), !show_bt);
layer_set_hidden(bitmap_layer_get_layer(s_bt_disconnect_bitmap_layer), !show_bt_disconnect);
}

void bluetooth_callback(bool connected) {
bluetooth_icons_refresh(connected);
if (!connected && config_vibe())
if (!connected && g_config->vibe)
vibes_double_pulse();
}

bool show_qt_icon() {
return config_show_qt() && quiet_time_is_active();
return g_config->show_qt && quiet_time_is_active();
}

void status_icons_refresh() {
Expand Down
3 changes: 3 additions & 0 deletions src/c/watchface.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@
#include "windows/main_window.h"
#include "appendix/app_message.h"
#include "appendix/persist.h"
#include "appendix/config.h"


static void init() {
app_message_init();
persist_init();
config_load();
main_window_create();
}

static void deinit() {
config_unload();
main_window_destroy();
}

Expand Down
7 changes: 5 additions & 2 deletions src/pkjs/clay/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,10 @@ module.exports = [
"type": "input",
"label": "Location override",
"messageKey": "location",
"description": "Leave this blank to use GPS"
"description": "Example: \"Manhattan\" or \"123 Oak St Plainsville KY\".<br><a href=\"https://locationiq.com/#demo\">Click here</a> to test out your location query.<br>To use GPS, leave this blank and ensure GPS is enabled on your device.",
"attributes": {
"placeholder": "Using GPS",
}
}
]
},
Expand Down Expand Up @@ -220,4 +223,4 @@ module.exports = [
"type": "text",
"defaultValue": "v" + meta.version
}
]
]

0 comments on commit 754779c

Please sign in to comment.