forked from neal/PebbleBucks
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6662b56
Showing
12 changed files
with
429 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
build | ||
.lock-waf* | ||
src/js/config.js | ||
src/js/pebble-js-app.js | ||
resources/images/barcode.png |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# PebbleBucks 2.0 | ||
|
||
PebbleBucks is a Starbucks watch app for the Pebble Smartwatch. It shows your Starbucks barcode and your account information - including the dollar balance, time when it was last updated, number of stars and number of rewards. | ||
|
||
Select button updates the account info with the latest data available. | ||
|
||
Idea and images are from the original PebbleBucks by mattdonders. | ||
|
||
## Requirements | ||
|
||
* Place your barcode in `resources/images/barcode.png`. | ||
* Take a screenshot of the mobile app. | ||
* Crop the image to longer side being 168 pixels and shorter side being about 63 pixels. | ||
* Rotate it 90° such that the height is longer than the width. | ||
* Add your Starbucks credentials in `src/js/config.js`. | ||
|
||
Note: By default, PebbleBucks uses my own API that scrapes the required data from starbucks.com. It is open sourced [here](), feel free to run it on your own server if you don't want to pass your credentials through mine. (although I try to keep my server very secure and the API does not keep any logs or store anything.) | ||
|
||
## Build | ||
|
||
$ sh build.sh | ||
|
||
The `build.sh` script generates the `pebble-js-app.js` with your Starbucks credentials, so use that instead of the normal `pebble build`. | ||
|
||
## Install | ||
|
||
Build and install: | ||
|
||
$ sh build.sh install | ||
|
||
Only install: | ||
|
||
$ pebble install | ||
|
||
## Screenshot | ||
|
||
 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"uuid": "716c56e6-44f7-4ed4-82a5-779dbc560b62", | ||
"shortName": "PebbleBucks", | ||
"longName": "PebbleBucks", | ||
"companyName": "Neal", | ||
"versionCode": 1, | ||
"versionLabel": "1.0.0", | ||
"watchapp": { | ||
"watchface": false | ||
}, | ||
"appKeys": { | ||
"rewards": 0, | ||
"stars": 1, | ||
"balance": 2, | ||
"status": 3 | ||
}, | ||
"resources": { | ||
"media": [ | ||
{ | ||
"menuIcon": true, | ||
"type": "png", | ||
"name": "IMAGE_MENU_ICON", | ||
"file": "images/icon.png" | ||
}, | ||
{ | ||
"type": "png", | ||
"name": "IMAGE_BARCODE", | ||
"file": "images/barcode.png" | ||
}, | ||
{ | ||
"type": "png", | ||
"name": "IMAGE_REWARD", | ||
"file": "images/reward.png" | ||
}, | ||
{ | ||
"type": "png", | ||
"name": "IMAGE_STAR", | ||
"file": "images/star.png" | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
rm src/js/pebble-js-app.js 2> /dev/null | ||
cat src/js/*.js >> src/js/pebble-js-app.js | ||
pebble build || { exit $?; } | ||
if [ "$1" = "install" ]; then | ||
pebble install --logs | ||
fi |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
var api_url = 'http://ineal.me/starbucks/api'; | ||
var username = ''; | ||
var password = ''; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
var maxAppMessageTries = 3; | ||
var appMessageRetryTimeout = 3000; | ||
var appMessageTimeout = 100; | ||
var appMessageQueue = []; | ||
|
||
function sendAppMessage() { | ||
if (appMessageQueue.length > 0) { | ||
currentAppMessage = appMessageQueue[0]; | ||
currentAppMessage.numTries = currentAppMessage.numTries || 0; | ||
currentAppMessage.transactionId = currentAppMessage.transactionId || -1; | ||
if (currentAppMessage.numTries < maxAppMessageTries) { | ||
console.log('Sending AppMessage to Pebble: ' + JSON.stringify(currentAppMessage.message)); | ||
Pebble.sendAppMessage( | ||
currentAppMessage.message, | ||
function(e) { | ||
appMessageQueue.shift(); | ||
setTimeout(function() { | ||
sendAppMessage(); | ||
}, appMessageTimeout); | ||
}, function(e) { | ||
console.log('Failed sending AppMessage for transactionId:' + e.data.transactionId + '. Error: ' + e.data.error.message); | ||
appMessageQueue[0].transactionId = e.data.transactionId; | ||
appMessageQueue[0].numTries++; | ||
setTimeout(function() { | ||
sendAppMessage(); | ||
}, appMessageRetryTimeout); | ||
} | ||
); | ||
} else { | ||
console.log('Failed sending AppMessage for transactionId:' + currentAppMessage.transactionId + '. Bailing. ' + JSON.stringify(currentAppMessage.message)); | ||
} | ||
} | ||
} | ||
|
||
function fetch() { | ||
var params = 'username=' + username + '&password=' + password; | ||
var xhr = new XMLHttpRequest(); | ||
xhr.open('POST', api_url, true); | ||
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); | ||
xhr.setRequestHeader('Content-length', params.length); | ||
xhr.setRequestHeader('Connection', 'close'); | ||
xhr.onload = function(e) { | ||
if (xhr.readyState == 4) { | ||
if (xhr.status == 200) { | ||
if (xhr.responseText) { | ||
res = JSON.parse(xhr.responseText); | ||
rewards = res.rewards || '0'; | ||
stars = res.stars || '0'; | ||
balance = res.dollar_balance || '0'; | ||
balance = '$' + parseFloat(Math.round(balance * 100) / 100).toFixed(2); | ||
status = res.dollar_balance_updated || ''; | ||
status = status.replace(' ', '\n'); | ||
appMessageQueue.push({'message': {'rewards': rewards, 'stars': stars, 'balance': balance, 'status': status}}); | ||
} else { | ||
console.log('Invalid response received! ' + JSON.stringify(xhr)); | ||
appMessageQueue.push({'message': {'status': 'Invalid response!'}}); | ||
} | ||
} else { | ||
console.log('Request returned error code ' + xhr.status.toString()); | ||
appMessageQueue.push({'message': {'status': 'HTTP/1.1 ' + xhr.statusText}}); | ||
} | ||
} | ||
sendAppMessage(); | ||
} | ||
xhr.onerror = function() { | ||
console.log('HTTP request return error'); | ||
appMessageQueue.push({'message': {'status': 'Failed to connect!'}}); | ||
sendAppMessage(); | ||
}; | ||
xhr.send(params); | ||
} | ||
|
||
Pebble.addEventListener('ready', function(e) { | ||
fetch(); | ||
}); | ||
|
||
Pebble.addEventListener('appmessage', function(e) { | ||
fetch(); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/*** | ||
* Pebble Assist | ||
* Copyright (C) 2013 Matthew Tole | ||
***/ | ||
|
||
#pragma once | ||
|
||
#define INFO(...) app_log(APP_LOG_LEVEL_INFO, __FILE__, __LINE__, __VA_ARGS__) | ||
#define LOG(...) app_log(APP_LOG_LEVEL_DEBUG, __FILE__, __LINE__, __VA_ARGS__) | ||
#define WARN(...) app_log(APP_LOG_LEVEL_WARNING, __FILE__, __LINE__, __VA_ARGS__) | ||
#define ERROR(...) app_log(APP_LOG_LEVEL_ERROR, __FILE__, __LINE__, __VA_ARGS__) | ||
|
||
#ifndef MENU_CELL_BASIC_CELL_HEIGHT | ||
#define MENU_CELL_BASIC_CELL_HEIGHT 44 | ||
#endif | ||
|
||
#ifndef PEBBLE_HEIGHT | ||
#define PEBBLE_HEIGHT 168 | ||
#endif | ||
|
||
#ifndef PEBBLE_WIDTH | ||
#define PEBBLE_WIDTH 144 | ||
#endif | ||
|
||
#ifndef STATUS_HEIGHT | ||
#define STATUS_HEIGHT 16 | ||
#endif | ||
|
||
#define layer_add_to_window(layer, window) layer_add_child(window_get_root_layer(window), layer) | ||
#define text_layer_add_to_window(layer, window) layer_add_child(window_get_root_layer(window), text_layer_get_layer(layer)) | ||
#define bitmap_layer_add_to_window(layer, window) layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(layer)) | ||
#define inverter_layer_add_to_window(layer, window) layer_add_child(window_get_root_layer(window), inverter_layer_get_layer(layer)) | ||
#define menu_layer_add_to_window(layer, window) layer_add_child(window_get_root_layer(window), menu_layer_get_layer(layer)) | ||
#define simple_menu_layer_add_to_window(layer, window) layer_add_child(window_get_root_layer(window), simple_menu_layer_get_layer(layer)) | ||
#define text_layer_set_system_font(layer, font) text_layer_set_font(layer, fonts_get_system_font(font)) | ||
#define text_layer_set_colours(layer, foreground, background) text_layer_set_text_color(layer, foreground); text_layer_set_background_color(layer, background) | ||
#define text_layer_set_colors(layer, foreground, background) text_layer_set_text_color(layer, foreground); text_layer_set_background_color(layer, background) | ||
#define layer_create_fullscreen(window) layer_create(layer_get_bounds(window_get_root_layer(window))); | ||
#define text_layer_create_fullscreen(window) text_layer_create(layer_get_bounds(window_get_root_layer(window))); | ||
#define menu_layer_create_fullscreen(window) menu_layer_create(layer_get_bounds(window_get_root_layer(window))); | ||
#define action_bar_layer_create_and_add(action_bar, window) action_bar = action_bar_layer_create(); action_bar_layer_add_to_window(action_bar, window) | ||
|
||
#define window_destroy_safe(window) if (window != NULL) { window_destroy(window); } | ||
#define number_window_destroy_safe(window) if (window != NULL ) { number_window_destroy(window); } | ||
#define text_layer_destroy_safe(layer) if (layer != NULL) { text_layer_destroy(layer); } | ||
#define bitmap_layer_destroy_safe(layer) if (layer != NULL) { bitmap_layer_destroy(layer); } | ||
#define layer_destroy_safe(layer) if (layer != NULL) { layer_destroy(layer); } | ||
#define menu_layer_destroy_safe(layer) if (layer != NULL) { menu_layer_destroy(layer); } | ||
#define simple_menu_layer_destroy_safe(layer) if (layer != NULL) { simple_menu_layer_destroy(layer); } | ||
#define action_bar_layer_destroy_safe(layer) if (layer != NULL) { action_bar_layer_destroy(layer); } | ||
#define scroll_layer_destroy_safe(layer) if (layer != NULL) { scroll_layer_destroy(layer); } | ||
#define app_timer_cancel_safe(timer) if (timer != NULL) { app_timer_cancel(timer); timer = NULL; } | ||
|
||
#define persist_read_int_safe(key, value) if (persist_exists(key)) { return persist_read_int(key); } else { return value; } | ||
#define persist_read_bool_safe(key, value) if (persist_exists(key)) { return persist_read_bool(key); } else { return value; } | ||
|
||
#define fonts_load_resource_font(resource) fonts_load_custom_font(resource_get_handle(resource)) | ||
|
||
#define action_bar_layer_clear_icons(action_bar) action_bar_layer_clear_icon(action_bar, BUTTON_ID_SELECT); action_bar_layer_clear_icon(action_bar, BUTTON_ID_DOWN); action_bar_layer_clear_icon(action_bar, BUTTON_ID_UP) | ||
|
||
#define menu_layer_reload_data_and_mark_dirty(layer) menu_layer_reload_data(layer); layer_mark_dirty(menu_layer_get_layer(layer)); |
Oops, something went wrong.