↵ select ↓ ↑ navigate esc close

Una Watch - SDK and Writing Your First App

Terence Eden’s Blog ·

I don't know why hardware manufacturers find it so hard to write decent documentation. As I've said before you need to actually test your readme. The Una Watch development instructions are scattered across a bunch of different files.

So here's how to go from zero to your first "Hello, World!" Glance app with the minimum of fuss.

This all assumes a fairly modern Debian / Ubuntu / Pop OS Linux.

Prerequisites

This installs most of the tools you will need:

1sudo apt update
2sudo apt install -y git python3 python3-pip cmake build-essential

STM32CubeCLT

Visit https://www.st.com/en/development-tools/stm32cubeclt.html and download the Linux version of the tool. Inexplicably, you need to give your email address. I recommend giving a disposable one from https://10minutemail.com/

After downloading, unzip the file.

On the command line, cd into the directory containing the unzipped file.

1chmod +x stm32cubeclt_*.sh
2sudo ./stm32cubeclt_*.sh

You will need to agree to their licence. Just hit y.

That installs everything in /opt/st/stm32cubeclt_1.22.0/

You will need to make that available to your PATH.

1export PATH="/opt/st/stm32cubeclt_1.22.0/GNU-tools-for-STM32/bin:$PATH"

Clone the repo

You will need to copy the Una SDK. I keep my git repos in ~/git/ - you will need the location of the directory later.

1cd ~/git/
2git clone git@github.com:UNAWatch/una-sdk.git
3cd una-sdk/
4git submodule update --init ThirdParty/lvgl

Then update all the Python dependencies.

1export UNA_SDK="$PWD"
2python3 -m pip install --upgrade pip
3python3 -m pip install -r "$UNA_SDK/Utilities/Scripts/app_packer/requirements.txt"

Check it has all worked

Paste this into your terminal. Check for any errors.

1which arm-none-eabi-gcc || true
2which cmake || true
3which make || true
4which python3 || true
5python3 -m pip --version
6arm-none-eabi-gcc --version || true
7cmake --version || true
8make --version || true

Build the demo app

If all of the above has worked, you should be able to build the demo app with:

1cd /tmp
2mkdir -p MyAlarm
3cp -r "$UNA_SDK/Examples/Apps/Alarm/"* MyAlarm
4mkdir -p MyAlarm/build
5cmake -G "Unix Makefiles" -S MyAlarm/Software/Apps/Alarm-CMake -B MyAlarm/build
6cmake --build MyAlarm/build

Make it permanent

Store the paths permanently. If you put cloned the Una SDK to somewhere other than ~/git/ you'll need to edit this next bit of code:

1echo 'export UNA_SDK="$HOME/git/una-sdk"' >> ~/.bashrc
2echo 'export PATH="/opt/st/stm32cubeclt_1.22.0/GNU-tools-for-STM32/bin:$PATH"' >> ~/.bashrc
3source ~/.bashrc

Build a Glance app

At the moment, the only way to build a GUI app is using the Windows only (Booooo!) TouchGFX0. So, instead, we'll make a "Hello World" glance. All it will do is draw some text.

The GlanceFloors demo app is the simplest one to copy.

1cd $UNA_SDK/Examples/Apps/
2cp -r  GlanceFloors/ GlanceHello

Use an IDE or a text editor to open up the new GlanceHello directory.

  • Rename the directory GlanceHello/Software/App/GlanceFloors-CMake/ to GlanceHello/Software/App/GlanceHello-CMake/
  • Edit the file GlanceHello/Software/App/GlanceFloors-CMake/CMakeLists.txt - specifically the # App configuration section.
  • Change the APP_NAME to GlanceHello
  • Change the APP_USER_NAME to Hello

For a demo, you can leave the DEV_ID and APP_ID as their default values.

Minimum viable app

You will need to edit two more files.

In GlanceHello/Software/Libs/Header/Service.hpp remove the following lines:

1SDK::Sensor::Connection mSensorFloors;
2uint32_t                mFloorsValue;
3bool                    mDataReceived;

Then save the file.

Edit GlanceHello/Software/Libs/Source/Service.cpp and replace its entire contents with this:

 1#include "Service.hpp"
 2#include "SDK/Messages/CommandMessages.hpp"
 3#include "SDK/Messages/MessageGuard.hpp"
 4
 5Service::Service(SDK::Kernel &kernel)
 6    : mKernel(kernel)
 7    , mGlanceUI()
 8    , mGlanceTitle()
 9    , mGlanceValue()
10{}
11
12Service::~Service(){}
13
14void Service::run()
15{
16    while (true) {
17        SDK::MessageBase *msg;
18        if(!mKernel.comm.getMessage(msg)) {
19            continue;
20        }
21
22        switch (msg->getType()) {
23
24            case SDK::MessageType::EVENT_GLANCE_START:
25                if (configGui()) {
26                    createGuiControls();
27                } else {
28                    mKernel.comm.releaseMessage(msg);
29                    mKernel.sys.exit(0);
30                }
31                break;
32
33            case SDK::MessageType::COMMAND_APP_STOP:
34            case SDK::MessageType::EVENT_GLANCE_STOP:
35                mKernel.comm.releaseMessage(msg);
36                return;
37                break;
38
39            case SDK::MessageType::EVENT_GLANCE_TICK:
40                onGlanceTick();
41                break;
42
43            default:
44                break;
45        }
46
47        mKernel.comm.releaseMessage(msg);
48    }
49}
50
51void Service::onGlanceTick()
52{
53    if (mGlanceUI.isInvalid()) {
54        if (auto upd = SDK::make_msg<SDK::Message::RequestGlanceUpdate>(mKernel)) {
55            upd->name           = APP_NAME;
56            upd->controls       = mGlanceUI.data();
57            upd->controlsNumber = static_cast<uint32_t>(mGlanceUI.size());
58            upd.send(100);
59        }
60
61        mGlanceUI.setValid();
62}
63}
64
65bool Service::configGui()
66{
67    bool status = false;
68    if (auto gc = SDK::make_msg<SDK::Message::RequestGlanceConfig>(mKernel)) {
69        if (gc.send(100) && gc.ok()) {
70            if (gc->maxControls >= 3) {
71                mGlanceUI.setWidth(gc->width);
72                mGlanceUI.setHeight(gc->height);
73                status = true;
74            }
75        }
76    }
77    return status;
78}
79
80void Service::createGuiControls()
81{
82    mGlanceTitle = mGlanceUI.createText();
83    mGlanceTitle.pos({ kTitleX, kTitleY }, { kTitleW, kTitleH })
84        .font(GlanceFont_t::GLANCE_FONT_POPPINS_SEMIBOLD_20)
85        .color(GlanceColor_t::GLANCE_COLOR_TEAL)
86        .setText("Hello, World!")
87        .alignment(GlanceAlignH_t::GLANCE_ALIGN_H_CENTER);
88    mGlanceValue = mGlanceUI.createText();
89    mGlanceValue.pos({ 0, kValueY }, { 200, kValueH })
90        .font(GlanceFont_t::GLANCE_FONT_POPPINS_SEMIBOLD_20)
91        .color(GlanceColor_t::GLANCE_COLOR_WHITE)
92        .setText("I know C++")
93        .alignment(GlanceAlignH_t::GLANCE_ALIGN_H_CENTER);
94}

Save the file.

Compile it

On the command line

1cd $UNA_SDK/Examples/Apps/GlanceHello/Software/App/GlanceHello-CMake
2cmake -G "Unix Makefiles" -S . -B build
3cmake --build build

It should finish with a success message of [100%] Built target GlanceHelloApp

Copying it to your watch

  • Plug your watch into your computer with a USB-C cable.
  • On your computer, open the watch's filesystem.
  • Open the Apps directory.
  • Create a new directory.
  • Name the new directory with the string of characters from the APP_ID which is set in CMakeLists.txt
  • The app is stored in GlanceHello/Output/ and will be called Hello_1.5.0-rc5.uapp or similar.
  • Copy the .uapp file from your computer to the directory you just created on the watch.
  • Eject the watch.
  • Unplug the cable.
  • Restart the watch by pressing the "Up" button until you get to "Power Off", then press "Select", then press "Select" again.
  • Turn the watch on by holding down "Select".
  • Once the watch has fully restarted, press the "Down" button until you see the "Hello" glance.

If it has worked, you should see this:

A watch displaying "Hello World" and "I know C++". The latter if off centre because I don't know C++.

Hurrah! Treat yourself to a beer 🍻


  1. Just after I wrote this, the SDK was updated to allow LVGL which should work on Linux. There's no documentation for it yet that I could find. ↩︎