SlideShare uma empresa Scribd logo
1 de 25
Aniruddha Chakrabarti
Principal Architect | caniruddha@Hotmail.com
Building apps for pebble
A bit of history
• 2011 – pebble was born
• 2012 – Record breaking KickStarter surpassing $10 million
• 2013 – pebble Watch was launched
• 2014 – pebble Steel was launched
• 2015 – pebble Time was launched
pebble Watch pebble Steel pebble Time Steel
pebble Time – in KickStarter
How to develop for pebble – two type of apps
PebbleFace:
• Apps developed using Pebble C SDK (current version is 3.0) are called PebbleFace
• Apps could be written in C. There are two options -
• CloudPebble - New developers are encouraged to use this service to begin development without
installing any software whatsoever. This is also the preferred option for Windows users.
• C SDK - Use the C SDK locally. Advanced users are most likely to use this, especially if they are
building an Android or iOS companion app. Currently supports
• Mac OS X
• Linux
PebbleApp:
• Apps developed using alternate JavaScript library are called PebbleApp
• JavaScript library (pebble.js) is currently in beta
• PebbleApps could be written in JavaScript
CloudPebble - web IDE
CloudPebble - web IDE
What does a PebbleFace (custom Pebble App) contains
• Source files (.c files)
• Window layout
• Resources - image file, font, raw blob etc
• Manifest file (appinfo.json) - Details of the metadata that describes the app, such
as its name, resources and capabilities.
App metadata in manifest file
{
"uuid": "afb5b3ce-3701-436a-902f-098feaac9b29",
"shortName": "ExampleApp",
"longName": "ExampleApp",
"companyName": "MakeAwesomeHappen",
"versionCode": 1,
"versionLabel": "1.0",
"sdkVersion": "3",
"targetPlatforms": ["aplite", "basalt"],
"watchapp": {
"watchface": false
},
"appKeys": {
"dummy": 0
},
"resources": {
"media": []
}
}
Property Required Type Description
Uuid Yes UUID
Unique identifier for the app. Generated by pebble
new-project.
shortName Yes String
App's short name. This will appear in the launcher list
on the Watch.
longName Yes String
App's long name. This will appear in the Pebble
mobile application.
companyName Yes String Name of the app's developer.
versionLabel Yes String
Version label for the app. Must use the
format major or major.minor.
sdkVersion Yes String
The version of the SDK that this app is being written
for
targetPlatforms No
Array of
strings
Specify which platforms to build this app for (Aplite or
Basalt). Defaults to both if omitted.
watchapp Yes Object
Used to configure the app behavior on the watch.
Set watchface to true to behave as a watchapp.
capabilities No
Array of
strings
List of capabilities that your app requires. The only
two supported capabilities
arelocation and configurable. For more information,
refer to PebbleKit JS documentation
appKeys No Object
Keys used for AppMessage andAppSync. This is a
mapping from named string keys to
integer AppMessage keys. See PebbleKit JS
Guides for more information.
resources No Object
Contains one item media: an array of all of the media
resources to be bundled with your apps (Maximum
256 per app). See Managing App Resources for
more information.
appinfo.json
App Metadata (in CloudPebble)
App Window
• Starting point of any kind of user interface on Pebble.
• Whenever a new screen slides into view, that is the result of a new window being pushed onto the
stack.
• The window stack can be thought of in a similar manner to a stack of playing cards, with the most
recent card on the top.
• In this way a window is removed by popping it off the top of the stack.
• Each app's UI begins with its first window. By adding multiple windows it is possible to expand the
capabilities of an app beyond one screen.
• A window's main purpose is to contain and display Layers, such as TextLayers or BitmapLayers for
example. A layer must be added to a window as a child in order to be visible to the user.
• When it is created, it can be given a set of references to handlers for various events throughout its
life, such as load and unload.
Create the first Watchface app
#include <pebble.h>
// Create a pointer to a variable of Window type
static Window *main_window;
static void init(){
// Create the window itself in app initialization and assign to the pointer
main_window = window_create();
// Push the newly created window to the window stack
// Show the Window on the watch, with animated=true
window_stack_push(main_window, true);
}
static void deinit(){
window_destroy(main_window);
}
// Entry point to the app
int main(){
init();
app_event_loop();
deinit();
}
Window events (load and unload)
static void main_window_load(Window *window) {
// Code to be executed during window load comes here
}
static void main_window_unload(Window *window) {
// Code to be executed during window unload comes here
}
static void init(){
// Create the window itself in app initialization and assign to the pointer
main_window = window_create();
// Set handlers to manage the elements inside the Window
window_set_window_handlers(main_window, (WindowHandlers) {
.load = main_window_load,
.unload = main_window_unload
});
// Push the newly created window to the window stack
// Show the Window on the watch, with animated=true
window_stack_push(main_window, true);
}
Add a TextLayer (label)
#include <pebble.h>
Window *main_window;
TextLayer *text_layer_hello;
Layer *root_layer;
void handle_init(void) {
main_window = window_create();
root_layer = window_get_root_layer(main_window);
text_layer_hello = text_layer_create(GRect(0, 0, 144, 20));
text_layer_set_text(text_layer_hello,"Hello I am Pebble!");
layer_add_child(root_layer, text_layer_get_layer(text_layer_hello));
window_stack_push(main_window, true);
}
void handle_deinit(void) {
text_layer_destroy(text_layer_hello);
window_destroy(main_window);
}
int main(void) {
handle_init();
app_event_loop();
handle_deinit();
}
Set window and text layer color
• Set window background color
• Set text layer background and text (or foreground) color
void handle_init(void) {
main_window = window_create();
root_layer = window_get_root_layer(main_window);
text_layer_hello = text_layer_create(GRect(0, 0, 144, 40));
text_layer_set_text(text_layer_hello,"Hello I am Pebble!");
window_set_background_color(main_window, GColorBlack); // Set window background color to Black
text_layer_set_text_color(text_layer_hello, GColorBlack); // Set text layer text/foreground color to Black
text_layer_set_background_color(text_layer_hello, GColorWhite); // Set text layer Background color to White
layer_add_child(root_layer, text_layer_get_layer(text_layer_hello));
window_stack_push(main_window, true);
}
System Fonts
• Gothic 14
• Gothic 14 Bold
• Gothic 18
• Gothic 18 Bold
• Gothic 24
• Gothic 24 Bold
• Gothic 28
• Gothic 28 Bold
• Bitham 30 Black
• Bitham 42 Bold
• Bitham 42 Light
• Bitham 34 Medium Numbers
• Bitham 42 Medium Numbers
• Roboto 21 Condensed
• Roboto 49 Bold Subset
• Droid 28 Bold
Set TextLayer font
void handle_init(void) {
main_window = window_create();
root_layer = window_get_root_layer(main_window);
text_layer_hello = text_layer_create(GRect(0, 0, 144, 40));
text_layer_set_text(text_layer_hello,"Hello Pebble!");
window_set_background_color(main_window, GColorBlack);
// Set System Font to Gothic font size 28
text_layer_set_font(text_layer_hello, fonts_get_system_font(FONT_KEY_GOTHIC_28));
text_layer_set_text_color(text_layer_hello, GColorBlack);
text_layer_set_background_color(text_layer_hello, GColorWhite);
layer_add_child(root_layer, text_layer_get_layer(text_layer_hello));
window_stack_push(main_window, true);
}
Set TextLayer font (2)
void handle_init(void) {
main_window = window_create();
root_layer = window_get_root_layer(main_window);
text_layer_hello = text_layer_create(GRect(0, 0, 144, 40));
text_layer_set_text(text_layer_hello,"Hello Pebble!");
window_set_background_color(main_window, GColorBlack);
// Set System Font to Gothic font size 28
text_layer_set_font(text_layer_hello, fonts_get_system_font(FONT_KEY_BITHAM_42_LIGHT));
text_layer_set_text_color(text_layer_hello, GColorBlack);
text_layer_set_background_color(text_layer_hello, GColorWhite);
layer_add_child(root_layer, text_layer_get_layer(text_layer_hello));
window_stack_push(main_window, true);
}
Button Clicks
static void up_click_handler(ClickRecognizerRef recognizer, void *context) {
text_layer_set_text(text_layer_hello, "Up pressed!");
}
static void click_config_provider(void *context) {
// Register the ClickHandlers
window_single_click_subscribe(BUTTON_ID_UP, up_click_handler);
}
void handle_init(void) {
main_window = window_create();
root_layer = window_get_root_layer(main_window);
text_layer_set_font(text_layer_hello, fonts_get_system_font(FONT_KEY_GOTHIC_24));
text_layer_hello = text_layer_create(GRect(0, 0, 144, 60));
text_layer_set_text(text_layer_hello,"Hello!");
layer_add_child(root_layer, text_layer_get_layer(text_layer_hello));
window_stack_push(main_window, true);
window_set_click_config_provider(main_window, click_config_provider);
}
Up
Button
Down
Button
Select
Button
Button Clicks (2)
static void up_click_handler(ClickRecognizerRef recognizer, void *context) {
text_layer_set_text(text_layer_hello, "Up pressed!");
}
static void select_click_handler(ClickRecognizerRef recognizer, void *context) {
text_layer_set_text(text_layer_hello, "Select pressed!");
}
static void down_click_handler(ClickRecognizerRef recognizer, void *context) {
text_layer_set_text(text_layer_hello, "Down pressed!");
}
static void click_config_provider(void *context) {
window_single_click_subscribe(BUTTON_ID_UP, up_click_handler);
window_single_click_subscribe(BUTTON_ID_SELECT, select_click_handler);
window_single_click_subscribe(BUTTON_ID_DOWN, down_click_handler);
}
void handle_init(void) {
main_window = window_create();
root_layer = window_get_root_layer(main_window);
text_layer_set_font(text_layer_hello, fonts_get_system_font(FONT_KEY_GOTHIC_24));
text_layer_hello = text_layer_create(GRect(0, 0, 144, 60));
text_layer_set_text(text_layer_hello,"Hello!");
layer_add_child(root_layer, text_layer_get_layer(text_layer_hello));
window_stack_push(main_window, true);
window_set_click_config_provider(main_window, click_config_provider);
}
Up
Button
Down
Button
Select
Button
App Events / Services
• Pebble apps rely on callbacks, allowing the developer to define behavior for
different types of events, such as when the battery is low, the Bluetooth
connection state changes or the watch is tapped.
• This allows apps to update their UI when these events happen, instead of
constantly polling for a change in conditions.
• Services
• Bluetooth Connection Service
• Battery State Service
• Time Ticker Service
• App Focus Service (For interruptions)
• Wakeup API – allows developers to schedule an app launch in the future, even if the app itself
is closed in the meantime.
Bluetooth connection service
• The Bluetooth connection service allows your app to know whether Pebble is
connected to the phone. This can be done in two ways -
1. Ask the system for this information at any time -
static void up_click_handler(ClickRecognizerRef recognizer, void *context) {
if (bluetooth_connection_service_peek()) {
text_layer_set_text(text_layer_hello, "Phone is connected!");
}
else {
text_layer_set_text(text_layer_hello, "Phone is not connected!");
}
}
Bluetooth connection service (2)
• The Bluetooth connection service allows your app to know whether Pebble is
connected to the phone. This can be done in two ways -
2. register for Bluetooth connection and disconnection events -
Step 1: Declare the event handler
static void bluetooth_handler(bool is_connected) {
if (is_connected) {
text_layer_set_text(text_layer_hello, "Phone is connected!");
}
else {
text_layer_set_text(text_layer_hello, "Phone is not connected!");
}
}
Step 2: Register the event handler with Bluetooth service in init event
// Register the event handler with the bluetooth service
bluetooth_connection_service_subscribe(bluetooth_handler);
Step 3: Deregister from Bluetooth service in deinit event
// Unsubscribe from bluetooth service
bluetooth_connection_service_unsubscribe();
Battery state service
• The Battery State Service lets you know when the battery state changes, i.e., its current charge level,
whether it is plugged and charging.
• It uses the BatteryChargeState structure to describe the current power state of Pebble.
• Similar to the Bluetooth Connection Service , you can get the current state at any given moment or
register to be notified when the state changes.
static void up_click_handler(ClickRecognizerRef recognizer, void *context) {
static char s_battery_buffer[16];
BatteryChargeState charge_state = battery_state_service_peek();
if (charge_state.is_charging) {
snprintf(s_battery_buffer, sizeof(s_battery_buffer), "charging");
} else {
snprintf(s_battery_buffer, sizeof(s_battery_buffer), "%d%% charged", charge_state.charge_percent);
}
text_layer_set_text(text_layer_hello, s_battery_buffer);
}
Battery state service (2)
• Register for Bluetooth connection and disconnection events -
Step 1: Declare the event handler
static void battery_handler(BatteryChargeState charge_state) {
static char s_battery_buffer[16];
if (charge_state.is_charging) {
snprintf(s_battery_buffer, sizeof(s_battery_buffer), "charging");
} else {
snprintf(s_battery_buffer, sizeof(s_battery_buffer), "%d%% charged", charge_state.charge_percent);
}
text_layer_set_text(text_layer_hello, s_battery_buffer);
}
Step 2: Register the event handler with Battery State service in init event
// Register the event handler with the Battery state service
battery_state_service_subscribe(battery_handler);
Step 3: Deregister from Bluetooth service in deinit event
// Unsubscribe from Battery state service
battery_state_service_unsubscribe();
Resources
• Pebble - https://getpebble.com/
• Developer Portal - http://developer.getpebble.com/
• Getting Started - https://developer.getpebble.com/getting-started
• Developer Guides - https://developer.getpebble.com/guides/
• Documentation - https://developer.getpebble.com/docs/
• CloudPebble online IDE - https://cloudpebble.net

Mais conteúdo relacionado

Mais procurados

F# Type Provider for R Statistical Platform
F# Type Provider for R Statistical PlatformF# Type Provider for R Statistical Platform
F# Type Provider for R Statistical Platform
Howard Mansell
 

Mais procurados (20)

Start dart
Start dartStart dart
Start dart
 
Javascript
JavascriptJavascript
Javascript
 
Dart
DartDart
Dart
 
Dart presentation
Dart presentationDart presentation
Dart presentation
 
8 introduction to_java_script
8 introduction to_java_script8 introduction to_java_script
8 introduction to_java_script
 
Java script
Java scriptJava script
Java script
 
F# Type Provider for R Statistical Platform
F# Type Provider for R Statistical PlatformF# Type Provider for R Statistical Platform
F# Type Provider for R Statistical Platform
 
Domain-Specific Languages
Domain-Specific LanguagesDomain-Specific Languages
Domain-Specific Languages
 
Drupaljam xl 2019 presentation multilingualism makes better programmers
Drupaljam xl 2019 presentation   multilingualism makes better programmersDrupaljam xl 2019 presentation   multilingualism makes better programmers
Drupaljam xl 2019 presentation multilingualism makes better programmers
 
Javascript functions
Javascript functionsJavascript functions
Javascript functions
 
Developer’s viewpoint on swift programming language
Developer’s viewpoint on swift programming languageDeveloper’s viewpoint on swift programming language
Developer’s viewpoint on swift programming language
 
From DOT to Dotty
From DOT to DottyFrom DOT to Dotty
From DOT to Dotty
 
Introduction to c++ ppt 1
Introduction to c++ ppt 1Introduction to c++ ppt 1
Introduction to c++ ppt 1
 
DIWE - Programming with JavaScript
DIWE - Programming with JavaScriptDIWE - Programming with JavaScript
DIWE - Programming with JavaScript
 
Swift Tutorial Part 1. The Complete Guide For Swift Programming Language
Swift Tutorial Part 1. The Complete Guide For Swift Programming LanguageSwift Tutorial Part 1. The Complete Guide For Swift Programming Language
Swift Tutorial Part 1. The Complete Guide For Swift Programming Language
 
C sharp
C sharpC sharp
C sharp
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
 
Python for katana
Python for katanaPython for katana
Python for katana
 
Extending the Xbase Typesystem
Extending the Xbase TypesystemExtending the Xbase Typesystem
Extending the Xbase Typesystem
 
Maths&programming forartists wip
Maths&programming forartists wipMaths&programming forartists wip
Maths&programming forartists wip
 

Destaque

Destaque (14)

Building RIA Apps with Silverlight
Building RIA Apps with SilverlightBuilding RIA Apps with Silverlight
Building RIA Apps with Silverlight
 
WPF Deep Dive
WPF Deep DiveWPF Deep Dive
WPF Deep Dive
 
Groovy Programming Language
Groovy Programming LanguageGroovy Programming Language
Groovy Programming Language
 
memcached Distributed Cache
memcached Distributed Cachememcached Distributed Cache
memcached Distributed Cache
 
Overview of CoffeeScript
Overview of CoffeeScriptOverview of CoffeeScript
Overview of CoffeeScript
 
Redis and it's data types
Redis and it's data typesRedis and it's data types
Redis and it's data types
 
Level DB - Quick Cheat Sheet
Level DB - Quick Cheat SheetLevel DB - Quick Cheat Sheet
Level DB - Quick Cheat Sheet
 
TypeScript Overview
TypeScript OverviewTypeScript Overview
TypeScript Overview
 
Agile Practices - eXtreme Programming
Agile Practices - eXtreme ProgrammingAgile Practices - eXtreme Programming
Agile Practices - eXtreme Programming
 
Wideband Delphi Estimation
Wideband Delphi EstimationWideband Delphi Estimation
Wideband Delphi Estimation
 
CoAP - Web Protocol for IoT
CoAP - Web Protocol for IoTCoAP - Web Protocol for IoT
CoAP - Web Protocol for IoT
 
Lisp
LispLisp
Lisp
 
Design Patterns (Examples in .NET)
Design Patterns (Examples in .NET)Design Patterns (Examples in .NET)
Design Patterns (Examples in .NET)
 
Amazon alexa - building custom skills
Amazon alexa - building custom skillsAmazon alexa - building custom skills
Amazon alexa - building custom skills
 

Semelhante a pebble - Building apps on pebble

Android Development project
Android Development projectAndroid Development project
Android Development project
Minhaj Kazi
 
Android installation guide
Android installation guideAndroid installation guide
Android installation guide
magicshui
 
android training_material ravy ramio
android training_material ravy ramioandroid training_material ravy ramio
android training_material ravy ramio
slesulvy
 

Semelhante a pebble - Building apps on pebble (20)

Android Development project
Android Development projectAndroid Development project
Android Development project
 
Android Lab Mannual 18SUITSP5.docx
Android Lab Mannual 18SUITSP5.docxAndroid Lab Mannual 18SUITSP5.docx
Android Lab Mannual 18SUITSP5.docx
 
Ios - Introduction to platform & SDK
Ios - Introduction to platform & SDKIos - Introduction to platform & SDK
Ios - Introduction to platform & SDK
 
Presentation - Windows App Development - II - Mr. Chandan Gupta
Presentation - Windows App Development - II - Mr. Chandan GuptaPresentation - Windows App Development - II - Mr. Chandan Gupta
Presentation - Windows App Development - II - Mr. Chandan Gupta
 
Android Workshop
Android WorkshopAndroid Workshop
Android Workshop
 
Android momobxl
Android momobxlAndroid momobxl
Android momobxl
 
Flutter vs Java Graphical User Interface Frameworks - text
Flutter vs Java Graphical User Interface Frameworks - textFlutter vs Java Graphical User Interface Frameworks - text
Flutter vs Java Graphical User Interface Frameworks - text
 
Industrial Training in Android Application
Industrial Training in Android ApplicationIndustrial Training in Android Application
Industrial Training in Android Application
 
Ignite your app development with Angular, NativeScript and Firebase
Ignite your app development with Angular, NativeScript and FirebaseIgnite your app development with Angular, NativeScript and Firebase
Ignite your app development with Angular, NativeScript and Firebase
 
Apache Cordova In Action
Apache Cordova In ActionApache Cordova In Action
Apache Cordova In Action
 
Android installation guide
Android installation guideAndroid installation guide
Android installation guide
 
android training_material ravy ramio
android training_material ravy ramioandroid training_material ravy ramio
android training_material ravy ramio
 
Make Cross-platform Mobile Apps Quickly - SIGGRAPH 2014
Make Cross-platform Mobile Apps Quickly - SIGGRAPH 2014Make Cross-platform Mobile Apps Quickly - SIGGRAPH 2014
Make Cross-platform Mobile Apps Quickly - SIGGRAPH 2014
 
[Devoxx Morocco 2015] Apache Cordova In Action
[Devoxx Morocco 2015] Apache Cordova In Action[Devoxx Morocco 2015] Apache Cordova In Action
[Devoxx Morocco 2015] Apache Cordova In Action
 
Cross Platform Mobile Development using Flutter by Wei Meng Lee at Mobile foc...
Cross Platform Mobile Development using Flutter by Wei Meng Lee at Mobile foc...Cross Platform Mobile Development using Flutter by Wei Meng Lee at Mobile foc...
Cross Platform Mobile Development using Flutter by Wei Meng Lee at Mobile foc...
 
Android Intro
Android IntroAndroid Intro
Android Intro
 
Titanium appcelerator my first app
Titanium appcelerator my first appTitanium appcelerator my first app
Titanium appcelerator my first app
 
Developer Student Clubs NUK - Flutter for Beginners
Developer Student Clubs NUK - Flutter for BeginnersDeveloper Student Clubs NUK - Flutter for Beginners
Developer Student Clubs NUK - Flutter for Beginners
 
Intro to appcelerator
Intro to appceleratorIntro to appcelerator
Intro to appcelerator
 
React Native +Redux + ES6 (Updated)
React Native +Redux + ES6 (Updated)React Native +Redux + ES6 (Updated)
React Native +Redux + ES6 (Updated)
 

Mais de Aniruddha Chakrabarti

Mphasis Digital POV - Emerging Open Standard Protocol stack for IoT
Mphasis Digital POV - Emerging Open Standard Protocol stack for IoTMphasis Digital POV - Emerging Open Standard Protocol stack for IoT
Mphasis Digital POV - Emerging Open Standard Protocol stack for IoT
Aniruddha Chakrabarti
 

Mais de Aniruddha Chakrabarti (13)

Pinecone Vector Database.pdf
Pinecone Vector Database.pdfPinecone Vector Database.pdf
Pinecone Vector Database.pdf
 
Mphasis-Annual-Report-2018.pdf
Mphasis-Annual-Report-2018.pdfMphasis-Annual-Report-2018.pdf
Mphasis-Annual-Report-2018.pdf
 
Thomas Cook and Accenture expand relationship with 10 year technology consult...
Thomas Cook and Accenture expand relationship with 10 year technology consult...Thomas Cook and Accenture expand relationship with 10 year technology consult...
Thomas Cook and Accenture expand relationship with 10 year technology consult...
 
NLP using JavaScript Natural Library
NLP using JavaScript Natural LibraryNLP using JavaScript Natural Library
NLP using JavaScript Natural Library
 
Third era of computing
Third era of computingThird era of computing
Third era of computing
 
Golang - Overview of Go (golang) Language
Golang - Overview of Go (golang) LanguageGolang - Overview of Go (golang) Language
Golang - Overview of Go (golang) Language
 
Using Node-RED for building IoT workflows
Using Node-RED for building IoT workflowsUsing Node-RED for building IoT workflows
Using Node-RED for building IoT workflows
 
Mphasis Digital - Use Go (gloang) for system programming, distributed systems...
Mphasis Digital - Use Go (gloang) for system programming, distributed systems...Mphasis Digital - Use Go (gloang) for system programming, distributed systems...
Mphasis Digital - Use Go (gloang) for system programming, distributed systems...
 
Using Swift for all Apple platforms (iOS, watchOS, tvOS and OS X)
Using Swift for all Apple platforms (iOS, watchOS, tvOS and OS X)Using Swift for all Apple platforms (iOS, watchOS, tvOS and OS X)
Using Swift for all Apple platforms (iOS, watchOS, tvOS and OS X)
 
Future of .NET - .NET on Non Windows Platforms
Future of .NET - .NET on Non Windows PlatformsFuture of .NET - .NET on Non Windows Platforms
Future of .NET - .NET on Non Windows Platforms
 
Mphasis Digital POV - Emerging Open Standard Protocol stack for IoT
Mphasis Digital POV - Emerging Open Standard Protocol stack for IoTMphasis Digital POV - Emerging Open Standard Protocol stack for IoT
Mphasis Digital POV - Emerging Open Standard Protocol stack for IoT
 
MS-Misys Opics Plus.PDF
MS-Misys Opics Plus.PDFMS-Misys Opics Plus.PDF
MS-Misys Opics Plus.PDF
 
Misys Opics Plus Solution Brief
Misys Opics Plus Solution BriefMisys Opics Plus Solution Brief
Misys Opics Plus Solution Brief
 

pebble - Building apps on pebble

  • 1. Aniruddha Chakrabarti Principal Architect | caniruddha@Hotmail.com Building apps for pebble
  • 2. A bit of history • 2011 – pebble was born • 2012 – Record breaking KickStarter surpassing $10 million • 2013 – pebble Watch was launched • 2014 – pebble Steel was launched • 2015 – pebble Time was launched pebble Watch pebble Steel pebble Time Steel
  • 3. pebble Time – in KickStarter
  • 4. How to develop for pebble – two type of apps PebbleFace: • Apps developed using Pebble C SDK (current version is 3.0) are called PebbleFace • Apps could be written in C. There are two options - • CloudPebble - New developers are encouraged to use this service to begin development without installing any software whatsoever. This is also the preferred option for Windows users. • C SDK - Use the C SDK locally. Advanced users are most likely to use this, especially if they are building an Android or iOS companion app. Currently supports • Mac OS X • Linux PebbleApp: • Apps developed using alternate JavaScript library are called PebbleApp • JavaScript library (pebble.js) is currently in beta • PebbleApps could be written in JavaScript
  • 7. What does a PebbleFace (custom Pebble App) contains • Source files (.c files) • Window layout • Resources - image file, font, raw blob etc • Manifest file (appinfo.json) - Details of the metadata that describes the app, such as its name, resources and capabilities.
  • 8. App metadata in manifest file { "uuid": "afb5b3ce-3701-436a-902f-098feaac9b29", "shortName": "ExampleApp", "longName": "ExampleApp", "companyName": "MakeAwesomeHappen", "versionCode": 1, "versionLabel": "1.0", "sdkVersion": "3", "targetPlatforms": ["aplite", "basalt"], "watchapp": { "watchface": false }, "appKeys": { "dummy": 0 }, "resources": { "media": [] } } Property Required Type Description Uuid Yes UUID Unique identifier for the app. Generated by pebble new-project. shortName Yes String App's short name. This will appear in the launcher list on the Watch. longName Yes String App's long name. This will appear in the Pebble mobile application. companyName Yes String Name of the app's developer. versionLabel Yes String Version label for the app. Must use the format major or major.minor. sdkVersion Yes String The version of the SDK that this app is being written for targetPlatforms No Array of strings Specify which platforms to build this app for (Aplite or Basalt). Defaults to both if omitted. watchapp Yes Object Used to configure the app behavior on the watch. Set watchface to true to behave as a watchapp. capabilities No Array of strings List of capabilities that your app requires. The only two supported capabilities arelocation and configurable. For more information, refer to PebbleKit JS documentation appKeys No Object Keys used for AppMessage andAppSync. This is a mapping from named string keys to integer AppMessage keys. See PebbleKit JS Guides for more information. resources No Object Contains one item media: an array of all of the media resources to be bundled with your apps (Maximum 256 per app). See Managing App Resources for more information. appinfo.json
  • 9. App Metadata (in CloudPebble)
  • 10. App Window • Starting point of any kind of user interface on Pebble. • Whenever a new screen slides into view, that is the result of a new window being pushed onto the stack. • The window stack can be thought of in a similar manner to a stack of playing cards, with the most recent card on the top. • In this way a window is removed by popping it off the top of the stack. • Each app's UI begins with its first window. By adding multiple windows it is possible to expand the capabilities of an app beyond one screen. • A window's main purpose is to contain and display Layers, such as TextLayers or BitmapLayers for example. A layer must be added to a window as a child in order to be visible to the user. • When it is created, it can be given a set of references to handlers for various events throughout its life, such as load and unload.
  • 11. Create the first Watchface app #include <pebble.h> // Create a pointer to a variable of Window type static Window *main_window; static void init(){ // Create the window itself in app initialization and assign to the pointer main_window = window_create(); // Push the newly created window to the window stack // Show the Window on the watch, with animated=true window_stack_push(main_window, true); } static void deinit(){ window_destroy(main_window); } // Entry point to the app int main(){ init(); app_event_loop(); deinit(); }
  • 12. Window events (load and unload) static void main_window_load(Window *window) { // Code to be executed during window load comes here } static void main_window_unload(Window *window) { // Code to be executed during window unload comes here } static void init(){ // Create the window itself in app initialization and assign to the pointer main_window = window_create(); // Set handlers to manage the elements inside the Window window_set_window_handlers(main_window, (WindowHandlers) { .load = main_window_load, .unload = main_window_unload }); // Push the newly created window to the window stack // Show the Window on the watch, with animated=true window_stack_push(main_window, true); }
  • 13. Add a TextLayer (label) #include <pebble.h> Window *main_window; TextLayer *text_layer_hello; Layer *root_layer; void handle_init(void) { main_window = window_create(); root_layer = window_get_root_layer(main_window); text_layer_hello = text_layer_create(GRect(0, 0, 144, 20)); text_layer_set_text(text_layer_hello,"Hello I am Pebble!"); layer_add_child(root_layer, text_layer_get_layer(text_layer_hello)); window_stack_push(main_window, true); } void handle_deinit(void) { text_layer_destroy(text_layer_hello); window_destroy(main_window); } int main(void) { handle_init(); app_event_loop(); handle_deinit(); }
  • 14. Set window and text layer color • Set window background color • Set text layer background and text (or foreground) color void handle_init(void) { main_window = window_create(); root_layer = window_get_root_layer(main_window); text_layer_hello = text_layer_create(GRect(0, 0, 144, 40)); text_layer_set_text(text_layer_hello,"Hello I am Pebble!"); window_set_background_color(main_window, GColorBlack); // Set window background color to Black text_layer_set_text_color(text_layer_hello, GColorBlack); // Set text layer text/foreground color to Black text_layer_set_background_color(text_layer_hello, GColorWhite); // Set text layer Background color to White layer_add_child(root_layer, text_layer_get_layer(text_layer_hello)); window_stack_push(main_window, true); }
  • 15. System Fonts • Gothic 14 • Gothic 14 Bold • Gothic 18 • Gothic 18 Bold • Gothic 24 • Gothic 24 Bold • Gothic 28 • Gothic 28 Bold • Bitham 30 Black • Bitham 42 Bold • Bitham 42 Light • Bitham 34 Medium Numbers • Bitham 42 Medium Numbers • Roboto 21 Condensed • Roboto 49 Bold Subset • Droid 28 Bold
  • 16. Set TextLayer font void handle_init(void) { main_window = window_create(); root_layer = window_get_root_layer(main_window); text_layer_hello = text_layer_create(GRect(0, 0, 144, 40)); text_layer_set_text(text_layer_hello,"Hello Pebble!"); window_set_background_color(main_window, GColorBlack); // Set System Font to Gothic font size 28 text_layer_set_font(text_layer_hello, fonts_get_system_font(FONT_KEY_GOTHIC_28)); text_layer_set_text_color(text_layer_hello, GColorBlack); text_layer_set_background_color(text_layer_hello, GColorWhite); layer_add_child(root_layer, text_layer_get_layer(text_layer_hello)); window_stack_push(main_window, true); }
  • 17. Set TextLayer font (2) void handle_init(void) { main_window = window_create(); root_layer = window_get_root_layer(main_window); text_layer_hello = text_layer_create(GRect(0, 0, 144, 40)); text_layer_set_text(text_layer_hello,"Hello Pebble!"); window_set_background_color(main_window, GColorBlack); // Set System Font to Gothic font size 28 text_layer_set_font(text_layer_hello, fonts_get_system_font(FONT_KEY_BITHAM_42_LIGHT)); text_layer_set_text_color(text_layer_hello, GColorBlack); text_layer_set_background_color(text_layer_hello, GColorWhite); layer_add_child(root_layer, text_layer_get_layer(text_layer_hello)); window_stack_push(main_window, true); }
  • 18. Button Clicks static void up_click_handler(ClickRecognizerRef recognizer, void *context) { text_layer_set_text(text_layer_hello, "Up pressed!"); } static void click_config_provider(void *context) { // Register the ClickHandlers window_single_click_subscribe(BUTTON_ID_UP, up_click_handler); } void handle_init(void) { main_window = window_create(); root_layer = window_get_root_layer(main_window); text_layer_set_font(text_layer_hello, fonts_get_system_font(FONT_KEY_GOTHIC_24)); text_layer_hello = text_layer_create(GRect(0, 0, 144, 60)); text_layer_set_text(text_layer_hello,"Hello!"); layer_add_child(root_layer, text_layer_get_layer(text_layer_hello)); window_stack_push(main_window, true); window_set_click_config_provider(main_window, click_config_provider); } Up Button Down Button Select Button
  • 19. Button Clicks (2) static void up_click_handler(ClickRecognizerRef recognizer, void *context) { text_layer_set_text(text_layer_hello, "Up pressed!"); } static void select_click_handler(ClickRecognizerRef recognizer, void *context) { text_layer_set_text(text_layer_hello, "Select pressed!"); } static void down_click_handler(ClickRecognizerRef recognizer, void *context) { text_layer_set_text(text_layer_hello, "Down pressed!"); } static void click_config_provider(void *context) { window_single_click_subscribe(BUTTON_ID_UP, up_click_handler); window_single_click_subscribe(BUTTON_ID_SELECT, select_click_handler); window_single_click_subscribe(BUTTON_ID_DOWN, down_click_handler); } void handle_init(void) { main_window = window_create(); root_layer = window_get_root_layer(main_window); text_layer_set_font(text_layer_hello, fonts_get_system_font(FONT_KEY_GOTHIC_24)); text_layer_hello = text_layer_create(GRect(0, 0, 144, 60)); text_layer_set_text(text_layer_hello,"Hello!"); layer_add_child(root_layer, text_layer_get_layer(text_layer_hello)); window_stack_push(main_window, true); window_set_click_config_provider(main_window, click_config_provider); } Up Button Down Button Select Button
  • 20. App Events / Services • Pebble apps rely on callbacks, allowing the developer to define behavior for different types of events, such as when the battery is low, the Bluetooth connection state changes or the watch is tapped. • This allows apps to update their UI when these events happen, instead of constantly polling for a change in conditions. • Services • Bluetooth Connection Service • Battery State Service • Time Ticker Service • App Focus Service (For interruptions) • Wakeup API – allows developers to schedule an app launch in the future, even if the app itself is closed in the meantime.
  • 21. Bluetooth connection service • The Bluetooth connection service allows your app to know whether Pebble is connected to the phone. This can be done in two ways - 1. Ask the system for this information at any time - static void up_click_handler(ClickRecognizerRef recognizer, void *context) { if (bluetooth_connection_service_peek()) { text_layer_set_text(text_layer_hello, "Phone is connected!"); } else { text_layer_set_text(text_layer_hello, "Phone is not connected!"); } }
  • 22. Bluetooth connection service (2) • The Bluetooth connection service allows your app to know whether Pebble is connected to the phone. This can be done in two ways - 2. register for Bluetooth connection and disconnection events - Step 1: Declare the event handler static void bluetooth_handler(bool is_connected) { if (is_connected) { text_layer_set_text(text_layer_hello, "Phone is connected!"); } else { text_layer_set_text(text_layer_hello, "Phone is not connected!"); } } Step 2: Register the event handler with Bluetooth service in init event // Register the event handler with the bluetooth service bluetooth_connection_service_subscribe(bluetooth_handler); Step 3: Deregister from Bluetooth service in deinit event // Unsubscribe from bluetooth service bluetooth_connection_service_unsubscribe();
  • 23. Battery state service • The Battery State Service lets you know when the battery state changes, i.e., its current charge level, whether it is plugged and charging. • It uses the BatteryChargeState structure to describe the current power state of Pebble. • Similar to the Bluetooth Connection Service , you can get the current state at any given moment or register to be notified when the state changes. static void up_click_handler(ClickRecognizerRef recognizer, void *context) { static char s_battery_buffer[16]; BatteryChargeState charge_state = battery_state_service_peek(); if (charge_state.is_charging) { snprintf(s_battery_buffer, sizeof(s_battery_buffer), "charging"); } else { snprintf(s_battery_buffer, sizeof(s_battery_buffer), "%d%% charged", charge_state.charge_percent); } text_layer_set_text(text_layer_hello, s_battery_buffer); }
  • 24. Battery state service (2) • Register for Bluetooth connection and disconnection events - Step 1: Declare the event handler static void battery_handler(BatteryChargeState charge_state) { static char s_battery_buffer[16]; if (charge_state.is_charging) { snprintf(s_battery_buffer, sizeof(s_battery_buffer), "charging"); } else { snprintf(s_battery_buffer, sizeof(s_battery_buffer), "%d%% charged", charge_state.charge_percent); } text_layer_set_text(text_layer_hello, s_battery_buffer); } Step 2: Register the event handler with Battery State service in init event // Register the event handler with the Battery state service battery_state_service_subscribe(battery_handler); Step 3: Deregister from Bluetooth service in deinit event // Unsubscribe from Battery state service battery_state_service_unsubscribe();
  • 25. Resources • Pebble - https://getpebble.com/ • Developer Portal - http://developer.getpebble.com/ • Getting Started - https://developer.getpebble.com/getting-started • Developer Guides - https://developer.getpebble.com/guides/ • Documentation - https://developer.getpebble.com/docs/ • CloudPebble online IDE - https://cloudpebble.net