Upload files to "src/c"

This commit is contained in:
2024-10-06 20:42:09 +00:00
parent a16d7921e5
commit 3738226764
3 changed files with 220 additions and 0 deletions

5
src/c/options.h Normal file
View File

@@ -0,0 +1,5 @@
#pragma once
#define KEY_OPTIONS 99
void init_options();

207
src/c/weather.c Normal file
View File

@@ -0,0 +1,207 @@
#include <pebble.h>
#include "ninety_one_dub.h"
#include "constants.h"
#include "options.h"
extern TextLayer *weather_layer1;
extern AppTimer *lohi_display_timer;
GFont g_weather_font;
extern Options s_options;
void update_weather_layer();
//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) {
int weather_Y_readability_offset = 0;
if (s_options.weather_readability) {
weather_Y_readability_offset = DEFAULT_WEATHER_Y_OFFSET_READABILITY;
g_weather_font = fonts_get_system_font(FONT_KEY_GOTHIC_18);
weather_layer1 = text_layer_create(GRect(0, 0 - weather_Y_readability_offset, width, 23));
}
else {
weather_Y_readability_offset = 0;
g_weather_font = fonts_get_system_font(FONT_KEY_GOTHIC_14);
weather_layer1 = text_layer_create(GRect(0, 0 - weather_Y_readability_offset, width, 19));
}
//weather layer
//text_layer_set_background_color(weather_layer1, GColorBlack);
if (s_options.invert) {
text_layer_set_background_color(weather_layer1, GColorWhite);
}
else {
text_layer_set_background_color(weather_layer1, GColorBlack);
}
init_static_row(weather_layer1, g_weather_font);
layer_add_child(window_layer, text_layer_get_layer(weather_layer1));
//update weather layer
update_weather_layer();
}
//checks updates weather display lines
void update_weather_layer() {
static char weather1_layer_buffer[32];
//check if need to convert options (if too long)
convert_conditions(s_options.condition_code);
if (s_options.use_celsius){
snprintf(weather1_layer_buffer, sizeof(weather1_layer_buffer), "%dC - %s", s_options.tempC, s_options.conditions);
}
else {
snprintf(weather1_layer_buffer, sizeof(weather1_layer_buffer), "%dF - %s", s_options.tempF, s_options.conditions);
}
//write weather text row
if (strlen(s_options.conditions) != 0) {
text_layer_set_text(weather_layer1, weather1_layer_buffer);
#if DEBUG
APP_LOG(APP_LOG_LEVEL_DEBUG, "update_weather_layer: Successful weather row information written at %s. ", s_options.last_weather_update24hr);
#endif
}
else { //empty temp & conditions
text_layer_set_text(weather_layer1, DEFAULT_ERROR_WEATHER_UPDATE);
#if DEBUG
APP_LOG(APP_LOG_LEVEL_DEBUG, "update_weather_layer: Error displaying weather %s. ", s_options.last_weather_update24hr);
#endif
}
}
void handle_timer(void *data) {
update_weather_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];
if (s_options.use_celsius){
if (clock_is_24h_style()) {
snprintf(weather1_layer_buffer, sizeof(weather1_layer_buffer), "Lo %dC-Hi %dC %s", s_options.tempCLo, s_options.tempCHi, s_options.last_weather_update24hr);
}
else {
snprintf(weather1_layer_buffer, sizeof(weather1_layer_buffer), "Lo %dC-Hi %dC %s", s_options.tempCLo, s_options.tempCHi, s_options.last_weather_update12hr);
}
}
else {
if (clock_is_24h_style()) {
snprintf(weather1_layer_buffer, sizeof(weather1_layer_buffer), "Lo %dF-Hi %dF %s", s_options.tempFLo, s_options.tempFHi, s_options.last_weather_update24hr);
}
else {
snprintf(weather1_layer_buffer, sizeof(weather1_layer_buffer), "Lo %dF-Hi %dF %s", s_options.tempFLo, s_options.tempFHi, s_options.last_weather_update12hr);
}
}
//write weather text row
if (strlen(s_options.conditions) != 0) {
if (clock_is_24h_style()) {
//text_layer_set_text(date_layer, s_options.last_weather_update24hr); //***** last update
}
else {
//text_layer_set_text(date_layer, s_options.last_weather_update12hr); //***** last update
}
text_layer_set_text(weather_layer1, weather1_layer_buffer);
}
else { //empty temp & conditions
//text_layer_set_text(date_layer, s_options.last_weather_update12hr); //***** last update
//text_layer_set_text(date_layer, s_options.last_weather_update24hr); //***** last update
text_layer_set_text(weather_layer1, DEFAULT_ERROR_WEATHER_UPDATE);
}
lohi_display_timer = app_timer_register(DEFAULT_DISPLAY_LOHI_TIMER, handle_timer, NULL);
}

8
src/c/weather.h Normal file
View File

@@ -0,0 +1,8 @@
#pragma once
void add_weather_layers(Layer *window_layer, int16_t width); //adds/configures weather/date display lines
void update_weather_layer(); //checks updates weather display lines
void display_lohi_weather_info(); //temporarily sets and displays Lo/Hi temp and last updates info on weather/date lines
void handle_timer(void *data); //sets weather/date lines back to weather/date info after timer expires
void convert_conditions(int conditionCode); //check if need to convert weather condition codes (too long)