Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented emulator for #190 #289

Merged
merged 186 commits into from
Sep 11, 2022
Merged
Show file tree
Hide file tree
Changes from 184 commits
Commits
Show all changes
186 commits
Select commit Hold shift + click to select a range
2e71035
Remove specific libs
simonmicro Feb 3, 2022
558553a
First successful build of emulator
simonmicro Feb 17, 2022
d1f4b9e
Implemented String and Preferences
simonmicro Feb 17, 2022
8f4b845
Made service manager comaptible with nullptr-workaround
simonmicro Mar 3, 2022
3568e32
Migrated consistently to gfx_2d (from Arduino_GFX) and ported all rem…
simonmicro Mar 3, 2022
8d35e1b
Removed two warnings
simonmicro Mar 3, 2022
bc16371
First successful render!
simonmicro Mar 3, 2022
e6febda
First virtual button presses
simonmicro Mar 17, 2022
b18b0c6
Finally fixed String class
simonmicro May 31, 2022
9b5d0ad
Disable optimization for debug
simonmicro May 31, 2022
fdbf8f0
Added constructor
simonmicro May 31, 2022
97eb7c2
Implemented basic deep sleep support (e.g. not crash)
simonmicro May 31, 2022
3027f14
Implemented rtc_get_reset_reason()
simonmicro May 31, 2022
b7f5f86
Switch to SDL2
simonmicro May 31, 2022
737f0a9
Fixed compile errors
simonmicro Jun 11, 2022
a60feca
Implemented flickery demo window
simonmicro Jun 11, 2022
18b81ad
Minor cleanup
simonmicro Jun 12, 2022
2a88c73
Added real button control
simonmicro Jun 12, 2022
59c7676
Added flicker reduction
simonmicro Jun 12, 2022
5e5e46a
Added info window and deep sleep trigger
simonmicro Jun 12, 2022
7ccc907
Proper light sleep handling
simonmicro Jun 12, 2022
f0185d8
Added plots
simonmicro Jun 12, 2022
0c150a9
Merged windows
simonmicro Jun 12, 2022
306b00f
Minor alignment
simonmicro Jun 13, 2022
1f908cd
Implemented ESP.restart()
simonmicro Aug 5, 2022
a3ddf4c
Implemented binary preferences
simonmicro Aug 5, 2022
cc299c2
Implemented more minor stuff
simonmicro Aug 5, 2022
5cc08e3
Fixed typo in string operators
simonmicro Aug 5, 2022
ce8386b
Refactor emulator define
simonmicro Aug 5, 2022
91dee27
Updated libs
simonmicro Aug 5, 2022
a880e67
Pngle build fix
simonmicro Aug 5, 2022
96e376b
Fix lib (again)
simonmicro Aug 5, 2022
224da51
Using real-value defines
simonmicro Aug 5, 2022
354082a
Removed submodule
simonmicro Aug 16, 2022
ebd16ca
initial commit
uvwxy Aug 26, 2020
1c76f4d
update readme
uvwxy Aug 26, 2020
82cf6d9
add more docs
uvwxy Aug 26, 2020
147ecdf
refactor 2d graphics to chunk mode
uvwxy Aug 26, 2020
71e3569
fix watch-simple, add license
uvwxy Aug 27, 2020
4b690b1
add perlin noise, refactoring
uvwxy Aug 27, 2020
1f2e75f
fix doomfire demo
uvwxy Aug 30, 2020
640bada
add osm.h
uvwxy Sep 15, 2020
35d5da4
improve osm.h
uvwxy Sep 16, 2020
cc81389
add water ripple demo
uvwxy Oct 11, 2020
1927240
add drawGraphics2D
uvwxy Oct 11, 2020
96eb081
flatten source structure
uvwxy Oct 13, 2020
753838a
refactoring
uvwxy Oct 13, 2020
2df624d
add library.properties
uvwxy Oct 13, 2020
b0cafee
fix build setups, add rotation code
uvwxy Nov 1, 2020
536e3bf
add rotate + advanced rotate
uvwxy Nov 1, 2020
1e713a8
improve rotation
uvwxy Nov 2, 2020
658d528
fix example, cleanup gfx_2d.h
uvwxy Nov 8, 2020
4329c6b
fix cmakelists, add circ buffer example to examples/shapes/
uvwxy Dec 6, 2020
322d149
fix range glitch on HLine/VLine
uvwxy Dec 28, 2020
1bcd003
add missing asset
uvwxy Dec 28, 2020
3f1f3cb
add round buffer support
uvwxy Dec 29, 2020
5fef075
add osm render stub
uvwxy Dec 30, 2020
1b60dbc
add map app
uvwxy Dec 30, 2020
02daddb
cleanup osm render
uvwxy Dec 30, 2020
ac8a84d
add firework anim + helper functions
uvwxy Jan 1, 2021
75863cc
fix example SDL color space
uvwxy Jan 4, 2021
fb90143
add draw arc, draw thick line
uvwxy Jan 4, 2021
74658d3
add missing import
uvwxy Jan 6, 2021
7008538
remove warning
uvwxy Jan 17, 2021
171430c
add support to disable buffer
uvwxy Jan 24, 2021
06ff7b2
add moon test shape
uvwxy Jan 24, 2021
10a3345
add usb connector icon shape
uvwxy Jan 25, 2021
e36a203
improve freeing of resources in gfx2d
uvwxy Feb 12, 2021
7d96ad9
add tile caching
uvwxy Mar 9, 2021
4b446e5
add inPsram option to BufferedTile constructor
uvwxy Mar 12, 2021
26f01d0
ugly copy/paste job from ArduinoGFX to support print(...) in SDL code
uvwxy Mar 17, 2021
a82ff58
add more utility functions
uvwxy Mar 17, 2021
19a3662
add text example
uvwxy Mar 18, 2021
59e1403
initialization
max9901 Apr 7, 2021
99fa40b
better control over text alligment fixing issue #14
max9901 Apr 11, 2021
1643d35
add writeDigits
uvwxy May 2, 2021
f786d50
cleanup text printing
uvwxy May 2, 2021
36c287f
speedup drawThickLine
uvwxy May 3, 2021
c5e433d
add missing btn functions
uvwxy May 3, 2021
5663273
comment unused var
uvwxy May 8, 2021
ecdeeae
add rgb565 rgb888 helper
uvwxy May 8, 2021
4830aaa
refactor setTextCursor(Button ..) (which needs to be removed)
uvwxy May 13, 2021
db5375a
gfx_2d_print add resetText
uvwxy May 13, 2021
50baee7
remove button function
uvwxy May 13, 2021
0e4a927
add flag to dry high quality thickline/arcs
uvwxy May 16, 2021
bea7a3c
initialize 2dgfx framebuffer
uvwxy May 16, 2021
be2d1af
gfx_2d.h: expose 'highquality'
uvwxy May 26, 2021
e2a5758
change default missing color
uvwxy Jul 3, 2021
150d2be
update to current Arduino_GFX import paths
uvwxy Jul 23, 2021
a14a4f2
check for GPS_EDITION_ROTATED
uvwxy Jul 31, 2021
d3f3c15
fix missing glyph pointer with new Arduino_GFX
uvwxy Aug 2, 2021
101043b
add matrix animation
uvwxy Aug 2, 2021
90c69d3
increase base matrix brightness
uvwxy Aug 2, 2021
47ee6fd
add todo
uvwxy Aug 2, 2021
890ff20
Add some documentation for newbee like me !
Aug 16, 2021
5d8ad75
Specials characters
Aug 17, 2021
ec64596
doc: add documentation use 2D emulator with Windows + WSL doc
GPaddle May 8, 2021
2610c1c
refactor: generalize draw ticks function
GPaddle May 16, 2021
06ff453
fix headers
uvwxy Sep 5, 2021
9228dc9
Fixed compiler warning
simonmicro Sep 16, 2021
0a89a67
Fixed bug when ram is inited to zero, psram is not reloaded -> causin…
simonmicro Oct 9, 2021
908727d
Added sanity check to prevent infinite loops by underflows
simonmicro Oct 14, 2021
3847bf9
Fixed compile issues
simonmicro Nov 24, 2021
6854548
Merked cmakelists and switched to system lib versions
simonmicro Nov 24, 2021
8042226
Updated example names and instructions to run on Linux
simonmicro Nov 24, 2021
070b447
Corrected wrong include path
simonmicro Nov 24, 2021
2413fdc
make it work on macos and some small fixes
uvwxy Nov 24, 2021
62e13d3
Update : Adjust the size of the flat panel
RuffaloLavoisier Nov 25, 2021
88f853a
Remove : Delete unnecessary libraries
RuffaloLavoisier Nov 25, 2021
e602997
Added two copy-pastes for osw-emulator
simonmicro Mar 3, 2022
20ea05a
Fireworks : delete unnecessary libraries
RuffaloLavoisier Feb 21, 2022
9f2f36d
Perlin : delete unnecessary libraries
RuffaloLavoisier Feb 21, 2022
3b794c1
Watch-simple : delete unnecessary libraries
RuffaloLavoisier Feb 21, 2022
c3281c2
Text : delete unnecessary libraries
RuffaloLavoisier Feb 21, 2022
b9e3401
CMakeLists.txt : add Watchface-MIX Graphics2D test environment
RuffaloLavoisier Mar 18, 2022
3e7aa36
Mix-face : implement date, time and step-history virtual simulation
RuffaloLavoisier Mar 18, 2022
863f451
Shape : fixed moving for hours ThickTick
RuffaloLavoisier Mar 29, 2022
4aa911e
Workflows : add workflows for OSW libs
RuffaloLavoisier Mar 23, 2022
7eb9009
Fixed complie warning
simonmicro May 4, 2022
5fd4182
lib-open-smartwatch : update comment
RuffaloLavoisier May 17, 2022
2f03636
Added std::string support
simonmicro May 31, 2022
5a530d1
Add printSlice function
RuffaloLavoisier Jul 14, 2022
8aca599
Anim : refactoring doom-fire class
RuffaloLavoisier Jul 20, 2022
d2909ef
Gfx_2d_print : correct spelling on word
RuffaloLavoisier Jul 27, 2022
704da95
Return type change
RuffaloLavoisier Jul 27, 2022
73a4dcb
DoomFire: Not used after refactoring
RuffaloLavoisier Aug 2, 2022
7af2613
gfx_2d_print: rename function and add statement
RuffaloLavoisier Aug 5, 2022
8bd11b2
Refactor emulator define
simonmicro Aug 5, 2022
ab11c71
osm: fix in comment
RuffaloLavoisier Aug 8, 2022
c0005b4
Recreated main repo folder structure
simonmicro Aug 16, 2022
b00c81b
Merged lib-open-smartwatch into main source tree
simonmicro Aug 18, 2022
bf9836b
Fixed compiler warning
simonmicro Aug 18, 2022
65fa877
Added emulator usage to the README
simonmicro Aug 18, 2022
e2d62ae
CMake minimum version and SDL (min version) patches
simonmicro Aug 18, 2022
9f3d225
Readded dropped code (by refactor) from 2434c4592239b47355c17780aa50e…
simonmicro Sep 3, 2022
1b87974
Updated modules
simonmicro Sep 3, 2022
f0582b7
Fixed PIO build again
simonmicro Sep 3, 2022
136594f
Fixed PIO build again
simonmicro Sep 3, 2022
56263eb
Removed CI for osw-lib
simonmicro Sep 3, 2022
dca9e83
Fixed cmake lib requirement typo
simonmicro Sep 3, 2022
ee6deaa
Added CI for emulator
simonmicro Sep 3, 2022
5d39225
Removed accidantially readded format style file
simonmicro Sep 3, 2022
617dbf0
Removed old wx-stuff
simonmicro Sep 3, 2022
463ba79
Minor cleanup
simonmicro Sep 3, 2022
6317268
Typo and TODO-comment
simonmicro Sep 3, 2022
4453e82
Make config.h optional again
simonmicro Sep 3, 2022
a38dbea
OswAppWatchface: fix libraries path
RuffaloLavoisier Sep 4, 2022
7e1738d
Removed FPS limiter (and workarounds)
simonmicro Sep 4, 2022
7fce3ba
Switch to short git hash variant
simonmicro Sep 4, 2022
db8ff61
Added GDB settings for VSCode and the emulator
simonmicro Sep 4, 2022
5f4a170
Moved types into own enum
simonmicro Sep 6, 2022
f128daa
Reverted broken library update
simonmicro Sep 6, 2022
fa3fad3
Updated ImGUI
simonmicro Sep 6, 2022
5819c4e
Removed source exclusion via CMakeLists.txt
simonmicro Sep 6, 2022
df905a4
Fixed compile warning
simonmicro Sep 6, 2022
76d145d
Added virtual sensor inputs
simonmicro Sep 6, 2022
1935d3b
Resolve conflict
RuffaloLavoisier Sep 6, 2022
a8987a6
Emulator: add virtual check-box for web interface
RuffaloLavoisier Aug 20, 2022
d4ca469
Emulator: add Color-strip
RuffaloLavoisier Aug 20, 2022
3f1b97f
Emulator: add dropdown item
RuffaloLavoisier Aug 21, 2022
3e62824
Emulator: update dropdown item
RuffaloLavoisier Aug 21, 2022
6634e9a
Emulator: add web-interface key
RuffaloLavoisier Aug 21, 2022
f1f1d4f
Resolve conflict comment
RuffaloLavoisier Sep 6, 2022
8966f5a
Emulator: refactoring web interface short-code
RuffaloLavoisier Aug 23, 2022
651c1f8
Emulator: set DateFormat dropdown item
RuffaloLavoisier Aug 25, 2022
859b674
Emulator: update DateFormat
RuffaloLavoisier Aug 25, 2022
3f1e05e
Emulator: fixed DateFormat index
RuffaloLavoisier Aug 25, 2022
f51ea6e
Emulator: refactoring osw config key
RuffaloLavoisier Aug 27, 2022
dbe4f69
Set emulator window title
RuffaloLavoisier Sep 6, 2022
a0b86e1
Implemented Configuration window with write-back
simonmicro Sep 6, 2022
9cced63
Removed unused function
simonmicro Sep 6, 2022
7fe89ea
Removed unused snippets
simonmicro Sep 6, 2022
9e5183e
Merge pull request #287 from Open-Smartwatch/webWindow
RuffaloLavoisier Sep 6, 2022
1f53f26
Added configuration section labels and fixed the config-window loosin…
simonmicro Sep 8, 2022
bfffc0c
Persistent SDL window size and an emulator property
simonmicro Sep 8, 2022
4fec0dd
Implemented step-statistics support in emulator
simonmicro Sep 8, 2022
934b4cf
Fixed compile error
simonmicro Sep 8, 2022
1975efa
OswAppWatchfaceBinary: remove parameter
RuffaloLavoisier Sep 10, 2022
30f5c7b
README: update OSW emulator with docker
RuffaloLavoisier Sep 10, 2022
d94281d
Common: fix typo on code
RuffaloLavoisier Sep 10, 2022
20fb06c
README: update OSW sample
RuffaloLavoisier Sep 10, 2022
6c49692
Fixed missing file
simonmicro Sep 11, 2022
9733578
Fixed name collisions
simonmicro Sep 11, 2022
63e7554
Header cleanup
simonmicro Sep 11, 2022
57e29bb
Comments and typos
simonmicro Sep 11, 2022
b3647b1
Fixed broken package list
simonmicro Sep 11, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: 40 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ 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,42 @@ 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:

## With Docker

If a library is restricted, you can test it using a docker.(Maybe Ubuntu 20.04)
Proceed with a typical docker installation.

Showing an application running in a docker as a host requires several actions.

Host PC (Ubuntu 20.04)
```
$ 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
```
$ xauth add <'xauth list' command result>
```
### 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
RuffaloLavoisier marked this conversation as resolved.
Show resolved Hide resolved
$ sudo apt install libsdl2-dev libsdl2-image-dev g++ gcc make build
$ 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.
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);
25 changes: 25 additions & 0 deletions emulator/include/Arduino_G.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#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;
35 changes: 35 additions & 0 deletions emulator/include/Display.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#pragma once

#include <memory>

#include <SDL2/SDL.h>

#include "Arduino_GFX.h"
#include "Defines.h"

class FakeDisplay : public Arduino_G {
public:
FakeDisplay(int width, int height, SDL_Window* window, SDL_Renderer* renderer);
~FakeDisplay();

void displayOn();
void displayOff();

void drawPixel(int32_t x, int32_t y, uint16_t color);

// Required by Arduino_G
void begin(int32_t speed = 0) override;
void drawBitmap(int16_t x, int16_t y, uint8_t *bitmap, int16_t w, int16_t h, uint16_t color, uint16_t bg) override;
void drawIndexedBitmap(int16_t x, int16_t y, uint8_t *bitmap, uint16_t *color_index, int16_t w, int16_t h) override;
void draw3bitRGBBitmap(int16_t x, int16_t y, uint8_t *bitmap, int16_t w, int16_t h) override;
void draw16bitRGBBitmap(int16_t x, int16_t y, uint16_t *bitmap, int16_t w, int16_t h) override;
void draw24bitRGBBitmap(int16_t x, int16_t y, uint8_t *bitmap, int16_t w, int16_t h) override;
private:
SDL_Window* mainWindow;
SDL_Renderer* mainRenderer;
const int width;
const int height;
bool isEnabled = false;
};

extern std::unique_ptr<FakeDisplay> fakeDisplayInstance;
16 changes: 16 additions & 0 deletions emulator/include/ESP.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

#include "Emulator.hpp"
#include "Defines.h"

class ESP_t {
public:
void restart() {
OswEmulator::instance->enterSleep(true);
throw OswEmulator::EmulatorSleep();
}
};

extern ESP_t ESP;

#define ESP_OK true
Loading