Skip to content

Commit

Permalink
Merge pull request #290 from Open-Smartwatch/develop
Browse files Browse the repository at this point in the history
New release
  • Loading branch information
simonmicro committed Sep 20, 2022
2 parents a2d2967 + efd51f5 commit 0a71a6d
Show file tree
Hide file tree
Showing 182 changed files with 8,080 additions and 310 deletions.
19 changes: 19 additions & 0 deletions .github/setMatrix.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
if [ "$1" = "--default-lang" ]; then
# default_lang
echo $(X=$(if [ -e include/locales/en-US.h ]; then X=$(ls include/locales/en-US.h); else X=$(ls include/locales/*.h -1 | head -1); fi; echo ${X:16:5});X=($X);jq --compact-output --null-input '$ARGS.positional' --args -- "${X[@]}")
elif [ "$1" = "--default-mod" ]; then
# default_mod
echo $(X=$(X=$(cat platformio.ini | grep "defau"); echo "${X:15}");X=($X);jq --compact-output --null-input '$ARGS.positional' --args -- "${X[@]}")
elif [ "$1" = "--get-flag" ]; then
# get_flag
echo $(X=$(curl https://api.github.com/repos/Open-smartwatch/open-smartwatch.github.io/contents/docs/resources/firmware.md | jq -r ".content" | base64 --decode | grep -o '^-.*` |'); X=$(echo $X | tr '` |-' ' ');X=($X);jq --compact-output --null-input '$ARGS.positional' --args -- "${X[@]}")
elif [ "$1" = "--get-models" ]; then
# get_models
echo $(X=$(cat platformio.ini | grep "\[\env:" | sed -e 's/\[\env://' | tr ']\n' ' ');X=($X);jq --compact-output --null-input '$ARGS.positional' --args -- "${X[@]}")
elif [ "$1" = "--get-languages" ]; then
# get_languages
echo $(cd include/locales/; X=$(ls *.h -1 | sed -e 's/\.h$//' | tr '\n' ' ');X=($X);jq --compact-output --null-input '$ARGS.positional' --args -- "${X[@]}")
else
echo "Try, again ! $(date +%F)"
exit 1
fi
6 changes: 3 additions & 3 deletions .github/workflows/test-FEATURE.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ jobs:
submodules: recursive
- id: get-flag
run: |
echo "::set-output name=feature::$(D=$(curl https://api.github.com/repos/Open-smartwatch/open-smartwatch.github.io/contents/docs/resources/firmware.md | jq -r ".content" | base64 --decode | grep -o '^-.*` |'); V=$(echo $D | tr '` |-' ' ');V=($V);jq --compact-output --null-input '$ARGS.positional' --args -- "${V[@]}")"
echo "::set-output name=feature::$(./.github/setMatrix.sh --get-flag)"
- id: default_mod
run: |
echo "::set-output name=default_model::$(R=$(x=$(cat platformio.ini | grep "defau"); echo "${x:15}"); R=($R);jq --compact-output --null-input '$ARGS.positional' --args -- "${R[@]}")"
echo "::set-output name=default_model::$(./.github/setMatrix.sh --default-mod)"
- id: default_lang
run: |
echo "::set-output name=default_language::$(A=$(if [ -e include/locales/en-US.h ]; then s=$(ls include/locales/en-US.h); else s=$(ls include/locales/*.h -1 | head -1); fi; echo ${s:16:5});A=($A);jq --compact-output --null-input '$ARGS.positional' --args -- "${A[@]}")"
echo "::set-output name=default_language::$(./.github/setMatrix.sh --default-lang)"
outputs:
feature: ${{ steps.get-flag.outputs.feature }}
default_model: ${{ steps.default_mod.outputs.default_model }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-OSW.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ jobs:
with:
submodules: recursive
- id: get-languages
run: echo "::set-output name=languages_matrix::$(cd include/locales/; X=$(ls *.h -1 | sed -e 's/\.h$//' | tr '\n' ' '); X=($X); jq --compact-output --null-input '$ARGS.positional' --args -- "${X[@]}")"
run: echo "::set-output name=languages_matrix::$(./.github/setMatrix.sh --get-languages)"
- id: get-models
run: echo "::set-output name=models_matrix::$(F=$(cat platformio.ini | grep "\[\env:" | sed -e 's/\[\env://' | tr ']\n' ' ');F=($F);jq --compact-output --null-input '$ARGS.positional' --args -- "${F[@]}")"
run: echo "::set-output name=models_matrix::$(./.github/setMatrix.sh --get-models)"
outputs:
languages_matrix: ${{ steps.get-languages.outputs.languages_matrix }}
models_matrix: ${{ steps.get-models.outputs.models_matrix }}
Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/test-emulator.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: OSW-EMULATOR-test

on:
workflow_dispatch:
push:
pull_request:
branches: [ master, develop ]

jobs:
build-EMULATOR:
runs-on: ubuntu-22.04
steps:
- name: Checkout repository and submodules
uses: actions/checkout@v2
with:
submodules: recursive
- name: Update packages
run: sudo apt-get update && sudo apt-get upgrade -y
- name: Install packages
run: sudo apt-get -y install gcc g++ cmake libsdl2-dev libsdl2-image-dev
- name: Create build directory
run: mkdir build
- name: CMake (debug)
run: cd build && cmake -DCMAKE_BUILD_TYPE=Debug ..
- name: Make
run: cd build && make
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ firmware.elf
bin
/*.png
screenshots/
build/
emulator_nvs/
12 changes: 9 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "lib/lib-open-smartwatch"]
path = lib/lib-open-smartwatch
url = https://github.com/Open-Smartwatch/lib-open-smartwatch.git
[submodule "lib/pngle"]
path = lib/pngle
url = https://github.com/kikuchan/pngle.git
Expand All @@ -23,3 +20,12 @@
path = lib/LUA
url = https://github.com/lua/lua.git
branch = v5.3
[submodule "emulator/lib/ArduinoJson"]
path = emulator/lib/ArduinoJson
url = https://github.com/bblanchon/ArduinoJson.git
[submodule "emulator/lib/Jzon"]
path = emulator/lib/Jzon
url = https://github.com/Zguy/Jzon.git
[submodule "emulator/lib/ImGUI"]
path = emulator/lib/ImGUI
url = https://github.com/ocornut/imgui.git
29 changes: 29 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "GDB: Emulator",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/emulator.run",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}/build",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
}
]
}
108 changes: 108 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
cmake_minimum_required (VERSION 3.10)
project (OSW-OS-Emulator)

set(CMAKE_CXX_STANDARD 20)

# Prepare some defines, which are normally evaluated using some Python snippets...
execute_process(COMMAND "git" "rev-parse" "--short" "HEAD" OUTPUT_VARIABLE GIT_COMMIT_HASH)
execute_process(COMMAND "git" "log" "-1" "--pretty=format:%cd" "--date=format:%Y-%m-%dT%H:%M:%S%z" OUTPUT_VARIABLE GIT_COMMIT_TIME)
execute_process(COMMAND "git" "rev-parse" "--abbrev-ref" "HEAD" OUTPUT_VARIABLE GIT_BRANCH_NAME)
string(STRIP ${GIT_COMMIT_HASH} GIT_COMMIT_HASH)
string(STRIP ${GIT_COMMIT_TIME} GIT_COMMIT_TIME)
string(STRIP ${GIT_BRANCH_NAME} GIT_BRANCH_NAME)

# For threads
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)

# This uses pkg-config, as sdl2-image does not has any CMake bindings (and the sdl2 package via vcpkg is just broken under Linux)
INCLUDE(FindPkgConfig)
PKG_SEARCH_MODULE(SDL2 REQUIRED sdl2>=2.0.20)
PKG_SEARCH_MODULE(SDL2IMAGE REQUIRED SDL2_image)

# Pngle
file(GLOB_RECURSE SOURCES_Pngle ./lib/pngle/*.c)
add_library(Pngle ${SOURCES_Pngle})
target_include_directories(Pngle PUBLIC ./lib/pngle/src/)

# ArduinoJSON
add_subdirectory(emulator/lib/ArduinoJson)

# Jzon
add_library(Jzon emulator/lib/Jzon/Jzon.cpp)
target_include_directories(Jzon PUBLIC emulator/lib/Jzon/)

# ImGUI
add_library(ImGUI
emulator/lib/ImGUI/imgui.cpp
emulator/lib/ImGUI/imgui_draw.cpp
emulator/lib/ImGUI/imgui_widgets.cpp
emulator/lib/ImGUI/imgui_tables.cpp
emulator/lib/ImGUI/backends/imgui_impl_sdl.cpp
emulator/lib/ImGUI/backends/imgui_impl_sdlrenderer.cpp
)
target_include_directories(ImGUI PUBLIC
emulator/lib/ImGUI/
emulator/lib/ImGUI/backends
${SDL2_INCLUDE_DIRS}
)
target_link_libraries(ImGUI LINK_PUBLIC
${SDL2_LIBRARY}
${SDL2IMAGE_LIBRARIES}
)

# Emulator
file(GLOB_RECURSE SOURCES_OSW ./src/*.cpp)
file(GLOB_RECURSE SOURCES_OSW_EMULATOR ./emulator/src/*.cpp)
add_executable(emulator.run
${SOURCES_OSW}
${SOURCES_OSW_EMULATOR}
)
target_include_directories(emulator.run PUBLIC
./emulator/include
./include
./lib/lib-open-smartwatch
emulator/lib/Jzon/
${SDL2_INCLUDE_DIRS}
${SDL2IMAGE_INCLUDE_DIRS}
)
target_link_libraries(emulator.run LINK_PUBLIC
Pngle
ArduinoJson
Threads::Threads
Jzon
${SDL2_LIBRARY}
${SDL2IMAGE_LIBRARIES}
ImGUI
)
target_compile_definitions(emulator.run PUBLIC
OSW_TARGET_PLATFORM_HEADER="platform/EMULATOR.h"
OSW_EMULATOR=1
GIT_COMMIT_HASH="${GIT_COMMIT_HASH}"
GIT_COMMIT_TIME="${GIT_COMMIT_TIME}"
GIT_BRANCH_NAME="${GIT_BRANCH_NAME}"
PIO_ENV_NAME="VIRTUAL"
$<$<CONFIG:Debug>:
DEBUG=1 # Just for legacy reasons
>
$<$<CONFIG:Release>:
NDEBUG=1
>
# Comment these as you wish...
OSW_FEATURE_STATS_STEPS
)
target_compile_options(emulator.run PUBLIC
$<$<CONFIG:Debug>:
-O0
-g3
-Wall
>
$<$<CONFIG:Release>:
-O4
>
)

# Including SDL2 using the system libraries is broken under MacOS, so we have to add this path manually...
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
link_directories(/usr/local/lib)
endif()
41 changes: 39 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ $ pio run -e pico32_GPS_EDITION -t upload

Depending on the watch model.

## Debugging(CLI)
## Debugging (CLI)

If you want to print out the log for debugging, following command:

```
$ pio device monitor
```

## Creating Screen Shots of your Apps
## Creating Screenshots of your Apps

<img src="./screenshots/watchface_analog_osw.png" width="40%"><img src="./screenshots/watchface_digital_osw.png" width="40%">

Expand Down Expand Up @@ -98,3 +98,40 @@ You did not rename `include/config.h.example`
### Failed to connect to ESP32: Timed out waiting for packet header

You did not hold down BTN1(FLASH) and then tap the RESET button on the watch whilst platform.io was trying to connect.

## OSW Emulator
![emulator](screenshots/emulator_demo.png)

The OS itself can be executed as a regular program on your machine. This saves you time compiling for the watch and flashing the OS, every time you make a minor change - e.g. while developing the UI or a game, which not explicitly depend on the hardware of the watch.

This also implies some limitations what you can do with the emulator, as we had to hack and reimplement some of the Arduino-specific libraries and their (conflicting) simplifications. This also means, that it maybe necessary to extend those extensions down the road as we (likely) missed that one specific function you try to use... :wink:

### Build (cmake)
The emulator can be build using the `CMakeLists.txt` file - you may need to install additional libraries to be able to use it.

Here is a small example running on "Ubuntu 22.04 LTS":
```bash
$ sudo apt install libsdl2-dev libsdl2-image-dev g++ gcc cmake make build-essential
$ mkdir build && cd build
$ cmake ..
$ make -j $(nproc)
$ ./emulator.run
```

You also may extend the `cmake`-command with `-DCMAKE_BUILD_TYPE=Release` to get an even faster and smaller binary.

### With Docker
If a library is unavailable, you can still use the emulator using docker (e.g. on Ubuntu 20.04 SDL2 is too old). Proceed with a typical docker installation. Showing an application running in docker requires some additional steps:

#### Host PC
*Tested on Ubuntu 20.04.*
```bash
$ xhost +
$ xauth list # Copy the result of the command.
$ docker run --net=host -e DISPLAY -v /tmp/.X11-unix -d --name OSW -p 22:22 -it --privileged ubuntu:22.04
```

#### Docker
```bash
$ xauth add <'xauth list' command result>
```
9 changes: 9 additions & 0 deletions emulator/include/Arduino.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "DataTypes.h"
#include "Defines.h"

unsigned long millis();
long random(int howbig);
long random(int howsmall, int howbig);
void delay(long millis);
int32_t min(int32_t a, int32_t b);
int32_t max(int32_t a, int32_t b);
24 changes: 24 additions & 0 deletions emulator/include/Arduino_G.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

#include "DataTypes.h"

// Code for Arduino_G was copy-pasted from Arduino_GFX

class Arduino_G {
public:
Arduino_G(int16_t w, int16_t h): WIDTH(w), HEIGHT(h) {}; // Constructor

// This MUST be defined by the subclass:
virtual void begin(int32_t speed = 0) = 0;

virtual void drawBitmap(int16_t x, int16_t y, uint8_t* bitmap, int16_t w, int16_t h, uint16_t color, uint16_t bg) = 0;
virtual void drawIndexedBitmap(int16_t x, int16_t y, uint8_t* bitmap, uint16_t* color_index, int16_t w, int16_t h) = 0;
virtual void draw3bitRGBBitmap(int16_t x, int16_t y, uint8_t* bitmap, int16_t w, int16_t h) = 0;
virtual void draw16bitRGBBitmap(int16_t x, int16_t y, uint16_t* bitmap, int16_t w, int16_t h) = 0;
virtual void draw24bitRGBBitmap(int16_t x, int16_t y, uint8_t* bitmap, int16_t w, int16_t h) = 0;

protected:
int16_t
WIDTH, ///< This is the 'raw' display width - never changes
HEIGHT; ///< This is the 'raw' display height - never changes
};
6 changes: 6 additions & 0 deletions emulator/include/Arduino_GFX.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once

class Graphics2DPrint;
typedef Graphics2DPrint Arduino_GFX;

#include "Arduino_G.h"
3 changes: 3 additions & 0 deletions emulator/include/CPU.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once

void setCpuFrequencyMhz(int);
4 changes: 4 additions & 0 deletions emulator/include/DataTypes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include <cstdint>
#include <math.h>

#define RTC_DATA_ATTR
12 changes: 12 additions & 0 deletions emulator/include/Defines.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#include <iostream>

#define PI 3.1415926535897932384626433832795
#define HALF_PI 1.5707963267948966192313216916398
#define TWO_PI 6.283185307179586476925286766559
#define DEG_TO_RAD 0.017453292519943295769236907684886
#define RAD_TO_DEG 57.295779513082320876798154814105
#define EULER 2.718281828459045235360287471352

#define OSW_EMULATOR_THIS_IS_NOT_IMPLEMENTED std::cerr << "FIXME: " << __FILE__ << ":" << __LINE__ << "->" << __FUNCTION__ << "() Not implemented!" << std::endl;
Loading

0 comments on commit 0a71a6d

Please sign in to comment.