Upload files to "src/c"
This commit is contained in:
4
src/c/digital_time.h
Normal file
4
src/c/digital_time.h
Normal file
@@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
void update_digital_time_layer();
|
||||
void add_digital_time_layer(Layer *window_layer, int16_t width, int16_t height);
|
||||
187
src/c/messaging.c
Normal file
187
src/c/messaging.c
Normal file
@@ -0,0 +1,187 @@
|
||||
#include <pebble.h>
|
||||
#include "messaging.h"
|
||||
#include "constants.h"
|
||||
#include "weather.h"
|
||||
#include "digital_time.h"
|
||||
#include "basic.h"
|
||||
//#include <pebble-battery-bar/pebble-battery-bar.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_HOUR_FONT:
|
||||
s_options.hourFont = (int)t->value->int32;
|
||||
break;
|
||||
|
||||
case KEY_MINUTES_FONT:
|
||||
s_options.minutesFont = (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_DISPLAY_DIGITAL_TIME:
|
||||
s_options.display_digital_time = (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));
|
||||
text_layer_set_background_color(s_bluetooth_battery_text_layer, GColorFromHEX(s_options.background_color));
|
||||
break;
|
||||
|
||||
case KEY_HR_COLOR:
|
||||
s_options.hr_color = (int)t->value->int32;
|
||||
set_hr_layer_color(GColorFromHEX(s_options.hr_color));
|
||||
break;
|
||||
|
||||
case KEY_MIN_COLOR:
|
||||
s_options.min_color = (int)t->value->int32;
|
||||
set_min_layer_color(GColorFromHEX(s_options.min_color));
|
||||
break;
|
||||
|
||||
case KEY_WSD_COLOR:
|
||||
s_options.wsd_color = (int)t->value->int32;
|
||||
set_wsd_layers_color(GColorFromHEX(s_options.wsd_color));
|
||||
#ifdef PBL_BW
|
||||
battery_bar_set_colors(GColorFromHEX(s_options.wsd_color), GColorFromHEX(s_options.wsd_color), GColorFromHEX(s_options.wsd_color), GColorFromHEX(s_options.wsd_color));
|
||||
#endif
|
||||
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_digital_time_layer();
|
||||
update_weather_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);
|
||||
65
src/c/options.c
Normal file
65
src/c/options.c
Normal file
@@ -0,0 +1,65 @@
|
||||
#include <pebble.h>
|
||||
#include "options.h"
|
||||
#include "constants.h"
|
||||
#include "basic.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.condition_code = DEFAULT_CONDITION_CODE;
|
||||
s_options.display_digital_time = DEFAULT_DISPLAY_DIGITAL_TIME;
|
||||
s_options.hr_color = DEFAULT_HR_COLOR;
|
||||
#ifdef PBL_COLOR // If on basalt
|
||||
s_options.min_color = DEFAULT_MIN_COLOR;
|
||||
#else
|
||||
s_options.min_color = DEFAULT_HR_COLOR; //white
|
||||
#endif
|
||||
s_options.wsd_color = DEFAULT_WSD_COLOR;
|
||||
s_options.background_color = DEFAULT_BACKGROUND_COLOR;
|
||||
s_options.hourFont = DEFAULT_HOUR_FONT;
|
||||
s_options.minutesFont = DEFAULT_MINUTES_FONT;
|
||||
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.condition_code: %d", s_options.condition_code);
|
||||
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.hr_color: %d", s_options.hr_color);
|
||||
APP_LOG(APP_LOG_LEVEL_DEBUG, "init_options: s_options.min_color: %d", s_options.min_color);
|
||||
APP_LOG(APP_LOG_LEVEL_DEBUG, "init_options: s_options.wsd_color: %d", s_options.wsd_color);
|
||||
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.hourFont: %d", s_options.hourFont);
|
||||
APP_LOG(APP_LOG_LEVEL_DEBUG, "init_options: s_options.minutesFont: %d", s_options.minutesFont);
|
||||
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();
|
||||
Reference in New Issue
Block a user