Upload files to "src/c"
This commit is contained in:
223
src/c/messaging.c
Normal file
223
src/c/messaging.c
Normal file
@@ -0,0 +1,223 @@
|
|||||||
|
#include <pebble.h>
|
||||||
|
#include "messaging.h"
|
||||||
|
#include "constants.h"
|
||||||
|
#include "weather.h"
|
||||||
|
#include "date.h"
|
||||||
|
#include "digital_time.h"
|
||||||
|
#include "battery.h"
|
||||||
|
#include "analog_wd.h"
|
||||||
|
|
||||||
|
extern Options s_options;
|
||||||
|
extern Layer *s_canvas_layer;
|
||||||
|
|
||||||
|
void send(int key, int value, int key2, int value2, int key3, char value3[64]){
|
||||||
|
#if DEBUG
|
||||||
|
APP_LOG(APP_LOG_LEVEL_DEBUG, "send: s_options.pebble_js_ready: %d", s_options.pebble_js_ready);
|
||||||
|
#endif
|
||||||
|
if (s_options.pebble_js_ready) {
|
||||||
|
|
||||||
|
DictionaryIterator *iterator;
|
||||||
|
app_message_outbox_begin(&iterator);
|
||||||
|
dict_write_int(iterator, key, &value, sizeof(int), true);
|
||||||
|
dict_write_int(iterator, key2, &value2, sizeof(int), true);
|
||||||
|
dict_write_cstring(iterator, key3, value3);
|
||||||
|
|
||||||
|
app_message_outbox_send();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void inbox_received_callback(DictionaryIterator *iterator, void *context) {
|
||||||
|
|
||||||
|
// Read first item
|
||||||
|
Tuple *t = dict_read_first(iterator);
|
||||||
|
|
||||||
|
// For all items
|
||||||
|
while(t != NULL) {
|
||||||
|
// Which key was received?
|
||||||
|
switch(t->key) {
|
||||||
|
|
||||||
|
case KEY_TEMPERATURE:
|
||||||
|
s_options.tempF = (int)t->value->int32;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case KEY_TEMPERATURE_LO:
|
||||||
|
s_options.tempFLo = (int)t->value->int32;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case KEY_TEMPERATURE_HI:
|
||||||
|
s_options.tempFHi = (int)t->value->int32;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case KEY_TEMPERATURE_IN_C:
|
||||||
|
s_options.tempC = (int)t->value->int32;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case KEY_TEMPERATURE_IN_C_LO:
|
||||||
|
s_options.tempCLo = (int)t->value->int32;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case KEY_TEMPERATURE_IN_C_HI:
|
||||||
|
s_options.tempCHi = (int)t->value->int32;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case KEY_CONDITIONS:
|
||||||
|
snprintf(s_options.conditions, sizeof(s_options.conditions), "%s", t->value->cstring);
|
||||||
|
|
||||||
|
//check if successful weather retrieval
|
||||||
|
if (strlen(s_options.conditions) > 0) {
|
||||||
|
// Get a tm structure
|
||||||
|
time_t temp = time(NULL);
|
||||||
|
struct tm *tick_time = localtime(&temp);
|
||||||
|
//strftime(s_options.last_weather_update, sizeof("00:00"), "%H:%M", tick_time);
|
||||||
|
strftime(s_options.last_weather_update24hr, sizeof("00:00"), "%H:%M", tick_time);
|
||||||
|
strftime(s_options.last_weather_update12hr, sizeof("00:00 pm"), "%l:%M %P", tick_time);
|
||||||
|
s_options.last_update = temp;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case KEY_CONDITION_CODE:
|
||||||
|
s_options.condition_code = (int)t->value->int32;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case KEY_SHAKE_FOR_LOHI:
|
||||||
|
s_options.shake_for_lohi = (int)t->value->int32;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case KEY_USE_CELSIUS:
|
||||||
|
s_options.use_celsius = (int)t->value->int32;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case KEY_WEATHER_USE_GPS:
|
||||||
|
//force weather update after each config page Save
|
||||||
|
memset(s_options.conditions, 0,sizeof(s_options.conditions));
|
||||||
|
s_options.condition_code = DEFAULT_CONDITION_CODE;
|
||||||
|
|
||||||
|
s_options.weather_use_GPS = (int)t->value->int32;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case KEY_WEATHER_LOCATION:
|
||||||
|
snprintf(s_options.weather_location, sizeof(s_options.weather_location), "%s", t->value->cstring);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case KEY_WEATHER_FREQUENCY:
|
||||||
|
s_options.weather_frequency = (int)t->value->int32;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case KEY_BACKGROUND_COLOR:
|
||||||
|
s_options.background_color = (int)t->value->int32;
|
||||||
|
window_set_background_color(s_main_window, GColorFromHEX(s_options.background_color));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case KEY_TEXT_COLOR:
|
||||||
|
s_options.text_color = (int)t->value->int32;
|
||||||
|
|
||||||
|
text_layer_set_text_color(weather_layer1, GColorFromHEX(s_options.text_color));
|
||||||
|
text_layer_set_text_color(weather_layer_center, GColorFromHEX(s_options.text_color));
|
||||||
|
text_layer_set_text_color(weather_layer2, GColorFromHEX(s_options.text_color));
|
||||||
|
text_layer_set_text_color(digital_time_layer, GColorFromHEX(s_options.text_color));
|
||||||
|
text_layer_set_text_color(date_layer1, GColorFromHEX(s_options.text_color));
|
||||||
|
text_layer_set_text_color(date_layer2, GColorFromHEX(s_options.text_color));
|
||||||
|
text_layer_set_text_color(battery_layer, GColorFromHEX(s_options.text_color));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case KEY_HOUR_HAND_COLOR:
|
||||||
|
s_options.hour_hand_color = (int)t->value->int32;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case KEY_MINUTE_HAND_COLOR:
|
||||||
|
s_options.minute_hand_color = (int)t->value->int32;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case KEY_SECONDS_HAND_COLOR:
|
||||||
|
s_options.seconds_hand_color = (int)t->value->int32;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case KEY_HOUR_MARKERS_COLOR:
|
||||||
|
s_options.hour_markers_color = (int)t->value->int32;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case KEY_MINOR_MARKERS_COLOR:
|
||||||
|
s_options.minor_markers_color = (int)t->value->int32;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case KEY_READABILITY:
|
||||||
|
s_options.readability = (int)t->value->int32;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case KEY_DISPLAY_DIGITAL_TIME:
|
||||||
|
s_options.display_digital_time = (int)t->value->int32;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case KEY_DISPLAY_DATE:
|
||||||
|
s_options.display_date = (int)t->value->int32;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case KEY_VIBBRATE_BT_STATUS:
|
||||||
|
s_options.vibrate_bt_status = (int)t->value->int32;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case KEY_USE_THIN_HANDS:
|
||||||
|
s_options.use_thin_hands = (int)t->value->int32;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case KEY_DISPLAY_BATTERY:
|
||||||
|
s_options.display_battery = (int)t->value->int32;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case KEY_DISPLAY_HOUR_DIGITS:
|
||||||
|
s_options.display_hour_digits = (int)t->value->int32;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case KEY_DISPLAY_SECONDS_HAND:
|
||||||
|
s_options.display_seconds_hand = (int)t->value->int32;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case KEY_JS_READY:
|
||||||
|
s_options.pebble_js_ready = (int)t->value->int32;
|
||||||
|
#if DEBUG
|
||||||
|
APP_LOG(APP_LOG_LEVEL_DEBUG, "inbox_received_callback: s_options.pebble_js_ready: %d", s_options.pebble_js_ready);
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// Look for next item
|
||||||
|
t = dict_read_next(iterator);
|
||||||
|
}
|
||||||
|
|
||||||
|
//check update weather, date, digital time, and battery layers
|
||||||
|
update_date_layer();
|
||||||
|
update_digital_time_layer();
|
||||||
|
update_weather_layer();
|
||||||
|
update_battery_layer();
|
||||||
|
}
|
||||||
|
|
||||||
|
char *translate_error(AppMessageResult result) {
|
||||||
|
switch (result) {
|
||||||
|
case APP_MSG_OK: return "APP_MSG_OK";
|
||||||
|
case APP_MSG_SEND_TIMEOUT: return "APP_MSG_SEND_TIMEOUT";
|
||||||
|
case APP_MSG_SEND_REJECTED: return "APP_MSG_SEND_REJECTED";
|
||||||
|
case APP_MSG_NOT_CONNECTED: return "APP_MSG_NOT_CONNECTED";
|
||||||
|
case APP_MSG_APP_NOT_RUNNING: return "APP_MSG_APP_NOT_RUNNING";
|
||||||
|
case APP_MSG_INVALID_ARGS: return "APP_MSG_INVALID_ARGS";
|
||||||
|
case APP_MSG_BUSY: return "APP_MSG_BUSY";
|
||||||
|
case APP_MSG_BUFFER_OVERFLOW: return "APP_MSG_BUFFER_OVERFLOW";
|
||||||
|
case APP_MSG_ALREADY_RELEASED: return "APP_MSG_ALREADY_RELEASED";
|
||||||
|
case APP_MSG_CALLBACK_ALREADY_REGISTERED: return "APP_MSG_CALLBACK_ALREADY_REGISTERED";
|
||||||
|
case APP_MSG_CALLBACK_NOT_REGISTERED: return "APP_MSG_CALLBACK_NOT_REGISTERED";
|
||||||
|
case APP_MSG_OUT_OF_MEMORY: return "APP_MSG_OUT_OF_MEMORY";
|
||||||
|
case APP_MSG_CLOSED: return "APP_MSG_CLOSED";
|
||||||
|
case APP_MSG_INTERNAL_ERROR: return "APP_MSG_INTERNAL_ERROR";
|
||||||
|
default: return "UNKNOWN ERROR";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void message_dropped(AppMessageResult reason, void *context) {
|
||||||
|
APP_LOG(APP_LOG_LEVEL_ERROR, "Dropped message! Reason given: %s", translate_error(reason));
|
||||||
|
}
|
||||||
|
|
||||||
|
void message_out_success(DictionaryIterator *iter, void *context) {
|
||||||
|
APP_LOG(APP_LOG_LEVEL_DEBUG, "Message sent.");
|
||||||
|
}
|
||||||
|
|
||||||
|
void message_out_failed(DictionaryIterator *iter, AppMessageResult reason, void *context) {
|
||||||
|
APP_LOG(APP_LOG_LEVEL_DEBUG, "Failed to send message. Reason = %s", translate_error(reason));
|
||||||
|
}
|
||||||
7
src/c/messaging.h
Normal file
7
src/c/messaging.h
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
void send(int key, int value, int key2, int value2, int key3, char value3[64]);
|
||||||
|
void inbox_received_callback(DictionaryIterator *iterator, void *context);
|
||||||
|
void message_dropped(AppMessageResult reason, void *context);
|
||||||
|
void message_out_success(DictionaryIterator *iter, void *context);
|
||||||
|
void message_out_failed(DictionaryIterator *iter, AppMessageResult reason, void *context);
|
||||||
78
src/c/options.c
Normal file
78
src/c/options.c
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
#include <pebble.h>
|
||||||
|
#include "options.h"
|
||||||
|
#include "constants.h"
|
||||||
|
#include "analog_wd.h"
|
||||||
|
|
||||||
|
extern Options s_options;
|
||||||
|
|
||||||
|
void init_options() {
|
||||||
|
|
||||||
|
if (persist_exists(KEY_OPTIONS)) {
|
||||||
|
persist_read_data(KEY_OPTIONS, &s_options, sizeof(s_options));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
s_options.shake_for_lohi = DEFAULT_SHAKE_FOR_LOHI;
|
||||||
|
s_options.display_weather = DEFAULT_DISPLAY_WEATHER;
|
||||||
|
s_options.use_celsius = DEFAULT_USE_CELSIUS;
|
||||||
|
s_options.weather_use_GPS = DEFAULT_WEATHER_USE_GPS;
|
||||||
|
memset(s_options.weather_location, 0,sizeof(s_options.weather_location));
|
||||||
|
s_options.weather_frequency = DEFAULT_WEATHER_FREQUENCY;
|
||||||
|
s_options.min_since_last_forecast = DEFAULT_MIN_SINCE_WEATHER_UPDATE;
|
||||||
|
s_options.background_color = DEFAULT_BACKGROUND_COLOR;
|
||||||
|
s_options.text_color = DEFAULT_TEXT_COLOR;
|
||||||
|
s_options.hour_hand_color = DEFAULT_HOUR_HAND_COLOR;
|
||||||
|
s_options.minute_hand_color = DEFAULT_MINUTE_HAND_COLOR;
|
||||||
|
s_options.seconds_hand_color = DEFAULT_SECONDS_HAND_COLOR;
|
||||||
|
s_options.hour_markers_color = DEFAULT_HOUR_MARKERS_COLOR;
|
||||||
|
s_options.minor_markers_color = DEFAULT_MINOR_MARKERS_COLOR;
|
||||||
|
s_options.readability = DEFAULT_READABILITY;
|
||||||
|
s_options.condition_code = DEFAULT_CONDITION_CODE;
|
||||||
|
s_options.display_digital_time = DEFAULT_DISPLAY_DIGITAL_TIME;
|
||||||
|
s_options.display_date = DEFAULT_DISPLAY_DATE;
|
||||||
|
s_options.vibrate_bt_status = DEFAULT_VIBRATE_BT_STATUS;
|
||||||
|
s_options.use_thin_hands = DEFAULT_USE_THIN_HANDS;
|
||||||
|
s_options.display_battery = DEFAULT_DISPLAY_BATTERY;
|
||||||
|
s_options.display_hour_digits = DEFAULT_DISPLAY_HOUR_DIGITS;
|
||||||
|
s_options.display_seconds_hand = DEFAULT_DISPLAY_SECONDS_HAND;
|
||||||
|
memset(s_options.conditions, 0,sizeof(s_options.conditions));
|
||||||
|
snprintf(s_options.last_weather_update12hr, sizeof(s_options.last_weather_update12hr), "--:--");
|
||||||
|
snprintf(s_options.last_weather_update24hr, sizeof(s_options.last_weather_update24hr), "--:--");
|
||||||
|
//persist_write_data(KEY_OPTIONS, &s_options, sizeof(s_options));
|
||||||
|
}
|
||||||
|
#if DEBUG
|
||||||
|
APP_LOG(APP_LOG_LEVEL_DEBUG, "init_options: s_options.shake_for_lohi: %d", s_options.shake_for_lohi);
|
||||||
|
APP_LOG(APP_LOG_LEVEL_DEBUG, "init_options: s_options.tempF: %d", s_options.tempF);
|
||||||
|
APP_LOG(APP_LOG_LEVEL_DEBUG, "init_options: s_options.tempFLo: %d", s_options.tempFLo);
|
||||||
|
APP_LOG(APP_LOG_LEVEL_DEBUG, "init_options: s_options.tempFHi: %d", s_options.tempFHi);
|
||||||
|
APP_LOG(APP_LOG_LEVEL_DEBUG, "init_options: s_options.tempC: %d", s_options.tempC);
|
||||||
|
APP_LOG(APP_LOG_LEVEL_DEBUG, "init_options: s_options.tempCLo: %d", s_options.tempCLo);
|
||||||
|
APP_LOG(APP_LOG_LEVEL_DEBUG, "init_options: s_options.tempCHi: %d", s_options.tempCHi);
|
||||||
|
APP_LOG(APP_LOG_LEVEL_DEBUG, "init_options: s_options.display_weather: %d", s_options.display_weather);
|
||||||
|
APP_LOG(APP_LOG_LEVEL_DEBUG, "init_options: s_options.weather_use_GPS: %d", s_options.weather_use_GPS);
|
||||||
|
APP_LOG(APP_LOG_LEVEL_DEBUG, "init_options: s_options.weather_location: %s", s_options.weather_location);
|
||||||
|
APP_LOG(APP_LOG_LEVEL_DEBUG, "init_options: s_options.use_celsius: %d", s_options.use_celsius);
|
||||||
|
APP_LOG(APP_LOG_LEVEL_DEBUG, "init_options: s_options.weather_frequency: %d", s_options.weather_frequency);
|
||||||
|
APP_LOG(APP_LOG_LEVEL_DEBUG, "init_options: s_options.min_since_last_forecast: %d", s_options.min_since_last_forecast);
|
||||||
|
APP_LOG(APP_LOG_LEVEL_DEBUG, "init_options: s_options.display_date: %d", s_options.display_date);
|
||||||
|
APP_LOG(APP_LOG_LEVEL_DEBUG, "init_options: s_options.background_color: %d", s_options.background_color);
|
||||||
|
APP_LOG(APP_LOG_LEVEL_DEBUG, "init_options: s_options.text_color: %d", s_options.text_color);
|
||||||
|
APP_LOG(APP_LOG_LEVEL_DEBUG, "init_options: s_options.hour_hand_color: %d", s_options.hour_hand_color);
|
||||||
|
APP_LOG(APP_LOG_LEVEL_DEBUG, "init_options: s_options.minute_hand_color: %d", s_options.minute_hand_color);
|
||||||
|
APP_LOG(APP_LOG_LEVEL_DEBUG, "init_options: s_options.seconds_hand_color: %d", s_options.seconds_hand_color);
|
||||||
|
APP_LOG(APP_LOG_LEVEL_DEBUG, "init_options: s_options.hour_markers_color: %d", s_options.hour_markers_color);
|
||||||
|
APP_LOG(APP_LOG_LEVEL_DEBUG, "init_options: s_options.minor_markers_color: %d", s_options.minor_markers_color);
|
||||||
|
APP_LOG(APP_LOG_LEVEL_DEBUG, "init_options: s_options.readability: %d", s_options.readability);
|
||||||
|
APP_LOG(APP_LOG_LEVEL_DEBUG, "init_options: s_options.condition_code: %d", s_options.condition_code);
|
||||||
|
APP_LOG(APP_LOG_LEVEL_DEBUG, "init_options: s_options.bluetooth_state: %d", s_options.bluetooth_state);
|
||||||
|
APP_LOG(APP_LOG_LEVEL_DEBUG, "init_options: s_options.display_digital_time: %d", s_options.display_digital_time);
|
||||||
|
APP_LOG(APP_LOG_LEVEL_DEBUG, "init_options: s_options.vibrate_bt_status: %d", s_options.vibrate_bt_status);
|
||||||
|
APP_LOG(APP_LOG_LEVEL_DEBUG, "init_options: s_options.use_thin_hands: %d", s_options.use_thin_hands);
|
||||||
|
APP_LOG(APP_LOG_LEVEL_DEBUG, "init_options: s_options.display_battery: %d", s_options.display_battery);
|
||||||
|
APP_LOG(APP_LOG_LEVEL_DEBUG, "init_options: s_options.display_hour_digits: %d", s_options.display_hour_digits);
|
||||||
|
APP_LOG(APP_LOG_LEVEL_DEBUG, "init_options: s_options.display_seconds_hand: %d", s_options.display_seconds_hand);
|
||||||
|
APP_LOG(APP_LOG_LEVEL_DEBUG, "init_options: s_options.conditions: %s", s_options.conditions);
|
||||||
|
APP_LOG(APP_LOG_LEVEL_DEBUG, "init_options: s_options.last_weather_update12hr: %s", s_options.last_weather_update12hr);
|
||||||
|
APP_LOG(APP_LOG_LEVEL_DEBUG, "init_options: s_options.last_weather_update24hr: %s", s_options.last_weather_update24hr);
|
||||||
|
APP_LOG(APP_LOG_LEVEL_DEBUG, "init_options: options sizeof(s_options) %zu", sizeof(s_options));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
5
src/c/options.h
Normal file
5
src/c/options.h
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#define KEY_OPTIONS 99
|
||||||
|
|
||||||
|
void init_options();
|
||||||
235
src/c/weather.c
Normal file
235
src/c/weather.c
Normal file
@@ -0,0 +1,235 @@
|
|||||||
|
#include <pebble.h>
|
||||||
|
#include "weather.h"
|
||||||
|
#include "constants.h"
|
||||||
|
#include "digital_time.h"
|
||||||
|
#include "analog_wd.h"
|
||||||
|
|
||||||
|
extern TextLayer *weather_layer1, *weather_layer2, *weather_layer_center;
|
||||||
|
extern AppTimer *lohi_display_timer;
|
||||||
|
|
||||||
|
extern Options s_options;
|
||||||
|
|
||||||
|
//check if need to convert weather condition codes (too long)
|
||||||
|
void convert_conditions(int conditionCode) {
|
||||||
|
|
||||||
|
switch(conditionCode) {
|
||||||
|
case 0: // tornado
|
||||||
|
case 1: // tropical storm
|
||||||
|
case 2: // hurricane
|
||||||
|
case 4: // thunderstorms
|
||||||
|
case 8: //freezing drizzle
|
||||||
|
case 9: //drizzle
|
||||||
|
case 10: //freezing rain
|
||||||
|
case 11: //showers
|
||||||
|
case 12: //showers
|
||||||
|
case 13: //snow flurries
|
||||||
|
case 15: //blowing snow
|
||||||
|
case 16: //snow
|
||||||
|
case 17: //hail
|
||||||
|
case 18: //sleet
|
||||||
|
case 19: //dust
|
||||||
|
case 20: //foggy
|
||||||
|
case 21: //haze
|
||||||
|
case 22: //smoky
|
||||||
|
case 23: //blustery
|
||||||
|
case 24: //windy
|
||||||
|
case 25: //cold
|
||||||
|
case 26: //cloudy
|
||||||
|
case 32: //sunny
|
||||||
|
case 36: //hot
|
||||||
|
case 40: //scattered showers
|
||||||
|
case 41: //heavy snow
|
||||||
|
case 43: //heavy snow
|
||||||
|
case 44: //partly cloudy
|
||||||
|
case 45: //thundershowers
|
||||||
|
case 46: //snow showers
|
||||||
|
//no need to convert, do nothing
|
||||||
|
break;
|
||||||
|
case 3: // severe thunderstorms
|
||||||
|
case 37: //isolated thunderstorms
|
||||||
|
case 38: //scattered thunderstorms
|
||||||
|
case 39: //scattered thunderstorms
|
||||||
|
snprintf(s_options.conditions, sizeof(s_options.conditions), "Thunderstorms");
|
||||||
|
break;
|
||||||
|
case 5: //mixed rain and snow
|
||||||
|
snprintf(s_options.conditions, sizeof(s_options.conditions), "Rain and Snow");
|
||||||
|
break;
|
||||||
|
case 6: //mixed rain and sleet
|
||||||
|
snprintf(s_options.conditions, sizeof(s_options.conditions), "Rain and Sleet");
|
||||||
|
break;
|
||||||
|
case 7: //mixed snow and sleet
|
||||||
|
snprintf(s_options.conditions, sizeof(s_options.conditions), "Snow and Sleet");
|
||||||
|
break;
|
||||||
|
case 14: //light snow showers
|
||||||
|
snprintf(s_options.conditions, sizeof(s_options.conditions), "Snow Showers");
|
||||||
|
break;
|
||||||
|
case 27: //mostly cloudy (night)
|
||||||
|
case 28: //mostly cloudy (day)
|
||||||
|
snprintf(s_options.conditions, sizeof(s_options.conditions), "Mostly Cloudy");
|
||||||
|
break;
|
||||||
|
case 29: //partly cloudy (night)
|
||||||
|
case 30: //partly cloudy (day)
|
||||||
|
snprintf(s_options.conditions, sizeof(s_options.conditions), "Partly Cloudy");
|
||||||
|
break;
|
||||||
|
case 31: //clear (night)
|
||||||
|
snprintf(s_options.conditions, sizeof(s_options.conditions), "Clear");
|
||||||
|
break;
|
||||||
|
case 33: //fair (night)
|
||||||
|
case 34: //fair (day)
|
||||||
|
snprintf(s_options.conditions, sizeof(s_options.conditions), "Fair");
|
||||||
|
break;
|
||||||
|
case 35: //mixed rain and hail
|
||||||
|
snprintf(s_options.conditions, sizeof(s_options.conditions), "Rain and Hail");
|
||||||
|
break;
|
||||||
|
case 42: //scattered snow showers
|
||||||
|
snprintf(s_options.conditions, sizeof(s_options.conditions), "Snow Showers");
|
||||||
|
break;
|
||||||
|
case 47: //isolated thundershowers
|
||||||
|
snprintf(s_options.conditions, sizeof(s_options.conditions), "Thundershowers");
|
||||||
|
break;
|
||||||
|
case 3200: //Unknown
|
||||||
|
snprintf(s_options.conditions, sizeof(s_options.conditions), ".....");
|
||||||
|
break;
|
||||||
|
default: //invalid condition code, clear conditions
|
||||||
|
memset(s_options.conditions, 0,sizeof(s_options.conditions));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//adds/configures weather display lines
|
||||||
|
void add_weather_layers(Layer *window_layer, int16_t width, int16_t height) {
|
||||||
|
|
||||||
|
GFont weather_font;
|
||||||
|
int weather_Y_readability_offset = 0;
|
||||||
|
int weather_Y_hour_digits_offset = 0;
|
||||||
|
int chalk_weather1_Y_offset = 0;
|
||||||
|
int chalk_weather_center_Y_offset = 0;
|
||||||
|
int chalk_weather2_Y_offset = 0;
|
||||||
|
|
||||||
|
chalk_weather1_Y_offset = DEFAULT_CHALK_WEATHER1_Y_OFFSET;
|
||||||
|
chalk_weather_center_Y_offset = DEFAULT_CHALK_WEATHER_CENTER_Y_OFFSET;
|
||||||
|
chalk_weather2_Y_offset = DEFAULT_CHALK_WEATHER2_Y_OFFSET;
|
||||||
|
|
||||||
|
if (s_options.readability) {
|
||||||
|
weather_Y_readability_offset = DEFAULT_WEATHER_Y_OFFSET_READABILITY;
|
||||||
|
weather_font = fonts_get_system_font(FONT_KEY_GOTHIC_24);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
weather_font = fonts_get_system_font(FONT_KEY_GOTHIC_18);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (s_options.display_hour_digits) {
|
||||||
|
weather_Y_hour_digits_offset = DEFAULT_WEATHER_Y_OFFSET_HOUR_DIGITS;
|
||||||
|
}
|
||||||
|
|
||||||
|
//weather layers
|
||||||
|
weather_layer1 = text_layer_create(GRect(0, 5 - weather_Y_readability_offset + chalk_weather1_Y_offset + weather_Y_hour_digits_offset, width, 28));
|
||||||
|
text_layer_set_text_alignment(weather_layer1, GTextAlignmentCenter);
|
||||||
|
init_static_row(weather_layer1, weather_font);
|
||||||
|
layer_add_child(window_layer, text_layer_get_layer(weather_layer1));
|
||||||
|
|
||||||
|
weather_layer2 = text_layer_create(GRect(0, 5 - weather_Y_readability_offset + chalk_weather2_Y_offset + weather_Y_hour_digits_offset, width, 28));
|
||||||
|
text_layer_set_text_alignment(weather_layer2, GTextAlignmentCenter);
|
||||||
|
init_static_row(weather_layer2, weather_font);
|
||||||
|
layer_add_child(window_layer, text_layer_get_layer(weather_layer2));
|
||||||
|
|
||||||
|
weather_layer_center = text_layer_create(GRect(0, 5 - weather_Y_readability_offset + chalk_weather_center_Y_offset + weather_Y_hour_digits_offset, width, 28));
|
||||||
|
text_layer_set_text_alignment(weather_layer_center, GTextAlignmentCenter);
|
||||||
|
init_static_row(weather_layer_center, weather_font);
|
||||||
|
layer_add_child(window_layer, text_layer_get_layer(weather_layer_center));
|
||||||
|
}
|
||||||
|
|
||||||
|
//checks updates weather display lines
|
||||||
|
void update_weather_layer() {
|
||||||
|
static char weather1_layer_buffer[32];
|
||||||
|
static char weather2_layer_buffer[32];
|
||||||
|
static char weather_center_layer_buffer[32];
|
||||||
|
|
||||||
|
//check if need to convert options (if too long)
|
||||||
|
convert_conditions(s_options.condition_code);
|
||||||
|
|
||||||
|
if (s_options.use_celsius){
|
||||||
|
memset(weather1_layer_buffer, 0,sizeof(weather1_layer_buffer));
|
||||||
|
snprintf(weather_center_layer_buffer, sizeof(weather_center_layer_buffer), "%dC %s", s_options.tempC, s_options.conditions);
|
||||||
|
memset(weather2_layer_buffer, 0,sizeof(weather2_layer_buffer));
|
||||||
|
if (strlen(s_options.conditions) > MAX_CHALK_SINGLE_LINE_CONDITIONS_LEN) {
|
||||||
|
snprintf(weather1_layer_buffer, sizeof(weather1_layer_buffer), "%dC", s_options.tempC);
|
||||||
|
memset(weather_center_layer_buffer, 0,sizeof(weather_center_layer_buffer));
|
||||||
|
snprintf(weather2_layer_buffer, sizeof(weather2_layer_buffer), "%s", s_options.conditions);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
memset(weather1_layer_buffer, 0,sizeof(weather1_layer_buffer));
|
||||||
|
snprintf(weather_center_layer_buffer, sizeof(weather_center_layer_buffer), "%dF %s", s_options.tempF, s_options.conditions);
|
||||||
|
memset(weather2_layer_buffer, 0,sizeof(weather2_layer_buffer));
|
||||||
|
if (strlen(s_options.conditions) > MAX_CHALK_SINGLE_LINE_CONDITIONS_LEN) {
|
||||||
|
snprintf(weather1_layer_buffer, sizeof(weather1_layer_buffer), "%dF", s_options.tempF);
|
||||||
|
memset(weather_center_layer_buffer, 0,sizeof(weather_center_layer_buffer));
|
||||||
|
snprintf(weather2_layer_buffer, sizeof(weather2_layer_buffer), "%s", s_options.conditions);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//write weather text row
|
||||||
|
if (strlen(s_options.conditions) != 0) {
|
||||||
|
text_layer_set_text(weather_layer1, weather1_layer_buffer);
|
||||||
|
text_layer_set_text(weather_layer_center, weather_center_layer_buffer);
|
||||||
|
text_layer_set_text(weather_layer2, weather2_layer_buffer);
|
||||||
|
#if DEBUG
|
||||||
|
APP_LOG(APP_LOG_LEVEL_DEBUG, "update_weather_layer: Successful weather row information written at %s. ", s_options.last_weather_update12hr);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}
|
||||||
|
else { //empty temp & conditions
|
||||||
|
text_layer_set_text(weather_layer1, "");
|
||||||
|
text_layer_set_text(weather_layer_center, DEFAULT_ERROR_WEATHER_UPDATE);
|
||||||
|
text_layer_set_text(weather_layer2, "");
|
||||||
|
#if DEBUG
|
||||||
|
APP_LOG(APP_LOG_LEVEL_DEBUG, "update_weather_layer: Error displaying weather %s. ", s_options.last_weather_update12hr);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void handle_timer(void *data) {
|
||||||
|
update_weather_layer();
|
||||||
|
update_digital_time_layer();
|
||||||
|
}
|
||||||
|
|
||||||
|
//temporarily sets and displays Lo/Hi temp and last updates info on weather/date lines
|
||||||
|
void display_lohi_weather_info() {
|
||||||
|
static char weather1_layer_buffer[32];
|
||||||
|
static char weather2_layer_buffer[32];
|
||||||
|
static char weather_center_layer_buffer[32];
|
||||||
|
|
||||||
|
if (s_options.use_celsius){
|
||||||
|
snprintf(weather1_layer_buffer, sizeof(weather1_layer_buffer), "Lo %dC", s_options.tempCLo);
|
||||||
|
snprintf(weather2_layer_buffer, sizeof(weather2_layer_buffer), "Hi %dC", s_options.tempCHi);
|
||||||
|
memset(weather_center_layer_buffer, 0,sizeof(weather_center_layer_buffer));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
snprintf(weather1_layer_buffer, sizeof(weather1_layer_buffer), "Lo %dF", s_options.tempFLo);
|
||||||
|
snprintf(weather2_layer_buffer, sizeof(weather2_layer_buffer), "Hi %dF", s_options.tempFHi);
|
||||||
|
memset(weather_center_layer_buffer, 0,sizeof(weather_center_layer_buffer));
|
||||||
|
}
|
||||||
|
|
||||||
|
//write weather text row
|
||||||
|
if (strlen(s_options.conditions) != 0) {
|
||||||
|
if (clock_is_24h_style()) {
|
||||||
|
text_layer_set_text(digital_time_layer, s_options.last_weather_update24hr);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
text_layer_set_text(digital_time_layer, s_options.last_weather_update12hr);
|
||||||
|
}
|
||||||
|
text_layer_set_text(weather_layer1, weather1_layer_buffer);
|
||||||
|
text_layer_set_text(weather_layer_center, weather_center_layer_buffer);
|
||||||
|
text_layer_set_text(weather_layer2, weather2_layer_buffer);
|
||||||
|
}
|
||||||
|
else { //empty temp & conditions
|
||||||
|
text_layer_set_text(digital_time_layer, s_options.last_weather_update12hr);
|
||||||
|
text_layer_set_text(digital_time_layer, s_options.last_weather_update24hr);
|
||||||
|
text_layer_set_text(weather_layer1, "");
|
||||||
|
text_layer_set_text(weather_layer_center, DEFAULT_ERROR_WEATHER_UPDATE);
|
||||||
|
text_layer_set_text(weather_layer2, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
lohi_display_timer = app_timer_register(DEFAULT_DISPLAY_LOHI_TIMER, handle_timer, NULL);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user