aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Häggqvist <[email protected]>2014-01-23 13:02:16 +0100
committerVictor Häggqvist <[email protected]>2014-01-23 13:02:16 +0100
commit43f59a9737e3f157c707c6868314bbfa77d4a005 (patch)
tree328cff70bb7bb8f698b573c1c1157c42a92a3d40
init
-rw-r--r--.gitignore3
-rw-r--r--appinfo.json17
-rw-r--r--src/battery.c77
-rw-r--r--wscript24
4 files changed, 121 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..9ed9d4f
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+
+# Ignore build generated files
+build
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..1fd9584
--- /dev/null
+++ b/src/battery.c
@@ -0,0 +1,77 @@
+#include <pebble.h>
+#include <inttypes.h>
+
+static Window *window;
+static TextLayer *battery_percentage;
+static TextLayer *charge_status;
+static BatteryChargeState chargeState;
+static char percent_show[5];
+
+static void battery_state_receiver(BatteryChargeState chargeState){
+
+ uint8_t percent = chargeState.charge_percent;
+
+ snprintf(percent_show, 5, "%i%%", percent);
+
+ APP_LOG(APP_LOG_LEVEL_DEBUG, "percent: %s", percent_show);
+ text_layer_set_text(battery_percentage, percent_show);
+
+ if(chargeState.is_charging){
+ text_layer_set_text(charge_status, "Charging");
+ APP_LOG(APP_LOG_LEVEL_DEBUG, "charge state: charging");
+ }
+ else{
+ text_layer_set_text(charge_status, "Discharging");
+ APP_LOG(APP_LOG_LEVEL_DEBUG, "charge state: discharging");
+ }
+
+ if(chargeState.is_plugged)
+ APP_LOG(APP_LOG_LEVEL_DEBUG, "charge state: plugged");
+ else
+ APP_LOG(APP_LOG_LEVEL_DEBUG, "charge state: unplugged");
+}
+
+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);
+
+ chargeState = battery_state_service_peek();
+ battery_state_receiver(chargeState);
+
+ 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);
+}
+
+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();
+}
diff --git a/wscript b/wscript
new file mode 100644
index 0000000..0554dc8
--- /dev/null
+++ b/wscript
@@ -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'))