Commit 74607bbd authored by Zachary Seguin's avatar Zachary Seguin

Initial commit

parents
{
"uuid": "b6206a52-7eef-40a2-a225-e5797785b2b2",
"shortName": "Zachary Seguin",
"longName": "Zachary Seguin - Watchface",
"companyName": "Zachary Seguin",
"versionCode": 1,
"versionLabel": "1.0.0",
"watchapp": {
"watchface": true
},
"appKeys": {
"weather_icon": 0,
"weather_conditions": 1,
"temperature": 2,
"information": 3
},
"capabilities" : [ "location" ],
"resources": {
"media": [
{
"type" : "font",
"name" : "ICONS_12",
"file" : "fonts/icomoon.ttf"
},
{
"type" : "font",
"name" : "ICONS_18",
"file" : "fonts/icomoon.ttf"
}
]
}
}
all:
pebble build
build:
pebble build
install:
pebble install --phone 10.0.1.6 --logs
#pebble logs --phone 10.0.1.6
clean:
pebble clean
\ No newline at end of file
File added
This diff is collapsed.
/*
COPYRIGHT © 2013 - Zachary Seguin
All Rights Reserved.
www.zacharyseguin.ca
contact@zacharyseguin.c
*/
#include "display.h"
/*
COPYRIGHT © 2013 - Zachary Seguin
All Rights Reserved.
www.zacharyseguin.ca
contact@zacharyseguin.c
*/
#include <pebble.h>
#include "icons.h"
#define CLOCK_TIME_PLACEHOLDER "00:00"
#define CLOCK_DATE_PLACEHOLDER "Xxx., Xxx. ##, ####"
#define CLOCK_TIME_FORMAT_24HR "%R"
#define CLOCK_TIME_FORMAT_12HR "%I:%M"
#define CLOCK_DATE_FORMAT "%a., %b. %e, %Y"
static void display_clock(struct tm *tick_time, TimeUnits units_changed, TextLayer *time_layer, TextLayer *date_layer)
{
APP_LOG(APP_LOG_LEVEL_DEBUG, "Displaying time...");
// Minute changed
// NOTE: This will also handle the hour changing
if (units_changed & MINUTE_UNIT)
{
APP_LOG(APP_LOG_LEVEL_DEBUG, "Minute units have changed");
// Declare variables
static char time_text[] = CLOCK_TIME_PLACEHOLDER;
char *time_format;
// Format the time
if (clock_is_24h_style())
time_format = CLOCK_TIME_FORMAT_24HR;
else
time_format = CLOCK_TIME_FORMAT_12HR;
strftime(time_text, sizeof(time_text), time_format, tick_time);
// Shift everything over if there is a 0 as the leading digit
if (!clock_is_24h_style() && (time_text[0] == '0'))
memmove(time_text, &time_text[1], sizeof(time_text) - 1);
text_layer_set_text(time_layer, time_text);
}// End of if
// Date changed
// NOTE: This will also handle the hour changing
if (units_changed & DAY_UNIT)
{
APP_LOG(APP_LOG_LEVEL_DEBUG, "Date units have changed");
// Declare variables
static char date_text[] = CLOCK_DATE_PLACEHOLDER;
strftime(date_text, sizeof(date_text), CLOCK_DATE_FORMAT, tick_time);
text_layer_set_text(date_layer, date_text);
}// End of if
APP_LOG(APP_LOG_LEVEL_DEBUG, "Done displaying time");
}// End of display_time method
static void display_battery(BatteryChargeState battery, TextLayer *battery_icon_layer, TextLayer *battery_layer)
{
APP_LOG(APP_LOG_LEVEL_DEBUG, "Updating battery state...");
static char battery_icon_string[] = ICON_SWITCH;
snprintf(battery_icon_string, sizeof(battery_icon_string), (battery.is_charging) ? ICON_POWER_CORD : ICON_SWITCH);
static char battery_string[4];
snprintf(battery_string, sizeof(battery_string), "%d%%", battery.charge_percent);
text_layer_set_text(battery_icon_layer, battery_icon_string);
text_layer_set_text(battery_layer, battery_string);
}// End of display_battery method
static void display_bluetooth(bool connected, TextLayer *bluetooth_layer)
{
APP_LOG(APP_LOG_LEVEL_DEBUG, "Updating bluetooth connection state...");
static char bluetooth_string[] = ICON_PHONE_HANG_UP;
snprintf(bluetooth_string, sizeof(bluetooth_string), (connected) ? ICON_PHONE : ICON_PHONE_HANG_UP);
text_layer_set_text(bluetooth_layer, bluetooth_string);
}// End of display_bluetooth method
static void display_weather(const int icon, const char *conditions, const int temperature, TextLayer *weather_icon_layer, TextLayer *weather_layer)
{
APP_LOG(APP_LOG_LEVEL_DEBUG, "Updating weather...");
static char weather_icon[] = ICON_CANCEL_CIRCLE;
switch(icon)
{
case 1:
snprintf(weather_icon, sizeof(weather_icon), WEATHER_ICON_SUNNY);
break;
case 2:
snprintf(weather_icon, sizeof(weather_icon), WEATHER_ICON_PARTLY_SUNNY);
break;
case 3:
snprintf(weather_icon, sizeof(weather_icon), WEATHER_ICON_CLOUDY);
break;
case 4:
snprintf(weather_icon, sizeof(weather_icon), WEATHER_ICON_RAIN);
break;
case 5:
snprintf(weather_icon, sizeof(weather_icon), WEATHER_ICON_THUNDERSTORM);
break;
case 6:
snprintf(weather_icon, sizeof(weather_icon), WEATHER_ICON_SNOW);
break;
}// End of switch
text_layer_set_text(weather_icon_layer, weather_icon);
static char weather_string[20];
snprintf(weather_string, sizeof(weather_string), "%d\u00B0 - %s", temperature, conditions);
text_layer_set_text(weather_layer, weather_string);
}// End of display_weather method
static void display_information(char *information, TextLayer *information_layer)
{
APP_LOG(APP_LOG_LEVEL_DEBUG, "Updating information...");
static char information_string[40];
memcpy(information_string, information, strlen(information));
text_layer_set_text(information_layer, information_string);
}// End of display_information method
\ No newline at end of file
/*
COPYRIGHT © 2013 - Zachary Seguin
All Rights Reserved.
www.zacharyseguin.ca
contact@zacharyseguin.ca
*/
#define ICON_DROPLET "\ue600"
#define ICON_PHONE "\ue601"
#define ICON_PHONE_HANG_UP "\ue602"
#define ICON_LIGHTNING "\ue603"
#define ICON_SWITCH "\ue604"
#define ICON_POWER_CORD "\ue605"
#define ICON_CLOUD "\ue606"
#define ICON_NOTIFICATION "\ue607"
#define ICON_WARNING "\ue608"
#define ICON_CANCEL_CIRCLE "\ue609"
#define ICON_CHECKMARK_CIRCLE "\ue60a"
#define ICON_INFO "\ue60b"
#define ICON_INFO2 "\ue60c"
#define ICON_BLOCKED "\ue60d"
#define ICON_BRIGHTNESS "\ue60e"
#define ICON_HALF_BRIGHTNESS "\ue60f"
#define ICON_TWO_DOTS "\ue610"
/* WEATHER ICONS */
#define WEATHER_ICON_SUNNY ICON_BRIGHTNESS
#define WEATHER_ICON_PARTLY_SUNNY ICON_HALF_BRIGHTNESS
#define WEATHER_ICON_CLOUDY ICON_CLOUD
#define WEATHER_ICON_RAIN ICON_DROPLET
#define WEATHER_ICON_THUNDERSTORM ICON_LIGHTNING
#define WEATHER_ICON_SNOW ICON_TWO_DOTS
\ No newline at end of file
/*
COPYRIGHT © 2013 - Zachary Seguin
All Rights Reserved.
www.zacharyseguin.ca
contact@zacharyseguin.ca
*/
// Gets the current position of the phone.
function getPosition(success_callback, error_callback) {
navigator.geolocation.getCurrentPosition(function(position) {
success_callback(position);
}, function(error) {
error_callback(error);
});
}// End of getPosition function
// Loads weather for a given set of coordinates
function loadWeather(coordinates, success_callback, error_callback) {
var http = new XMLHttpRequest();
console.log("Weather URL: http://api.worldweatheronline.com/free/v1/weather.ashx?q=" + coordinates.latitude + "," + coordinates.longitude + "&format=json&num_of_days=0&key=p42vw9n4zrzcymdqzxsswxyu");
http.open('GET', "http://api.worldweatheronline.com/free/v1/weather.ashx?q=" + coordinates.latitude + "," + coordinates.longitude + "&format=json&num_of_days=0&key=p42vw9n4zrzcymdqzxsswxyu", true);
http.onload = function(event) {
if (http.readyState == 4 && http.status == 200) {
var response = JSON.parse(http.responseText);
success_callback(response);
}// End of if
};// End of onload function
http.onerror = function(error) {
error_callback(error);
}; // End of onerror method
http.send(null);
}// End of loadWeather function
// Loads information
function loadInformation(success_callback, error_callback) {
var http = new XMLHttpRequest();
console.log("Information URL: " + "https://zacharyseguin.ca/pebble/information.php");
http.open('GET', "https://zacharyseguin.ca/pebble/information.php", true);
http.onload = function(event) {
if (http.readyState == 4 && http.status == 200) {
var response = JSON.parse(http.responseText);
success_callback(response);
}// End of if
};// End of onload function
http.onerror = function(error) {
error_callback(error);
}; // End of onerror method
http.send(null);
}// End of loadInformation function
function selectWeatherIcon(code) {
switch(code) {
case 113: // Sunny
return 1;
break;
case 116: // Partly Cloudy
return 2;
break;
case 119: // Cloudy
case 122: // Overcase
case 248: // Fog
case 260: // Freezing Fog
return 3;
break;
case 143: // Mist
case 176: // Patchy rain
case 182: // Patchy sleet
case 185: // Patch freezing drizzle
case 263: // Patchy light drizzle
case 266: // Light drizzle
case 281: // Freezing drizzle
case 284: // Heavy freezing drizzle
case 293: // Patch light rain
case 296: // Light rain
case 299: // Moderate rain at times
case 302: // Moderate rain
case 305: // Heavy rain at times
case 308: // Heavy rain
case 353: // Light rain shower
case 356: // Moderate or heavy rain shower
case 359: // Torrential rain shower
return 4;
break;
case 200: // Thundery outbreak
case 386: // Patchy light rain with thunder
case 389: // Moderator or heavy rain with thunder
case 392: // Patchy light snow with thunder
case 395: // Moderator or heavy shown with thunder
return 5;
break;
case 179: // Patch snow
case 227: // Blowing snow
case 230: // Blizzard
case 311: // Ligh freezing rain
case 314: // Moderate or heavy freezing rain
case 317: // Light sleet
case 320: // Moderate or heavy sleet
case 323: // Patchy light snow
case 326: // Light snow
case 329: // Patchy moderate snow
case 332: // Moderate snow
case 335: // Patchy heavy snow
case 338: // Heavy snow
case 350: // Ice pellets
case 362: // Light sleet showers
case 365: // Moderate or heavy sleet showers
case 368: // Light snow showers
case 371: // Moderate or heavy snow showers
case 374: // Light showers of ice pellets
case 377: // Moderate or heavy showers of ice pellets
return 6;
break;
default:
return 3;
}
}// End of selectWeatherIcon method
function sendUpdate() {
getPosition(function(position) {
console.log("Position Received");
loadWeather(position.coords, function(weather) {
console.log("Weather Received");
loadInformation(function(information) {
console.log("Information Received");
var icon = selectWeatherIcon(parseInt(weather['data']['current_condition'][0]['weatherCode']));
console.log(icon);
var data = {
weather_icon : icon,
weather_conditions : weather['data']['current_condition'][0]['weatherDesc'][0]['value'],
temperature: parseInt(weather['data']['current_condition'][0]['temp_C']),
information : information.information
};
window.localStorage["data"] = JSON.stringify(data);
window.localStorage["lastUpdate"] = (new Date()).toString();
console.log(window.localStorage['data']);
sendData(data);
}, function(error) { console.log("Error: " + error.message); } );
}, function(error) { console.log("Error: " + error.message); });
}, function(error) { console.log("Error: " + error.message); });
}
function sendData(data) {
console.log("Sending data to Pebble...");
console.log("Sending: " + JSON.stringify(data));
Pebble.sendAppMessage(data, function(e) {
console.log("Message successfully received by Pebble");
}, function(e) {
console.log("Message failed to send. Error: " + e.error);
});
}
Pebble.addEventListener("appmessage", function(e) {
console.log("Message Received: " + e.payload);
sendUpdate();
});
Pebble.addEventListener("ready", function(e) {
console.log("JavaScript application ready.");
//window.localStorage.removeItem('data');
if (window.localStorage["lastUpdate"]) {
var last = new Date(window.localStorage['lastUpdate']);
var now = new Date();
var difference = Math.round((now - last) / 10000 / 60);
if (difference >= 10)
sendUpdate();
else if (window.localStorage["data"])
sendData(JSON.parse(window.localStorage["data"]));
else
sendUpdate();
} else
sendUpdate();
});
\ No newline at end of file
/*
COPYRIGHT © 2013 - Zachary Seguin
All Rights Reserved.
www.zacharyseguin.ca
contact@zacharyseguin.c
*/
#include "utilities.h"
TextLayer* zs_create_text_layer(const GRect rect, const char *text, const GFont font, const GTextAlignment textAlignment, const GColor backgroundColour, const GColor foregroundColour, Layer *add_to_layer)
{
TextLayer *text_layer = text_layer_create(rect);
// Configure the text layer
text_layer_set_font(text_layer, font);
text_layer_set_text_alignment(text_layer, textAlignment);
text_layer_set_background_color(text_layer, backgroundColour);
text_layer_set_text_color(text_layer, foregroundColour);
text_layer_set_text(text_layer, text);
layer_add_child(add_to_layer, text_layer_get_layer(text_layer));
return text_layer;
}// End of zs_create_text_layer method
\ No newline at end of file
/*
COPYRIGHT © 2013 - Zachary Seguin
All Rights Reserved.
www.zacharyseguin.ca
contact@zacharyseguin.c
*/
#include <pebble.h>
/* DEFAULT VALUES */
#define ZS_DEFAULT_FONT fonts_get_system_font(FONT_KEY_GOTHIC_14)
#define ZS_DEFAULT_ALIGNMENT GTextAlignmentCenter
#define ZS_DEFAULT_BACKGROUND_COLOUR GColorBlack
#define ZS_DEFAULT_FOREGROUND_COLOUR GColorWhite
TextLayer* zs_create_text_layer(const GRect rect, const char *text, const GFont font, const GTextAlignment textAlignment, const GColor backgroundColour, const GColor foregroundColour, Layer *add_to_layer);
\ No newline at end of file
#
# This file is the default set of rules to compile a Pebble project.
#
# Feel free to customize this to your needs.
#
top = '.'
out = 'build'
def options(ctx):
ctx.load('pebble_sdk')
def configure(ctx):
ctx.load('pebble_sdk')
def build(ctx):
ctx.load('pebble_sdk')
ctx.pbl_program(source=ctx.path.ant_glob('src/**/*.c'),
target='pebble-app.elf')
ctx.pbl_bundle(elf='pebble-app.elf',
js=ctx.path.ant_glob('src/js/**/*.js'))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment