Introduction
It's been so fascinating that Smart watches have evolved so much with different flavours and different types. It is now one of the essential things you have when you want to stay connected with the digital world. Hence the curiosity to learn a bit and share.
Background
This tip will cover the basic app structure of Pebble, what are the essential functions needed and getting started with Cloud Pebble with C Language.
Let's Start
Developing for Pebble is fun as we can use our age old language C to code it.
There are 2 different ways to develop for Pebble:
- One being direct SDK based development for Linux and Mac OS.
- For Windows users and also for Mac and Linux users, it can also be done with Cloud Pebble.
We will start with Cloud Pebble and will develop a simple Hello CP
app and cover the app architecture.
We will modify a watch interface with our CodeProject Bob icon.
Let's get a feel of Cloud Pebble:
- First of all, you need to create an account at Cloud pebble: https://cloudpebble.net
- I found out lot of examples to tweek from http://developer.getpebble.com/tutorials
A look at Cloud Pebble:
Get going with Hello CodeProject
:
Open a new account, go to the project Tab. Click on create.
Project Name: "Project Name" and Template as Blank and leave everything as it is. Click on create.
As everything will be blank and there is nothing to start with, we need to click source files, add new with file type as .C target would be app/watchface.
How the Pebble Development Environment Works
Everything happens in the main function.
Within Main
function for declaration, we have init
function for initialization and denit
function for de-initialization.
You need to declare pointers.
You need to allocate the pointers and finally deallocate it.
An overview of the architecture is shown below:
First, you need to declare pointers first for the Window Size of the Watch and then to show text we need to declare the pointer. After declaration, we need to allocate the pointers as shown below:
In the final step, we need to deallocate the pointers that too in deinit
function:
TextLayer *text_layer;
text_layer_destroy(text_layer);
window_destroy(window);
The whole code for the Watch
is as follows:
#include <pebble.h><pebble.h>
Window *window;
TextLayer *text_layer;
void init() {
window = window_create();
text_layer = text_layer_create(GRect(0, 0, 144, 40));
text_layer_set_text(text_layer, "Hello, CodeProject!");
layer_add_child(window_get_root_layer(window),
text_layer_get_layer(text_layer));
window_stack_push(window, true);
}
void deinit() {
text_layer_destroy(text_layer);
window_destroy(window);
}
int main() {
init();
app_event_loop();
deinit();
return 0;
}
Save the project and run it in emulator. It will look like this:
References