JaxNode 6/18/2015
On a Mac, run the following command;
brew install pebble/pebble-sdk/pebble-sdk
Â
On linux, follow the instructions on this page;
https://developer.getpebble.com/sdk/install/linux/
Â
#include <pebble.h>
Window *window;
TextLayer *text_layer;
void handle_init(void) {
window = window_create();
text_layer = text_layer_create(GRect(0, 0, 144, 154));
text_layer_set_text(text_layer, "Hello World!");
text_layer_set_font(text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD));
text_layer_set_text_alignment(text_layer, GTextAlignmentCenter);
layer_add_child(window_get_root_layer(window), text_layer_get_layer(text_layer));
window_stack_push(window, true);
APP_LOG(APP_LOG_LEVEL_DEBUG, "Just pushed a window!");
}
void handle_deinit(void) {
text_layer_destroy(text_layer);
window_destroy(window);
}
int main(void) {
handle_init();
app_event_loop();
handle_deinit();
}
function locationSuccess(pos) {
var coordinates = pos.coords;
fetchWeather(coordinates.latitude, coordinates.longitude);
}
function locationError(err) {
console.warn('location error (' + err.code + '): ' + err.message);
Pebble.sendAppMessage({
"WEATHER_CITY_KEY":"Loc Unavailable",
"WEATHER_TEMPERATURE_KEY":"N/A"
});
}
var locationOptions = { "timeout": 15000, "maximumAge": 60000 };
Pebble.addEventListener("ready", function(e) {
console.log("connect!" + e.ready);
locationWatcher = window.navigator.geolocation.getCurrentPosition(
locationSuccess, locationError, locationOptions);
console.log(e.type);
});
Settings
UI.Card
UI.Menu
Window
Rect
Circle
Text
Image
Light
Vibe
Accel
Ajax
Â
// Import the UI elements
var UI = require('ui');
// Create a simple Card
var card = new UI.Card({
title: 'Hello World',
body: 'This is your first Pebble app!'
});
var window = new UI.Window();
window.on('click', 'up', function() {
// Up click detected!
});
// Display to the user
card.show();
var ajax = require('ajax');
var URL = 'http://api.openweathermap.org/data/2.5/weather?q=London,uk';
var splashCard = new UI.Card({
title: "Please Wait",
body: "Downloading..."
});
splashCard.show();
// Download data
ajax({url: URL, type: 'json'},
function(json) {
var temp = Math.round(json.main.temp - 273.15);
var resultsCard = new UI.Card({
title: 'London, UK',
body: json.weather[0].main + '\nTemp: ' + temp
});
resultsCard.show();
splashCard.hide();
},
function(error) {
console.log('Ajax failed: ' + error);
}
);
npm install pebble-api --save
var Timeline = require('pebble-api');
var USER_TOKEN = 'a70b23d3820e9ee640aeb590fdf03a56';
var timeline = new Timeline();
var pin = new Timeline.Pin({
id: 'test-pin-5245',
time: new Date(),
duration: 10,
layout: new Timeline.Pin.Layout({
type: Timeline.Pin.LayoutType.GENERIC_PIN,
tinyIcon: Timeline.Pin.Icon.PIN,
title: 'Pin Title'
})
});
timeline.sendUserPin(USER_TOKEN, pin, function (err) {
if (err) {
return console.error(err);
}
console.log('Pin sent successfully!');
});