Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ClusterM/pebble-my-data.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbahbka <bahbka@gmail.com>2014-07-13 14:58:03 +0400
committerbahbka <bahbka@gmail.com>2014-07-13 14:58:03 +0400
commit16d647d76ec15e56148f39b230e2e71eba055e53 (patch)
treefa25aab5575342991b931a3bbf8e7d258a099416 /src
parentc2d2725f0da8ba42b33935de4d7a4cb09851fc8d (diff)
Update with shaking function.
Diffstat (limited to 'src')
-rw-r--r--src/js/pebble-js-app.src.js15
-rw-r--r--src/pebble-my-data.c30
2 files changed, 40 insertions, 5 deletions
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);