diff --git a/meson.build b/meson.build index 17d5b323..3c4f0cdf 100644 --- a/meson.build +++ b/meson.build @@ -22,7 +22,7 @@ def = {} openrtx_src = ['openrtx/src/core/state.c', 'openrtx/src/core/threads.c', 'openrtx/src/core/battery.c', - 'openrtx/src/core/graphics.c', + 'openrtx/src/core/graphics.cpp', 'openrtx/src/core/input.c', 'openrtx/src/core/calibUtils.c', 'openrtx/src/core/queue.c', @@ -353,19 +353,23 @@ linux_l_args = ['-lm', '-lreadline'] # Add AddressSanitizer if required if get_option('asan') linux_c_args += '-fsanitize=address' + linux_cpp_args += '-fsanitize=address' linux_l_args += '-fsanitize=address' endif # Add Undefined Behaviour Sanitizer if required if get_option('ubsan') linux_c_args += '-fsanitize=undefined' + linux_cpp_args += '-fsanitize=undefined' linux_l_args += '-fsanitize=undefined' endif foreach k, v : linux_def if v == '' linux_c_args += '-D@0@'.format(k) + linux_cpp_args += '-D@0@'.format(k) else linux_c_args += '-D@0@=@1@'.format(k, v) + linux_cpp_args += '-D@0@=@1@'.format(k, v) endif endforeach diff --git a/openrtx/include/interfaces/graphics.h b/openrtx/include/interfaces/graphics.h index 5808b973..93e967b0 100644 --- a/openrtx/include/interfaces/graphics.h +++ b/openrtx/include/interfaces/graphics.h @@ -35,6 +35,12 @@ #include #include +#ifdef __cplusplus +#include + +extern "C" { +#endif + /** * Standard high-level graphic interface for all display types. * This interface is based on the lower level interface display.h @@ -335,4 +341,18 @@ void gfx_drawGPSgraph(point_t start, uint16_t width, uint16_t height, sat_t *sat */ void gfx_drawGPScompass(point_t start, uint16_t radius, float deg, bool active); +#ifdef __cplusplus +} + +/** + * Function to plot a collection of data on the screen. + * Starting coordinates are relative to the top left point. + * @param start: Plot start point, in pixel coordinates. + * @param width: Plot width + * @param height: Plot height + * @param data: pointer to the deque containing data + */ +void gfx_plotData(point_t start, uint16_t width, uint16_t height, std::deque data); +#endif + #endif /* GRAPHICS_H */ diff --git a/openrtx/src/core/graphics.c b/openrtx/src/core/graphics.cpp similarity index 95% rename from openrtx/src/core/graphics.c rename to openrtx/src/core/graphics.cpp index c1b9afe9..0e56e975 100644 --- a/openrtx/src/core/graphics.c +++ b/openrtx/src/core/graphics.cpp @@ -30,9 +30,9 @@ #include #include #include +#include // Variable swap macro -#define SWAP(x, y) do { typeof(x) t = x; x = y; y = t; } while(0) #define DEG_RAD 0.017453292519943295769236907684886 #define SIN(x) sinf((x) * DEG_RAD) #define COS(x) cosf((x) * DEG_RAD) @@ -207,14 +207,28 @@ void gfx_drawLine(point_t start, point_t end, color_t color) if (steep) { - SWAP(start.x, start.y); - SWAP(end.x, end.y); + uint16_t tmp; + // Swap start.x and start.y + tmp = start.x; + start.x = start.y; + start.y = tmp; + // Swap end.x and end.y + tmp = end.x; + end.x = end.y; + end.y = tmp; } if (start.x > end.x) { - SWAP(start.x, end.x); - SWAP(start.y, end.y); + uint16_t tmp; + // Swap start.x and end.x + tmp = start.x; + start.x = end.x; + end.x = tmp; + // Swap start.y and end.y + tmp = start.y; + start.y = end.y; + end.y = tmp; } int16_t dx, dy; @@ -840,3 +854,29 @@ void gfx_drawGPScompass(point_t start, point_t n_pos = {start.x + radius - 3, start.y + 7}; gfx_print(n_pos, FONT_SIZE_6PT, TEXT_ALIGN_LEFT, white, "N"); } + +void gfx_plotData(point_t start, + uint16_t width, + uint16_t height, + std::deque data) +{ + gfx_clearScreen(); + uint16_t horizontal_pos = start.x; + color_t white = {255, 255, 255, 255}; + point_t prev_pos {0, 0}, pos{0, 0}; + bool first_iteration = true; + for (auto d : data) + { + horizontal_pos++; + if (horizontal_pos > start.x + width) + break; + pos.x = horizontal_pos; + pos.y = start.y + height / 2 + (float) d / (2 * SHRT_MAX) * height; + if (!first_iteration) + gfx_drawLine(prev_pos, pos, white); + prev_pos = pos; + if (first_iteration) + first_iteration = false; + } + gfx_render(); +} diff --git a/platform/targets/DM-1801/hwconfig.h b/platform/targets/DM-1801/hwconfig.h index edfe16a9..e3555f1c 100644 --- a/platform/targets/DM-1801/hwconfig.h +++ b/platform/targets/DM-1801/hwconfig.h @@ -23,6 +23,10 @@ #include "MK22F51212.h" +#ifdef __cplusplus +extern "C" { +#endif + /* Screen dimensions */ #define SCREEN_WIDTH 128 #define SCREEN_HEIGHT 64 @@ -98,4 +102,8 @@ #define DMR_MOSI GPIOD,2 #define DMR_MISO GPIOD,3 +#ifdef __cplusplus +} #endif + +#endif /* HWCONFIG_H */ diff --git a/platform/targets/GD-77/hwconfig.h b/platform/targets/GD-77/hwconfig.h index 5160285d..9985d1d7 100644 --- a/platform/targets/GD-77/hwconfig.h +++ b/platform/targets/GD-77/hwconfig.h @@ -23,6 +23,10 @@ #include "MK22F51212.h" +#ifdef __cplusplus +extern "C" { +#endif + /* Screen dimensions */ #define SCREEN_WIDTH 128 #define SCREEN_HEIGHT 64 @@ -98,4 +102,8 @@ #define DMR_MOSI GPIOD,2 #define DMR_MISO GPIOD,3 +#ifdef __cplusplus +} #endif + +#endif /* HWCONFIG_H */ diff --git a/platform/targets/MD-3x0/hwconfig.h b/platform/targets/MD-3x0/hwconfig.h index e5c89879..8989ba2c 100644 --- a/platform/targets/MD-3x0/hwconfig.h +++ b/platform/targets/MD-3x0/hwconfig.h @@ -22,6 +22,10 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + /* Device has a working real time clock */ #define HAS_RTC @@ -142,4 +146,8 @@ /* M17 demodulation */ #define M17_RX_SAMPLE_RATE 24000 +#ifdef __cplusplus +} #endif + +#endif /* HWCONFIG_H */ diff --git a/platform/targets/MD-9600/hwconfig.h b/platform/targets/MD-9600/hwconfig.h index cb751470..64f00197 100644 --- a/platform/targets/MD-9600/hwconfig.h +++ b/platform/targets/MD-9600/hwconfig.h @@ -23,6 +23,10 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + /* Device has a working real time clock */ #define HAS_RTC @@ -101,4 +105,8 @@ #define DMR_MOSI GPIOE,4 #define DMR_MISO GPIOE,5 +#ifdef __cplusplus +} #endif + +#endif /* HWCONFIG_H */ diff --git a/platform/targets/MD-UV3x0/hwconfig.h b/platform/targets/MD-UV3x0/hwconfig.h index 372f924b..6027928f 100644 --- a/platform/targets/MD-UV3x0/hwconfig.h +++ b/platform/targets/MD-UV3x0/hwconfig.h @@ -22,6 +22,10 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + /* Device has a working real time clock */ #define HAS_RTC @@ -150,4 +154,8 @@ * #define ENABLE_BKLIGHT_DIMMING */ +#ifdef __cplusplus +} #endif + +#endif /* HWCONFIG_H */ diff --git a/platform/targets/linux/hwconfig.h b/platform/targets/linux/hwconfig.h index 2f43d7b2..75f328aa 100644 --- a/platform/targets/linux/hwconfig.h +++ b/platform/targets/linux/hwconfig.h @@ -15,6 +15,13 @@ * along with this program; if not, see * ***************************************************************************/ +#ifndef HWCONFIG_H +#define HWCONFIG_H + +#ifdef __cplusplus +extern "C" { +#endif + /* Device has a working real time clock */ #define HAS_RTC @@ -57,3 +64,9 @@ /* M17 demodulation */ #define M17_RX_SAMPLE_RATE 48000 + +#ifdef __cplusplus +} +#endif + +#endif /* HWCONFIG_H */