### Installing Toolchain Dependencies (x64) Source: https://github.com/google/pebble/blob/main/third_party/jerryscript/targets/esp8266/docs/ESP-PREREQUISITES.md Installs necessary dependencies for the x64 architecture using apt-get. These are required to build the ESP8266 firmware. Prerequisites include an active internet connection and sudo privileges. ```bash sudo apt-get install git autoconf build-essential gperf \n bison flex texinfo libtool libncurses5-dev wget \n gawk libc6-dev-amd64 python-serial libexpat-dev sudo mkdir /opt/Espressif sudo chown $USER /opt/Espressif/ ``` -------------------------------- ### Installing Toolchain Dependencies (x86) Source: https://github.com/google/pebble/blob/main/third_party/jerryscript/targets/esp8266/docs/ESP-PREREQUISITES.md Installs necessary dependencies for the x86 architecture using apt-get. These are required to build the ESP8266 firmware. Prerequisites include an active internet connection and sudo privileges. ```bash sudo apt-get install git autoconf build-essential gperf \n bison flex texinfo libtool libncurses5-dev wget \n gawk libc6-dev-i386 python-serial libexpat-dev sudo mkdir /opt/Espressif sudo chown $USER /opt/Espressif/ ``` -------------------------------- ### Pebble SDK 2.0 Project Creation (C) Source: https://github.com/google/pebble/blob/main/devsite/source/_guides/migration/migration-guide.md Demonstrates the use of the `pebble` command-line tool to create a new Pebble project. The example shows the basic commands for project creation and listing the project directory contents. No dependencies are required beyond the installed Pebble SDK 2.0. ```bash $ pebble new-project helloworld $ cd helloworld $ ls appinfo.json resources src wscript ``` -------------------------------- ### Installing ESP Image Tool Source: https://github.com/google/pebble/blob/main/third_party/jerryscript/targets/esp8266/docs/ESP-PREREQUISITES.md Downloads and installs the ESP image tool using dpkg. This tool is used for flashing the firmware onto the ESP8266. Requires wget and dpkg (usually available on Debian-based systems). ```bash cd /opt/Espressif wget -O esptool_0.0.2-1_i386.deb https://github.com/esp8266/esp8266-wiki/raw/master/deb/esptool_0.0.2-1_i386.deb sudo dpkg -i esptool_0.0.2-1_i386.deb ``` -------------------------------- ### Cloning and Setting up Espressif SDK Source: https://github.com/google/pebble/blob/main/third_party/jerryscript/targets/esp8266/docs/ESP-PREREQUISITES.md Clones the Espressif official SDK, creates a symbolic link, and checkouts a specific version. This SDK contains necessary libraries and examples for ESP8266 development. Requires Git. ```bash cd /opt/Esprissif git clone https://github.com/espressif/ESP8266_RTOS_SDK.git ESP8266_RTOS_SDK.git ln -s ESP8266_RTOS_SDK.git ESP8266_SDK cd ESP8266_SDK git checkout -b jerry a2b413ad2996450fe2f173b6afab243f6e1249aa ``` -------------------------------- ### Pebble SDK 2.0 App Installation (C) Source: https://github.com/google/pebble/blob/main/devsite/source/_guides/migration/migration-guide.md Shows how to install a Pebble app using the `pebble install` command, specifying the phone's IP address and enabling application logging. Requires the Pebble SDK 2.0, a built app, and the Pebble app on the specified phone. ```bash $ pebble install --phone 10.0.64.113 --logs [INFO ] Installation successful [INFO ] Enabling application logging... [INFO ] Displaying logs ... Ctrl-C to interrupt. [INFO ] D helloworld.c:58 Done initializing, pushed window: 0x2001a524 ``` -------------------------------- ### Compiling Blinky Example (Old Method) Source: https://github.com/google/pebble/blob/main/third_party/jerryscript/targets/esp8266/docs/ESP-PREREQUISITES.md Compiles the Blinky example using an older method. The reliability of this method is uncertain. ```make make BOOT=new APP=0 SPI_SPEED=80 SPI_MODE=QIO SPI_SIZE_MAP=2 ``` -------------------------------- ### Downloading Xtensa Libraries Source: https://github.com/google/pebble/blob/main/third_party/jerryscript/targets/esp8266/docs/ESP-PREREQUISITES.md Downloads the necessary Xtensa libraries. This step is required for linking during the compilation process. Requires wget. ```bash cd /opt/Espressif/ESP8266_SDK wget -O lib/libhal.a https://github.com/esp8266/esp8266-wiki/raw/master/libs/libhal.a ``` -------------------------------- ### Starting Jekyll Web Server Source: https://github.com/google/pebble/blob/main/devsite/README.md This command starts the Jekyll web server, which is used to build and serve the website. It uses `bundle exec` to ensure that the correct gem versions (as specified in the Gemfile) are used. This makes sure the website is built and served correctly. ```shell bundle exec jekyll serve ``` -------------------------------- ### Installing documentation.js Source: https://github.com/google/pebble/blob/main/devsite/README.md This command installs the documentation.js framework globally using npm. This framework is used to generate documentation for the PebbleKit JS and Rocky documentation from JSDocs contained within the js-docs folder. ```shell npm install -g documentation ``` -------------------------------- ### YAML Metadata Example Source: https://github.com/google/pebble/blob/main/devsite/README.md This is an example of the YAML metadata block that should be placed at the start of a blog post Markdown file. It includes the title, author, and tags, which are used for generating the blog post metadata and organizing it. ```yaml --- title: Parlez-vous Pebble? Sprechen sie Pebble? ¿Hablas Pebble? author: blogUsername tags: - Freshly Baked --- ``` -------------------------------- ### Setting up crosstool-NG Source: https://github.com/google/pebble/blob/main/third_party/jerryscript/targets/esp8266/docs/ESP-PREREQUISITES.md Clones, configures, and builds crosstool-NG, a toolchain for building embedded systems. This step is crucial for compiling the ESP8266 firmware. Requires Git and sufficient disk space. ```bash cd /opt/Espressif git clone -b lx106-g++-1.21.0 git://github.com/jcmvbkbc/crosstool-NG.git cd crosstool-NG ./bootstrap && ./configure --prefix=`pwd` && make && make install ./ct-ng xtensa-lx106-elf ./ct-ng build ``` -------------------------------- ### Compiling Blinky Example (2048KB Flash) Source: https://github.com/google/pebble/blob/main/third_party/jerryscript/targets/esp8266/docs/ESP-PREREQUISITES.md Compiles the Blinky example for an ESP8266 with 2048KB flash memory. Uses the 'make' command with specific settings. Requires a properly configured build environment. ```make BOOT=new APP=1 SPI_SPEED=80 SPI_MODE=QIO SPI_SIZE_MAP=5 make BOOT=new APP=2 SPI_SPEED=80 SPI_MODE=QIO SPI_SIZE_MAP=5 make ``` -------------------------------- ### Setting up ESP Upload Tool Source: https://github.com/google/pebble/blob/main/third_party/jerryscript/targets/esp8266/docs/ESP-PREREQUISITES.md Clones the ESP upload tool and creates a symbolic link. This tool is an alternative method for uploading firmware to the ESP8266. Requires Git. ```bash cd /opt/Espressif git clone https://github.com/themadinventor/esptool esptool-py sudo ln -s $PWD/esptool-py/esptool.py crosstool-NG/builds/xtensa-lx106-elf/bin/esptool.py ``` -------------------------------- ### Installing Ruby Dependencies Source: https://github.com/google/pebble/blob/main/devsite/README.md This command installs the Ruby dependencies required by the Jekyll-based website. It utilizes Bundler to manage these dependencies. If Bundler isn't installed, the provided command shows how to install it using RubyGems. ```shell bundle install ``` -------------------------------- ### Pebble SDK 4 Installation via Homebrew (bash) Source: https://github.com/google/pebble/blob/main/devsite/source/sdk4/getting-started.md This bash script utilizes Homebrew to update, upgrade, and install the latest version of the Pebble SDK. It requires Homebrew to be already installed on the macOS system. The script executes three commands sequentially, updating Homebrew, upgrading the Pebble SDK, and finally installing the latest SDK version. ```bash $ brew update \u0026\u0026 brew upgrade pebble-sdk \u0026\u0026 pebble sdk install latest ``` -------------------------------- ### HTML Input Elements for Configuration Source: https://github.com/google/pebble/blob/main/devsite/source/_guides/user-interfaces/app-configuration-static.md This snippet shows example HTML input elements (text input and checkboxes) for collecting user preferences on the configuration page. These elements should be styled appropriately with CSS. ```HTML Background Color Foreground Color Enable Second Ticks Show Animations ``` -------------------------------- ### Installing SDKs Source: https://github.com/google/pebble/blob/main/devsite/source/_posts/2015-12-01-A-New-Pebble-Tool.md This snippet shows the process of installing an SDK using the `pebble sdk install` command. It includes a prompt to accept the Pebble Terms of Use and Developer License, followed by the downloading, extracting, and dependency installation steps. The output demonstrates the installation process for SDK version 3.6.2. ```text katharine@kbrmbp ~> pebble sdk install 3.6.2 Installing SDK... Do you accept the Pebble Terms of Use and the Pebble Developer License? (y/n) y Downloading... 100%[======================================================] 1.40 MB/s 0:00:01 Extracting... Preparing virtualenv... (this may take a while) Installing dependencies... Done. Installed. ``` -------------------------------- ### Flashing Firmware (Old Method) Source: https://github.com/google/pebble/blob/main/third_party/jerryscript/targets/esp8266/docs/ESP-PREREQUISITES.md Flashes the compiled firmware using an older method with esptool.py. The reliability of this method is uncertain. Replace `/dev/ttyUSB0` with the actual port. ```bash cd $BIN_PATH sudo /opt/Espressif/esptool-py/esptool.py \n--port /dev/ttyUSB0 write_flash \n0x00000 eagle.flash.bin 0x40000 eagle.irom0text.bin ``` -------------------------------- ### Setting SDK and BIN Environment Variables Source: https://github.com/google/pebble/blob/main/third_party/jerryscript/targets/esp8266/docs/ESP-PREREQUISITES.md Sets environment variables for the SDK path and the output binary path. These are used during compilation and flashing. Requires editing a shell configuration file such as .profile or .bashrc. ```bash export SDK_PATH=/opt/Espressif/ESP8266_SDK export BIN_PATH=(to output folder path) ``` -------------------------------- ### Image Feature YAML Example Source: https://github.com/google/pebble/blob/main/devsite/README.md This YAML example represents a feature configuration for the landing page, specifically focusing on image-based features. It includes fields like title, URL, background image, button text, button colors, and duration for slideshow timing. ```yaml - title: Want to make your apps more internationally friendly? url: /guides/publishing-tools/i18n-guide/ background_image: /images/landing-page/i18n-guide.png button_text: Read our brand new guide to find out how button_fg: black button_bg: yellow duration: 5000 ``` -------------------------------- ### Initializing and Executing - C Source: https://github.com/google/pebble/blob/main/third_party/jerryscript/docs/03.API-EXAMPLE.md This code expands on the previous example by explicitly splitting the initialization, script execution, and cleanup steps for JerryScript. It calls `jerry_init`, `jerry_parse`, `jerry_run`, and `jerry_cleanup` to manage the engine's lifecycle. The example executes the same "Hello, World!" script. ```C #include #include "jerry-api.h" int main (int argc, char *argv[]) { const jerry_char_t script[] = "print ('Hello, World!');"; size_t script_size = strlen ((const char *) script); /* Initialize engine */ jerry_init (JERRY_INIT_EMPTY); /* Setup Global scope code */ jerry_value_t parsed_code = jerry_parse (script, script_size, false); if (!jerry_value_has_error_flag (parsed_code)) { /* Execute the parsed source code in the Global scope */ jerry_value_t ret_value = jerry_run (parsed_code); /* Returned value must be freed */ jerry_release_value (ret_value); } /* Parsed source code must be freed */ jerry_release_value (parsed_code); /* Cleanup engine */ jerry_cleanup (); return 0; } ``` -------------------------------- ### Curie BSP One-Time Setup (Make) Source: https://github.com/google/pebble/blob/main/third_party/jerryscript/targets/curie_bsp/README.md This Make command performs a one-time setup within the Curie BSP directory. It checks, downloads, and installs necessary tools. This step should only be executed once. It sets up the environment for the subsequent build steps. ```make make -C wearable_device_sw/projects/curie_bsp_jerry/ one_time_setup ``` -------------------------------- ### Flashing Firmware (New Method) Source: https://github.com/google/pebble/blob/main/third_party/jerryscript/targets/esp8266/docs/ESP-PREREQUISITES.md Flashes the compiled firmware onto the ESP8266 using esptool.py. Requires the ESP8266 to be connected and GPIO pins configured correctly. Replace `/dev/ttyUSB0` with the actual port. ```bash sudo /opt/Espressif/esptool-py/esptool.py \n --port /dev/ttyUSB0 write_flash \n 0x00000 $SDK_PATH/bin/\"boot_v1.4(b1).bin\" \n 0x01000 $BIN_PATH/upgrade/user1.2048.new.5.bin \n 0x101000 $BIN_PATH/upgrade/user2.2048.new.5.bin \n 0x3FE000 $SDK_PATH/bin/blank.bin \n 0x3FC000 $SDK_PATH/bin/esp_init_data_default.bin ``` -------------------------------- ### Installing Bundler Source: https://github.com/google/pebble/blob/main/devsite/README.md This command installs Bundler, a dependency manager for Ruby projects. It's a prerequisite for managing the project's Ruby dependencies and is executed using RubyGems, the package manager for Ruby. ```shell [sudo] gem install bundler ``` -------------------------------- ### Install Python Package and Editable Install with Pip Source: https://github.com/google/pebble/blob/main/third_party/pbl/pblconvert/requirements.txt This command uses pip to install a Python package from the specified index URL (https://pypi.python.org/simple/) and then installs the current project in editable mode. The `-e` option indicates an editable install, which means that any changes to the project's source code will immediately be reflected in the installation. The `.` at the end refers to the current directory. ```Bash --index-url https://pypi.python.org/simple/ -e . ``` -------------------------------- ### Basic HTML Configuration Page Structure Source: https://github.com/google/pebble/blob/main/devsite/source/_guides/user-interfaces/app-configuration-static.md This HTML snippet provides a basic template for the configuration page. It includes a title and placeholder content. Additional UI elements, like input fields and buttons, need to be added within the `` tag for user interaction. ```HTML Example Configuration

This is an example HTML forms configuration page.

``` -------------------------------- ### Building Nanopb Example with CMake (Bash) Source: https://github.com/google/pebble/blob/main/third_party/nanopb/examples/cmake_simple/README.txt This script demonstrates the process of building a nanopb example using CMake on a Linux system. It involves creating a build directory, running CMake, compiling the code using make, and then executing the resulting binary. The process assumes a CMake-compatible environment is already set up. ```bash mkdir build cd build/ cmake .. make ``` ```bash ./simple ``` -------------------------------- ### Installing Pebble App via Different Connection Methods Using Shell Source: https://github.com/google/pebble/blob/main/devsite/source/_guides/tools-and-resources/pebble-tool.md Demonstrates how to install a Pebble app to a physical watch or emulator via multiple connection types: Wi-Fi phone IP, QEMU instance, local serial Bluetooth connection, and CloudPebble proxy. Each command shows the use of the `pebble install` command with flags specifying connection details. Dependencies include access to a Pebble watch or an emulator instance and proper phone or device configuration. Inputs include IP address, host and port, or serial device path. Outputs are app installations onto the target Pebble device or emulator. ```shell $ pebble install --phone IP ``` ```shell $ pebble install --qemu HOST:PORT ``` ```shell $ pebble install --serial SERIAL ``` ```shell $ pebble install --cloudpebble ``` -------------------------------- ### Install Latest SDK Using Pebble Tool Source: https://github.com/google/pebble/blob/main/devsite/source/sdk/download.md This command installs the latest available SDK version using the `pebble` tool. It assumes that the `pebble` tool is already installed and configured. The `latest` argument specifies that the newest available SDK should be installed. The output typically shows the download progress and installation status. ```bash $ pebble sdk install latest ``` -------------------------------- ### Installing pblconvert using pip Source: https://github.com/google/pebble/blob/main/third_party/pbl/pblconvert/README.rst This snippet demonstrates how to install the pblconvert tool using pip. It utilizes the 'pip install .' command to install the tool from the current directory. This assumes that the project has a setup.py file configured correctly. The installation makes the tool available for use in the user's environment. ```Bash $ pip install . ``` -------------------------------- ### Initializing Setup and Loop Functions Source: https://github.com/google/pebble/blob/main/devsite/source/_guides/smartstraps/talking-to-pebble.md Defines the standard `setup()` and `loop()` functions, which are the main components of an Arduino sketch. The `setup()` function is used to initialize the serial communication and other configurations, and the `loop()` function runs repeatedly to handle the main program logic. ```c++ void setup() { } void loop() { } ``` -------------------------------- ### Creating New Rocky.js Project via CLI Source: https://github.com/google/pebble/blob/main/devsite/source/_guides/rocky-js/rocky-js-overview.md This snippet provides an example of creating a new Rocky.js project using the Pebble SDK command-line interface. It requires the Pebble SDK to be installed and properly configured. ```text $ pebble new-project --rocky projectname ``` -------------------------------- ### Initializing PebbleKit in Swift Source: https://github.com/google/pebble/blob/main/devsite/source/_guides/migration/pebblekit-ios-3.md This Swift code snippet demonstrates the basic initialization of PebbleKit in a Swift project. It sets the appUUID and delegate, and then starts the central manager. ```Swift func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { let pebbleCentral = PBPebbleCentral.defaultCentral() pebbleCentral.appUUID = PBGolfUUID pebbleCentral.delegate = self pebbleCentral.run() return true } ``` -------------------------------- ### Opening Configuration URL (PebbleKit JS) Source: https://github.com/google/pebble/blob/main/devsite/source/_guides/user-interfaces/app-configuration-static.md This JavaScript code snippet, within a `showConfiguration` event listener, opens the developer's custom configuration HTML page using `Pebble.openURL()`. Requires the PebbleKit JS library to be included in the project. ```JavaScript Pebble.addEventListener('showConfiguration', function() { var url = 'http://example.com/config.html'; Pebble.openURL(url); }); ``` -------------------------------- ### Initializing PebbleKit JS & Handling Events Source: https://github.com/google/pebble/blob/main/devsite/source/tutorials/watchface-tutorial/part3.md This JavaScript snippet demonstrates the basic setup for PebbleKit JS. It includes event listeners for the 'ready' and 'appmessage' events, providing a starting point for watchface functionality. It requires PebbleKit JS library and a Pebble watch. ```JavaScript // Listen for when the watchface is opened Pebble.addEventListener('ready', function(e) { console.log('PebbleKit JS ready!'); } ); // Listen for when an AppMessage is received Pebble.addEventListener('appmessage', function(e) { console.log('AppMessage received!'); } ); ``` -------------------------------- ### Setting PATH Environment Variable Source: https://github.com/google/pebble/blob/main/third_party/jerryscript/targets/esp8266/docs/ESP-PREREQUISITES.md Adds the crosstool-NG build directory to the PATH environment variable. This allows the system to find the compiled Xtensa toolchain. Requires editing a shell configuration file such as .profile or .bashrc. ```bash PATH=$PWD/builds/xtensa-lx106-elf/bin:$PATH ``` -------------------------------- ### Video Feature YAML Example Source: https://github.com/google/pebble/blob/main/devsite/README.md This YAML code defines a video feature for the landing page's slideshow. It specifies the title, target URL, background image, video URL (hosted on S3), button text and colors, and duration. This sets up a landing page video element. ```yaml - title: Send a Smile with Android Actionable Notifications url: /blog/2014/12/19/Leverage-Android-Actionable-Notifications/ background_image: /images/landing-page/actionable-notifications.png video: url: https://s3.amazonaws.com/developer.getpebble.com/videos/actionable-notifications.mp4 button_text: Learn how to supercharge Your Android Apps button_fg: white button_bg: green duration: 5000 ``` -------------------------------- ### Installing with Emulator Source: https://github.com/google/pebble/blob/main/devsite/source/_posts/2015-12-01-A-New-Pebble-Tool.md This snippet illustrates how to install an application using the emulator while specifying a particular SDK version using the `--sdk` flag. This allows developers to install on a specific SDK version, useful when using different SDK versions in build and install commands. ```text katharine@kbrmbp ~> pebble install --emulator basalt --sdk 3.7 ``` -------------------------------- ### Installing pbl using pip Source: https://github.com/google/pebble/blob/main/third_party/pbl/pbl/README.md This command installs the `pbl` tool from a Git repository using pip. The `git+ssh://...` specifies the Git repository's SSH URL. The installation is required to use the `pbl` tool. There are no specific dependencies mentioned other than pip and git. This will install the `pbl` tool and make it available for use. ```shell pip install git+ssh://git@github.com/pebble/pbl.git ``` -------------------------------- ### Install Pebble SDK with Homebrew Source: https://github.com/google/pebble/blob/main/devsite/source/sdk/download.md This command installs the Pebble SDK using Homebrew. The command first updates the package lists and then installs the pebble-sdk package. This is used when the user has not previously installed the Pebble SDK with Homebrew. The `brew` command is used to manage packages. ```bash $ brew update && brew install pebble/pebble-sdk/pebble-sdk ``` -------------------------------- ### Creating a Directory for Pebble Tools - Bash Source: https://github.com/google/pebble/blob/main/devsite/source/_includes/sdk/steps_install_sdk.md This snippet creates a directory to host all Pebble tools. It uses the `mkdir` command followed by the directory path specified by `site.data.sdk.path`. This directory is where the Pebble SDK will be extracted. ```Bash mkdir {{ site.data.sdk.path }} ``` -------------------------------- ### Pebble SDK 2.x App Initialization (C) Source: https://github.com/google/pebble/blob/main/devsite/source/_guides/migration/migration-guide.md Shows the simplified app initialization in Pebble SDK 2.x using `main()`, directly calling `handle_init()` and `handle_deinit()`. This is a revised approach compared to the SDK 1.x method. ```c int main(void) { handle_init(); app_event_loop(); handle_deinit(); } ``` -------------------------------- ### Installing Pebble Clay Package Source: https://github.com/google/pebble/blob/main/devsite/source/_posts/2016-06-24-introducing-clay.md This code snippet demonstrates how to install the Clay module via the Pebble Packages command-line tool or by adding the dependency to your CloudPebble project. It is a prerequisite for using the Clay configuration framework in a Pebble app. It specifies the command to install the package with SDK and how to add the dependency for CloudPebble. ```bash $ pebble package install pebble-clay ``` -------------------------------- ### Markdown Emoji Example Source: https://github.com/google/pebble/blob/main/devsite/docs/markdown.md This snippet demonstrates the use of emoji in Markdown using the colon syntax. It shows an example of how to include an emoji in text. ```markdown If you're a beginner Pebble developer, you should use :cloud:Pebble ``` -------------------------------- ### Markdown Table Example Source: https://github.com/google/pebble/blob/main/devsite/docs/markdown.md This snippet provides an example of a Markdown table using the PHP Markdown Extra syntax. It shows the basic structure of a table with headers and content cells. ```markdown | First Header | Second Header | | ------------- | ------------- | | Content Cell | Content Cell | | Content Cell | Content Cell | ``` -------------------------------- ### Pebble SDK 1.x App Initialization (C) Source: https://github.com/google/pebble/blob/main/devsite/source/_guides/migration/migration-guide.md Shows the app initialization in Pebble SDK 1.x using `pbl_main()` and `PebbleAppHandlers`. This is contrasted with the SDK 2.x approach in another snippet. ```c void pbl_main(void *params) { PebbleAppHandlers handlers = { .init_handler = &handle_init }; app_event_loop(params, &handlers); } ``` -------------------------------- ### Installing and Launching Pebble App with GDB Source: https://github.com/google/pebble/blob/main/devsite/source/_guides/debugging/debugging-with-gdb.md This snippet demonstrates the commands to install a Pebble app into the emulator and then launch it under the GDB debugger. Requires the Pebble Tool to be installed and configured. The output shows the GDB prompt, indicating readiness for debugging commands. ```text $ pebble install --emulator basalt $ pebble gdb --emulator basalt ``` -------------------------------- ### Building and Installing with Pebble Tool - Shell Source: https://github.com/google/pebble/blob/main/devsite/source/_posts/2016-05-16-Pebble-JS-Round.md This shell snippet shows the command to build and install a Pebble project on the Chalk emulator. The `pebble clean` command is used to remove all generated files, then `pebble build && pebble install --emulator=chalk --logs` builds the project and installs it on the Chalk emulator. ```Shell > pebble clean > pebble build && pebble install --emulator=chalk --logs ``` -------------------------------- ### JerryScript Simple Run Example (C) Source: https://github.com/google/pebble/blob/main/third_party/jerryscript/docs/02.API-REFERENCE.md Demonstrates a simple execution of JavaScript code within JerryScript. Shows how to use jerry_run_simple to execute a short script. No dependencies besides the JerryScript library. Prints \"Hello, World!\" to the console. ```C { const jerry_char_t *script = \"print ('Hello, World!');\"; jerry_run_simple (script, strlen ((const char *) script), JERRY_INIT_EMPTY); } ``` -------------------------------- ### Installing pip and virtualenv with Bash Source: https://github.com/google/pebble/blob/main/devsite/source/_includes/sdk/steps_python.md This snippet demonstrates installing pip and virtualenv on macOS using easy_install or on Linux using apt-get. These tools are prerequisites for managing Python dependencies needed by Pebble SDK. 'pip' enables Python package management, while 'virtualenv' is required for isolated environment setup. ```bash sudo easy_install pip sudo pip install virtualenv ``` ```bash sudo apt-get install python-pip python2.7-dev sudo pip install virtualenv ``` -------------------------------- ### Pebble SDK 2.0 Build Process (C) Source: https://github.com/google/pebble/blob/main/devsite/source/_guides/migration/migration-guide.md Illustrates the simplified build process using the `pebble build` command. This snippet shows the output of the build process, including memory usage information. Requires the Pebble SDK 2.0 and a correctly configured project. ```bash $ pebble build ... Memory usage: ============= Total app footprint in RAM: 801 bytes / ~24kb Free RAM available (heap): 23775 bytes [12\/13] inject-metadata: build\/pebble-app.raw.bin build\/app_resources.pbpack.data -> build\/pebble-app.bin [13\/13] helloworld.pbw: build\/pebble-app.bin build\/app_resources.pbpack -> build\/helloworld.pbw ... 'build' finished successfully (0.562s) ``` -------------------------------- ### Output of Global Object Method Example (Bash) Source: https://github.com/google/pebble/blob/main/third_party/jerryscript/docs/03.API-EXAMPLE.md Shows the expected console output generated when the JerryScript engine executes the JavaScript script in the first C example, which calls the native `MyObject.myFunc()` method. ```Bash Hello World ``` -------------------------------- ### JavaScript Code Block Example Source: https://github.com/google/pebble/blob/main/devsite/docs/markdown.md This snippet provides a basic example of a JavaScript code block within Markdown. It demonstrates the use of triple backticks to denote a code block and the specification of the language for syntax highlighting. Click to copy functionality is enabled by default. ```javascript var foo = 'bar'; ``` -------------------------------- ### Client Execution and Directory Listing Request Source: https://github.com/google/pebble/blob/main/third_party/nanopb/examples/network_server/README.txt Executes the compiled client, passing the directory `/bin` as an argument. The client connects to the server and requests a listing of the specified directory. The server responds with the file listing. ```Bash ./client /bin ``` -------------------------------- ### FreeRTOS Task Function: Get Stack Start Address (C) Source: https://github.com/google/pebble/blob/main/devsite/source/_posts/2014-10-10-FreeRTOS-Modifications-From-Pebble-v2.md This function retrieves the starting memory address of a task's stack space. It's useful for implementing routines that check available stack space to prevent stack overflow errors. ```C uintptr_t ulTaskGetStackStart( xTaskHandle xTask ); ``` -------------------------------- ### Installing Clay - CLI Source: https://github.com/google/pebble/blob/main/devsite/source/_guides/user-interfaces/app-configuration.md This code snippet shows how to install the pebble-clay package using the Pebble command-line interface (CLI). This command must be executed within the project folder. ```text $ pebble package install pebble-clay ``` -------------------------------- ### Setting Up Express Server - JavaScript Source: https://github.com/google/pebble/blob/main/devsite/source/_posts/2015-03-20-Getting-Started-With-Timeline.md This code sets up a basic Express server. It imports the necessary modules (Express and the pebble-api module). The server listens on port 5000 or the environment's PORT. A route for the root ('/') is defined to return a 'Hello, world!' message. Dependencies are Express and pebble-api. ```javascript var express = require('express'); var request = require('request'); var Timeline = require('pebble-api'); var app = express(); app.set('port', (process.env.PORT || 5000)); var timeline = new Timeline(); app.get('/', function(req, res) { res.send('Hello, world!'); }); // start the webserver var server = app.listen(app.get('port'), function () { console.log('Package Tracker server listening on port %s', app.get('port')); }); ``` -------------------------------- ### Set and Get Native Handle on JerryScript Object in C Source: https://github.com/google/pebble/blob/main/third_party/jerryscript/docs/02.API-REFERENCE.md This example, also shown for `jerry_get_object_native_handle`, demonstrates associating a native handle (`handle_set`) with a JerryScript object (`object`) using `jerry_set_object_native_handle` and then retrieving it using `jerry_get_object_native_handle`. It illustrates the basic usage of setting and getting handles. ```C { jerry_value_t object; uintptr_t handle_set; ... // receive or construct object and handle_set value jerry_set_object_native_handle (object, handle_set, NULL); ... uintptr_t handle_get; bool is_there_associated_handle = jerry_get_object_native_handle (object, &handle_get); } ``` -------------------------------- ### Pebble Timeline Pin Pushing: Python Source: https://github.com/google/pebble/blob/main/devsite/source/_guides/pebble-timeline/timeline-libraries.md This Python code utilizes the `pypebbleapi` library to send shared pins to the Pebble timeline. It requires installing the library via pip. The example creates a pin with an ID and date, and sends it to specified topics using the `send_shared_pin` method. Error handling is not explicitly shown in this example. ```python from pypebbleapi import Timeline, Pin import datetime timeline = Timeline(my_api_key) my_pin = Pin(id='123', datetime.date.today().isoformat()) timeline.send_shared_pin(['a_topic', 'another_topic'], my_pin) ``` -------------------------------- ### Setting up MenuLayer in C Source: https://github.com/google/pebble/blob/main/devsite/source/_guides/user-interfaces/layers.md This snippet sets up a `MenuLayer` by creating it, configuring click event handling, and assigning the defined callback functions. It enables the user to interact with the menu using up/down and select buttons. The created menu layer is then added to the window. ```C // Create the MenuLayer s_menu_layer = menu_layer_create(bounds); // Let it receive click events menu_layer_set_click_config_onto_window(s_menu_layer, window); // Set the callbacks for behavior and rendering menu_layer_set_callbacks(s_menu_layer, NULL, (MenuLayerCallbacks) { .get_num_rows = get_num_rows_callback, .draw_row = draw_row_callback, .get_cell_height = get_cell_height_callback, .select_click = select_callback, }); // Add to the Window layer_add_child(root_layer, menu_layer_get_layer(s_menu_layer)); ``` -------------------------------- ### Extracting the Pebble SDK - Bash Source: https://github.com/google/pebble/blob/main/devsite/source/_includes/sdk/steps_install_sdk.md This snippet extracts the downloaded Pebble SDK using the `tar` command. It navigates to the directory where the SDK was downloaded and then executes the extraction. The specific file name to extract changes depending on the operating system (macOS or Linux 64-bit). ```Bash cd {{ site.data.sdk.path }} tar -jxf ~/Downloads/pebble-sdk-{{ site.data.sdk.pebble_tool.version }}-{% if include.mac %}mac{% else %}linux64{% endif %}.tar.bz2 ``` -------------------------------- ### Getting message size Source: https://github.com/google/pebble/blob/main/third_party/nanopb/docs/concepts.md This snippet demonstrates how to calculate the encoded size of a message without actually storing the encoded data. It uses a zeroed-out pb_ostream_t stream to encode a Person message. ```C Person myperson = ...; pb_ostream_t sizestream = {0}; pb_encode(&sizestream, Person_fields, &myperson); printf("Encoded size is %d\n", sizestream.bytes_written); ``` -------------------------------- ### Initializing PBPebbleCentral and Handling Onboarding (Objective-C) Source: https://github.com/google/pebble/blob/main/devsite/source/_guides/migration/pebblekit-ios-3.md This code shows how to initialize `PBPebbleCentral` and conditionally run it based on user onboarding status. It demonstrates deferred execution of `[[PBPebbleCentral defaultCentral] run]` to avoid immediate Bluetooth permission prompts and provides a better user experience. ```Objective-C // MyAppDelegate.m - Set up PBPebbleCentral and run if the user has already // performed onboarding - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [PBPebbleCentral defaultCentral].delegate = self; [PBPebbleCentral defaultCentral].appUUID = myAppUUID; if ([MySettings sharedSettings].userDidPerformOnboarding) { [[PBPebbleCentral defaultCentral] run]; } } ``` ```Objective-C // MyOnboarding.m - Once the pop-up has been accepted, begin PBPebbleCentral - (IBAction)didTapGrantBluetoothPermissionButton:(id)sender { [MySettings sharedSettings].userDidPerformOnboarding = YES; [[PBPebbleCentral defaultCentral] run]; // will trigger pop-up } ``` -------------------------------- ### Install Latest Beta SDK Source: https://github.com/google/pebble/blob/main/devsite/source/sdk/download.md This command installs the latest beta SDK available after setting the channel to beta with `pebble sdk set-channel beta`. This retrieves the latest available beta version. This allows the user to access and test the latest features that are not included in the stable releases of Pebble SDK. ```bash $ pebble sdk install latest ``` -------------------------------- ### Markdown SDK Documentation Links Source: https://github.com/google/pebble/blob/main/devsite/docs/markdown.md This snippet explains how to create links to sections within the SDK documentation using double backticks. It shows examples of creating inline links and links within text. ```markdown This will link to the ``window_create`` documentation. You should check out the page on [Events](``event services``) ``` -------------------------------- ### Liquid Alert Tags in Markdown Source: https://github.com/google/pebble/blob/main/devsite/docs/markdown.md This snippet shows how to use Liquid tags to create alerts with different levels of importance ('important' and 'notice'). It provides examples for both alert types and demonstrates how to specify the alert level. ```liquid {% alert important %} PebbleKit JS and PebbleKit Android/iOS may **not** be used in conjunction. {% endalert %} {% alert notice %} This API is currently in the beta stage, and may be changed before final release. {% endalert %} ``` -------------------------------- ### Initializing Simple Pebble App Source: https://github.com/google/pebble/blob/main/devsite/source/tutorials/advanced/vector-animations.md This code snippet provides the basic structure for a Pebble app, creating a window and defining the necessary load and unload functions. It initializes the app and pushes a blank window onto the stack. ```c #include static Window *s_main_window; static void main_window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); } static void main_window_unload(Window *window) { } static void init() { s_main_window = window_create(); window_set_window_handlers(s_main_window, (WindowHandlers) { .load = main_window_load, .unload = main_window_unload, }); window_stack_push(s_main_window, true); } static void deinit() { window_destroy(s_main_window); } int main() { init(); app_event_loop(); deinit(); } ``` -------------------------------- ### Markdown Button Creation Source: https://github.com/google/pebble/blob/main/devsite/docs/markdown.md This snippet explains how to create buttons in Markdown using a link with a trailing `>` and optional classes for styling. It shows examples of basic buttons and buttons with custom classes for width and color modifications. ```markdown [Button Text >](http://google.com/) [Wide Orange Button >{wide,fg-orange}](http://google.com) ``` -------------------------------- ### Markdown Image Sizing Source: https://github.com/google/pebble/blob/main/devsite/docs/markdown.md This snippet demonstrates how to control the width and optionally the height of images in Markdown. It uses a specific syntax to specify dimensions within the image link. The example shows both width-only and width-height specifications. ```markdown ![Image with width](/images/huge_image.png =300) ![Image with width and height](/images/huge_image.png =300x400) ``` -------------------------------- ### Cloning and Building JerryScript for mbed OS 5 using Bash Source: https://github.com/google/pebble/blob/main/third_party/jerryscript/targets/mbedos5/README.md This snippet demonstrates the initial steps to build JerryScript on mbed OS 5, including cloning the repository, navigating to the target directory, fetching libraries, and building for specific boards. It requires `git`, `make`, and mbed CLI and appropriate dependencies to be installed. The output is a binary file ready to be uploaded to the target board. ```Bash git clone https://github.com/Samsung/jerryscript cd jerryscript/targets/mbedos5 make getlibs # NRF52 Development Kit: make BOARD=NRF52_DK # FRDM K64F make BOARD=K64F ``` -------------------------------- ### Setting up JerryScript Build Environment (Bash) Source: https://github.com/google/pebble/blob/main/third_party/jerryscript/targets/nuttx-stm32f4/README.md This script clones the necessary Git repositories (JerryScript, NuttX, apps, and stlink) into a designated directory to create the build environment for running JerryScript on the STM32F4-Discovery board. It requires Git to be installed and properly configured. The output is a directory containing the source code for each component. ```bash mkdir jerry-nuttx cd jerry-nuttx git clone https://github.com/Samsung/jerryscript.git git clone https://bitbucket.org/nuttx/nuttx.git git clone https://bitbucket.org/nuttx/apps.git git clone https://github.com/texane/stlink.git ``` -------------------------------- ### Pebble Window Initialization (C) Source: https://github.com/google/pebble/blob/main/devsite/source/tutorials/watchface-tutorial/part1.md This snippet demonstrates how to initialize a main window in a Pebble watchface application using the Pebble SDK. It declares a window pointer, creates a window, sets window handlers, and pushes the window to the window stack. This requires the Pebble SDK. The output is a window that is displayed on the Pebble watch. ```C static Window *s_main_window; static void main_window_load(Window *window) { } static void main_window_unload(Window *window) { } static void init() { // Create main Window element and assign to pointer s_main_window = window_create(); // Set handlers to manage the elements inside the Window window_set_window_handlers(s_main_window, (WindowHandlers) { .load = main_window_load, .unload = main_window_unload }); // Show the Window on the watch, with animated=true window_stack_push(s_main_window, true); } ``` -------------------------------- ### Initializing Pebble Communication in Objective-C Source: https://github.com/google/pebble/blob/main/devsite/source/_guides/communication/using-pebblekit-ios.md Demonstrates initializing the PBPebbleCentral and setting the app UUID and the delegate to establish communication with Pebble watches. The code uses the singleton pattern to get the default central instance and start communication. ```objective-c central = [PBPebbleCentral defaultCentral]; central.appUUID = myAppUUID; [central run]; ``` -------------------------------- ### Building JerryScript with Various Options - Bash Source: https://github.com/google/pebble/blob/main/third_party/jerryscript/docs/01.GETTING-STARTED.md Demonstrates commands to build the JerryScript interpreter using the provided Python build script. Includes examples for building debug versions, toggling link-time optimization, passing custom CMake arguments, selecting feature profiles, using different libc implementations, and specifying toolchain files for cross-compilation. ```bash python tools/build.py --debug ``` ```bash python tools/build.py --debug --lto=off ``` ```bash python tools/build.py --cmake-param=CMAKE_PARAM ``` ```bash python tools/build.py --feature=full|minimal ``` ```bash python tools/build.py --jerry-libc=off ``` ```bash python tools/build.py --jerry-libc=off --compile-flag="-nostdlib -I/path/to/ext-libc/include" --link-lib="-lext-c" ``` ```bash python tools/build.py --toolchain=TOOLCHAIN ``` ```bash python tools/build.py --toolchain=cmake/toolchain_linux_armv7l.cmake ``` ```bash python tools/build.py --help ``` -------------------------------- ### Running Minicom (Bash) Source: https://github.com/google/pebble/blob/main/third_party/jerryscript/targets/nuttx-stm32f4/README.md This command starts the minicom terminal program to connect to the serial console of the STM32F4-Discovery board. This requires minicom to be installed and the correct serial port (/dev/ttyACM0) to be specified. The output is a serial terminal connection to the board. ```bash sudo minicom --device=/dev/ttyACM0 --baud=115200 ``` -------------------------------- ### Marking App as Configurable (package.json) Source: https://github.com/google/pebble/blob/main/devsite/source/_guides/user-interfaces/app-configuration-static.md This snippet shows how to mark a Pebble app as configurable within the `package.json` file. This enables the configuration gear icon in the Pebble app. It requires modifying the `capabilities` array in the `package.json` file. ```JSON {"capabilities": [ "configurable" ]} ``` -------------------------------- ### Markdown Link with Data Attributes Source: https://github.com/google/pebble/blob/main/devsite/docs/markdown.md This snippet demonstrates how to add data attributes to links in Markdown for tracking purposes. It uses a specific syntax to include attributes within the link definition. The example shows adding 'data-track-event' and 'data-track-name' attributes. ```markdown [Link Text](http://google.com "Link Title >{track-event:click,track-name:google}") ``` -------------------------------- ### Example package.json Source: https://github.com/google/pebble/blob/main/devsite/source/_guides/tools-and-resources/app-metadata.md Demonstrates a sample `package.json` file that defines the metadata for a Pebble app. This file is created when a new Pebble SDK project is initialized and contains settings for the app's name, author, version, and Pebble-specific configurations. ```JavaScript { "name": "example-app", "author": "MakeAwesomeHappen", "version": "1.0.0", "keywords": ["pebble-app"], "private": true, "dependencies": {}, "pebble": { "displayName": "example-app", "uuid": "5e5b3966-60b3-453a-a83b-591a13ae47d5", "sdkVersion": "3", "enableMultiJS": true, "targetPlatforms": [ "aplite", "basalt", "chalk" ], "watchapp": { "watchface": false }, "messageKeys": [ "dummy" ], "resources": { "media": [] } } } ``` -------------------------------- ### Setting GPoint in Animation - C Source: https://github.com/google/pebble/blob/main/devsite/source/_guides/migration/migration-guide-3.md Demonstrates how to access and set the values in a `PropertyAnimation`. Accessing internal fields of PropertyAnimation has also changed. For example, to access the GPoint in the from member of an animation, the way to set the `from` value is shown for both SDK 2.x and 3.x. ```c GPoint p; PropertyAnimation *prop_anim; // SDK 2.x prop_animation->values.from.gpoint = p; // SDK 3.x property_animation_set_from_gpoint(prop_anim, &p); ``` -------------------------------- ### Basic Pebble App Structure in C Source: https://github.com/google/pebble/blob/main/devsite/source/_guides/tools-and-resources/cloudpebble.md This code defines the basic structure of a Pebble app, including the required `init()` and `deinit()` functions for initialization and deinitialization, and a `main()` function to set up the app's event loop. This sets up the fundamental building blocks needed for any Pebble app to run. ```C void init() { } void deinit() { } int main() { init(); app_event_loop(); deinit(); } ``` -------------------------------- ### Creating and configuring the Window Source: https://github.com/google/pebble/blob/main/devsite/source/_posts/2014-06-10-Pebble-SDK-Tutorial-1.md This snippet shows how to create a window. It creates a `Window` object using `window_create()`, and registers handlers for loading and unloading the window. `window_set_window_handlers()` sets the callback functions that will be called when the window is loaded or unloaded, managing the lifecycle of the window. ```c void init() { //Create the app elements here! g_window = window_create(); window_set_window_handlers(g_window, (WindowHandlers) { .load = window_load, .unload = window_unload, }); } ``` -------------------------------- ### Compass Heading Handler Example - C Source: https://github.com/google/pebble/blob/main/devsite/source/_guides/events-and-services/compass.md This code defines a `compass_heading_handler` function to process compass heading data received from the service. It checks the compass status to determine if the compass is calibrated. The function logs the compass status, including if it is calibrating, calibrated, or invalid. ```c static void compass_heading_handler(CompassHeadingData heading_data) { // Is the compass calibrated? switch(heading_data.compass_status) { case CompassStatusDataInvalid: APP_LOG(APP_LOG_LEVEL_INFO, "Not yet calibrated."); break; case CompassStatusCalibrating: APP_LOG(APP_LOG_LEVEL_INFO, "Calibration in progress. Heading is %ld", TRIGANGLE_TO_DEG(TRIG_MAX_ANGLE - heading_data.magnetic_heading)); break; case CompassStatusCalibrated: APP_LOG(APP_LOG_LEVEL_INFO, "Calibrated! Heading is %ld", TRIGANGLE_TO_DEG(TRIG_MAX_ANGLE - heading_data.magnetic_heading)); break; } } ``` -------------------------------- ### Get JavaScript Object Keys in C (jerry_get_object_keys) Source: https://github.com/google/pebble/blob/main/third_party/jerryscript/docs/02.API-REFERENCE.md This example demonstrates retrieving the keys of a JerryScript object (`object`) using `jerry_get_object_keys`. It obtains the keys as a `jerry_value_t` array and releases the array value when no longer needed. ```C { jerry_value_t object; ... // create or acquire object jerry_value_t keys_array = jerry_get_object_keys (object); ... // usage of keys_array jerry_release_value (keys_array); } ``` -------------------------------- ### Converting to Clockwise Angle - C Source: https://github.com/google/pebble/blob/main/devsite/source/_guides/events-and-services/compass.md This snippet demonstrates the conversion of magnetic heading to a clockwise angle, starting from North (0 degrees). The magnetic heading is measured counter-clockwise from north, so this calculation converts the heading from a counter-clockwise angle to a clockwise angle by subtracting the `magnetic_heading` from `TRIG_MAX_ANGLE`. ```c int clockwise_angle = TRIG_MAX_ANGLE - heading_data.magnetic_heading; ``` -------------------------------- ### Server Compilation (C) Source: https://github.com/google/pebble/blob/main/third_party/nanopb/examples/network_server/README.txt Compiles the server application (`server.c`). It uses the C compiler (`cc`) with specified flags for ANSI compliance, warnings, debugging, and optimization. It links with the nanopb library and generated protobuf code (`fileproto.pb.c`) along with common utility functions. This results in an executable named `server`. ```C cc -ansi -Wall -Werror -I .. -g -O0 -I../.. -o server server.c ../../pb_decode.c ../../pb_encode.c fileproto.pb.c common.c ``` -------------------------------- ### Registering Data Handler Source: https://github.com/google/pebble/blob/main/devsite/source/_guides/communication/using-pebblekit-android.md This snippet demonstrates how to register the `PebbleDataReceiver` within an Android Activity's `onResume()` method. This ensures that the application starts listening for messages from the Pebble watch when the Activity becomes active. The receiver processes incoming data and handles it appropriately. ```java @Override public void onResume() { super.onResume(); // Register the receiver PebbleKit.registerReceivedDataHandler(getApplicationContext(), dataReceiver); } ```