Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Getting Started with Smart Watch Development with Pebble

0.00/5 (No votes)
15 Oct 2015 1  
Smartwatch Development with pebble

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:

  1. One being direct SDK based development for Linux and Mac OS.
  2. 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:

  1. First of all, you need to create an account at Cloud pebble: https://cloudpebble.net
  2. 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:

//
// Window *window;
//window = window_create();
//
//
// TextLayer *text_layer;
//text_layer = text_layer_create(GRect(0, 0, 144, 40));
//

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

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here