chore: remove Qt and SDL2 from radio unit tests (#6452)

This commit is contained in:
Raphael Coeffic
2025-07-24 08:05:18 +10:00
committed by GitHub
parent 9e86a3ea84
commit 538721ef6b
17 changed files with 226 additions and 200 deletions
+13 -17
View File
@@ -5,13 +5,12 @@ if(NOT SIMU_TARGET)
return()
endif()
target_compile_options(radiolib_native PUBLIC -DSIMU)
set(SIMU_DRIVERS
simpgmspace.cpp
simufatfs.cpp
simudisk.cpp
simulcd.cpp
audio_driver.cpp
switch_driver.cpp
adc_driver.cpp
module_drivers.cpp
@@ -40,7 +39,6 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR})
if(SDL2_FOUND)
include_directories(${SDL2_INCLUDE_DIRS})
target_compile_options(radiolib_native PUBLIC -DSIMU_AUDIO)
list(APPEND SIMU_DRIVERS simuaudio.cpp)
if(TARGET SDL2::SDL2)
set(SDL2_LIBRARIES SDL2::SDL2)
endif()
@@ -97,20 +95,24 @@ if(Qt6Widgets_FOUND)
qt_wrap_cpp(SIMULATOR_SRC
${COMPANION_SRC_DIRECTORY}/simulation/simulatorinterface.h
opentxsimulator.h
)
)
list(APPEND SIMULATOR_SRC ${SIMU_SRC} opentxsimulator.cpp)
add_library(${SIMULATOR_TARGET} SHARED ${SIMULATOR_SRC})
if(SDL2_FOUND)
target_sources(${SIMULATOR_TARGET} PRIVATE simuaudio.cpp)
else()
target_sources(${SIMULATOR_TARGET} PRIVATE no_audio.cpp)
endif()
target_compile_options(${SIMULATOR_TARGET} PRIVATE ${SIMU_SRC_OPTIONS})
target_compile_definitions(${SIMULATOR_TARGET} PUBLIC ${APP_COMMON_DEFINES})
target_link_libraries(${SIMULATOR_TARGET} ${SDL2_LIBRARIES} Qt::Core Qt::SerialPort)
# Remove debug symbols on release builds
if(NOT CLANG)
if("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
add_custom_command(TARGET ${SIMULATOR_TARGET} POST_BUILD
COMMAND ${CMAKE_STRIP} $<TARGET_FILE:${SIMULATOR_TARGET}>)
endif()
if("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
add_custom_command(TARGET ${SIMULATOR_TARGET} POST_BUILD
COMMAND ${CMAKE_STRIP} -x $<TARGET_FILE:${SIMULATOR_TARGET}>)
endif()
add_custom_command(
@@ -118,7 +120,7 @@ if(Qt6Widgets_FOUND)
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/plugins/
COMMAND ${CMAKE_COMMAND} -E copy
$<TARGET_FILE:${SIMULATOR_TARGET}> ${CMAKE_BINARY_DIR}/plugins/
)
)
# Introduced at 2.5 - TODO replace with a code change
# When compiled shared simulators using libopenui and Companion have classes named MainWindow
@@ -152,13 +154,6 @@ if(Qt6Widgets_FOUND)
add_custom_target(all-simu-libs COMMAND ${all_libs_cmd} USES_TERMINAL WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
endif()
if(WIN32)
include_directories(SYSTEM ${WIN_INCLUDE_DIRS})
if(Qt6Widgets_FOUND)
target_link_libraries(${SIMULATOR_TARGET} PRIVATE ${WIN_LINK_LIBRARIES})
endif()
endif(WIN32)
if(MINGW)
# struct packing breaks on MinGW w/out -mno-ms-bitfields: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52991 & http://stackoverflow.com/questions/24015852/struct-packing-and-alignment-with-mingw
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mno-ms-bitfields")
@@ -178,6 +173,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS}")
add_executable(simu
EXCLUDE_FROM_ALL
${SIMU_SRC}
simuaudio.cpp
display.cpp
widgets.cpp
knobs.cpp
+57
View File
@@ -0,0 +1,57 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "audio.h"
#include "simuaudio.h"
#if !defined(SOFTWARE_VOLUME)
static int _simu_volume = 0;
void audioSetVolume(uint8_t volume)
{
_simu_volume = volume;
}
#endif
int simuAudioGetVolume()
{
#if !defined(SOFTWARE_VOLUME)
return _simu_volume;
#else
return VOLUME_LEVEL_MAX;
#endif
}
void simuQueueAudio(const uint8_t* data, uint32_t len);
void audioConsumeCurrentBuffer()
{
auto& fifo = audioQueue.buffersFifo;
while(true) {
auto nextBuffer = fifo.getNextFilledBuffer();
if (!nextBuffer) return;
auto data = (const uint8_t*)nextBuffer->data;
uint32_t len = nextBuffer->size * sizeof(audio_data_t);
simuQueueAudio(data, len);
fifo.freeNextFilledBuffer();
}
}
+26
View File
@@ -0,0 +1,26 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "simuaudio.h"
bool simuAudioInit() { return false; }
void simuAudioDeInit() {}
void simuQueueAudio(const uint8_t*, uint32_t) {}
-4
View File
@@ -22,10 +22,6 @@
#include "board.h"
#define SIMPGMSPC_USE_QT 0
#if defined(SIMU_AUDIO)
#include <SDL.h>
#endif
#include "edgetx.h"
#include "simulcd.h"
-8
View File
@@ -48,14 +48,6 @@ void simuStop();
bool simuIsRunning();
void startEepromThread(const char * filename = "eeprom.bin");
void stopEepromThread();
#if defined(SIMU_AUDIO)
int startAudio(int volumeGain = 10);
void stopAudio();
#else
#define startAudio(dummy) (-1)
#define stopAudio()
#endif
#endif
void simuMain();
+5 -39
View File
@@ -29,48 +29,14 @@
static SDL_AudioDeviceID _sdl_audio_device = 0;
void simuQueueAudio(const uint8_t* data, uint32_t len)
{
#if !defined(SOFTWARE_VOLUME)
static Uint8 _tmp_buf[AUDIO_BUFFER_SIZE * sizeof(audio_data_t)];
static int _simu_volume = 0;
void audioSetVolume(uint8_t volume)
{
_simu_volume = SDL_MIX_MAXVOLUME * volume / VOLUME_LEVEL_MAX;
}
static void _fill_with_silence(Uint8* dst, uint32_t len)
{
auto p = (audio_data_t*)dst;
auto end = p + len / sizeof(audio_data_t);
while (p < end) {
*p++ = AUDIO_DATA_SILENCE;
}
}
int volume = (simuAudioGetVolume() * SDL_MIX_MAXVOLUME ) / VOLUME_LEVEL_MAX;
SDL_MixAudioFormat((uint8_t*)data, data, SIMU_AUDIO_FMT, len, volume);
#endif
void audioConsumeCurrentBuffer()
{
while(true) {
auto nextBuffer = audioQueue.buffersFifo.getNextFilledBuffer();
if (!nextBuffer) return;
auto data = (const Uint8*)nextBuffer->data;
uint32_t len = nextBuffer->size * sizeof(audio_data_t);
#if !defined(SOFTWARE_VOLUME)
assert(len <= sizeof(_tmp_buf));
_fill_with_silence(_tmp_buf, len);
SDL_MixAudioFormat(_tmp_buf, data, SIMU_AUDIO_FMT, len, _simu_volume);
data = _tmp_buf;
#endif
SDL_QueueAudio(_sdl_audio_device, data, len);
audioQueue.buffersFifo.freeNextFilledBuffer();
}
SDL_QueueAudio(_sdl_audio_device, data, len);
}
bool simuAudioInit()
+4 -5
View File
@@ -21,10 +21,9 @@
#pragma once
#if defined(SIMU_AUDIO)
#include <stdint.h>
bool simuAudioInit();
void simuAudioDeInit();
#else
static inline bool simuAudioInit() { return false; }
static inline void simuAudioDeInit() {}
#endif
void simuQueueAudio(const uint8_t* data, uint32_t len);
int simuAudioGetVolume();