diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..31aa732 --- /dev/null +++ b/.clang-format @@ -0,0 +1,7 @@ +--- +BasedOnStyle: LLVM +TabWidth: 4 +IndentWidth: 4 +UseTab: ForIndentation +ColumnLimit: 0 +... diff --git a/clangd.zsh b/clangd.zsh new file mode 100755 index 0000000..933b8be --- /dev/null +++ b/clangd.zsh @@ -0,0 +1,19 @@ +#!/usr/bin/env zsh +echo "CompileFlags: + Add: + [ + -DPBL_DISPLAY_WIDTH=200, + -DPBL_DISPLAY_HEIGHT=228, + -xc, + -nostdinc, + -DPBL_COLOR, + -I${HOME}/.pebble-sdk/SDKs/current/sdk-core/pebble/emery/include, + -include$(pwd)/build/include/message_keys.auto.h, + -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/arm-none-eabi/include/string.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 diff --git a/package.json b/package.json new file mode 100644 index 0000000..1196b22 --- /dev/null +++ b/package.json @@ -0,0 +1,35 @@ +{ + "name": "civic-segments", + "author": "RandyTheSilly", + "version": "1.0.0", + "keywords": [ + "honda", + "civic", + "segment", + "display", + "speedometer" + ], + "private": true, + "dependencies": {}, + "pebble": { + "displayName": "Civic-Segments", + "uuid": "162d2a72-f509-4cc6-a570-e28031ff4602", + "sdkVersion": "3", + "enableMultiJS": true, + "targetPlatforms": [ + "emery" + ], + "watchapp": { + "watchface": true + }, + "messageKeys": [ + "CLAY_LED_COLOR", + "CLAY_BG_COLOR", + "CLAY_MG_COLOR", + "CLAY_FG_COLOR" + ], + "resources": { + "media": [] + } + } +} diff --git a/src/c/main.c b/src/c/main.c new file mode 100644 index 0000000..cbfb9d9 --- /dev/null +++ b/src/c/main.c @@ -0,0 +1,103 @@ +#include + +// window statics +static Window *s_main_window; +static TextLayer *s_time_mg_layer; +static TextLayer *s_time_layer; +// static GFont s_civic_font; +static const GRect s_time_grect = GRect(0, 0, PBL_DISPLAY_WIDTH, PBL_DISPLAY_HEIGHT); + +// persist statics&defines +static GColor8 s_led_color; +static GColor8 s_bg_color; +static GColor8 s_mg_color; +static GColor8 s_fg_color; +#define storage_key_led_color 0 +#define storage_key_bg_color 1 +#define storage_key_mg_color 2 +#define storage_key_fg_color 3 + +static void main_window_load() { + Layer *window_layer = window_get_root_layer(s_main_window); + + if (persist_exists(storage_key_led_color)) { + light_set_color_rgb888(persist_read_int(storage_key_led_color)); + } else { + light_set_color(GColorWhite); + } + + if (persist_exists(storage_key_bg_color)) { + window_set_background_color(s_main_window, (GColor8){.argb = persist_read_int(storage_key_bg_color)}); + } else { + window_set_background_color(s_main_window, GColorBlue); + } + + if (persist_exists(storage_key_mg_color)) { + s_time_mg_layer = text_layer_create(s_time_grect); + text_layer_set_background_color(s_time_mg_layer, GColorClear); + text_layer_set_text_color(s_time_mg_layer, (GColor8){.argb = persist_read_int(storage_key_mg_color)}); + // text_layer_set_font(s_time_mg_layer, s_civic_font); + layer_add_child(window_layer, text_layer_get_layer(s_time_mg_layer)); + } + + if (persist_exists(storage_key_fg_color)) { + text_layer_set_text_color(s_time_layer, (GColor8){.argb = persist_read_int(storage_key_fg_color)}); + } else { + text_layer_set_text_color(s_time_layer, GColorWhite); + } + + layer_add_child(window_layer, text_layer_get_layer(s_time_layer)); +} + +static void main_window_unload() { + if (s_time_mg_layer) { + text_layer_destroy(s_time_mg_layer); + } +} + +static void update_minute_1() { + time_t temp = time(NULL); + struct tm *tick_time = localtime(&temp); + static char s_time_buffer[8]; + strftime(s_time_buffer, sizeof(s_time_buffer), clock_is_24h_style() ? "%H:%M" : "%I:%M", tick_time); + text_layer_set_text(s_time_layer, s_time_buffer); +} + +static void minute_handler(struct tm *tick_time, TimeUnits units_changed) { + update_minute_1(); +} + +static void soft_reload(bool first_load) { + if (!first_load) { + window_stack_remove(s_main_window, false); + window_destroy(s_main_window); + } + s_main_window = window_create(); + window_set_window_handlers( + s_main_window, + (WindowHandlers){.load = main_window_load, .unload = main_window_unload}); + window_stack_push(s_main_window, false); +} + +static void init() { + // s_civic_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_CIVIC_FONT_100)); + s_time_layer = text_layer_create(s_time_grect); + text_layer_set_background_color(s_time_layer, GColorClear); + // text_layer_set_font(s_time_layer, s_civic_font); + update_minute_1(); + soft_reload(true); + tick_timer_service_subscribe(MINUTE_UNIT, minute_handler); +} + +static void deinit() { + tick_timer_service_unsubscribe(); + // fonts_unload_custom_font(s_civic_font); + text_layer_destroy(s_time_layer); + window_destroy(s_main_window); +} + +int main(void) { + init(); + app_event_loop(); + deinit(); +} diff --git a/wscript b/wscript new file mode 100644 index 0000000..5238bc8 --- /dev/null +++ b/wscript @@ -0,0 +1,54 @@ +# +# This file is the default set of rules to compile a Pebble application. +# +# Feel free to customize this to your needs. +# +import os.path + +top = '.' +out = 'build' + + +def options(ctx): + ctx.load('pebble_sdk') + + +def configure(ctx): + """ + This method is used to configure your build. ctx.load(`pebble_sdk`) automatically configures + a build for each valid platform in `targetPlatforms`. Platform-specific configuration: add your + change after calling ctx.load('pebble_sdk') and make sure to set the correct environment first. + Universal configuration: add your change prior to calling ctx.load('pebble_sdk'). + """ + ctx.load('pebble_sdk') + + +def build(ctx): + ctx.load('pebble_sdk') + + build_worker = os.path.exists('worker_src') + binaries = [] + + cached_env = ctx.env + for platform in ctx.env.TARGET_PLATFORMS: + ctx.env = ctx.all_envs[platform] + ctx.set_group(ctx.env.PLATFORM_NAME) + app_elf = '{}/pebble-app.elf'.format(ctx.env.BUILD_DIR) + ctx.pbl_build(source=ctx.path.ant_glob('src/c/**/*.c'), target=app_elf, bin_type='app') + + if build_worker: + worker_elf = '{}/pebble-worker.elf'.format(ctx.env.BUILD_DIR) + binaries.append({'platform': platform, 'app_elf': app_elf, 'worker_elf': worker_elf}) + ctx.pbl_build(source=ctx.path.ant_glob('worker_src/c/**/*.c'), + target=worker_elf, + bin_type='worker') + else: + binaries.append({'platform': platform, 'app_elf': app_elf}) + ctx.env = cached_env + + ctx.set_group('bundle') + ctx.pbl_bundle(binaries=binaries, + js=ctx.path.ant_glob(['src/pkjs/**/*.js', + 'src/pkjs/**/*.json', + 'src/common/**/*.js']), + js_entry_file='src/pkjs/index.js')