kopia lustrzana https://github.com/OpenRTX/OpenRTX
Add plotting function to graphics library
Added plotting function to graphics library which is native C++, so refactored the graphics source file to allow that, consequently adapted the hwconfig header files to be included also in C++ sources. Propagated compile flags also to C++ sources, including asan what was previously disabled for C++ compilation units. TG-81pull/68/head
rodzic
ae26cca46f
commit
f9c23452bc
|
@ -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
|
||||
|
||||
|
|
|
@ -35,6 +35,12 @@
|
|||
#include <FreeSans18pt7b.h>
|
||||
#include <FreeSans24pt7b.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <deque>
|
||||
|
||||
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<int16_t> data);
|
||||
#endif
|
||||
|
||||
#endif /* GRAPHICS_H */
|
||||
|
|
|
@ -30,9 +30,9 @@
|
|||
#include <stdarg.h>
|
||||
#include <interfaces/display.h>
|
||||
#include <interfaces/graphics.h>
|
||||
#include <climits>
|
||||
|
||||
// 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<int16_t> 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();
|
||||
}
|
|
@ -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 */
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -22,6 +22,10 @@
|
|||
|
||||
#include <stm32f4xx.h>
|
||||
|
||||
#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 */
|
||||
|
|
|
@ -23,6 +23,10 @@
|
|||
|
||||
#include <stm32f4xx.h>
|
||||
|
||||
#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 */
|
||||
|
|
|
@ -22,6 +22,10 @@
|
|||
|
||||
#include <stm32f4xx.h>
|
||||
|
||||
#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 */
|
||||
|
|
|
@ -15,6 +15,13 @@
|
|||
* along with this program; if not, see <http://www.gnu.org/licenses/> *
|
||||
***************************************************************************/
|
||||
|
||||
#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 */
|
||||
|
|
Ładowanie…
Reference in New Issue