Introducing Pebble SDK 2.0

download

Embed Size (px)

description

 

transcript

  • Introducing Pebble SDK 2.0 November 6th 2013
  • A MAJOR UPDATE New Tools SDK Overhaul New APIs
  • Introducing Pebble SDK 2.0 If you are watching live, you can ask questions On our IRC channel: #pebble on irc.freenode.net During our AMA on Reddit at 12pm PST today This is recorded and will be available on our YouTube channel and on the developer web site Friendly warning: This presentation is mostly intended for developers
  • New Tools Improving the developer experience CloudPebble Simplied build system Deploying from the command line Application logs Documentation
  • New Tools CloudPebble Now open-sourced and hosted by Pebble Technology
  • New Tools CloudPebble No installation - From zero to rst installed app in 60 seconds
  • New Tools Simplied build system One tool for all your Pebble development
  • New Tools Simplied build system $ pebble new-project helloworld Creating new project hello-world $ cd helloworld $ pebble build Memory usage: ============= Total app footprint in RAM: 822 bytes / ~24kb Free RAM available (heap): 23754 bytes 'build' finished successfully (0.351s)
  • New Tools Developer Connection Use the Pebble mobile application to install and debug apps.
  • New Tools Developer Connection $ export PEBBLE_PHONE=192.168.1.42 $ pebble install --logs [INFO [INFO [INFO [INFO ] ] ] ] Installation successful Enabling application logging... Displaying logs ... Ctrl-C to interrupt. D helloworld.c:58 Done initializing A very simple and reliable way to install and watch log messages
  • New Tools Documentation We have re-written almost all of Pebble Documentation Pebble documentation now includes: A Getting Started Guide Pebble Developer Guide with 11 chapters Pebble Mobile Developer Guide Pebble 2.0 Migration Guide API Reference for Pebble, iOS and Android
  • New Tools Improving the developer experience CloudPebble Simplied build system Deploying from the command line Application logs Documentation
  • SDK Overhaul Getting ready for bigger applications and an evolving SDK
  • SDK Overhaul Migrating to Pebble 2.0 Pebble 2.0 is a major evolution of Pebble 1.0 with lots of changes in the system and in the SDK Pebble 2.0 is not compatible with 1.0 apps Developers need to migrate their application to Pebble 2.0 Refer to Pebble 2.0 Migration Guide http://developer.getpebble.com/2/guides/migration-guide.html
  • SDK Overhaul Pebble application must provide some metadata through a JSON le in the project called appinfo.json Application name UUID Watchface / Watchapp Resources etc Application metadata
  • SDK Overhaul Using pointers and dynamic memory In Pebble OS 2.0, all the SDK structures are opaque. This means we can change them without you having to recompile your apps. You cannot allocate structures as global variables as you did in 1.0. You must use pointers and memory allocated dynamically by the system. All calls to _init() functions become are replaced by _create() calls Window my_window; window_init(&my_window); becomes Window *my_window; my_window = window_create();
  • SDK Overhaul Getting closer to standards: C/UNIX pbl_main() is now called main() PblTm is replaced by struct tm string_format_time() is replaced by strftime() Pebble does not support timezones yet but we introduce gmtime() and localtime() to prepare for timezone support. get_time() is replaced by localtime(time(NULL))
  • SDK Overhaul Enforcing a subscription based Event system Pebble 2.0 relies heavily on Events. You register to events with _register functions. All Pebble 1.x APIs have been updated: Timer, Tick, AppMessage, etc PebbleAppHandlers handlers = { .timer_handler = &handle_timer }; becomes timer = app_timer_register(1500, timer_callback, NULL);
  • SDK Overhaul Dynamic Memory Introducing two old friends: malloc() and free() Each application has its own heap and is cleaned automatically You can attach data to layers and windows (layer_create_with_data() and window_set_user_data()) Your total memory is ~24k. Your heap space is 24k minus app size. Pebble SDK includes tool to help you manage your memory: $ pebble build Memory usage: ============= Total app footprint in RAM: 822 bytes / ~24kb Free RAM available (heap): 23754 bytes ! $ pebble logs ... [INFO ] I Heap Usage for : Available Used Still allocated
  • SDK Overhaul Migration in a nutshell Use pebble convert-project to generate the new appinfo.json le Rename pbl_main() into main() Use pointers to structures instead of statically allocated structures Use the SDK APIs to allocate memory and initialize the structs Check the other APIs for changes Refer to Pebble 2.0 Migration Guide http://developer.getpebble.com/2/guides/migration-guide.html
  • SDK Overhaul Getting ready for bigger applications and an evolving SDK
  • New Frameworks Event Services A unique design pattern that communicates with Pebble OS subsystems
  • New Frameworks Event Services The App Focus Service lets you know when your app is covered by a modal window typedef void (*AppFocusHandler)(bool in_focus); ! void app_focus_service_subscribe(AppFocusHandler handler); void app_focus_service_unsubscribe();
  • New Frameworks Event Services The Bluetooth Connection Service lets you know when the watch is connected to the phone typedef void (*BluetoothConnectionHandler)(bool connected); void bluetooth_connection_service_subscribe(BluetoothConnectionHandler handler); void bluetooth_connection_service_unsubscribe(void); ! bool bluetooth_connection_service_peek(void);
  • New Frameworks Event Services The Battery State Service can let you know when the watch is plugged or unplugged typedef struct { uint8_t charge_percent; bool is_charging; bool is_plugged; } BatteryChargeState; ! typedef void (*BatteryStateHandler)(BatteryChargeState charge); void battery_state_service_subscribe(BatteryStateHandler handler); void battery_state_service_unsubscribe(); ! void battery_state_service_peek(void);
  • New Frameworks Event Services A unique design pattern that communicates with Pebble OS subsystems Bluetooth, App Focus, Battery Status Refer to Pebble 2.0 Event Services Guide http://developer.getpebble.com/2/guides/event-service-guide.html
  • New Frameworks Accelerometer Lets shake things up ... The Accelerometer framework is designed with all use cases in mind: user interaction for watchfaces, games, activity monitor, etc
  • New Frameworks Accelerometer Hardware accelerometer ! Able to detect taps Perform measurements at a given frequency Store samples to save CPU time
  • New Frameworks Accelerometer The simplest way to use the accelerometer is to register for tap events Those events are generated by the hardware and use very little energy void accel_tap_handler(AccelAxisType axism int32_t direction) { // Process tap on ACCEL_AXIS_X, ACCEL_AXIS_Y or ACCEL_AXIS_Z } ! void handle_init() { accel_tap_service_subscribe(&accel_tap_handler); } ! void handle_deinit() { accel_tap_service_unsubscribe(); }
  • New Frameworks Accelerometer You can register to receive raw events one at a time void accel_data_handler(AccelData *data, uint32_t num_samples) { process_sample(&data); } ! void handle_init() { accel_data_service_subscribe(1, &accel_data_handler); } ! void handle_deinit() { accel_data_service_unsubscribe(); }
  • New Frameworks Accelerometer The accelerometer API also supports storing samples on the hardware void accel_data_handler(AccelData *data, uint32_t num_samples) { // Process 10 events - every 1 second } ! void handle_init() { accel_data_service_subscribe(10, &accel_data_handler); accel_service_set_sampling_rate(ACCEL_SAMPLING_10HZ); }
  • New Frameworks Accelerometer You can also peek at the accelerometer when updating your UI This is the strategy we recommend for game developers void tick_handler() { AccelData data; accel_service_peek(&data); } !