1
0

initial commit

This commit is contained in:
2023-04-04 20:48:51 +02:00
commit 3cf894b67f
21 changed files with 1002 additions and 0 deletions

View File

@@ -0,0 +1,128 @@
#include <pebble.h>
static Window *s_window;
static Layer *s_canvas;
static int s_hours, s_minutes;
/*uint8_t sortedcolors[64] = {
0, 1, 2, 16, 3, 17, 18, 4, 32, 19, 5, 33, 6, 34, 20, 48,
7, 35, 21, 49, 22, 50, 8, 36, 23, 51, 9, 37, 10, 38, 24, 52,
11, 39, 25, 53, 26, 54, 12, 40, 27, 55, 13, 41, 14, 42, 28, 56,
15, 43, 29, 57, 30, 58, 44, 31, 59, 45, 46, 60, 47, 61, 62, 63
};*/
uint8_t sortedcolors[64] = {0,1,16,2,17,18,3,4,5,19,20,32,6,21,33,22,34,7,23,35,36,37,38,39,48,49,50,51,52,8,9,53,24,10,25,54,26,11,55,27,40,41,42,43,56,57,58,59,12,13,28,14,29,30,15,31,44,45,46,47,60,61,62,63};
int compare( const void* a, const void* b)
{
uint32_t int_a = * ( (uint32_t*) a );
uint32_t int_b = * ( (uint32_t*) b );
if ( int_a == int_b ) return 0;
else if ( int_a < int_b ) return -1;
else return 1;
}
/*
static uint16_t int_sqrt(uint16_t value)
{
uint16_t answer = value;
uint16_t answer_sqr = value*value;
while(answer_sqr>value)
{
answer = (answer + value/answer)/2;
answer_sqr = answer * answer;
}
return answer;
}
*/
static void layer_update_proc(Layer *layer, GContext *ctx) {
GRect bounds = layer_get_bounds(layer);
GRect righthalf = GRect(bounds.size.w/2, bounds.origin.y, bounds.size.w/2, bounds.size.h);
graphics_context_set_fill_color(ctx, GColorBlack);
graphics_fill_rect(ctx, righthalf, 0, GCornerNone);
/*
uint32_t brightnesstable[64];
uint32_t brightnesstable2[64];
for(uint8_t i=0; i<64; i++) {
GColor8 color = (GColor8) { .argb = i+0b11000000 };
uint32_t brightness = color.r*475251000 + color.g*774330000 + color.b*181260000;
brightnesstable[i] = brightness;
brightnesstable2[i] = brightness;
}
uint8_t sortedcolors[64];
qsort(brightnesstable, 64, sizeof(uint32_t), compare);
for(uint8_t i=0; i<64; i++) {
for(uint8_t j=0; j<64; j++) {
if (brightnesstable[i] == brightnesstable2[j]) {
APP_LOG(APP_LOG_LEVEL_INFO, "%d", j);
sortedcolors[i] = j;
break;
}
}
}
*/
for(uint8_t i=0; i<64; i++) {
uint8_t argb = sortedcolors[i]+0b11000000;
//APP_LOG(APP_LOG_LEVEL_INFO, "Color %i", argb);
GRect colorstripe = GRect(26+bounds.origin.x+(i*2), bounds.origin.y, 2, bounds.size.h);
graphics_context_set_fill_color(ctx, (GColor8) { .argb = argb });
graphics_fill_rect(ctx, colorstripe, 0, GCornerNone);
}
}
static void window_load(Window *window) {
Layer *window_layer = window_get_root_layer(window);
GRect bounds = layer_get_bounds(window_layer);
s_canvas = layer_create(bounds);
layer_set_update_proc(s_canvas, layer_update_proc);
layer_add_child(window_layer, s_canvas);
}
static void window_unload(Window *window) {
layer_destroy(s_canvas);
window_destroy(s_window);
}
void main_window_push() {
s_window = window_create();
window_set_background_color(s_window, GColorWhite);
window_set_window_handlers(s_window, (WindowHandlers) {
.load = window_load,
.unload = window_unload,
});
window_stack_push(s_window, true);
}
void main_window_update(int hours, int minutes) {
s_hours = hours;
s_minutes = minutes;
layer_mark_dirty(s_canvas);
}
static void tick_handler(struct tm *time_now, TimeUnits changed) {
main_window_update(time_now->tm_hour, time_now->tm_min);
}
static void init() {
main_window_push();
tick_timer_service_subscribe(MINUTE_UNIT, tick_handler);
}
static void deinit() {
tick_timer_service_unsubscribe();
}
int main() {
init();
app_event_loop();
deinit();
}