From 16d647d76ec15e56148f39b230e2e71eba055e53 Mon Sep 17 00:00:00 2001 From: bahbka Date: Sun, 13 Jul 2014 14:58:03 +0400 Subject: Update with shaking function. --- appinfo.json | 7 ++++--- resources/configuration.html | 12 +++++++++++- src/js/pebble-js-app.src.js | 15 +++++++++++---- src/pebble-my-data.c | 30 +++++++++++++++++++++++++++++- 4 files changed, 55 insertions(+), 9 deletions(-) diff --git a/appinfo.json b/appinfo.json index 2bc396d..67125dd 100644 --- a/appinfo.json +++ b/appinfo.json @@ -3,8 +3,8 @@ "shortName": "My Data", "longName": "My Data", "companyName": "bahbka", - "versionCode": 220, - "versionLabel": "2.2.0", + "versionCode": 230, + "versionLabel": "2.3.0", "watchapp": { "watchface": false }, @@ -22,7 +22,8 @@ "updown": 9, "config_location": 10, "config_vibrate": 11, - "config_seconds": 12 + "config_seconds": 12, + "config_shake": 13 }, "resources": { "media": [ diff --git a/resources/configuration.html b/resources/configuration.html index 4f21aae..331537d 100644 --- a/resources/configuration.html +++ b/resources/configuration.html @@ -63,7 +63,7 @@ vim: sw=2 ts=2 expandtab ai

My Data

- v2.2.0, by bahbka + v2.3.0, by bahbka
@@ -111,6 +111,16 @@ vim: sw=2 ts=2 expandtab ai + +
+
+ Update with shaking:
+ (possible unnecessary updates) +
+
+ +
+
diff --git a/src/js/pebble-js-app.src.js b/src/js/pebble-js-app.src.js index bf08528..4bbb9d8 100644 --- a/src/js/pebble-js-app.src.js +++ b/src/js/pebble-js-app.src.js @@ -9,16 +9,18 @@ var MSG = { UP_LONG_PRESS_UPDATE: 4, DOWN_SHORT_PRESS_UPDATE: 5, DOWN_LONG_PRESS_UPDATE: 6, - JSON_RESPONSE: 7, - CONFIG: 8, - ERROR: 9 + SHAKE_UPDATE: 7, + JSON_RESPONSE: 8, + CONFIG: 9, + ERROR: 10 }; // default settings var config = { "config_location": false, "config_vibrate": true, - "config_seconds": true + "config_seconds": true, + "config_shake": false }; function http_request(url) { @@ -44,6 +46,9 @@ function http_request(url) { var response = JSON.parse(req.responseText); //console.log("success: " + JSON.stringify(response)); response["msg_type"] = MSG.JSON_RESPONSE; + + //TODO truncate content bytes= bytes.substring(0, bytes.length-1); + Pebble.sendAppMessage(response); if (response["auth"] != null) { @@ -146,6 +151,8 @@ Pebble.addEventListener("appmessage", url = url + s + "down=1"; } else if (e.payload["refresh"] == MSG.DOWN_LONG_PRESS_UPDATE) { url = url + s + "down=2"; + } else if (e.payload["refresh"] == MSG.SHAKE_UPDATE) { + url = url + s + "shake=1"; } fetch_data(url); diff --git a/src/pebble-my-data.c b/src/pebble-my-data.c index aba14d8..32e8c89 100644 --- a/src/pebble-my-data.c +++ b/src/pebble-my-data.c @@ -46,6 +46,7 @@ static uint8_t blink_count; bool config_vibrate = true; bool config_seconds = false; +bool config_shake = false; bool updown = false; @@ -73,7 +74,8 @@ enum { // AppMessage keys KEY_UPDOWN, KEY_CONFIG_LOCATION, KEY_CONFIG_VIBRATE, - KEY_CONFIG_SECONDS + KEY_CONFIG_SECONDS, + KEY_CONFIG_SHAKE }; enum { // msg type @@ -84,6 +86,7 @@ enum { // msg type MSG_UP_LONG_PRESS_UPDATE, MSG_DOWN_SHORT_PRESS_UPDATE, MSG_DOWN_LONG_PRESS_UPDATE, + MSG_SHAKE_UPDATE, MSG_JSON_RESPONSE, MSG_CONFIG, MSG_ERROR @@ -108,6 +111,7 @@ static void draw_digit(BitmapLayer *position, char digit); static void handle_timer_tick(struct tm *tick_time, TimeUnits units_changed); static void handle_battery(BatteryChargeState charge_state); static void handle_bluetooth(bool connected); +static void handle_shake(AccelAxisType axis, int32_t direction); static void change_info_theme(uint8_t theme); static void blink_info(); @@ -264,6 +268,10 @@ static void handle_bluetooth(bool connected) { } } +static void handle_shake(AccelAxisType axis, int32_t direction) { + schedule_update(0, MSG_SHAKE_UPDATE); +} + // update data in main layer (content, font) static void update_info_layer(char *content, uint8_t font, bool scroll_up, bool new_updown) { // change font @@ -496,6 +504,21 @@ void in_received_handler(DictionaryIterator *received, void *context) { } } + Tuple *config_shake_tuple = dict_find(received, KEY_CONFIG_SHAKE); + if (config_shake_tuple) { + if (strcmp(config_shake_tuple->value->cstring, "true") == 0) { + if (!config_shake) { + config_shake = true; + accel_tap_service_subscribe(handle_shake); + } + } else { + if (config_shake) { + config_shake = false; + accel_tap_service_unsubscribe(); + } + } + } + // TODO location icon? } else if (msg_type_tuple->value->uint8 == MSG_ERROR) { @@ -753,6 +776,11 @@ static void window_unload(Window *window) { battery_state_service_unsubscribe(); bluetooth_connection_service_unsubscribe(); + if (config_shake) { + config_shake = false; + accel_tap_service_unsubscribe(); + } + text_layer_destroy(text_date_layer); text_layer_destroy(text_info_layer); -- cgit v1.2.3