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

PoC: SDL simu and WASM target #5940

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft

PoC: SDL simu and WASM target #5940

wants to merge 9 commits into from

Conversation

raphaelcoeffic
Copy link
Member

@raphaelcoeffic raphaelcoeffic commented Feb 23, 2025

Description

This PR rewrites simu based only SDL2 and ImGui. Additionally, it adds a WASM target based on emscripten, thus allowing to run simu in a browser.

Features so far:

  • dynamic controls for switches and pots (based on radio configuration)
  • keyboard controls (see handleKeyEvents())
  • touch controls with mouse/trackpad input

TODOs:

  • generic:
    • handle empty storage better: currently, starting simu with empty storage leads to corrupted control layout.
    • better application layout.
  • WASM:
    • Storage API support: so far there is local storage supported at all, so that simu always starts with empty storage.
Screenshot Screenshot 2025-02-23 at 08 12 48

Requirements

The WASM target requires emscripten to be installed. I'm using the version installed by brew, which is fairly new:

brew install emscripten

Usage

simu can be used as usual:

make -j16 simu && ./native/simu

The WASM target can be compiled and run with:

make -j16 wasm-simu && emrun --no-browser wasm/simu.html

@jtaylor2
Copy link
Contributor

I don't know if my testing this on openSUSE Leap 15.6 is of any value to you, but I have been compiling openTX/edgeTX since 2013 and everything has always worked. In compiling and testing simu (will need to install Emscripten to test wasm) I get the following:

Compile error using G++ 11:

[ 93%] Building CXX object radio/src/targets/simu/CMakeFiles/simu_drivers.dir/simuaudio.cpp.o
/home/jim/edgetx/edgetx/radio/src/targets/simu/simuaudio.cpp: In function ‘bool simuAudioInit()’:
/home/jim/edgetx/edgetx/radio/src/targets/simu/simuaudio.cpp:83:3: sorry, unimplemented: non-trivial designated initializers not supported
   };
   ^
make[3]: **

According to https://stackoverflow.com/questions/31215971/non-trivial-designated-initializers-not-supported
With g++ the order of initialization needs to be in the exact order of declaration. So changing simuaudio.cpp to the following allows it to compile.

diff --git a/radio/src/targets/simu/simuaudio.cpp b/radio/src/targets/simu/simuaudio.cpp
index b22b30adf..0d8ca0b03 100644
--- a/radio/src/targets/simu/simuaudio.cpp
+++ b/radio/src/targets/simu/simuaudio.cpp
@@ -79,6 +79,7 @@ bool simuAudioInit()
     .freq = AUDIO_SAMPLE_RATE,
     .format = SIMU_AUDIO_FMT,
     .channels = 1,
+    .silence = NULL,
     .samples = 1024,
   };

After that change it compiles, but when running the simu comes up (see screen shot) with the current model but the audio is very noisy and scratchy and the program hangs and has to be killed (see screen shot running in debuger).
dbScreenshot

@jtaylor2
Copy link
Contributor

Compiled WASM on openSUSE 15.6. Had to use emsdk 4.0.2 as Leap 15.6 has python 3.6 and emsdk main requires python 3.8.

Compiled and seems to work fine but I can't figure out how to point it to my SD card image. It comes up with a Storage Warning and initializes to a new radio. Don't know how to make it see my SD image.
wasm

@gagarinlg
Copy link
Member

Filesystem access is not yet possible.

@jtaylor2
Copy link
Contributor

Of course it's not.....says that in the TODOs. I need to learn to read.

@raphaelcoeffic
Copy link
Member Author

@jtaylor2 thx for trying it out! I've just fixed the audio, which was somehow still using unsigned 16 bit, instead of signed 16 bit, as we do now across all targets. It seems I forgot that while rebasing the code on main.

@jtaylor2
Copy link
Contributor

Simu audio good now but I have to comment out radio/src/targets/simu/sdl_simu.cpp:706 to get it to actually run. Otherwise it just comes up and hangs in the delay loop:

//SDL_Delay(floor(16.666f - elapsedMS));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants