Skip to content

Latest commit

 

History

History
52 lines (35 loc) · 2.16 KB

README.md

File metadata and controls

52 lines (35 loc) · 2.16 KB

Lite Wearable Sample Code

This repository hosts a basic sample code for HarmonyOS Lite Wearables. The app allows users to monitor their heart rate (HR) and see its evolution on a graph.

Screeshot of the app on the simulator

What you can find

The example is implemented as a unique page based on feature abilities (FA) using JavaScript APIs.

Compatible with HarmonyOS SDK 2.2.0 (API 6), and supports SDK 3.0.0 (API 7).

In the code, you can check the controls for conditional rendering and state properties binding (i.e., in pages/index/index.hml):

<div class="reading-animation" if="{{readingHR}}" >
    <image-animator class="heart" ref="animator" images="{{heartFrames}}" duration="0.4s" />
    <text class="hr" >{{hr}}</text>
</div>

In the logic of the app (i.e., pages/index/index.js), you can check how to subscribe to sensor changes, like the HR and on-body sensors:

sensor.subscribeHeartRate({
    success: function(ret) {
        // Every time a change is detected, updates the buffer and chart
        console.debug(`Got HR value: ${ret.heartRate}`);
    },
    fail: function(data, code) {
        console.error(`[subscribeHR()] Subscription failed. Code = ${code}, Data = ${data}`);
    },
});

Also some functions that use the local device filesystem (i.e., write, list, and read files).

In the /config.json file, you can find how to declare permissions to use powerful features.

Quick start

  1. Clone this repository to access the code locally.
  2. Download the latest version of the DevEco Studio IDE.
  3. Load the project in the IDE and get the dependencies.
  4. Test it on the built-in Huawei Lite Wearable Simulator (in the IDE).
  5. Test the app on a real device (see this blog post for more info)

You can improve the code as you wish. Have a look at the official development documentation for lite wearables.