Skip to content

Commit 6e7d19f

Browse files
committed
Fix crash bug with small font
1 parent a49cde6 commit 6e7d19f

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

src/main.c

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include <pebble.h>
22

33
static Window *main_win;
4-
static GFont *small_font;
54
static BitmapLayer *box_blue;
65
static BitmapLayer *box_batt;
76
static BitmapLayer *box_apm;
@@ -116,7 +115,7 @@ static void initialise_ui(void) {
116115
text_layer_set_background_color(box_date, GColorWhite);
117116
text_layer_set_text_color(box_date, GColorBlack);
118117
text_layer_set_text_alignment(box_date, GTextAlignmentCenter);
119-
text_layer_set_font(box_date, small_font);
118+
text_layer_set_font(box_date, fonts_get_system_font(FONT_KEY_GOTHIC_14));
120119
layer_add_child(root_layer, (Layer *)box_date);
121120

122121
// am/pm bitmap
@@ -146,7 +145,7 @@ static void initialise_ui(void) {
146145
text_layer_set_text_color(hour_text, GColorBlack);
147146
text_layer_set_text(hour_text, "??");
148147
text_layer_set_text_alignment(hour_text, GTextAlignmentRight);
149-
text_layer_set_font(hour_text, small_font);
148+
text_layer_set_font(hour_text, fonts_get_system_font(FONT_KEY_GOTHIC_14));
150149
layer_add_child(root_layer, (Layer *)hour_text);
151150

152151
// Icon line
@@ -221,14 +220,6 @@ static void handle_window_unload(Window* window) {
221220
}
222221
}
223222

224-
enum {
225-
POW_LINES,
226-
POW_LOGO,
227-
POW_NUMS,
228-
POW_BOXES,
229-
POW_PROGRESS
230-
};
231-
232223
// Macros to simplify these commands.
233224
#define HIDE(lay) layer_set_hidden((Layer *) lay, true)
234225
#define SHOW(lay) layer_set_hidden((Layer *) lay, false)
@@ -256,10 +247,12 @@ void powerdown() {
256247
}
257248

258249
void powerup_lines(void *val) {
250+
APP_LOG(APP_LOG_LEVEL_DEBUG, "Powerup - Lines");
259251
SHOW(icon_line);
260252
SHOW(secs_line);
261253
}
262254
void powerup_logo(void *val) {
255+
APP_LOG(APP_LOG_LEVEL_DEBUG, "Powerup - Logo");
263256
SHOW(ap_logo);
264257

265258
// Hide everything from powerup_nums to allow switching between them
@@ -269,12 +262,15 @@ void powerup_logo(void *val) {
269262
HIDE(icon_bg);
270263
}
271264
void powerup_nums(void *val) {
265+
APP_LOG(APP_LOG_LEVEL_DEBUG, "Powerup - Nums");
272266
SHOW(min_dig_ten);
273267
SHOW(min_dig_one);
274268
SHOW(hour_text);
275269
SHOW(icon_bg);
276-
}
270+
}
271+
277272
void powerup_boxes(void *val) {
273+
APP_LOG(APP_LOG_LEVEL_DEBUG, "Powerup - Boxes");
278274
SHOW(box_blue);
279275
SHOW(box_batt);
280276
SHOW(box_apm);
@@ -287,6 +283,7 @@ void powerup_boxes(void *val) {
287283
static bool playing_powerup = false;
288284

289285
void powerup_progress(void *val) {
286+
APP_LOG(APP_LOG_LEVEL_DEBUG, "Powerup - Complete");
290287
SHOW(secs_layer);
291288

292289
light_enable_interaction(); // Return light to normal
@@ -310,7 +307,6 @@ static void powerup() {
310307
app_timer_register( 800, &powerup_logo, NULL);
311308
app_timer_register( 900, &powerup_nums, NULL);
312309
app_timer_register(1100, &powerup_boxes, NULL);
313-
app_timer_register(1500, &powerup_boxes, NULL);
314310
app_timer_register(1800, &powerup_progress, NULL);
315311
}
316312

@@ -325,15 +321,15 @@ static void draw_seconds(struct Layer *layer, GContext *ctx) {
325321
time_t temp = time(NULL);
326322
struct tm *cur_time = localtime(&temp);
327323
graphics_context_set_stroke_color(ctx, GColorBlack);
328-
#ifdef PBL_COLOR
324+
#ifdef PBL_COLOR
329325
// On color Pebbles, draw 'off' bars in grey
330326
for(int i = 2; i <= 60 * 2; i += 2) {
331327
if ((cur_time -> tm_sec *2) + 2 == i) {
332328
graphics_context_set_stroke_color(ctx, GColorLightGray);
333329
}
334-
#else
330+
#else
335331
for (int i = 2; i <= (cur_time->tm_sec * 2); i += 2) {
336-
#endif
332+
#endif
337333
graphics_draw_line(ctx, GPoint(i, 0), GPoint(i, 8));
338334
}
339335
}
@@ -535,8 +531,6 @@ static void init() {
535531
res_bluetooth_on = gbitmap_create_with_resource(RESOURCE_ID_IMG_BLUE_ON);
536532
res_bluetooth_off = gbitmap_create_with_resource(RESOURCE_ID_IMG_BLUE_OFF);
537533

538-
small_font = fonts_get_system_font(FONT_KEY_GOTHIC_14);
539-
540534
res_ap_logo = gbitmap_create_with_resource(RESOURCE_ID_IMG_AP_LOGO);
541535

542536
res_am = gbitmap_create_with_resource(RESOURCE_ID_TS_ICO_AM);
@@ -571,10 +565,15 @@ static void init() {
571565

572566
int main() {
573567
srand(time(NULL));
568+
APP_LOG(APP_LOG_LEVEL_DEBUG, "Starting up");
574569

575570
init();
571+
572+
APP_LOG(APP_LOG_LEVEL_DEBUG, "initialised");
576573
show_main_window();
577574

575+
APP_LOG(APP_LOG_LEVEL_DEBUG, "Shown window");
576+
578577
// Get a tm structure
579578
time_t temp = time(NULL);
580579
struct tm *cur_time = localtime(&temp);
@@ -583,6 +582,7 @@ int main() {
583582
time_handler(cur_time, SECOND_UNIT | HOUR_UNIT | MINUTE_UNIT | DAY_UNIT);
584583
bluetooth_check(bluetooth_connection_service_peek());
585584
battery_update(battery_state_service_peek());
585+
APP_LOG(APP_LOG_LEVEL_DEBUG, "Done checks");
586586

587587
tick_timer_service_subscribe(SECOND_UNIT | HOUR_UNIT | MINUTE_UNIT | DAY_UNIT, time_handler);
588588

@@ -591,6 +591,7 @@ int main() {
591591
accel_tap_service_subscribe(shake_handler);
592592

593593
shuffle_icons(); // also starts the powerup animation
594+
APP_LOG(APP_LOG_LEVEL_DEBUG, "Shuffled icons");
594595

595596
app_event_loop();
596597

0 commit comments

Comments
 (0)