Files
analog_weather/src/c/battery.c
2024-10-06 20:49:40 +00:00

57 lines
1.7 KiB
C

#include <pebble.h>
#include "battery.h"
#include "constants.h"
#include "analog_wd.h"
extern Options s_options;
//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 battery_X_hour_digits_offset = 0;
if (s_options.readability) {
battery_Y_readability_offset = DEFAULT_BATTERY_OFFSET_READABILITY;
battery_font = fonts_get_system_font(FONT_KEY_GOTHIC_24);
}
else {
battery_font = fonts_get_system_font(FONT_KEY_GOTHIC_18);
}
if (s_options.display_hour_digits) {
battery_X_hour_digits_offset = DEFAULT_BATTERY_OFFSET_HOUR_DIGITS;
}
battery_layer = text_layer_create(GRect(17 + battery_X_hour_digits_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));
}
//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
}