Добавлен плот не по массиву и экзампл для синуса

This commit is contained in:
2025-02-21 12:30:34 +03:00
parent d58273fe41
commit 9a4e3c3dad
5 changed files with 71 additions and 47 deletions

View File

@@ -2,8 +2,8 @@
#include "math.h"
int menu_white_theme = 0;
//#define SINE_EXAMPLE
#define ECG_EXAMPLE
#define SINE_EXAMPLE
//#define ECG_EXAMPLE
//#define PLAYER_EXAMPLE
@@ -84,15 +84,18 @@ void Example_OLED_GFX_Update(PlayerTypeDef *player)
oled_refresh();
}
}
float sine2plot;
float sine_cnt_step = 0.01;
int shift = 1;
float ecg_cnt = 0;
float ecg_cnt_step = 1;
float ecg_scale = 16;
float sine_cnt = 1;
void Example_GFX_CreateFrame(PlayerTypeDef *player)
{
#if defined(SINE_EXAMPLE) || defined(ECG_EXAMPLE)
GFX_Draw_Plotter(oled_buf, &plotter);
#if defined(SINE_EXAMPLE)
sine2plot = sinf(sine_cnt);
GFX_FloatPlotter(oled_buf, &plotter, &sine2plot);
sine_cnt += sine_cnt_step;
#elif defined(ECG_EXAMPLE)
GFX_FloatPlotter(oled_buf, &plotter, NULL);
#elif defined(PLAYER_EXAMPLE)
GFX_Clean_Buffer_Frame(oled_buf);
@@ -202,15 +205,14 @@ void Example_GFX_PlotterInit(void)
plotter.plotXAxis = 1;
plotter.plotYAxis = 1;
#if defined(SINE_EXAMPLE)
int pix_y = (int)((float)(sinf(sine_cnt)+shift)*((float)32/(1+shift)));
#if defined(SINE_EXAMPLE)
plotter.dataMax = 1.1;
plotter.signedData = 1;
#elif defined(ECG_EXAMPLE)
plotter.pDataPtr = ecg_data;
plotter.dataMax = 1.1;
plotter.dataSize = 550;
plotter.signedData = 1;
plotter.plotShift = 0;
plotter.plotSpeed = 2.5;
#endif

View File

@@ -436,7 +436,7 @@ void GFX_Draw_Arc(uint8_t *Buffer_Frame, GFX_ArcHandleTypeDef *hArc)
/* Функция вывода графика */
void GFX_Draw_Plotter(uint8_t *Buffer_Frame, GFX_PlotterFloatHandleTypeDef *hPlot)
void GFX_FloatPlotter(uint8_t *Buffer_Frame, GFX_PlotterFloatHandleTypeDef *hPlot, float *numb2plot)
{
if((Buffer_Frame == NULL) || (hPlot == NULL))
return;
@@ -444,6 +444,8 @@ void GFX_Draw_Plotter(uint8_t *Buffer_Frame, GFX_PlotterFloatHandleTypeDef *hPlo
return;
if((hPlot->yPos + hPlot->plotHeight == NULL) || (hPlot->xPos + hPlot->plotWidth == NULL))
return;
if((numb2plot == NULL) && (hPlot->pDataPtr == NULL))
return;
if(hPlot->__initialized == 0)
{
@@ -493,7 +495,11 @@ void GFX_Draw_Plotter(uint8_t *Buffer_Frame, GFX_PlotterFloatHandleTypeDef *hPlo
/* Расчет позиции пикселя */
float pix_y_float = (hPlot->pDataPtr[(int)hPlot->plotInd]);
float pix_y_float;
if(numb2plot != NULL)
pix_y_float = *numb2plot;
else
pix_y_float = (hPlot->pDataPtr[(int)hPlot->plotInd]);
// масштабирование под размеры графика
hPlot->pixY = (pix_y_float/hPlot->dataMax)*(hPlot->plotHeight);
// если график должен быть знаковым, то уменьшаем машстаб еще в два раза
@@ -533,15 +539,18 @@ void GFX_Draw_Plotter(uint8_t *Buffer_Frame, GFX_PlotterFloatHandleTypeDef *hPlo
}
/* Смещение графика далее */
hPlot->pixX++;
hPlot->plotInd += hPlot->plotSpeed;
if(hPlot->plotInd >= hPlot->dataSize)
hPlot->plotInd -= hPlot->dataSize;
if(hPlot->plotInd < 0)
hPlot->plotInd += hPlot->dataSize;
hPlot->pixX++;
hPlot->prevPixY = hPlot->pixY;
// Если используется массив плота
if(numb2plot == NULL)
{
hPlot->plotInd += hPlot->plotSpeed;
if(hPlot->plotInd >= hPlot->dataSize)
hPlot->plotInd -= hPlot->dataSize;
if(hPlot->plotInd < 0)
hPlot->plotInd += hPlot->dataSize;
}
}
/* Функция инвертирования прямоугольной области */
@@ -679,11 +688,7 @@ void __GFX_Draw_Circle_Filled(uint8_t *Buffer_Frame, int8_t xPos, int8_t yPos, i
}
/* функция рисования треугольника */
void __GFX_Draw_Triangle(uint8_t *Buffer_Frame,
uint8_t xPos1, uint8_t yPos1,
uint8_t xPos2, uint8_t yPos2,
uint8_t xPos3, uint8_t yPos3,
uint8_t pxColor)
void __GFX_Draw_Triangle(uint8_t *Buffer_Frame, uint8_t xPos1, uint8_t yPos1, uint8_t xPos2, uint8_t yPos2, uint8_t xPos3, uint8_t yPos3, uint8_t pxColor)
{
__GFX_Draw_Line(Buffer_Frame, xPos1, yPos1, xPos2, yPos2, pxColor);
__GFX_Draw_Line(Buffer_Frame, xPos2, yPos2, xPos3, yPos3, pxColor);

View File

@@ -126,7 +126,7 @@ void GFX_Draw_Circle(uint8_t *Buffer_Frame, GFX_CircleHandleTypeDef *hCircle);
void GFX_Draw_Triangle(uint8_t *Buffer_Frame, GFX_TriangleHandleTypeDef *hTriangle);
void GFX_Draw_Arrow(uint8_t *Buffer_Frame, GFX_ArrowHandleTypeDef *hArrow);
void GFX_Draw_Arc(uint8_t *Buffer_Frame, GFX_ArcHandleTypeDef *hArc);
void GFX_Draw_Plotter(uint8_t *Buffer_Frame, GFX_PlotterFloatHandleTypeDef *hPlot);
void GFX_FloatPlotter(uint8_t *Buffer_Frame, GFX_PlotterFloatHandleTypeDef *hPlot, float *numb2plot);