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@bahbka.com>2014-06-30 13:41:35 +0400
committerbahbka <bahbka@bahbka.com>2014-06-30 13:41:35 +0400
commit47573c0bc5409c7a77121d99fec5d1603cf31f59 (patch)
tree96331141f9276d1df1555f8266516e40ccebe9e3
parentdaad0dec4f26d95105d4c4e0b040deee0107ddda (diff)
Append GET param to url on short/long select button update.
-rw-r--r--README.md18
-rw-r--r--appinfo.json4
-rw-r--r--resources/configuration.html5
-rw-r--r--src/js/pebble-js-app.src.js63
-rw-r--r--src/pebble-my-data.c57
5 files changed, 91 insertions, 56 deletions
diff --git a/README.md b/README.md
index 19bf706..64575a5 100644
--- a/README.md
+++ b/README.md
@@ -13,6 +13,7 @@ Inspired by [Pebble Cards](http://keanulee.com/pebblecards).
* Fetch JSON from custom URL, specified in settings
* No companion app required, using PebbleKit JS
* Force update with select button
+* Append short=1 or long=1 GET param on short/long select button update
* Scrollable data area
* Custom update interval, specified in JSON
* Vibrate on update if specified in JSON
@@ -41,6 +42,7 @@ JSON output example (some fields are optional):
"theme": 0
}
+GET param short=1 or long=1 added to URL on short or long select button update
### Vibrate
- 0 - Don't vibrate
@@ -50,14 +52,14 @@ JSON output example (some fields are optional):
### Fonts
-- 1 - FONT_KEY_GOTHIC_14
-- 2 - FONT_KEY_GOTHIC_14_BOLD
-- 3 - FONT_KEY_GOTHIC_18
-- 4 - FONT_KEY_GOTHIC_18_BOLD
-- 5 - FONT_KEY_GOTHIC_24
-- 6 - FONT_KEY_GOTHIC_24_BOLD
-- 7 - FONT_KEY_GOTHIC_28
-- 8 - FONT_KEY_GOTHIC_28_BOLD
+- 1 - GOTHIC_14
+- 2 - GOTHIC_14_BOLD
+- 3 - GOTHIC_18
+- 4 - GOTHIC_18_BOLD
+- 5 - GOTHIC_24
+- 6 - GOTHIC_24_BOLD
+- 7 - GOTHIC_28
+- 8 - GOTHIC_28_BOLD
### Theme
diff --git a/appinfo.json b/appinfo.json
index 9eed41a..4047a91 100644
--- a/appinfo.json
+++ b/appinfo.json
@@ -3,8 +3,8 @@
"shortName": "My Data",
"longName": "My Data",
"companyName": "bahbka",
- "versionCode": 1,
- "versionLabel": "1.0.0",
+ "versionCode": 2,
+ "versionLabel": "1.1.0",
"watchapp": {
"watchface": false
},
diff --git a/resources/configuration.html b/resources/configuration.html
index 4877397..b2757f3 100644
--- a/resources/configuration.html
+++ b/resources/configuration.html
@@ -15,7 +15,7 @@
</head>
<body>
<h1>My Data</h1>
- <h3>v1.0.0, by bahbka</h3>
+ <h3>v1.1.0, by bahbka</h3>
<br><br>
<form action="javascript: settings();" id="settings_form">
<h4>my server URL:</h4>
@@ -32,6 +32,9 @@
"font": 1, // 1..8, try them all
"theme": 0 // 0 - black, 1 - white
}
+
+GET param short=1 or long=1 added to URL on
+short or long select button update
</pre>
<script>
diff --git a/src/js/pebble-js-app.src.js b/src/js/pebble-js-app.src.js
index 833d11b..cc3c3ad 100644
--- a/src/js/pebble-js-app.src.js
+++ b/src/js/pebble-js-app.src.js
@@ -5,34 +5,31 @@
var config = {};
-function fetch_data() {
+function fetch_data(url) {
var req = new XMLHttpRequest();
- if (config["url"]) {
- req.open('GET', config["url"], true);
- req.onload = function(e) {
-
- if (req.readyState == 4) {
- if(req.status == 200) {
- try {
- var response = JSON.parse(req.responseText);
- //console.log("success: " + JSON.stringify(response));
- Pebble.sendAppMessage(response);
-
- } catch(e) {
- console.log("json parse error");
- }
-
- } else {
- console.log("fetch error");
+ req.open('GET', url, true);
+ req.onload = function(e) {
+
+ if (req.readyState == 4) {
+ if(req.status == 200) {
+ try {
+ var response = JSON.parse(req.responseText);
+ //console.log("success: " + JSON.stringify(response));
+ Pebble.sendAppMessage(response);
+
+ } catch(e) {
+ console.log("json parse error");
}
+
+ } else {
+ console.log("fetch error");
}
}
- req.send(null);
- } else {
- Pebble.sendAppMessage({ "content": "URL not defined, chech settings in Pebble App" });
}
+
+ req.send(null);
}
Pebble.addEventListener("ready",
@@ -56,7 +53,22 @@ Pebble.addEventListener("ready",
Pebble.addEventListener("appmessage",
function(e) {
//console.log("received message: " + JSON.stringify(e.payload));
- fetch_data();
+ if (config["url"]) {
+ var url = config["url"];
+ var s = (url.indexOf("?")===-1)?"?":"&";
+
+ if (e.payload["refresh"] == 1) {
+ url = url + s + "short=1";
+
+ } else if (e.payload["refresh"] == 2) {
+ url = url + s + "long=1";
+ }
+
+ fetch_data(url);
+
+ } else {
+ Pebble.sendAppMessage({ "content": "URL not defined, chech settings in Pebble App" });
+ }
}
);
@@ -77,6 +89,11 @@ Pebble.addEventListener("webviewclosed", function(e) {
window.localStorage.setItem('pebble-my-data', e.response);
- fetch_data();
+ if (config["url"]) {
+ fetch_data(config["url"]);
+
+ } else {
+ Pebble.sendAppMessage({ "content": "URL not defined, chech settings in Pebble App" });
+ }
}
});
diff --git a/src/pebble-my-data.c b/src/pebble-my-data.c
index 3a08b46..d3cdcf9 100644
--- a/src/pebble-my-data.c
+++ b/src/pebble-my-data.c
@@ -34,14 +34,13 @@ static GBitmap *update_error_icon_bitmap = NULL;
static AppTimer *timer = NULL;
static AppTimer *timeout_timer = NULL;
+static uint8_t theme = 255;
+
#define DEFAULT_REFRESH 300*1000
#define RETRY_DELAY 60*1000
#define REQUEST_TIMEOUT 30*1000
-static uint8_t theme = 255;
-
-// AppMessage keys
-enum {
+enum { // AppMessage keys
KEY_CONTENT,
KEY_REFRESH,
KEY_VIBRATE,
@@ -49,9 +48,22 @@ enum {
KEY_THEME
};
+enum { // update types
+ PERIODIC_UPDATE,
+ SHORT_PRESS_UPDATE,
+ LONG_PRESS_UPDATE
+};
+
+enum { // themes
+ THEME_BLACK,
+ THEME_WHITE
+};
+
+static uint8_t update_type = PERIODIC_UPDATE;
+
// fill layer used for drawing line and battery charge
static void fill_layer(Layer *layer, GContext* ctx) {
- if (theme != 0) {
+ if (theme != THEME_BLACK) {
graphics_context_set_fill_color(ctx, GColorBlack);
} else {
graphics_context_set_fill_color(ctx, GColorWhite);
@@ -68,10 +80,11 @@ static void request_update() {
layer_set_hidden(bitmap_layer_get_layer(update_icon_layer), false);
// prepare request
- DictionaryIterator *iter;
- app_message_outbox_begin(&iter);
- Tuplet value = TupletInteger(KEY_REFRESH, 255);
- dict_write_tuplet(iter, &value);
+ DictionaryIterator *send_message;
+ app_message_outbox_begin(&send_message);
+
+ Tuplet value = TupletInteger(KEY_REFRESH, update_type);
+ dict_write_tuplet(send_message, &value);
app_message_outbox_send();
@@ -80,7 +93,7 @@ static void request_update() {
}
// schedule request_update
-static void schedule_update(uint32_t delay) {
+static void schedule_update(uint32_t delay, uint8_t type) {
if (timeout_timer) {
app_timer_cancel(timeout_timer);
}
@@ -89,13 +102,14 @@ static void schedule_update(uint32_t delay) {
app_timer_cancel(timer);
}
+ update_type = type; // can't win callbacks data :( use global variable
timeout_timer = app_timer_register(delay, request_update, NULL);
}
// reschedule update if data waiting timed out, also set update_error icon
static void request_timeout() {
bitmap_layer_set_bitmap(update_icon_layer, update_error_icon_bitmap);
- schedule_update(RETRY_DELAY);
+ schedule_update(RETRY_DELAY, PERIODIC_UPDATE);
}
// handle minute tick to update time/date (got from Simplicity watchface without modification)
@@ -149,7 +163,7 @@ static void handle_battery(BatteryChargeState charge_state) {
static void handle_bluetooth(bool connected) {
if (connected) {
layer_set_hidden(bitmap_layer_get_layer(no_phone_icon_layer), true);
- schedule_update(5 * 1000); // schedule update when connection made
+ schedule_update(5 * 1000, PERIODIC_UPDATE); // schedule update when connection made
} else {
layer_set_hidden(bitmap_layer_get_layer(no_phone_icon_layer), false);
vibes_long_pulse(); // achtung! phone lost!
@@ -197,13 +211,13 @@ static void update_info_layer(char *content, uint8_t font) {
// change theme (black/white), do things only when theme realy changed
static void change_theme(uint8_t t) {
- if ((t == 0 || t == 1) && (t != theme)) {
+ if ((t == THEME_BLACK || t == THEME_WHITE) && (t != theme)) {
theme = t;
uint8_t bg = GColorBlack;
uint8_t fg = GColorWhite;
- if (theme == 1) {
+ if (theme == THEME_WHITE) {
bg = GColorWhite;
fg = GColorBlack;
}
@@ -234,7 +248,7 @@ static void change_theme(uint8_t t) {
gbitmap_destroy(update_error_icon_bitmap);
}
- if (theme == 0) {
+ if (theme == THEME_BLACK) {
wbatt_icon_bitmap = gbitmap_create_with_resource(RESOURCE_ID_WBATT_WHITE);
wbatt_charge_icon_bitmap = gbitmap_create_with_resource(RESOURCE_ID_WBATT_CHARGE_WHITE);
no_phone_icon_bitmap = gbitmap_create_with_resource(RESOURCE_ID_NO_PHONE_WHITE);
@@ -264,13 +278,13 @@ void out_sent_handler(DictionaryIterator *sent, void *context) {
// reschedule update if request_update sending failed, also set update_error icon
void out_failed_handler(DictionaryIterator *failed, AppMessageResult reason, void *context) {
bitmap_layer_set_bitmap(update_icon_layer, update_error_icon_bitmap);
- schedule_update(RETRY_DELAY);
+ schedule_update(RETRY_DELAY, PERIODIC_UPDATE);
}
// reschedule update if received data dropped, also set update_error icon
void in_dropped_handler(AppMessageResult reason, void *context) {
bitmap_layer_set_bitmap(update_icon_layer, update_error_icon_bitmap);
- schedule_update(RETRY_DELAY);
+ schedule_update(RETRY_DELAY, PERIODIC_UPDATE);
}
// process received data
@@ -320,18 +334,17 @@ void in_received_handler(DictionaryIterator *received, void *context) {
delay = refresh->value->uint32 * 1000;
}
- schedule_update(delay);
+ schedule_update(delay, PERIODIC_UPDATE);
}
// force update on select short click
static void select_click_handler(ClickRecognizerRef recognizer, void *context) {
- schedule_update(0);
+ schedule_update(0, SHORT_PRESS_UPDATE);
}
// force update on select long click
-// TODO longpress - second url
static void select_long_click_handler(ClickRecognizerRef recognizer, void *context) {
- schedule_update(0);
+ schedule_update(0, LONG_PRESS_UPDATE);
}
// handle select button clicks
@@ -396,7 +409,7 @@ static void window_load(Window *window) {
layer_add_child(window_layer, scroll_layer_get_layer(scroll_layer));
// apply black theme
- change_theme(0);
+ change_theme(THEME_BLACK);
// subscribe events
battery_state_service_subscribe(&handle_battery);