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

github.com/ClusterM/pebble-mario.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey 'Cluster' Avdyukhin <ClusterM@users.noreply.github.com>2015-05-23 07:19:09 +0300
committerAlexey 'Cluster' Avdyukhin <ClusterM@users.noreply.github.com>2015-05-23 07:19:09 +0300
commit2262d33820f737a19b9e9b08131b57f091532044 (patch)
treee639e42c013b1d89e11904fb7a6629ee98b23a04
parent62cb944b85e5b44ac6238f78e9b9a854e8c02b0d (diff)
Weather!
-rw-r--r--appinfo.json76
-rw-r--r--resources/images/weather_broken_clouds.pngbin0 -> 216 bytes
-rw-r--r--resources/images/weather_clear_sky_day.pngbin0 -> 226 bytes
-rw-r--r--resources/images/weather_clear_sky_night.pngbin0 -> 206 bytes
-rw-r--r--resources/images/weather_few_clouds_day.pngbin0 -> 235 bytes
-rw-r--r--resources/images/weather_few_clouds_night.pngbin0 -> 215 bytes
-rw-r--r--resources/images/weather_mist.pngbin0 -> 217 bytes
-rw-r--r--resources/images/weather_rain_day.pngbin0 -> 238 bytes
-rw-r--r--resources/images/weather_rain_night.pngbin0 -> 215 bytes
-rw-r--r--resources/images/weather_scattered_clouds.pngbin0 -> 222 bytes
-rw-r--r--resources/images/weather_shower_rain.pngbin0 -> 230 bytes
-rw-r--r--resources/images/weather_snow.pngbin0 -> 213 bytes
-rw-r--r--resources/images/weather_thunderstorm.pngbin0 -> 207 bytes
-rw-r--r--resources/images/weather_unknown.pngbin0 -> 259 bytes
-rw-r--r--src/js/pebble-js-app.js67
-rw-r--r--src/pebble-mario.c236
16 files changed, 347 insertions, 32 deletions
diff --git a/appinfo.json b/appinfo.json
index 9091189..5d22383 100644
--- a/appinfo.json
+++ b/appinfo.json
@@ -1,12 +1,19 @@
{
"appKeys": {
+ "battery_request": 4,
"config_background": 7,
"config_show_battery": 1,
"config_show_no_phone": 0,
"config_show_phone_battery": 6,
- "config_vibe": 2
+ "config_show_weather": 8,
+ "config_temperature_units": 999,
+ "config_vibe": 2,
+ "weather_icon_id": 10,
+ "weather_request": 12,
+ "weather_temperature": 11
},
"capabilities": [
+ "location",
"configurable"
],
"companyName": "Cluster",
@@ -15,6 +22,71 @@
"resources": {
"media": [
{
+ "file": "images/weather_few_clouds_night.png",
+ "name": "IMAGE_WEATHER_FEW_CLOUDS_NIGHT",
+ "type": "png"
+ },
+ {
+ "file": "images/weather_rain_night.png",
+ "name": "IMAGE_WEATHER_RAIN_NIGHT",
+ "type": "png"
+ },
+ {
+ "file": "images/weather_clear_sky_night.png",
+ "name": "IMAGE_WEATHER_CLEAR_SKY_NIGHT",
+ "type": "png"
+ },
+ {
+ "file": "images/weather_unknown.png",
+ "name": "IMAGE_WEATHER_UNKNOWN",
+ "type": "png"
+ },
+ {
+ "file": "images/weather_thunderstorm.png",
+ "name": "IMAGE_WEATHER_THUNDERSTORM",
+ "type": "png"
+ },
+ {
+ "file": "images/weather_snow.png",
+ "name": "IMAGE_WEATHER_SNOW",
+ "type": "png"
+ },
+ {
+ "file": "images/weather_shower_rain.png",
+ "name": "IMAGE_WEATHER_SHOWER_RAIN",
+ "type": "png"
+ },
+ {
+ "file": "images/weather_scattered_clouds.png",
+ "name": "IMAGE_WEATHER_SCATTERED_CLOUDS",
+ "type": "png"
+ },
+ {
+ "file": "images/weather_rain_day.png",
+ "name": "IMAGE_WEATHER_RAIN_DAY",
+ "type": "png"
+ },
+ {
+ "file": "images/weather_mist.png",
+ "name": "IMAGE_WEATHER_MIST",
+ "type": "png"
+ },
+ {
+ "file": "images/weather_few_clouds_day.png",
+ "name": "IMAGE_WEATHER_FEW_CLOUDS_DAY",
+ "type": "png"
+ },
+ {
+ "file": "images/weather_clear_sky_day.png",
+ "name": "IMAGE_WEATHER_CLEAR_SKY_DAY",
+ "type": "png"
+ },
+ {
+ "file": "images/weather_broken_clouds.png",
+ "name": "IMAGE_WEATHER_BROKEN_CLOUDS",
+ "type": "png"
+ },
+ {
"file": "images/watch_battery.png",
"name": "IMAGE_WATCH_BATTERY",
"type": "png"
@@ -101,7 +173,7 @@
"basalt"
],
"uuid": "43caa750-2896-4f46-94dc-1adbd4bc1ff3",
- "versionLabel": "3.01",
+ "versionLabel": "3.12",
"watchapp": {
"watchface": true
}
diff --git a/resources/images/weather_broken_clouds.png b/resources/images/weather_broken_clouds.png
new file mode 100644
index 0000000..a0f0475
--- /dev/null
+++ b/resources/images/weather_broken_clouds.png
Binary files differ
diff --git a/resources/images/weather_clear_sky_day.png b/resources/images/weather_clear_sky_day.png
new file mode 100644
index 0000000..d4750ae
--- /dev/null
+++ b/resources/images/weather_clear_sky_day.png
Binary files differ
diff --git a/resources/images/weather_clear_sky_night.png b/resources/images/weather_clear_sky_night.png
new file mode 100644
index 0000000..8d3e85f
--- /dev/null
+++ b/resources/images/weather_clear_sky_night.png
Binary files differ
diff --git a/resources/images/weather_few_clouds_day.png b/resources/images/weather_few_clouds_day.png
new file mode 100644
index 0000000..129170e
--- /dev/null
+++ b/resources/images/weather_few_clouds_day.png
Binary files differ
diff --git a/resources/images/weather_few_clouds_night.png b/resources/images/weather_few_clouds_night.png
new file mode 100644
index 0000000..fada714
--- /dev/null
+++ b/resources/images/weather_few_clouds_night.png
Binary files differ
diff --git a/resources/images/weather_mist.png b/resources/images/weather_mist.png
new file mode 100644
index 0000000..f7bf175
--- /dev/null
+++ b/resources/images/weather_mist.png
Binary files differ
diff --git a/resources/images/weather_rain_day.png b/resources/images/weather_rain_day.png
new file mode 100644
index 0000000..a4ee928
--- /dev/null
+++ b/resources/images/weather_rain_day.png
Binary files differ
diff --git a/resources/images/weather_rain_night.png b/resources/images/weather_rain_night.png
new file mode 100644
index 0000000..fada714
--- /dev/null
+++ b/resources/images/weather_rain_night.png
Binary files differ
diff --git a/resources/images/weather_scattered_clouds.png b/resources/images/weather_scattered_clouds.png
new file mode 100644
index 0000000..3d7302e
--- /dev/null
+++ b/resources/images/weather_scattered_clouds.png
Binary files differ
diff --git a/resources/images/weather_shower_rain.png b/resources/images/weather_shower_rain.png
new file mode 100644
index 0000000..b30be7a
--- /dev/null
+++ b/resources/images/weather_shower_rain.png
Binary files differ
diff --git a/resources/images/weather_snow.png b/resources/images/weather_snow.png
new file mode 100644
index 0000000..2f4e292
--- /dev/null
+++ b/resources/images/weather_snow.png
Binary files differ
diff --git a/resources/images/weather_thunderstorm.png b/resources/images/weather_thunderstorm.png
new file mode 100644
index 0000000..6b29cb6
--- /dev/null
+++ b/resources/images/weather_thunderstorm.png
Binary files differ
diff --git a/resources/images/weather_unknown.png b/resources/images/weather_unknown.png
new file mode 100644
index 0000000..90b1763
--- /dev/null
+++ b/resources/images/weather_unknown.png
Binary files differ
diff --git a/src/js/pebble-js-app.js b/src/js/pebble-js-app.js
index 018cb40..029fe08 100644
--- a/src/js/pebble-js-app.js
+++ b/src/js/pebble-js-app.js
@@ -1,12 +1,62 @@
var initialized = false;
var options = {
"config_show_no_phone": true,
+ "config_show_weather": true,
+ "config_temperature_units": 0,
"config_show_battery": true,
- "config_show_phone_battery": true,
+ "config_show_phone_battery": false,
"config_vibe": false,
"config_background": 0,
};
+var locationOptions = { "timeout": 60000, "maximumAge": 60000 * 30 };
+
+function locationSuccess(pos) {
+ coordinates = pos.coords;
+ console.log("Location: lat = "+coordinates.latitude+", lon = "+coordinates.longitude);
+ console.log("Requesting weather...");
+ var req = new XMLHttpRequest();
+ req.open('GET', "http://api.openweathermap.org/data/2.5/weather?lat="+coordinates.latitude+"&lon="+coordinates.longitude, true);
+ req.onreadystatechange = function() {
+ if (req.readyState == 4) {
+ if(req.status == 200) {
+ //console.log("Response: "+req.responseText);
+ var response = JSON.parse(req.responseText);
+ if (response.weather.length > 0)
+ {
+ var weather = response.weather[0];
+ var temp = response.main.temp;
+ //console.log("Icon: "+weather.icon);
+ //console.log("Temperature: "+temp);
+ var iconId = parseInt(weather.icon.substring(0,2));
+ if (weather.icon.charAt(2) == "n") iconId += 100;
+ var tempConverted = temp - 273.15;
+ if (options.config_temperature_units == 0)
+ tempConverted = Math.round(tempConverted*1.8 + 32);
+ else
+ tempConverted = Math.round(tempConverted);
+ console.log("Icon id: "+iconId);
+ console.log("Temperature: "+tempConverted);
+ Pebble.sendAppMessage({"weather_icon_id":iconId, "weather_temperature": tempConverted});
+ }
+ } else {
+ console.warn("HTTP error: "+req.status);
+ }
+ }
+ }
+ req.send(null);
+}
+
+function locationError() {
+ console.warn("Can't detect location");
+}
+
+function weatherUpdate()
+{
+ console.log("Requesting location...");
+ window.navigator.geolocation.getCurrentPosition(locationSuccess, locationError, locationOptions);
+}
+
Pebble.addEventListener("ready", function() {
initialized = true;
var json = window.localStorage.getItem('mario-config');
@@ -19,6 +69,7 @@ Pebble.addEventListener("ready", function() {
console.log("stored config json parse error: " + json + ' - ' + e);
}
}
+ //weatherUpdate();
});
Pebble.addEventListener("showConfiguration", function() {
@@ -32,7 +83,7 @@ Pebble.addEventListener("showConfiguration", function() {
}
var platform = "&platform=" + ((watch != null) ? watch.platform : "unknown");
console.log("showing configuration");
- Pebble.openURL("http://clusterrr.com/pebble_configs/mario.php" + cfg + platform);
+ Pebble.openURL("http://clusterrr.com/pebble_configs/mario_w.php" + cfg + platform);
});
Pebble.addEventListener("webviewclosed", function(e) {
@@ -42,9 +93,21 @@ Pebble.addEventListener("webviewclosed", function(e) {
try {
options = JSON.parse(response);
Pebble.sendAppMessage(options);
+ if (options.config_show_weather)
+ setTimeout(weatherUpdate, 5000);
} catch(e) {
console.log("Response config json parse error: " + response + ' - ' + e);
}
console.log("Options = " + response);
}
});
+
+Pebble.addEventListener("appmessage",
+ function(e) {
+ console.log("Appmessage: "+JSON.stringify(e.payload));
+ if ("weather_request" in e.payload)
+ {
+ setTimeout(weatherUpdate, 5000);
+ }
+ }
+);
diff --git a/src/pebble-mario.c b/src/pebble-mario.c
index f973b9d..b23423b 100644
--- a/src/pebble-mario.c
+++ b/src/pebble-mario.c
@@ -57,7 +57,6 @@ static GFont pixel_font_small;
static int mario_is_down = 1;
static int need_update_background = 0;
-// TODO: I can really make use of BitmapLayer here
static GBitmap *mario_normal_bmp = NULL;
static GBitmap *mario_jump_bmp = NULL;
static GBitmap *block_bmp = NULL;
@@ -67,6 +66,7 @@ static GBitmap *phone_battery_unknown_bmp = NULL;
static GBitmap *watch_bmp = NULL;
static GBitmap *battery_charging_bmp = NULL;
static GBitmap *background_day_bmp = NULL;
+static GBitmap *weather_icon_bmp = NULL;
static PropertyAnimation *mario_animation_beg = NULL;
static PropertyAnimation *mario_animation_end = NULL;
@@ -79,11 +79,22 @@ static PropertyAnimation *hour_animation_slide_in = NULL;
static bool config_show_no_phone = true;
static bool config_show_battery = true;
-static bool config_show_phone_battery = true;
+static bool config_show_phone_battery = false;
+static bool config_show_weather = true;
static bool config_vibe = false;
static int config_background = 0;
static int phone_battery_level = -1;
+static time_t weather_last_update = 0;
+static int weather_icon_id = -1;
+static int weather_temperature = -100;
+
+static int left_info_mode = 0;
+
+static char digits[10][15] = {{1,1,1,1,0,1,1,0,1,1,0,1,1,1,1},{0,0,1,0,0,1,0,0,1,0,0,1,0,0,1},{1,1,1,0,0,1,1,1,1,1,0,0,1,1,1},{1,1,1,0,0,1,1,1,1,0,0,1,1,1,1},
+ {1,0,1,1,0,1,1,1,1,0,0,1,0,0,1},{1,1,1,1,0,0,1,1,1,0,0,1,1,1,1},{1,1,1,1,0,0,1,1,1,1,0,1,1,1,1},{1,1,1,0,0,1,0,0,1,0,0,1,0,0,1},
+ {1,1,1,1,0,1,1,1,1,1,0,1,1,1,1},{1,1,1,1,0,1,1,1,1,0,0,1,1,1,1}};
+
#define BLOCK_SIZE 50
#define BLOCK_SPACING 0
#ifdef DEMO_SLOW
@@ -94,6 +105,9 @@ static int phone_battery_level = -1;
#define CLOCK_ANIMATION_DURATION 150
#endif
#define GROUND_HEIGHT 26
+
+#define WEATHER_MAX_AGE 60*60*5
+#define WEATHER_UPDATE_INTERVAL 60*60*3
#define MSG_SHOW_NO_PHONE 0
#define MSG_SHOW_BATTERY 1
@@ -102,6 +116,12 @@ static int phone_battery_level = -1;
#define MSG_BATTERY_ANSWER 5
#define MSG_SHOW_PHONE_BATTERY 6
#define MSG_BACKGROUND 7
+#define MSG_SHOW_WEATHER 8
+#define ID_WEATHER_LAST_UPDATE 9
+#define MSG_WEATHER_ICON_ID 10
+#define MSG_WEATHER_TEMPERATURE 11
+#define MSG_WEATHER_REQUEST 12
+#define ID_LEFT_INFO_MODE 13
void handle_tick(struct tm *tick_time, TimeUnits units_changed);
@@ -114,15 +134,25 @@ static void to_upcase(char* str)
}
}
-static void request_phone_battery()
+static void request_all()
{
- if (config_show_phone_battery)
+ int weather_age = time(NULL)-weather_last_update;
+
+ if (config_show_phone_battery || (config_show_weather && (weather_age > WEATHER_UPDATE_INTERVAL)))
{
- DictionaryIterator *iter;
- app_message_outbox_begin(&iter);
- Tuplet tupleRequest = TupletInteger(MSG_BATTERY_REQUEST, 0);
- dict_write_tuplet(iter, &tupleRequest);
- app_message_outbox_send();
+ DictionaryIterator *iter;
+ app_message_outbox_begin(&iter);
+ if (config_show_phone_battery)
+ {
+ Tuplet tupleRequest = TupletInteger(MSG_BATTERY_REQUEST, 0);
+ dict_write_tuplet(iter, &tupleRequest);
+ }
+ if (config_show_weather && (weather_age > WEATHER_UPDATE_INTERVAL))
+ {
+ Tuplet tupleRequest = TupletInteger(MSG_WEATHER_REQUEST, 0);
+ dict_write_tuplet(iter, &tupleRequest);
+ }
+ app_message_outbox_send();
}
}
@@ -288,7 +318,7 @@ void bluetooth_connection_callback(bool connected)
}
if (connected)
- request_phone_battery();
+ request_all();
else phone_battery_level = -1;
layer_mark_dirty(phone_battery_layer);
}
@@ -300,33 +330,80 @@ void phone_battery_update_callback(Layer *layer, GContext *ctx)
#endif
#if PBL_COLOR
graphics_context_set_compositing_mode(ctx, GCompOpSet);
+ graphics_context_set_fill_color(ctx, GColorWhite);
+ graphics_context_set_stroke_color(ctx, GColorWhite);
#else
graphics_context_set_compositing_mode(ctx, GCompOpAssignInverted);
+ graphics_context_set_fill_color(ctx, GColorBlack);
+ graphics_context_set_stroke_color(ctx, GColorBlack);
#endif
+
if (config_show_no_phone && !bluetooth_connection_service_peek())
{
GRect image_rect = gbitmap_get_bounds(no_phone_bmp);
+ image_rect.origin.y += 2;
graphics_draw_bitmap_in_rect(ctx, no_phone_bmp, image_rect);
- }
- else if (/*phone_battery_level >= 0 &&*/ config_show_phone_battery)
+ return;
+ }
+
+ if (config_show_weather && (!config_show_phone_battery || left_info_mode == 0))
+ {
+ GRect image_rect = gbitmap_get_bounds(weather_icon_bmp);
+ graphics_draw_bitmap_in_rect(ctx, weather_icon_bmp, image_rect);
+
+ if (weather_temperature > -100)
+ {
+ int temp_x = 13;
+ int temp_y = 4;
+
+ int digit1 = (weather_temperature / 10) % 10;
+ if (digit1 < 0) digit1 *= -1;
+ int digit2 = weather_temperature % 10;
+ if (digit2 < 0) digit2 *= -1;
+
+ int dx, dy;
+ for (dy = 0; dy < 5; dy++)
+ {
+ for (dx = 0; dx < 3; dx++)
+ {
+ if (digits[digit1][dx+dy*3])
+ graphics_draw_pixel(ctx, GPoint(temp_x+dx, temp_y+dy));
+ if (digits[digit2][dx+dy*3])
+ graphics_draw_pixel(ctx, GPoint(temp_x+dx+4, temp_y+dy));
+ }
+ }
+ graphics_draw_pixel(ctx, GPoint(temp_x+4+4, temp_y-2));
+ if (weather_temperature < 0)
+ {
+ graphics_draw_pixel(ctx, GPoint(temp_x-2, temp_y+2));
+ graphics_draw_pixel(ctx, GPoint(temp_x-3, temp_y+2));
+ }
+ }
+ }
+
+ if (config_show_phone_battery && (!config_show_weather || left_info_mode != 0))
{
if (phone_battery_level >= 0)
{
GRect image_rect = gbitmap_get_bounds(phone_battery_bmp);
+ image_rect.origin.y += 2;
graphics_draw_bitmap_in_rect(ctx, phone_battery_bmp, image_rect);
-#if PBL_COLOR
- graphics_context_set_fill_color(ctx, GColorWhite);
-#else
- graphics_context_set_fill_color(ctx, GColorBlack);
-#endif
- graphics_fill_rect(ctx, GRect(9, 2, phone_battery_level, 5), 0, GCornerNone);
+ graphics_fill_rect(ctx, GRect(9, 4, phone_battery_level, 5), 0, GCornerNone);
} else {
GRect image_rect = gbitmap_get_bounds(phone_battery_unknown_bmp);
+ image_rect.origin.y += 2;
graphics_draw_bitmap_in_rect(ctx, phone_battery_unknown_bmp, image_rect);
}
}
}
+static void accel_tap_handler(AccelAxisType axis, int32_t direction)
+{
+ left_info_mode ^= 1;
+ layer_mark_dirty(phone_battery_layer);
+ persist_write_int(ID_LEFT_INFO_MODE, left_info_mode);
+}
+
void battery_update_callback(Layer *layer, GContext *ctx)
{
if (config_show_battery)
@@ -430,8 +507,66 @@ void load_bitmaps()
update_background();
}
+void load_weather_icon()
+{
+#ifdef DEMO
+ weather_icon_id = 10;
+ weather_temperature = 52;
+#endif
+ if (weather_icon_bmp)
+ gbitmap_destroy(weather_icon_bmp);
+ switch (weather_icon_id)
+ {
+ case 1:
+ weather_icon_bmp = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_WEATHER_CLEAR_SKY_DAY);
+ break;
+ case 101:
+ weather_icon_bmp = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_WEATHER_CLEAR_SKY_NIGHT);
+ break;
+ case 2:
+ weather_icon_bmp = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_WEATHER_FEW_CLOUDS_DAY);
+ break;
+ case 102:
+ weather_icon_bmp = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_WEATHER_FEW_CLOUDS_NIGHT);
+ break;
+ case 3:
+ case 103:
+ weather_icon_bmp = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_WEATHER_SCATTERED_CLOUDS);
+ break;
+ case 4:
+ case 104:
+ weather_icon_bmp = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_WEATHER_BROKEN_CLOUDS);
+ break;
+ case 9:
+ case 109:
+ weather_icon_bmp = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_WEATHER_SHOWER_RAIN);
+ break;
+ case 10:
+ weather_icon_bmp = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_WEATHER_RAIN_DAY);
+ break;
+ case 110:
+ weather_icon_bmp = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_WEATHER_RAIN_NIGHT);
+ break;
+ case 11:
+ case 111:
+ weather_icon_bmp = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_WEATHER_THUNDERSTORM);
+ break;
+ case 13:
+ case 113:
+ weather_icon_bmp = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_WEATHER_SNOW);
+ break;
+ case 50:
+ case 150:
+ weather_icon_bmp = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_WEATHER_MIST);
+ break;
+ default:
+ weather_icon_bmp = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_WEATHER_UNKNOWN);
+ break;
+ }
+}
+
void in_received_handler(DictionaryIterator *received, void *context) {
- APP_LOG(APP_LOG_LEVEL_DEBUG, "Received config");
+// APP_LOG(APP_LOG_LEVEL_DEBUG, "Received config");
Tuple *tuple = dict_find(received, MSG_SHOW_NO_PHONE);
if (tuple) {
if (tuple->type == TUPLE_CSTRING)
@@ -449,6 +584,7 @@ void in_received_handler(DictionaryIterator *received, void *context) {
config_show_battery = tuple->value->int8;
layer_mark_dirty(battery_layer);
persist_write_bool(MSG_SHOW_BATTERY, config_show_battery);
+ request_all();
}
tuple = dict_find(received, MSG_SHOW_PHONE_BATTERY);
if (tuple) {
@@ -456,10 +592,18 @@ void in_received_handler(DictionaryIterator *received, void *context) {
config_show_phone_battery = (strcmp(tuple->value->cstring, "true") == 0);
else
config_show_phone_battery = tuple->value->int8;
- if (config_show_phone_battery) request_phone_battery();
layer_mark_dirty(phone_battery_layer);
persist_write_bool(MSG_SHOW_PHONE_BATTERY, config_show_phone_battery);
}
+ tuple = dict_find(received, MSG_SHOW_WEATHER);
+ if (tuple) {
+ if (tuple->type == TUPLE_CSTRING)
+ config_show_weather = (strcmp(tuple->value->cstring, "true") == 0);
+ else
+ config_show_weather = tuple->value->int8;
+ layer_mark_dirty(phone_battery_layer);
+ persist_write_bool(MSG_SHOW_WEATHER, config_show_weather);
+ }
tuple = dict_find(received, MSG_VIBE);
if (tuple) {
if (tuple->type == TUPLE_CSTRING)
@@ -480,6 +624,18 @@ void in_received_handler(DictionaryIterator *received, void *context) {
phone_battery_level = tuple->value->int8;
layer_mark_dirty(phone_battery_layer);
}
+ tuple = dict_find(received, MSG_WEATHER_ICON_ID);
+ if (tuple) {
+ weather_icon_id = tuple->value->int8;
+ tuple = dict_find(received, MSG_WEATHER_TEMPERATURE);
+ if (tuple) weather_temperature = tuple->value->int8;
+ weather_last_update = time(NULL);
+ load_weather_icon();
+ layer_mark_dirty(phone_battery_layer);
+ persist_write_int(ID_WEATHER_LAST_UPDATE, weather_last_update);
+ persist_write_int(MSG_WEATHER_ICON_ID, weather_icon_id);
+ persist_write_int(MSG_WEATHER_TEMPERATURE, weather_temperature);
+ }
}
void handle_init()
@@ -490,13 +646,23 @@ void handle_init()
config_show_battery = persist_read_bool(MSG_SHOW_BATTERY);
if (persist_exists(MSG_SHOW_PHONE_BATTERY))
config_show_phone_battery = persist_read_bool(MSG_SHOW_PHONE_BATTERY);
+ if (persist_exists(MSG_SHOW_WEATHER))
+ config_show_weather = persist_read_bool(MSG_SHOW_WEATHER);
if (persist_exists(MSG_VIBE))
config_vibe = persist_read_bool(MSG_VIBE);
if (persist_exists(MSG_BACKGROUND))
config_background = persist_read_bool(MSG_BACKGROUND);
+ if (persist_exists(ID_WEATHER_LAST_UPDATE))
+ weather_last_update = persist_read_int(ID_WEATHER_LAST_UPDATE);
+ if (persist_exists(MSG_WEATHER_ICON_ID))
+ weather_icon_id = persist_read_int(MSG_WEATHER_ICON_ID);
+ if (persist_exists(MSG_WEATHER_TEMPERATURE))
+ weather_temperature = persist_read_int(MSG_WEATHER_TEMPERATURE);
+ if (persist_exists(ID_LEFT_INFO_MODE))
+ left_info_mode = persist_read_int(ID_LEFT_INFO_MODE);
app_message_register_inbox_received(in_received_handler);
- app_message_open(64, 64);
+ app_message_open(128, 64);
window = window_create();
@@ -513,7 +679,7 @@ void handle_init()
background_rect = GRect(0, 0, 144, 168);
battery_rect = GRect(119, 5, 22, 9);
- phone_battery_rect = GRect(3, 5, 22, 9);
+ phone_battery_rect = GRect(3, 3, 24, 13);
pixel_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_GAMEGIRL_24));
//pixel_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_EMULOGIC_24));
@@ -554,15 +720,15 @@ void handle_init()
#define MARIO_TIME_UNIT MINUTE_UNIT
#endif
- phone_battery_level = -1;
-
tick_timer_service_subscribe(MARIO_TIME_UNIT, handle_tick);
bluetooth_connection_service_subscribe(bluetooth_connection_callback);
battery_state_service_subscribe(handle_battery);
+ accel_tap_service_subscribe(accel_tap_handler);
- request_phone_battery();
+ request_all();
- load_bitmaps();
+ load_bitmaps();
+ load_weather_icon();
#ifdef DEMO
light_enable(true);
#endif
@@ -596,6 +762,7 @@ void handle_deinit()
gbitmap_destroy(battery_charging_bmp);
gbitmap_destroy(block_bmp);
gbitmap_destroy(background_day_bmp);
+ gbitmap_destroy(weather_icon_bmp);
layer_destroy(time_layer);
layer_destroy(background_layer);
@@ -612,6 +779,7 @@ void handle_deinit()
bluetooth_connection_service_unsubscribe();
battery_state_service_unsubscribe();
app_message_deregister_callbacks();
+ accel_tap_service_unsubscribe();
}
void mario_down_animation_stopped(Animation *animation, void *data)
@@ -750,8 +918,20 @@ void handle_tick(struct tm *tick_time, TimeUnits units_changed)
animation_schedule((Animation *)mario_animation_beg);
animation_schedule((Animation *)block_animation_beg);
- if ((units_changed | MINUTE_UNIT) && (tick_time->tm_min % 30 == 0))
- request_phone_battery();
+ int weather_age = time(NULL)-weather_last_update;
+ if (units_changed | MINUTE_UNIT)
+ {
+ if ((tick_time->tm_min % 30 == 0) || ((tick_time->tm_min % 5 == 0) && (weather_age > WEATHER_UPDATE_INTERVAL)))
+ request_all();
+ }
+ if ((weather_age > WEATHER_MAX_AGE) && (weather_icon_id >= 0))
+ {
+ weather_icon_id = -1;
+ weather_temperature = -100;
+ load_weather_icon();
+ if (config_show_weather)
+ layer_mark_dirty(phone_battery_layer);
+ }
if (units_changed | HOUR_UNIT)
need_update_background = 1;