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
diff options
context:
space:
mode:
authorbahbka <bahbka@gmail.com>2014-07-08 09:52:10 +0400
committerbahbka <bahbka@gmail.com>2014-07-08 09:52:10 +0400
commit426dca7cbfa51b6c247a7c0adbf6c692bf8e1a3a (patch)
treed1ca428da70cb726db792eea91101b34add6fe94
parentd9d7c37da694dbae722dc4ce4bc51276d18250ed (diff)
Change up/down buttons behavior from JSON.
-rw-r--r--appinfo.json11
-rw-r--r--resources/configuration.html2
-rw-r--r--src/js/pebble-js-app.src.js31
-rw-r--r--src/pebble-my-data.c131
4 files changed, 148 insertions, 27 deletions
diff --git a/appinfo.json b/appinfo.json
index 8026976..14386ff 100644
--- a/appinfo.json
+++ b/appinfo.json
@@ -3,8 +3,8 @@
"shortName": "My Data",
"longName": "My Data",
"companyName": "bahbka",
- "versionCode": 203,
- "versionLabel": "2.0.3",
+ "versionCode": 210,
+ "versionLabel": "2.1.0",
"watchapp": {
"watchface": false
},
@@ -19,9 +19,10 @@
"scroll": 6,
"light": 7,
"blink": 8,
- "config_location": 9,
- "config_vibrate": 10,
- "config_seconds": 11
+ "updown": 9,
+ "config_location": 10,
+ "config_vibrate": 11,
+ "config_seconds": 12
},
"resources": {
"media": [
diff --git a/resources/configuration.html b/resources/configuration.html
index 7b6070d..9edae1c 100644
--- a/resources/configuration.html
+++ b/resources/configuration.html
@@ -54,7 +54,7 @@ vim: sw=2 ts=2 expandtab ai -->
</head>
<body onload="put_config();">
<h1>My Data</h1>
- <small>v2.0.3, by bahbka</small>
+ <small>v2.1.0, by bahbka</small>
<hr size="1" />
<form action="javascript: get_config();" id="config_form">
diff --git a/src/js/pebble-js-app.src.js b/src/js/pebble-js-app.src.js
index 93cbd2b..7358525 100644
--- a/src/js/pebble-js-app.src.js
+++ b/src/js/pebble-js-app.src.js
@@ -3,11 +3,15 @@
var MSG = {
PERIODIC_UPDATE: 0,
- SHORT_PRESS_UPDATE: 1,
- LONG_PRESS_UPDATE: 2,
- JSON_RESPONSE: 3,
- CONFIG: 4,
- ERROR: 5
+ SELECT_SHORT_PRESS_UPDATE: 1,
+ SELECT_LONG_PRESS_UPDATE: 2,
+ UP_SHORT_PRESS_UPDATE: 3,
+ UP_LONG_PRESS_UPDATE: 4,
+ DOWN_SHORT_PRESS_UPDATE: 5,
+ DOWN_LONG_PRESS_UPDATE: 6,
+ JSON_RESPONSE: 7,
+ CONFIG: 8,
+ ERROR: 9
};
// default settings
@@ -111,11 +115,18 @@ Pebble.addEventListener("appmessage",
var url = config["url"];
var s = (url.indexOf("?")===-1)?"?":"&";
- if (e.payload["refresh"] == MSG.SHORT_PRESS_UPDATE) {
- url = url + s + "short=1";
-
- } else if (e.payload["refresh"] == MSG.LONG_PRESS_UPDATE) {
- url = url + s + "long=1";
+ if (e.payload["refresh"] == MSG.SELECT_SHORT_PRESS_UPDATE) {
+ url = url + s + "select=1";
+ } else if (e.payload["refresh"] == MSG.SELECT_LONG_PRESS_UPDATE) {
+ url = url + s + "select=2";
+ } else if (e.payload["refresh"] == MSG.UP_SHORT_PRESS_UPDATE) {
+ url = url + s + "up=1";
+ } else if (e.payload["refresh"] == MSG.UP_LONG_PRESS_UPDATE) {
+ url = url + s + "up=2";
+ } else if (e.payload["refresh"] == MSG.DOWN_SHORT_PRESS_UPDATE) {
+ url = url + s + "down=1";
+ } else if (e.payload["refresh"] == MSG.DOWN_LONG_PRESS_UPDATE) {
+ url = url + s + "down=2";
}
fetch_data(url);
diff --git a/src/pebble-my-data.c b/src/pebble-my-data.c
index 8a164ad..9065a57 100644
--- a/src/pebble-my-data.c
+++ b/src/pebble-my-data.c
@@ -47,6 +47,8 @@ static uint8_t blink_count;
bool config_vibrate = true;
bool config_seconds = false;
+bool updown = false;
+
#define DEFAULT_REFRESH 300*1000
#define RETRY_DELAY 60*1000
#define REQUEST_TIMEOUT 30*1000
@@ -68,6 +70,7 @@ enum { // AppMessage keys
KEY_SCROLL,
KEY_LIGHT,
KEY_BLINK,
+ KEY_UPDOWN,
KEY_CONFIG_LOCATION,
KEY_CONFIG_VIBRATE,
KEY_CONFIG_SECONDS
@@ -75,8 +78,12 @@ enum { // AppMessage keys
enum { // msg type
MSG_PERIODIC_UPDATE,
- MSG_SHORT_PRESS_UPDATE,
- MSG_LONG_PRESS_UPDATE,
+ MSG_SELECT_SHORT_PRESS_UPDATE,
+ MSG_SELECT_LONG_PRESS_UPDATE,
+ MSG_UP_SHORT_PRESS_UPDATE,
+ MSG_UP_LONG_PRESS_UPDATE,
+ MSG_DOWN_SHORT_PRESS_UPDATE,
+ MSG_DOWN_LONG_PRESS_UPDATE,
MSG_JSON_RESPONSE,
MSG_CONFIG,
MSG_ERROR
@@ -89,6 +96,33 @@ enum { // themes
static uint8_t update_type = MSG_PERIODIC_UPDATE;
+// protos
+static void fill_layer(Layer *layer, GContext* ctx);
+
+static void request_update();
+static void schedule_update(uint32_t delay, uint8_t type);
+static void request_timeout();
+
+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 change_info_theme(uint8_t theme);
+static void blink_info();
+static void update_info_layer(char *content, uint8_t font, bool scroll_up, bool new_updown);
+static void change_theme(uint8_t t);
+
+static void select_click_handler(ClickRecognizerRef recognizer, void *context);
+static void select_long_click_handler(ClickRecognizerRef recognizer, void *context);
+static void up_click_handler(ClickRecognizerRef recognizer, void *context);
+static void up_long_click_handler(ClickRecognizerRef recognizer, void *context);
+static void down_click_handler(ClickRecognizerRef recognizer, void *context);
+static void down_long_click_handler(ClickRecognizerRef recognizer, void *context);
+static void click_config_provider(void *context);
+static void click_config_provider_updown(void *context);
+
// fill layer used for drawing line and battery charge
static void fill_layer(Layer *layer, GContext* ctx) {
if (theme != THEME_BLACK) {
@@ -99,8 +133,6 @@ static void fill_layer(Layer *layer, GContext* ctx) {
graphics_fill_rect(ctx, layer_get_bounds(layer), 0, GCornerNone);
}
-static void request_timeout(); // proto
-
// request data update thru AppMessage
static void request_update() {
// show update icon
@@ -233,7 +265,7 @@ static void handle_bluetooth(bool connected) {
}
// update data in main layer (content, font)
-static void update_info_layer(char *content, uint8_t font, bool scroll_up) {
+static void update_info_layer(char *content, uint8_t font, bool scroll_up, bool new_updown) {
// change font
switch (font) {
case 1:
@@ -264,6 +296,22 @@ static void update_info_layer(char *content, uint8_t font, bool scroll_up) {
break;
}
+ // change up/down buttons behavior
+ if (new_updown != updown) {
+ if (new_updown) {
+ scroll_layer_set_callbacks(scroll_layer, (ScrollLayerCallbacks) {
+ .click_config_provider = &click_config_provider_updown
+ });
+ scroll_layer_set_click_config_onto_window(scroll_layer, window);
+ } else {
+ scroll_layer_set_callbacks(scroll_layer, (ScrollLayerCallbacks) {
+ .click_config_provider = &click_config_provider
+ });
+ scroll_layer_set_click_config_onto_window(scroll_layer, window);
+ }
+ updown = new_updown;
+ }
+
text_layer_set_text(text_info_layer, content); // set text
GSize max_size = text_layer_get_content_size(text_info_layer);
max_size.w = 144;
@@ -467,12 +515,19 @@ void in_received_handler(DictionaryIterator *received, void *context) {
scroll_up = true;
}
- Tuple *font = dict_find(received, KEY_FONT);
+ Tuple *updown_tuple = dict_find(received, KEY_UPDOWN);
+ bool updown_beh = false;
+ if (updown_tuple && updown_tuple->value->uint8 == 1) {
+ updown_beh = true;
+ }
+
+ Tuple *font_tuple = dict_find(received, KEY_FONT);
+ uint8_t font = 0;
if (font) {
- update_info_layer(content, font->value->uint8, scroll_up);
- } else {
- update_info_layer(content, 0, scroll_up);
+ font = font_tuple->value->uint8;
}
+
+ update_info_layer(content, font, scroll_up, updown_beh);
}
// maybe need to vibrate?
@@ -532,6 +587,50 @@ void in_received_handler(DictionaryIterator *received, void *context) {
}
}
+// force update on up short click
+static void up_click_handler(ClickRecognizerRef recognizer, void *context) {
+ if (blink_count > 0) { // if blinking - stop it!
+ blink_count = 0;
+ blink_info();
+
+ } else {
+ schedule_update(0, MSG_UP_SHORT_PRESS_UPDATE);
+ }
+}
+
+// force update on up long click
+static void up_long_click_handler(ClickRecognizerRef recognizer, void *context) {
+ if (blink_count > 0) { // if blinking - stop it!
+ blink_count = 0;
+ blink_info();
+
+ } else {
+ schedule_update(0, MSG_UP_LONG_PRESS_UPDATE);
+ }
+}
+
+// force update on down short click
+static void down_click_handler(ClickRecognizerRef recognizer, void *context) {
+ if (blink_count > 0) { // if blinking - stop it!
+ blink_count = 0;
+ blink_info();
+
+ } else {
+ schedule_update(0, MSG_DOWN_SHORT_PRESS_UPDATE);
+ }
+}
+
+// force update on down long click
+static void down_long_click_handler(ClickRecognizerRef recognizer, void *context) {
+ if (blink_count > 0) { // if blinking - stop it!
+ blink_count = 0;
+ blink_info();
+
+ } else {
+ schedule_update(0, MSG_DOWN_LONG_PRESS_UPDATE);
+ }
+}
+
// force update on select short click
static void select_click_handler(ClickRecognizerRef recognizer, void *context) {
if (blink_count > 0) { // if blinking - stop it!
@@ -539,7 +638,7 @@ static void select_click_handler(ClickRecognizerRef recognizer, void *context) {
blink_info();
} else {
- schedule_update(0, MSG_SHORT_PRESS_UPDATE);
+ schedule_update(0, MSG_SELECT_SHORT_PRESS_UPDATE);
}
}
@@ -550,7 +649,7 @@ static void select_long_click_handler(ClickRecognizerRef recognizer, void *conte
blink_info();
} else {
- schedule_update(0, MSG_LONG_PRESS_UPDATE);
+ schedule_update(0, MSG_SELECT_LONG_PRESS_UPDATE);
}
}
@@ -560,6 +659,16 @@ static void click_config_provider(void *context) {
window_long_click_subscribe(BUTTON_ID_SELECT, 0, select_long_click_handler, NULL);
}
+// handle select/up/down buttons clicks
+static void click_config_provider_updown(void *context) {
+ window_single_click_subscribe(BUTTON_ID_SELECT, select_click_handler);
+ window_long_click_subscribe(BUTTON_ID_SELECT, 0, select_long_click_handler, NULL);
+ window_single_click_subscribe(BUTTON_ID_UP, up_click_handler);
+ window_long_click_subscribe(BUTTON_ID_UP, 0, up_long_click_handler, NULL);
+ window_single_click_subscribe(BUTTON_ID_DOWN, down_click_handler);
+ window_long_click_subscribe(BUTTON_ID_DOWN, 0, down_long_click_handler, NULL);
+}
+
// prepare window!
static void window_load(Window *window) {
Layer *window_layer = window_get_root_layer(window);