Upload files to "src/c"

This commit is contained in:
2024-10-06 21:25:32 +00:00
parent 80054591f4
commit a9dab72998
5 changed files with 330 additions and 0 deletions

67
src/c/battery.c Normal file
View File

@@ -0,0 +1,67 @@
#include <pebble.h>
#include "battery.h"
#include "constants.h"
#include "tictoc_wd.h"
extern Options s_options;
//checks/updates date display line
void update_battery_layer() {
static char battery_buffer[16];
const char *current_battery_layer;
//if displaying battery
if (s_options.display_battery) {
//get current date_layer text
current_battery_layer = text_layer_get_text(battery_layer);
//get battery percent
snprintf(battery_buffer, sizeof("100%"), "%d%%", battery_state_service_peek().charge_percent);
if (current_battery_layer != battery_buffer) {
text_layer_set_text(battery_layer, battery_buffer);
}
}
else {
text_layer_set_text(battery_layer, "");
}
#if DEBUG
APP_LOG(APP_LOG_LEVEL_DEBUG, "update_battery_layer: text_layer_set_text battery_layer: %s", battery_buffer);
#endif
}
//adds/configures display battery line
void add_battery_layer(Layer *window_layer, int16_t width, int16_t height) {
GFont battery_font;
int battery_Y_readability_offset = 0;
int markers_x_offset = 0;
int chalk_battery_x_offset = 0;
//if displaying minunte lines
if (s_options.display_minute_lines) {
markers_x_offset = DEFAULT_MARKERS_X_OFFSET;
}
if (s_options.readability) {
battery_Y_readability_offset = DEFAULT_BATTERY_OFFSET_READABILITY;
battery_font = fonts_get_system_font(FONT_KEY_GOTHIC_24);
}
else {
battery_Y_readability_offset = 0;
battery_font = fonts_get_system_font(FONT_KEY_GOTHIC_18);
}
#if defined(PBL_ROUND)
chalk_battery_x_offset = DEFAULT_CHALK_BATTERY_X_OFFSET;
#else
chalk_battery_x_offset = 0;
#endif
//battery_layer = text_layer_create(GRect(7 + markers_x_offset - battery_Y_readability_offset, (height / 2) - 20 - battery_Y_readability_offset - chalk_battery_y_offset, width, 28));
battery_layer = text_layer_create(GRect(4 + markers_x_offset + chalk_battery_x_offset, (height / 2) - 12 - battery_Y_readability_offset, width, 28));
text_layer_set_text_alignment(battery_layer, GTextAlignmentLeft);
init_static_row(battery_layer, battery_font);
layer_add_child(window_layer, text_layer_get_layer(battery_layer));
}

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

@@ -0,0 +1,4 @@
#pragma once
void update_battery_layer();
void add_battery_layer(Layer *window_layer, int16_t width, int16_t height);

51
src/c/constants.c Normal file
View File

@@ -0,0 +1,51 @@
#include <pebble.h>
#include "constants.h"
const int DEFAULT_SHAKE_FOR_LOHI = 1; //True - shake to show Lo Hi Temps
const int DEFAULT_DISPLAY_LOHI_TIMER = 5000; //length time (milliseconds) to display Lo Hi Temps
const int DEFAULT_MIN_SINCE_WEATHER_UPDATE = 0; //weather just updated
const char DEFAULT_LAST_WEATHER_UPDATE[16] = "--:--"; //default last update "time" display
const char DEFAULT_ERROR_WEATHER_UPDATE[16] = "---"; //default text display upon weather update error
const int DEFAULT_CONDITION_CODE = -99; //Invalid condition code to force weather update
const int DEFAULT_DISPLAY_WEATHER = 1; //true
const int DEFAULT_WEATHER_FREQUENCY = 30; //minutes
const int DEFAULT_WEATHER_USE_GPS = 1; //true
const int DEFAULT_USE_CELSIUS = 0; //false
const int DEFAULT_BACKGROUND_COLOR = 0x000000; //black
const int DEFAULT_TEXT_COLOR = 0xFFFFFF; //white
const int DEFAULT_HOUR_HAND_COLOR = 0xFF0000; //red
const int DEFAULT_MINUTE_HAND_COLOR = 0xFFFFFF; //white
const int DEFAULT_SECONDS_HAND_COLOR = 0xFFFFFF; //white
const int DEFAULT_HOUR_MARKERS_COLOR = 0xFF0000; //red
const int DEFAULT_MINOR_MARKERS_COLOR = 0xFFFFFF; //white
const int DEFAULT_DOTS_COLOR = 0xFFFFFF; //white
const int DEFAULT_READABILITY = 0; //false - use original size
const int DEFAULT_DISPLAY_DIGITAL_TIME = 0; //false
const int DEFAULT_DISPLAY_DATE = 1; //true
const int DEFAULT_DISPLAY_MONTH = 0; //false
const int DEFAULT_VIBRATE_BT_STATUS = 0; //false
const int DEFAULT_USE_THIN_HANDS = 0; //false
const int DEFAULT_DISPLAY_BATTERY = 0; //false
const int DEFAULT_DISPLAY_MINUTE_LINES = 0; //false
const int DEFAULT_DISPLAY_SECONDS_HAND = 0; //false
const int DEFAULT_MAX_WEATHER_RETRY_COUNT = 5; //max (seconds) weather retry counts
const uint MAX_CHALK_SINGLE_LINE_CONDITIONS_LEN = 4; //max length for weather conditions to display on single line. longer split to two lines
const int DEFAULT_CHALK_TIME_X_OFFSET = 20; //X-axis adjustment for time display on Chalk (Pebble Time Round)
const int DEFAULT_CHALK_TIME_Y_OFFSET = 10; //Y-axis adjustment for time display on Chalk (Pebble Time Round)
const int DEFAULT_MARKERS_X_OFFSET = 7; //X-axix adjustment for when displaying hour/minute markers
const int DEFAULT_CHALK_WEATHER1_Y_OFFSET = 10; //Y-axis adjustment for weather display on Chalk (Pebble Time Round)
const int DEFAULT_CHALK_WEATHER2_Y_OFFSET = 28; //Y-axis adjustment for weather display on Chalk (Pebble Time Round)
const int DEFAULT_WEATHER_Y_OFFSET_READABILITY = 4; //Y-axis adjustment for increased readability font options
const int DEFAULT_CHALK_WEATHER_CENTER_Y_OFFSET = 10; //Y-axis adjustment for weather display on Chalk (Pebble Time Round)
const int DEFAULT_DATE_Y_OFFSET_READABILITY = 4; //Y-axis adjustment for increased readability font options
const int DEFAULT_DIGITAL_TIME_Y_OFFSET_READABILITY = 5; //Y-axis adjustment for increased readability font options
const int DEFAULT_MARKERS_Y_OFFSET = 12; //Y-axix adjustment for when displaying hour/minute markers
const int DEFAULT_CHALK_DIGITAL_TIME_Y_OFFSET = 12; //Y-axis adjustment for digital time display on Chalk (Pebble Time Round)
const int DEFAULT_CHALK_BATTERY_X_OFFSET = 5; //X-axis adjustment for battery display on Chalk (Pebble Time Round)
const int DEFAULT_BATTERY_OFFSET_READABILITY = 5; //Y-axis adjustment for increased readability font options

84
src/c/constants.h Normal file
View File

@@ -0,0 +1,84 @@
#pragma once
#define DEBUG 0
#define KEY_TEMPERATURE_IN_C 1
#define KEY_CONDITIONS 2
#define KEY_BACKGROUND_COLOR 3
#define KEY_TEXT_COLOR 4
#define KEY_WEATHER_FREQUENCY 5
#define KEY_USE_CELSIUS 6
#define KEY_DISPLAY_WEATHER 7
#define KEY_MIN_SINCE_WEATHER_UPDATE 8
#define KEY_GET_WEATHER 9
#define KEY_TEMPERATURE 10
#define KEY_READABILITY 11
#define KEY_TEMPERATURE_LO 12
#define KEY_TEMPERATURE_HI 13
#define KEY_TEMPERATURE_IN_C_LO 14
#define KEY_TEMPERATURE_IN_C_HI 15
#define KEY_CONDITION_CODE 16
#define KEY_SHAKE_FOR_LOHI 17
#define KEY_DISPLAY_DIGITAL_TIME 18
#define KEY_DISPLAY_DATE 19
#define KEY_DISPLAY_MONTH 20
#define KEY_VIBBRATE_BT_STATUS 22
#define KEY_WEATHER_USE_GPS 23
#define KEY_WEATHER_LOCATION 24
#define KEY_USE_THIN_HANDS 25
#define KEY_DISPLAY_BATTERY 26
#define KEY_DISPLAY_MINUTE_LINES 27
#define KEY_JS_READY 28
#define KEY_HOUR_HAND_COLOR 29
#define KEY_MINUTE_HAND_COLOR 30
#define KEY_HOUR_MARKERS_COLOR 31
#define KEY_MINOR_MARKERS_COLOR 32
#define KEY_DOTS_COLOR 33
#define KEY_DISPLAY_SECONDS_HAND 34
#define KEY_SECONDS_HAND_COLOR 35
#define KEY_OPTIONS 99
extern const int DEFAULT_SHAKE_FOR_LOHI;
extern const int DEFAULT_DISPLAY_LOHI_TIMER;
extern const int DEFAULT_MIN_SINCE_WEATHER_UPDATE;
extern const char DEFAULT_LAST_WEATHER_UPDATE[16];
extern const char DEFAULT_ERROR_WEATHER_UPDATE[16];
extern const int DEFAULT_CONDITION_CODE;
extern const int DEFAULT_DISPLAY_WEATHER;
extern const int DEFAULT_WEATHER_FREQUENCY;
extern const int DEFAULT_WEATHER_USE_GPS;
extern const int DEFAULT_USE_CELSIUS;
extern const int DEFAULT_BACKGROUND_COLOR;
extern const int DEFAULT_TEXT_COLOR;
extern const int DEFAULT_HOUR_HAND_COLOR;
extern const int DEFAULT_MINUTE_HAND_COLOR;
extern const int DEFAULT_SECONDS_HAND_COLOR;
extern const int DEFAULT_HOUR_MARKERS_COLOR;
extern const int DEFAULT_MINOR_MARKERS_COLOR;
extern const int DEFAULT_DOTS_COLOR;
extern const int DEFAULT_READABILITY;
extern const int DEFAULT_DIGITAL_TIME_Y_OFFSET_READABILITY;
extern const int DEFAULT_DISPLAY_DIGITAL_TIME;
extern const int DEFAULT_DISPLAY_DATE;
extern const int DEFAULT_DISPLAY_MONTH;
extern const int DEFAULT_VIBRATE_BT_STATUS;
extern const int DEFAULT_USE_THIN_HANDS;
extern const int DEFAULT_DISPLAY_BATTERY;
extern const int DEFAULT_DISPLAY_MINUTE_LINES;
extern const int DEFAULT_DISPLAY_SECONDS_HAND;
extern const int DEFAULT_MAX_WEATHER_RETRY_COUNT;
extern const uint MAX_CHALK_SINGLE_LINE_CONDITIONS_LEN;
extern const int DEFAULT_WEATHER_Y_OFFSET_READABILITY;
extern const int DEFAULT_DATE_Y_OFFSET_READABILITY;
extern const int DEFAULT_CHALK_TIME_X_OFFSET;
extern const int DEFAULT_CHALK_WEATHER1_Y_OFFSET;
extern const int DEFAULT_CHALK_WEATHER2_Y_OFFSET;
extern const int DEFAULT_CHALK_WEATHER_CENTER_Y_OFFSET;
extern const int DEFAULT_CHALK_TIME_Y_OFFSET;
extern const int DEFAULT_CHALK_DIGITAL_TIME_Y_OFFSET;
extern const int DEFAULT_MARKERS_Y_OFFSET;
extern const int DEFAULT_MARKERS_X_OFFSET;
extern const int DEFAULT_CHALK_BATTERY_X_OFFSET;
extern const int DEFAULT_BATTERY_OFFSET_READABILITY;

124
src/c/date.c Normal file
View File

@@ -0,0 +1,124 @@
#include <pebble.h>
#include "date.h"
#include "constants.h"
#include "tictoc_wd.h"
#define DEBUG_DAY_DATE "Sun 02"
#define DEBUG_MONTH "Oct"
extern TextLayer *date_layer1, *date_layer2, *date_layer_center;
extern Options s_options;
//adds/configures date display lines
void add_date_layers(Layer *window_layer, int16_t width, int16_t height) {
GFont date_font;
int date_Y_readability_offset = 0;
int markers_x_offset = 0;
//if displaying minunte lines
if (s_options.display_minute_lines) {
markers_x_offset = DEFAULT_MARKERS_X_OFFSET;
}
if (s_options.readability) {
date_Y_readability_offset = DEFAULT_DATE_Y_OFFSET_READABILITY;
date_font = fonts_get_system_font(FONT_KEY_GOTHIC_24);
}
else {
date_font = fonts_get_system_font(FONT_KEY_GOTHIC_18);
}
#if defined(PBL_ROUND)
//date layers
date_layer1 = text_layer_create(GRect(62 - date_Y_readability_offset - markers_x_offset, (height / 2) - 20 - date_Y_readability_offset, width, 28));
text_layer_set_text_alignment(date_layer1, GTextAlignmentCenter);
init_static_row(date_layer1, date_font);
layer_add_child(window_layer, text_layer_get_layer(date_layer1));
date_layer2 = text_layer_create(GRect(62 - date_Y_readability_offset - markers_x_offset, (height / 2) - 5 - date_Y_readability_offset, width, 28));
text_layer_set_text_alignment(date_layer2, GTextAlignmentCenter);
init_static_row(date_layer2, date_font);
layer_add_child(window_layer, text_layer_get_layer(date_layer2));
date_layer_center = text_layer_create(GRect(62 - date_Y_readability_offset - markers_x_offset, (height / 2) - 12 - date_Y_readability_offset, width, 28));
text_layer_set_text_alignment(date_layer_center, GTextAlignmentCenter);
init_static_row(date_layer_center, date_font);
layer_add_child(window_layer, text_layer_get_layer(date_layer_center));
#else
//date layers
date_layer1 = text_layer_create(GRect(50 - date_Y_readability_offset - markers_x_offset, (height / 2) - 20 - date_Y_readability_offset, width, 28));
text_layer_set_text_alignment(date_layer1, GTextAlignmentCenter);
init_static_row(date_layer1, date_font);
layer_add_child(window_layer, text_layer_get_layer(date_layer1));
date_layer2 = text_layer_create(GRect(50 - date_Y_readability_offset - markers_x_offset, (height / 2) - 5 - date_Y_readability_offset, width, 28));
text_layer_set_text_alignment(date_layer2, GTextAlignmentCenter);
init_static_row(date_layer2, date_font);
layer_add_child(window_layer, text_layer_get_layer(date_layer2));
date_layer_center = text_layer_create(GRect(50 - date_Y_readability_offset - markers_x_offset, (height / 2) - 12 - date_Y_readability_offset, width, 28));
text_layer_set_text_alignment(date_layer_center, GTextAlignmentCenter);
init_static_row(date_layer_center, date_font);
layer_add_child(window_layer, text_layer_get_layer(date_layer_center));
#endif
}
//checks/updates date display line
void update_date_layer() {
static char date1_buffer[16], date2_buffer[16], date_center_buffer[16];
const char *current_date1_layer, *current_date2_layer, *current_date_center_layer;
//if displaying date
if (s_options.display_date) {
//get current from date layers
current_date1_layer = text_layer_get_text(date_layer1);
current_date2_layer = text_layer_get_text(date_layer2);
current_date_center_layer = text_layer_get_text(date_layer_center);
//get current date
time_t temp = time(NULL);
struct tm *tick_time = localtime(&temp);
if (s_options.display_month) {
strftime(date1_buffer, sizeof(date1_buffer), "%a %d", tick_time); //Week Day Day#
strftime(date2_buffer, sizeof(date2_buffer), "%b", tick_time); //month
#if DEBUG
strftime(date1_buffer, sizeof(date1_buffer), DEBUG_DAY_DATE, tick_time); //for screen shots
strftime(date2_buffer, sizeof(date2_buffer), DEBUG_MONTH, tick_time);
#endif
memset(date_center_buffer, 0,sizeof(date_center_buffer));
}
else {
memset(date1_buffer, 0,sizeof(date1_buffer));
memset(date2_buffer, 0,sizeof(date2_buffer));
strftime(date_center_buffer, sizeof(date_center_buffer), "%a %d", tick_time);
#if DEBUG
strftime(date_center_buffer, sizeof(date_center_buffer), DEBUG_DAY_DATE, tick_time); //for screen shots
#endif
//strftime(date_center_buffer, sizeof(date_center_buffer), "Sat 28", tick_time);
}
if (current_date1_layer != date1_buffer ||
current_date2_layer != date2_buffer ||
current_date_center_layer != date_center_buffer) {
text_layer_set_text(date_layer1, date1_buffer);
text_layer_set_text(date_layer2, date2_buffer);
text_layer_set_text(date_layer_center, date_center_buffer);
}
}
else {
text_layer_set_text(date_layer1, "");
text_layer_set_text(date_layer2, "");
text_layer_set_text(date_layer_center, "");
}
#if DEBUG
APP_LOG(APP_LOG_LEVEL_DEBUG, "update_date_layer: text_layer_set_text date_layer1: %s", date1_buffer);
APP_LOG(APP_LOG_LEVEL_DEBUG, "update_date_layer: text_layer_set_text date_layer2: %s", date2_buffer);
APP_LOG(APP_LOG_LEVEL_DEBUG, "update_date_layer: text_layer_set_text date_layer_center: %s", date_center_buffer);
#endif
}