Add clock

This commit is contained in:
2026-03-10 19:33:10 -04:00
parent 7c65eb4dcb
commit f59fb3131e
5 changed files with 116 additions and 86 deletions

7
.clang-format Normal file
View File

@@ -0,0 +1,7 @@
---
BasedOnStyle: LLVM
TabWidth: 4
IndentWidth: 4
UseTab: ForIndentation
ColumnLimit: 0
...

View File

@@ -2,7 +2,7 @@ MIT License
Copyright (c) 2026 hilariouspig
THIS LICENSE DOES NOT APPLY TO ANY ".png" FILES IN THIS REPOSITORY.
THIS LICENSE DOES NOT APPLY TO ANY ".png" NOR ".ttf" FILES IN THIS REPOSITORY.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@@ -537,6 +537,15 @@
"gabbro"
],
"type": "bitmap"
},
{
"file": "fonts/RetroComputer.ttf",
"name": "FONT_RETRO_COMPUTER_32",
"targetPlatforms": [
"emery",
"gabbro"
],
"type": "font"
}
]
},

View File

@@ -1,8 +1,10 @@
#include <pebble.h>
#include "palette_manip.h"
#include <pebble.h>
// declare general static pointers
static Window *s_main_window;
static GFont custom_font;
static TextLayer *s_time_layer;
static BitmapLayer *s_guy_head_layer;
static BitmapLayer *s_guy_butt_layer;
@@ -16,75 +18,77 @@ static GBitmap *s_butt_next;
// declare lookup tables
static const uint32_t randomHeadPool[] = {
RESOURCE_ID_H001, RESOURCE_ID_H002, RESOURCE_ID_H003,
RESOURCE_ID_H004, RESOURCE_ID_H005, RESOURCE_ID_H006,
RESOURCE_ID_H007, RESOURCE_ID_H008, RESOURCE_ID_H009,
RESOURCE_ID_H010, RESOURCE_ID_H011, RESOURCE_ID_H012,
RESOURCE_ID_H013, RESOURCE_ID_H014, RESOURCE_ID_H015,
RESOURCE_ID_H016, RESOURCE_ID_H017, RESOURCE_ID_H018,
RESOURCE_ID_H019, RESOURCE_ID_H020, RESOURCE_ID_H021,
RESOURCE_ID_H022
};
RESOURCE_ID_H001, RESOURCE_ID_H002, RESOURCE_ID_H003, RESOURCE_ID_H004,
RESOURCE_ID_H005, RESOURCE_ID_H006, RESOURCE_ID_H007, RESOURCE_ID_H008,
RESOURCE_ID_H009, RESOURCE_ID_H010, RESOURCE_ID_H011, RESOURCE_ID_H012,
RESOURCE_ID_H013, RESOURCE_ID_H014, RESOURCE_ID_H015, RESOURCE_ID_H016,
RESOURCE_ID_H017, RESOURCE_ID_H018, RESOURCE_ID_H019, RESOURCE_ID_H020,
RESOURCE_ID_H021, RESOURCE_ID_H022};
static const uint32_t randomButtPool[] = {
RESOURCE_ID_B001, RESOURCE_ID_B002, RESOURCE_ID_B003,
RESOURCE_ID_B004, RESOURCE_ID_B005, RESOURCE_ID_B006,
RESOURCE_ID_B007, RESOURCE_ID_B008, RESOURCE_ID_B009,
RESOURCE_ID_B010, RESOURCE_ID_B011, RESOURCE_ID_B012,
RESOURCE_ID_B013, RESOURCE_ID_B014, RESOURCE_ID_B015,
RESOURCE_ID_B016, RESOURCE_ID_B017, RESOURCE_ID_B018,
RESOURCE_ID_B019, RESOURCE_ID_B020, RESOURCE_ID_B021,
RESOURCE_ID_B022, RESOURCE_ID_XB001, RESOURCE_ID_XB002,
RESOURCE_ID_XB003, RESOURCE_ID_XB004
};
RESOURCE_ID_B001, RESOURCE_ID_B002, RESOURCE_ID_B003, RESOURCE_ID_B004,
RESOURCE_ID_B005, RESOURCE_ID_B006, RESOURCE_ID_B007, RESOURCE_ID_B008,
RESOURCE_ID_B009, RESOURCE_ID_B010, RESOURCE_ID_B011, RESOURCE_ID_B012,
RESOURCE_ID_B013, RESOURCE_ID_B014, RESOURCE_ID_B015, RESOURCE_ID_B016,
RESOURCE_ID_B017, RESOURCE_ID_B018, RESOURCE_ID_B019, RESOURCE_ID_B020,
RESOURCE_ID_B021, RESOURCE_ID_B022, RESOURCE_ID_XB001, RESOURCE_ID_XB002,
RESOURCE_ID_XB003, RESOURCE_ID_XB004};
static const GColor8 darkBGColorPool[] = {
// Red
GColorFolly,
GColorRed,
GColorFolly, GColorRed,
// Orange
GColorOrange,
GColorRajah,
GColorSunsetOrange,
GColorOrange, GColorRajah, GColorSunsetOrange,
// Yellow
GColorChromeYellow,
GColorIcterine,
GColorPastelYellow,
GColorYellow,
GColorChromeYellow, GColorIcterine, GColorPastelYellow, GColorYellow,
// Green
GColorInchworm,
GColorJaegerGreen,
GColorKellyGreen,
GColorMintGreen,
GColorInchworm, GColorJaegerGreen, GColorKellyGreen, GColorMintGreen,
// Blue
GColorElectricBlue,
GColorTiffanyBlue,
GColorVividCerulean,
GColorElectricBlue, GColorTiffanyBlue, GColorVividCerulean,
// Purple
GColorLavenderIndigo,
GColorPurpureus,
GColorRichBrilliantLavender,
GColorLavenderIndigo, GColorPurpureus, GColorRichBrilliantLavender,
// Pink
GColorBrilliantRose,
GColorMelon,
GColorBrilliantRose, GColorMelon,
// Brown
GColorRoseVale
};
GColorRoseVale};
static void update_minute() {
// get a tm structure
time_t temp = time(NULL);
struct tm *tick_time = localtime(&temp);
// write the current hours and minutes into a buffer
static char s_time_buffer[8];
strftime(s_time_buffer, sizeof(s_time_buffer), clock_is_24h_style() ? "%H:%M" : "%I:%M", tick_time);
// display this time on the TextLayer
text_layer_set_text(s_time_layer, s_time_buffer);
}
static void minute_handler(struct tm *tick_time, TimeUnits units_changed) {
update_minute();
}
// define contents of the Window upon load
static void main_window_load(Window *window) {
Layer *window_layer = window_get_root_layer(window);
// format silly guy layers
s_guy_head_layer = bitmap_layer_create(GRect(PBL_IF_ROUND_ELSE(0, -30), PBL_IF_ROUND_ELSE(0, -16), 260, 115));
s_guy_butt_layer = bitmap_layer_create(GRect(PBL_IF_ROUND_ELSE(0, -30), PBL_IF_ROUND_ELSE(145, 129), 260, 115));
bitmap_layer_set_compositing_mode(s_guy_head_layer, GCompOpSet);
bitmap_layer_set_background_color(s_guy_head_layer, GColorBlack);
bitmap_layer_set_bitmap(s_guy_head_layer, s_head_current);
bitmap_layer_set_compositing_mode(s_guy_butt_layer, GCompOpSet);
bitmap_layer_set_background_color(s_guy_butt_layer, GColorBlack);
bitmap_layer_set_bitmap(s_guy_butt_layer, s_butt_current);
// add silly guy layers as children to window
Layer *window_layer = window_get_root_layer(window);
// set up info layers
s_time_layer = text_layer_create(GRect(0, PBL_IF_ROUND_ELSE(110, 94), PBL_IF_ROUND_ELSE(260, 200), 32));
text_layer_set_background_color(s_time_layer, GColorClear);
text_layer_set_font(s_time_layer, custom_font);
text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter);
// add layers as children to window
layer_add_child(window_layer, bitmap_layer_get_layer(s_guy_head_layer));
layer_add_child(window_layer, bitmap_layer_get_layer(s_guy_butt_layer));
layer_add_child(window_layer, text_layer_get_layer(s_time_layer));
}
// free memory on Window close;
@@ -92,6 +96,7 @@ static void main_window_load(Window *window) {
static void main_window_unload(Window *window) {
bitmap_layer_destroy(s_guy_head_layer);
bitmap_layer_destroy(s_guy_butt_layer);
text_layer_destroy(s_time_layer);
}
// set up the app on launch (don't put app logic in here);
@@ -100,25 +105,33 @@ static void init() {
s_main_window = window_create();
// set handlers to manage the elements inside the Window
window_set_window_handlers(s_main_window, (WindowHandlers) {
window_set_window_handlers(s_main_window, (WindowHandlers){
.load = main_window_load,
.unload = main_window_unload
});
.unload = main_window_unload});
// load initial batch of silly guy parts into memory
s_head_current = gbitmap_create_with_resource(randomHeadPool[rand()%22]);
s_butt_current = gbitmap_create_with_resource(randomButtPool[rand()%26]);
s_head_next = gbitmap_create_with_resource(randomHeadPool[rand()%22]);
s_butt_next = gbitmap_create_with_resource(randomButtPool[rand()%26]);
s_head_current = gbitmap_create_with_resource(randomHeadPool[rand() % 22]);
s_butt_current = gbitmap_create_with_resource(randomButtPool[rand() % 26]);
s_head_next = gbitmap_create_with_resource(randomHeadPool[rand() % 22]);
s_butt_next = gbitmap_create_with_resource(randomButtPool[rand() % 26]);
// pick starting colors
s_random_color_current = darkBGColorPool[rand()%22];
s_random_color_next = darkBGColorPool[rand()%22];
s_random_color_current = darkBGColorPool[rand() % 22];
s_random_color_next = darkBGColorPool[rand() % 22];
replace_gbitmap_color(GColorGreen, s_random_color_current, s_head_current, NULL);
replace_gbitmap_color(GColorGreen, s_random_color_current, s_butt_current, NULL);
// load custom font
custom_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_RETRO_COMPUTER_32));
// show the Window on the watch, with animated=true
window_stack_push(s_main_window, true);
// make sure the time is displayed from the start
update_minute();
// register with TickTimerService
tick_timer_service_subscribe(MINUTE_UNIT, minute_handler);
}
// free memory on app exit;

View File

@@ -10,6 +10,7 @@ echo "CompileFlags:
-I$(pwd)/build/emery,
-include${HOME}/.pebble-sdk/SDKs/current/toolchain/arm-none-eabi/arm-none-eabi/include/stdint.h,
-include${HOME}/.pebble-sdk/SDKs/current/toolchain/arm-none-eabi/arm-none-eabi/include/stdlib.h,
-include${HOME}/.pebble-sdk/SDKs/current/toolchain/arm-none-eabi/arm-none-eabi/include/time.h,
-include${HOME}/.pebble-sdk/SDKs/current/toolchain/arm-none-eabi/lib/gcc/arm-none-eabi/14.2.1/include/stddef.h,
-include${HOME}/.pebble-sdk/SDKs/current/toolchain/arm-none-eabi/lib/gcc/arm-none-eabi/14.2.1/include/stdbool.h,
]" > ./.clangd