Upload files to "src/c"

This commit is contained in:
2024-10-06 21:25:43 +00:00
parent a9dab72998
commit 639ba9fa60
5 changed files with 328 additions and 0 deletions

4
src/c/date.h Normal file
View File

@@ -0,0 +1,4 @@
#pragma once
void add_date_layers(Layer *window_layer, int16_t width, int16_t height); //adds/configures weather/date display lines
void update_date_layer(); //checks/updates date display line

79
src/c/digital_time.c Normal file
View File

@@ -0,0 +1,79 @@
#include <pebble.h>
#include "digital_time.h"
#include "constants.h"
#include "tictoc_wd.h"
#define SCREEN_SHOT_HR 21
#define SCREEN_SHOT_MIN 22
extern Options s_options;
//checks/updates date display line
void update_digital_time_layer() {
static char digital_time_buffer[16];
const char *current_digital_time_layer;
//if displaying digital time
if (s_options.display_digital_time) {
//get current date_layer text
current_digital_time_layer = text_layer_get_text(digital_time_layer);
//get digital time
time_t temp = time(NULL);
struct tm *tick_time = localtime(&temp);
#if DEBUG
tick_time->tm_hour = SCREEN_SHOT_HR; //for screen shots
tick_time->tm_min = SCREEN_SHOT_MIN;
#endif
if (clock_is_24h_style()) {
strftime(digital_time_buffer, sizeof(digital_time_buffer), "%H:%M", tick_time);
} else {
strftime(digital_time_buffer, sizeof(digital_time_buffer), "%l:%M %P", tick_time);
}
if (current_digital_time_layer != digital_time_buffer) {
text_layer_set_text(digital_time_layer, digital_time_buffer);
}
}
else {
text_layer_set_text(digital_time_layer, "");
}
#if DEBUG
APP_LOG(APP_LOG_LEVEL_DEBUG, "update_digital_time_layer: text_layer_set_text digital_time_layer: %s", digital_time_buffer);
#endif
}
//adds/configures display digital time line
void add_digital_time_layer(Layer *window_layer, int16_t width, int16_t height) {
GFont digital_time_font;
int markers_Y_offset = 0;
int digital_time_Y_readability_offset = 0;
int chalk_digital_time_y_offset = 0;
#if defined(PBL_ROUND)
chalk_digital_time_y_offset = DEFAULT_CHALK_DIGITAL_TIME_Y_OFFSET;
#else
chalk_digital_time_y_offset = 0;
#endif
//if displaying minunte lines
if (s_options.display_minute_lines) {
markers_Y_offset = DEFAULT_MARKERS_Y_OFFSET;
}
if (s_options.readability) {
digital_time_Y_readability_offset = DEFAULT_DIGITAL_TIME_Y_OFFSET_READABILITY;
digital_time_font = fonts_get_system_font(FONT_KEY_GOTHIC_24);
}
else {
digital_time_Y_readability_offset = 0;
digital_time_font = fonts_get_system_font(FONT_KEY_GOTHIC_18);
}
digital_time_layer = text_layer_create(GRect(0, 137 - markers_Y_offset - digital_time_Y_readability_offset + chalk_digital_time_y_offset, width, 28));
text_layer_set_text_alignment(digital_time_layer, GTextAlignmentCenter);
init_static_row(digital_time_layer, digital_time_font);
layer_add_child(window_layer, text_layer_get_layer(digital_time_layer));
}

4
src/c/digital_time.h Normal file
View 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);

234
src/c/messaging.c Normal file
View File

@@ -0,0 +1,234 @@
#include <pebble.h>
#include "messaging.h"
#include "constants.h"
#include "weather.h"
#include "date.h"
#include "digital_time.h"
#include "battery.h"
#include "tictoc_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));
#if defined(PBL_ROUND)
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));
#endif
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(date_layer_center, GColorFromHEX(s_options.text_color));
text_layer_set_text_color(battery_layer, GColorFromHEX(s_options.text_color));
break;
case KEY_DOTS_COLOR:
s_options.dots_color = (int)t->value->int32;
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_DISPLAY_MONTH:
s_options.display_month = (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_MINUTE_LINES:
s_options.display_minute_lines = (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
View 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);