diff options
Diffstat (limited to '')
-rw-r--r-- | .gitignore | 6 | ||||
-rw-r--r-- | appinfo.json | 17 | ||||
-rw-r--r-- | src/battery.c | 67 | ||||
-rw-r--r-- | wscript | 24 |
4 files changed, 114 insertions, 0 deletions
@@ -1,3 +1,8 @@ +<<<<<<< HEAD + +# Ignore build generated files +build +======= # Object files *.o *.ko @@ -16,3 +21,4 @@ *.exe *.out *.app +>>>>>>> edd9e6670a145e3f41f34c4c6c1cfee44f61a2c7 diff --git a/appinfo.json b/appinfo.json new file mode 100644 index 0000000..889f4fb --- /dev/null +++ b/appinfo.json @@ -0,0 +1,17 @@ +{ + "uuid": "20146c38-3e2d-4f45-8f28-112961c0e2f4", + "shortName": "Battery", + "longName": "Battery Monitor", + "companyName": "Snilius", + "versionCode": 1, + "versionLabel": "1.0.0", + "watchapp": { + "watchface": false + }, + "appKeys": { + "dummy": 0 + }, + "resources": { + "media": [] + } +} diff --git a/src/battery.c b/src/battery.c new file mode 100644 index 0000000..24790b2 --- /dev/null +++ b/src/battery.c @@ -0,0 +1,67 @@ +#include <pebble.h> +#include <inttypes.h> + +static Window *window; +static TextLayer *battery_percentage; +static TextLayer *charge_status; +static char percent_show[5]; + +static void battery_state_receiver(BatteryChargeState chargeState){ + uint8_t percent = chargeState.charge_percent; + + snprintf(percent_show, 5, "%i%%", percent); + text_layer_set_text(battery_percentage, percent_show); + + if(chargeState.is_plugged && chargeState.is_charging) + text_layer_set_text(charge_status, "Charging"); + else if(chargeState.is_plugged && !chargeState.is_charging) + text_layer_set_text(charge_status, "Plugged - Not Charging"); + else if(!chargeState.is_plugged && !chargeState.is_charging) + text_layer_set_text(charge_status, "Discharging"); +} + +static void window_load(Window *window) { + Layer *window_layer = window_get_root_layer(window); + GRect bounds = layer_get_bounds(window_layer); + + battery_percentage = text_layer_create((GRect) { .origin = { 0, 52 }, .size = { bounds.size.w, 20 } }); + text_layer_set_text_alignment(battery_percentage, GTextAlignmentCenter); + + charge_status = text_layer_create((GRect) { .origin = { 0, 82 }, .size = { bounds.size.w, 20 } }); + text_layer_set_text_alignment(charge_status, GTextAlignmentCenter); + + // make a peek to start + battery_state_receiver(battery_state_service_peek()); + + layer_add_child(window_layer, text_layer_get_layer(battery_percentage)); + layer_add_child(window_layer, text_layer_get_layer(charge_status)); +} + +static void window_unload(Window *window) { + text_layer_destroy(battery_percentage); + text_layer_destroy(charge_status); +} + +static void init(void) { + window = window_create(); + window_set_window_handlers(window, (WindowHandlers) { + .load = window_load, + .unload = window_unload, + }); + const bool animated = true; + window_stack_push(window, animated); + battery_state_service_subscribe(battery_state_receiver); +} + +static void deinit(void) { + window_destroy(window); +} + +int main(void) { + init(); + + APP_LOG(APP_LOG_LEVEL_DEBUG, "Done initializing, pushed window: %p", window); + + app_event_loop(); + deinit(); +} @@ -0,0 +1,24 @@ + +# +# This file is the default set of rules to compile a Pebble project. +# +# Feel free to customize this to your needs. +# + +top = '.' +out = 'build' + +def options(ctx): + ctx.load('pebble_sdk') + +def configure(ctx): + ctx.load('pebble_sdk') + +def build(ctx): + ctx.load('pebble_sdk') + + ctx.pbl_program(source=ctx.path.ant_glob('src/**/*.c'), + target='pebble-app.elf') + + ctx.pbl_bundle(elf='pebble-app.elf', + js=ctx.path.ant_glob('src/js/**/*.js')) |