Функция рисования графика перенесена в gfx_lib и автоматизирована

This commit is contained in:
2025-02-21 12:19:14 +03:00
parent 411b9c2cf0
commit d58273fe41
9 changed files with 461 additions and 187 deletions

View File

@@ -3,15 +3,15 @@
int menu_white_theme = 0;
//#define SINE_EXAMPLE
//#define ECG_EXAMPLE
#define PLAYER_EXAMPLE
#define ECG_EXAMPLE
//#define PLAYER_EXAMPLE
#define ECG_SIZE 550
// Примерный массив, симулирующий ЭКГ-сигнал (нормализованный от 0 до 1)
const float ecg_data[ECG_SIZE] = {1.05893, 0.999357, 0.933132, 0.744792, 0.664672, 0.328846, 0.136133, -0.00837916, -0.131494,
float ecg_data[ECG_SIZE] = {1.05893, 0.999357, 0.933132, 0.744792, 0.664672, 0.328846, 0.136133, -0.00837916, -0.131494,
-0.1437, -0.182276, -0.215992, -0.128979, -0.131278, -0.0675223, 0.0027252, 0.0467067, -0.078859, -0.0658536, 0.0626352,
-0.0462435, 0.0476623, 0.0535328, 0.122938, 0.0501136, 0.034033, 0.0919253, 0.108374, 0.0667457, 0.0351678, -0.00115748,
0.0896459, 0.0288452, -0.0102636, 0.136738, 0.0397245, 0.0856079, 0.141222, 0.0826385, 0.165799, 0.105852, 0.172638,
@@ -63,94 +63,15 @@ const float ecg_data[ECG_SIZE] = {1.05893, 0.999357, 0.933132, 0.744792, 0.66467
void GFX_Draw_LoopIcon(uint8_t *Buffer_Frame, uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t pxColor);
GFXIconsTypeDef icons;
void Example_GFX_IconInit(void)
{
// play
icons.StopPlay.stop.xPos1 = play_icon_x_left-1;
icons.StopPlay.stop.yPos1 = play_icon_y_up;
icons.StopPlay.stop.xPos2 = play_icon_x_left-1;
icons.StopPlay.stop.yPos2 = play_icon_y_down;
icons.StopPlay.stop.xPos3 = play_icon_x_rigth+1;
icons.StopPlay.stop.yPos3 = play_icon_y_mid;
icons.StopPlay.stop.pxColor = 1;
// stop
icons.StopPlay.play_lines[0].xPos_Start = play_icon_x_left+1;
icons.StopPlay.play_lines[0].yPos_Start = play_icon_y_up;
icons.StopPlay.play_lines[0].xPos_End = play_icon_x_left+1;
icons.StopPlay.play_lines[0].yPos_End = play_icon_y_down;
icons.StopPlay.play_lines[0].pxColor = 1;
icons.StopPlay.play_lines[1].xPos_Start = play_icon_x_rigth;
icons.StopPlay.play_lines[1].yPos_Start = play_icon_y_up;
icons.StopPlay.play_lines[1].xPos_End = play_icon_x_rigth;
icons.StopPlay.play_lines[1].yPos_End = play_icon_y_down;
icons.StopPlay.play_lines[1].pxColor = 1;
// stop/play pressed
icons.StopPlay.PressedArea.selected_Width = selected_width;
icons.StopPlay.PressedArea.xPos_Start = play_icon_x_left-1-selected_width;
icons.StopPlay.PressedArea.yPos_Start = play_icon_y_up-selected_width;
icons.StopPlay.PressedArea.area_Width = play_icon_x_rigth+2-(play_icon_x_left-1)+2*selected_width+1;
icons.StopPlay.PressedArea.area_Height = play_icon_y_down-play_icon_y_up+2*selected_width+1;
// forward
icons.Forward.line.xPos_Start = forward_icon_x_rigth;
icons.Forward.line.yPos_Start = forward_icon_y_up;
icons.Forward.line.xPos_End = forward_icon_x_rigth;
icons.Forward.line.yPos_End = forward_icon_y_down;
icons.Forward.line.pxColor = 1;
icons.Forward.trig.xPos1 = forward_icon_x_left;
icons.Forward.trig.yPos1 = forward_icon_y_up;
icons.Forward.trig.xPos2 = forward_icon_x_left;
icons.Forward.trig.yPos2 = forward_icon_y_down;
icons.Forward.trig.xPos3 = forward_icon_x_rigth-1;
icons.Forward.trig.yPos3 = forward_icon_y_mid;
icons.Forward.trig.pxColor = 1;
// forward pressed
icons.Forward.PressedArea.selected_Width = selected_width;
icons.Forward.PressedArea.xPos_Start = forward_icon_x_left-selected_width;
icons.Forward.PressedArea.yPos_Start = forward_icon_y_up-selected_width;
icons.Forward.PressedArea.area_Width = forward_icon_x_rigth-(forward_icon_x_left)+2*selected_width+1;
icons.Forward.PressedArea.area_Height = forward_icon_y_down-forward_icon_y_up+2*selected_width+1;
// backward
icons.Backward.line.xPos_Start = backward_icon_x_left;
icons.Backward.line.yPos_Start = backward_icon_y_up;
icons.Backward.line.xPos_End = backward_icon_x_left;
icons.Backward.line.yPos_End = backward_icon_y_down;
icons.Backward.line.pxColor = 1;
icons.Backward.trig.xPos1 = backward_icon_x_rigth;
icons.Backward.trig.yPos1 = backward_icon_y_up;
icons.Backward.trig.xPos2 = backward_icon_x_rigth;
icons.Backward.trig.yPos2 = backward_icon_y_down;
icons.Backward.trig.xPos3 = backward_icon_x_left+1;
icons.Backward.trig.yPos3 = backward_icon_y_mid;
icons.Backward.trig.pxColor = 1;
// backward pressed
icons.Backward.PressedArea.xPos_Start = backward_icon_x_left-selected_width;
icons.Backward.PressedArea.yPos_Start = backward_icon_y_up-selected_width;
icons.Backward.PressedArea.area_Width = backward_icon_x_rigth-(backward_icon_x_left)+2*selected_width+1;
icons.Backward.PressedArea.area_Height = backward_icon_y_down-backward_icon_y_up+2*selected_width+1;
// loop
icons.Loop.xPos_Start = loop_icon_x_start;
icons.Loop.yPos_Start = loop_icon_y_start;
icons.Loop.icon_Width = loop_icon_width;
icons.Loop.icon_Height = loop_icon_height;
// loop pressed
icons.Loop.PressedArea.xPos_Start = loop_icon_x_start+3;
icons.Loop.PressedArea.yPos_Start = loop_icon_y_start+3;
icons.Loop.PressedArea.area_Width = loop_icon_width-5;
icons.Loop.PressedArea.area_Height = loop_icon_height-5;
// иконка зацикливания
GFX_Draw_LoopIcon(oled_buf, loop_icon_x_start, loop_icon_y_start, loop_icon_width, loop_icon_height, 1);
}
GFX_PlotterFloatHandleTypeDef plotter;
void Example_GFX_Init(void)
{
Example_GFX_PlotterInit();
Example_GFX_IconInit();
oled_init();
}
void Example_OLED_GFX_Update(PlayerTypeDef *player)
{
@@ -170,54 +91,11 @@ float ecg_cnt_step = 1;
float ecg_scale = 16;
void Example_GFX_CreateFrame(PlayerTypeDef *player)
{
#if defined(SINE_EXAMPLE) || defined(ECG_EXAMPLE)
static float sine_cnt;
static int display_cnt;
static int pix_y_prev = 0;
#if defined(SINE_EXAMPLE) || defined(ECG_EXAMPLE)
GFX_Draw_Plotter(oled_buf, &plotter);
#if defined(SINE_EXAMPLE)
int pix_y = (int)((float)(sinf(sine_cnt)+shift)*((float)32/(1+shift)));
#elif defined(ECG_EXAMPLE)
int pix_y = (ecg_data[(int)ecg_cnt]*ecg_scale)+16;
ecg_cnt += ecg_cnt_step;
if(ecg_cnt > ECG_SIZE)
ecg_cnt = 0;
#endif
if(pix_y - pix_y_prev > 0)
{
for(int y = pix_y_prev+1; y <= pix_y; y++)
{
if(y<=32)
GFX_Draw_Pixel(oled_buf, display_cnt, 32 - y, 1);
}
}
else if (pix_y - pix_y_prev < 0)
{
for(int y = pix_y_prev-1; y >= pix_y; y--)
{
if(y<=32)
GFX_Draw_Pixel(oled_buf, display_cnt, 32 - y, 1);
}
}
else
GFX_Draw_Pixel(oled_buf, display_cnt, 32 - pix_y, 1);
display_cnt++;
sine_cnt += sine_cnt_step;
pix_y_prev = pix_y;
if(display_cnt>GFX_BufferWidth)
{
display_cnt = 0;
GFX_Clean_Buffer_Frame(oled_buf, sizeof(oled_buf));
}
#elif defined(PLAYER_EXAMPLE)
GFX_Clean_Buffer_Frame(oled_buf, sizeof(oled_buf));
GFX_Clean_Buffer_Frame(oled_buf);
// название песни
GFX_Output_String(oled_buf, 0, 0, "Harry Potter Theme", 0, 0);
@@ -312,3 +190,115 @@ void GFX_Draw_LoopIcon(uint8_t *Buffer_Frame, uint8_t x, uint8_t y, uint8_t widt
__GFX_Draw_Line(Buffer_Frame, x + r+spot_width, y + height, x + r + arr_size+spot_width, y + height - arr_size, pxColor); // Нижняя стрелка
__GFX_Draw_Line(Buffer_Frame, x + r+spot_width, y + height, x + r + arr_size+spot_width, y + height + arr_size, pxColor);
}
void Example_GFX_PlotterInit(void)
{
plotter.xPos = 2;
plotter.yPos = 0;
plotter.plotWidth = 120;
plotter.plotHeight = 32;
plotter.plotXAxis = 1;
plotter.plotYAxis = 1;
#if defined(SINE_EXAMPLE)
int pix_y = (int)((float)(sinf(sine_cnt)+shift)*((float)32/(1+shift)));
#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
}
void Example_GFX_IconInit(void)
{
// play
icons.StopPlay.stop.xPos1 = play_icon_x_left-1;
icons.StopPlay.stop.yPos1 = play_icon_y_up;
icons.StopPlay.stop.xPos2 = play_icon_x_left-1;
icons.StopPlay.stop.yPos2 = play_icon_y_down;
icons.StopPlay.stop.xPos3 = play_icon_x_rigth+1;
icons.StopPlay.stop.yPos3 = play_icon_y_mid;
icons.StopPlay.stop.pxColor = 1;
// stop
icons.StopPlay.play_lines[0].xPos_Start = play_icon_x_left+1;
icons.StopPlay.play_lines[0].yPos_Start = play_icon_y_up;
icons.StopPlay.play_lines[0].xPos_End = play_icon_x_left+1;
icons.StopPlay.play_lines[0].yPos_End = play_icon_y_down;
icons.StopPlay.play_lines[0].pxColor = 1;
icons.StopPlay.play_lines[1].xPos_Start = play_icon_x_rigth;
icons.StopPlay.play_lines[1].yPos_Start = play_icon_y_up;
icons.StopPlay.play_lines[1].xPos_End = play_icon_x_rigth;
icons.StopPlay.play_lines[1].yPos_End = play_icon_y_down;
icons.StopPlay.play_lines[1].pxColor = 1;
// stop/play pressed
icons.StopPlay.PressedArea.selected_Width = selected_width;
icons.StopPlay.PressedArea.xPos_Start = play_icon_x_left-1-selected_width;
icons.StopPlay.PressedArea.yPos_Start = play_icon_y_up-selected_width;
icons.StopPlay.PressedArea.area_Width = play_icon_x_rigth+2-(play_icon_x_left-1)+2*selected_width+1;
icons.StopPlay.PressedArea.area_Height = play_icon_y_down-play_icon_y_up+2*selected_width+1;
// forward
icons.Forward.line.xPos_Start = forward_icon_x_rigth;
icons.Forward.line.yPos_Start = forward_icon_y_up;
icons.Forward.line.xPos_End = forward_icon_x_rigth;
icons.Forward.line.yPos_End = forward_icon_y_down;
icons.Forward.line.pxColor = 1;
icons.Forward.trig.xPos1 = forward_icon_x_left;
icons.Forward.trig.yPos1 = forward_icon_y_up;
icons.Forward.trig.xPos2 = forward_icon_x_left;
icons.Forward.trig.yPos2 = forward_icon_y_down;
icons.Forward.trig.xPos3 = forward_icon_x_rigth-1;
icons.Forward.trig.yPos3 = forward_icon_y_mid;
icons.Forward.trig.pxColor = 1;
// forward pressed
icons.Forward.PressedArea.selected_Width = selected_width;
icons.Forward.PressedArea.xPos_Start = forward_icon_x_left-selected_width;
icons.Forward.PressedArea.yPos_Start = forward_icon_y_up-selected_width;
icons.Forward.PressedArea.area_Width = forward_icon_x_rigth-(forward_icon_x_left)+2*selected_width+1;
icons.Forward.PressedArea.area_Height = forward_icon_y_down-forward_icon_y_up+2*selected_width+1;
// backward
icons.Backward.line.xPos_Start = backward_icon_x_left;
icons.Backward.line.yPos_Start = backward_icon_y_up;
icons.Backward.line.xPos_End = backward_icon_x_left;
icons.Backward.line.yPos_End = backward_icon_y_down;
icons.Backward.line.pxColor = 1;
icons.Backward.trig.xPos1 = backward_icon_x_rigth;
icons.Backward.trig.yPos1 = backward_icon_y_up;
icons.Backward.trig.xPos2 = backward_icon_x_rigth;
icons.Backward.trig.yPos2 = backward_icon_y_down;
icons.Backward.trig.xPos3 = backward_icon_x_left+1;
icons.Backward.trig.yPos3 = backward_icon_y_mid;
icons.Backward.trig.pxColor = 1;
// backward pressed
icons.Backward.PressedArea.xPos_Start = backward_icon_x_left-selected_width;
icons.Backward.PressedArea.yPos_Start = backward_icon_y_up-selected_width;
icons.Backward.PressedArea.area_Width = backward_icon_x_rigth-(backward_icon_x_left)+2*selected_width+1;
icons.Backward.PressedArea.area_Height = backward_icon_y_down-backward_icon_y_up+2*selected_width+1;
// loop
icons.Loop.xPos_Start = loop_icon_x_start;
icons.Loop.yPos_Start = loop_icon_y_start;
icons.Loop.icon_Width = loop_icon_width;
icons.Loop.icon_Height = loop_icon_height;
// loop pressed
icons.Loop.PressedArea.xPos_Start = loop_icon_x_start+3;
icons.Loop.PressedArea.yPos_Start = loop_icon_y_start+3;
icons.Loop.PressedArea.area_Width = loop_icon_width-5;
icons.Loop.PressedArea.area_Height = loop_icon_height-5;
// иконка зацикливания
GFX_Draw_LoopIcon(oled_buf, loop_icon_x_start, loop_icon_y_start, loop_icon_width, loop_icon_height, 1);
}

View File

@@ -105,6 +105,8 @@ typedef struct
}GFXIconsTypeDef;
void Example_GFX_Init(void);
void Example_GFX_PlotterInit(void);
void Example_GFX_IconInit(void);
void Example_GFX_CreateFrame(PlayerTypeDef *player);
void Example_OLED_GFX_Update(PlayerTypeDef *player);

View File

@@ -17,13 +17,35 @@
uint8_t chSpacing = 0; //межсимвольный интервал в px
/* функция очистки буфера кадра */
void GFX_Clean_Buffer_Frame(uint8_t *Buffer_Frame, uint32_t Buffer_Frame_Size)
void GFX_Clean_Buffer_Frame(uint8_t *Buffer_Frame)
{
if(Buffer_Frame == NULL)
return;
memset(Buffer_Frame, 0x00, Buffer_Frame_Size);
memset(Buffer_Frame, 0x00, GFX_BufferHeight*GFX_BufferWidth/8);
}
/* Функция очистки прямоугольной области */
void GFX_Clean_Area(uint8_t *Buffer_Frame, uint16_t xPos_Start, uint16_t yPos_Start, uint16_t width, uint16_t height)
{
if(Buffer_Frame == NULL)
return;
if ((xPos_Start+width > GFX_BufferWidth)||(xPos_Start < 0)||(yPos_Start+ height> GFX_BufferHeight)||(yPos_Start < 0))
{
//если значения по x и y больше пределов то выходим из функции
return;
}
for (uint16_t xPos = xPos_Start; xPos < xPos_Start + width; xPos++)
{
for(uint16_t yPos = yPos_Start; yPos < yPos_Start + height; yPos++)
{
uint16_t arrayPos = xPos + ((yPos/8)*GFX_BufferWidth);
Buffer_Frame[arrayPos] &= ~(1 << (yPos % 8)); // Очищаем бит, отвечающий за пиксель
}
}
}
/* функция прорисовки пикселя */
void GFX_Draw_Pixel(uint8_t *Buffer_Frame, uint8_t xPos, uint8_t yPos, uint8_t pxColor)
{
@@ -377,6 +399,17 @@ void GFX_Draw_Triangle(uint8_t *Buffer_Frame, GFX_TriangleHandleTypeDef *hTriang
__GFX_Draw_Line(Buffer_Frame, xPos2, yPos2, xPos3, yPos3, pxColor);
__GFX_Draw_Line(Buffer_Frame, xPos3, yPos3, xPos1, yPos1, pxColor);
}
/* функция рисования стрелки */
void GFX_Draw_Arrow(uint8_t *Buffer_Frame, GFX_ArrowHandleTypeDef *hArrow)
{
uint8_t xPos = hArrow->xPos;
uint8_t yPos = hArrow->yPos;
uint8_t size = hArrow->size;
uint16_t angle = hArrow->angle;
uint8_t pxColor = hArrow->pxColor;
__GFX_Draw_Arrow(Buffer_Frame, xPos, yPos, size, angle, pxColor);
}
/* Функция рисования дуги (четверти окружности) */
void GFX_Draw_Arc(uint8_t *Buffer_Frame, GFX_ArcHandleTypeDef *hArc)
@@ -401,6 +434,116 @@ void GFX_Draw_Arc(uint8_t *Buffer_Frame, GFX_ArcHandleTypeDef *hArc)
}
}
/* Функция вывода графика */
void GFX_Draw_Plotter(uint8_t *Buffer_Frame, GFX_PlotterFloatHandleTypeDef *hPlot)
{
if((Buffer_Frame == NULL) || (hPlot == NULL))
return;
if((hPlot->plotHeight == NULL) || (hPlot->plotWidth == NULL))
return;
if((hPlot->yPos + hPlot->plotHeight == NULL) || (hPlot->xPos + hPlot->plotWidth == NULL))
return;
if(hPlot->__initialized == 0)
{
hPlot->__initialized = 1;
hPlot->plotInd = 0;
GFX_Clean_Buffer_Frame(Buffer_Frame);
if(hPlot->plotXAxis)
{
__GFX_Draw_Line(Buffer_Frame, hPlot->xPos, hPlot->yPos+hPlot->plotHeight/2, hPlot->xPos+hPlot->plotWidth-1, hPlot->yPos+hPlot->plotHeight/2, 1);
__GFX_Draw_Arrow(Buffer_Frame, hPlot->xPos+hPlot->plotWidth-1, hPlot->yPos+hPlot->plotHeight/2, 2, 0, 1);
}
if(hPlot->plotYAxis)
{
__GFX_Draw_Line(Buffer_Frame, hPlot->xPos, hPlot->yPos, hPlot->xPos, hPlot->yPos+hPlot->plotHeight-1, 1);
__GFX_Draw_Arrow(Buffer_Frame, hPlot->xPos, hPlot->yPos, 2, 90, 1);
}
if(hPlot->plotFrame)
{
__GFX_Draw_Rectangle(Buffer_Frame, hPlot->xPos, hPlot->yPos, hPlot->plotWidth-1, hPlot->plotHeight-1, 1);
}
}
/* Подготовка к выводу графика */
if((hPlot->pixX < hPlot->xPos) || (hPlot->pixX >= hPlot->plotWidth))
{
hPlot->pixX = hPlot->xPos;
GFX_Clean_Area(Buffer_Frame, hPlot->xPos, hPlot->yPos, hPlot->plotWidth, hPlot->plotHeight);
if(hPlot->plotXAxis)
{
__GFX_Draw_Line(Buffer_Frame, hPlot->xPos, hPlot->yPos+hPlot->plotHeight/2, hPlot->xPos+hPlot->plotWidth-1, hPlot->yPos+hPlot->plotHeight/2, 1);
__GFX_Draw_Arrow(Buffer_Frame, hPlot->xPos+hPlot->plotWidth-1, hPlot->yPos+hPlot->plotHeight/2, 2, 0, 1);
}
if(hPlot->plotYAxis)
{
__GFX_Draw_Line(Buffer_Frame, hPlot->xPos, hPlot->yPos, hPlot->xPos, hPlot->yPos+hPlot->plotHeight-1, 1);
__GFX_Draw_Arrow(Buffer_Frame, hPlot->xPos, hPlot->yPos, 2, 90, 1);
}
if(hPlot->plotFrame)
{
__GFX_Draw_Rectangle(Buffer_Frame, hPlot->xPos, hPlot->yPos, hPlot->plotWidth-1, hPlot->plotHeight-1, 1);
}
}
/* Расчет позиции пикселя */
float pix_y_float = (hPlot->pDataPtr[(int)hPlot->plotInd]);
// масштабирование под размеры графика
hPlot->pixY = (pix_y_float/hPlot->dataMax)*(hPlot->plotHeight);
// если график должен быть знаковым, то уменьшаем машстаб еще в два раза
if(hPlot->signedData)
hPlot->pixY = (hPlot->pixY + hPlot->plotHeight)/2;
// инвертирование y потому что он считается сверху вниз
uint8_t plot_y_down = hPlot->yPos + hPlot->plotHeight;
hPlot->pixY = plot_y_down - hPlot->pixY;
// Сдвиг графика
hPlot->pixY += hPlot->plotShift;
/* Вывод пикселя позиции пикселя */
// Передний фронт
if(hPlot->pixY - hPlot->prevPixY > 0)
{
/* Цикл для заполнения пикселей по вертикали, когда фронт очень резкий */
for(int y = hPlot->prevPixY+1; y <= hPlot->pixY; y++)
{
if((y<=hPlot->yPos+hPlot->plotHeight) && (y>=hPlot->yPos))
GFX_Draw_Pixel(Buffer_Frame, hPlot->pixX, y, 1);
}
}// Задний фронт
else if (hPlot->pixY - hPlot->prevPixY < 0)
{
/* Цикл для заполнения пикселей по вертикали, когда фронт очень резкий */
for(int y = hPlot->prevPixY-1; y >= hPlot->pixY; y--)
{
if((y<=hPlot->yPos+hPlot->plotHeight) && (y>=hPlot->yPos))
GFX_Draw_Pixel(Buffer_Frame, hPlot->pixX, y, 1);
}
}// Плато
else
{
if((hPlot->pixY<=hPlot->yPos+hPlot->plotHeight) && (hPlot->pixY>=hPlot->yPos))
GFX_Draw_Pixel(Buffer_Frame, hPlot->pixX, hPlot->pixY, 1);
}
/* Смещение графика далее */
hPlot->pixX++;
hPlot->plotInd += hPlot->plotSpeed;
if(hPlot->plotInd >= hPlot->dataSize)
hPlot->plotInd -= hPlot->dataSize;
if(hPlot->plotInd < 0)
hPlot->plotInd += hPlot->dataSize;
hPlot->prevPixY = hPlot->pixY;
}
/* Функция инвертирования прямоугольной области */
void GFX_Invertion_Display(uint8_t *Buffer_Frame)
{
@@ -547,6 +690,66 @@ void __GFX_Draw_Triangle(uint8_t *Buffer_Frame,
__GFX_Draw_Line(Buffer_Frame, xPos3, yPos3, xPos1, yPos1, pxColor);
}
/* функция рисования стрелки */
void __GFX_Draw_Arrow(uint8_t *Buffer_Frame, uint8_t xPos, uint8_t yPos, uint8_t size, uint16_t angle, uint8_t pxColor)
{
int16_t x1, y1, x2, y2, x3, y3;
if(angle == 0) // >
{
x1 = xPos;
y1 = yPos;
x2 = xPos - size;
y2 = yPos - size;
x3 = xPos - size;
y3 = yPos + size;
}
else if(angle == 180) // <
{
x1 = xPos;
y1 = yPos;
x2 = xPos + size;
y2 = yPos - size;
x3 = xPos + size;
y3 = yPos + size;
}
else if(angle == 270) // ^
{
x1 = xPos;
y1 = yPos;
x2 = xPos - size;
y2 = yPos - size;
x3 = xPos + size;
y3 = yPos - size;
}
else if(angle == 90) // v
{
x1 = xPos;
y1 = yPos;
x2 = xPos - size;
y2 = yPos + size;
x3 = xPos + size;
y3 = yPos + size;
}
if(x1 < 0)
x1 = 0;
if(x2 < 0)
x2 = 0;
if(x3 < 0)
x3 = 0;
if(y1 < 0)
y1 = 0;
if(y2 < 0)
y2 = 0;
if(y3 < 0)
y3 = 0;
__GFX_Draw_Line(Buffer_Frame, x1, y1, x2, y2, pxColor);
__GFX_Draw_Line(Buffer_Frame, x1, y1, x3, y3, pxColor);
}
/* Функция рисования дуги (четверти окружности) */
void __GFX_Draw_Arc(uint8_t *Buffer_Frame, uint8_t xPos, uint8_t yPos, uint8_t radius, uint16_t startAngle, uint16_t endAngle, uint8_t pxColor)
{

View File

@@ -31,8 +31,6 @@ typedef struct
uint8_t yPos_End;
uint8_t pxColor;
}GFX_LineHandleTypeDef;
typedef struct
{
uint8_t xPos_Start;
@@ -51,7 +49,6 @@ typedef struct
uint8_t pxColor;
uint8_t Filled;
}GFX_CircleHandleTypeDef;
typedef struct
{
uint8_t xPos1;
@@ -63,6 +60,17 @@ typedef struct
uint8_t pxColor;
uint8_t Filled;
}GFX_TriangleHandleTypeDef;
typedef struct
{
uint8_t xPos;
uint8_t yPos;
uint8_t size;
uint16_t angle;
uint8_t pxColor;
uint8_t Filled;
}GFX_ArrowHandleTypeDef;
typedef struct
{
uint8_t xPos;
@@ -74,10 +82,36 @@ typedef struct
uint8_t Filled;
}GFX_ArcHandleTypeDef;
typedef struct
{
uint8_t xPos;
uint8_t yPos;
uint8_t plotHeight;
uint8_t plotWidth;
float *pDataPtr;
uint32_t dataSize;
float dataMax;
float plotSpeed;
float plotInd;
uint8_t plotShift;
uint8_t pixX;
int32_t pixY;
uint8_t prevPixY;
unsigned signedData:1;
unsigned plotFrame:1;
unsigned plotXAxis:1;
unsigned plotYAxis:1;
unsigned __initialized:1;
}GFX_PlotterFloatHandleTypeDef;
/* прототипы функций */
void GFX_Clean_Buffer_Frame(uint8_t *Buffer_Frame, uint32_t Buffer_Frame_Size);
void GFX_Clean_Buffer_Frame(uint8_t *Buffer_Frame);
void GFX_Clean_Area(uint8_t *Buffer_Frame, uint16_t xPos_Start, uint16_t yPos_Start, uint16_t width, uint16_t height);
void GFX_Draw_Pixel(uint8_t *Buffer_Frame, uint8_t xPos, uint8_t yPos, uint8_t pxColor);
void GFX_Invertion_Area(uint8_t *Buffer_Frame, uint16_t xPos_Start, uint16_t yPos_Start, uint16_t width, uint16_t height);
void GFX_Invertion_Display(uint8_t *Buffer_Frame);
@@ -90,7 +124,9 @@ void GFX_Draw_Line(uint8_t *Buffer_Frame, GFX_LineHandleTypeDef *hLine);
void GFX_Draw_Rectangle(uint8_t *Buffer_Frame, GFX_RectangleHandleTypeDef *hRectangle);
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);
@@ -104,5 +140,6 @@ void __GFX_Draw_Triangle(uint8_t *Buffer_Frame,
uint8_t xPos2, uint8_t yPos2,
uint8_t xPos3, uint8_t yPos3,
uint8_t pxColor);
void __GFX_Draw_Arrow(uint8_t *Buffer_Frame, uint8_t xPos, uint8_t yPos, uint8_t size, uint16_t angle, uint8_t pxColor);
void __GFX_Draw_Arc(uint8_t *Buffer_Frame, uint8_t xPos, uint8_t yPos, uint8_t radius, uint16_t startAngle, uint16_t endAngle, uint8_t pxColor);
#endif /* INC_PIXEL_GRAPHICS_H_ */

View File

@@ -90,7 +90,7 @@ int main(void)
MX_I2C1_Init();
/* USER CODE BEGIN 2 */
Menu_Control_Init(&player);
Example_GFX_IconInit();
Example_GFX_Init();
/* USER CODE END 2 */
/* Infinite loop */

File diff suppressed because one or more lines are too long

View File

@@ -163,7 +163,7 @@
<Ww>
<count>2</count>
<WinNumber>1</WinNumber>
<ItemText>sine_cnt_step</ItemText>
<ItemText>plotter,0x0A</ItemText>
</Ww>
<Ww>
<count>3</count>
@@ -205,6 +205,21 @@
<WinNumber>1</WinNumber>
<ItemText>ecg_scale</ItemText>
</Ww>
<Ww>
<count>11</count>
<WinNumber>1</WinNumber>
<ItemText>(pix_y_float/hPlot-&gt;dataMax)*(hPlot-&gt;plotHeight),0x0A</ItemText>
</Ww>
<Ww>
<count>12</count>
<WinNumber>1</WinNumber>
<ItemText>-4,0x0A</ItemText>
</Ww>
<Ww>
<count>13</count>
<WinNumber>1</WinNumber>
<ItemText>y,0x0A</ItemText>
</Ww>
</WatchWindow1>
<Tracepoint>
<THDelay>0</THDelay>

View File

@@ -129,7 +129,7 @@ Reset_Handler PROC
EXPORT Reset_Handler [WEAK]
IMPORT __main
IMPORT SystemInit
LDR R0, =SystemInit
1 LDR R0, =SystemInit
BLX R0
LDR R0, =__main
BX R0

View File

@@ -5,5 +5,5 @@
Включает в себя:
- библиотеку для рисования (Core\GFX_Lib)
- библиотеку для I2C OLED дисплея (Core\OLED_Driver)
- библиотеку для SPI OLED дисплея (Core\LCD_Driver) (не сделано пока)
- библиотеку для SPI LCD дисплея (Core\LCD_Driver) (не сделано пока)
- примеры использования (Core\Example) (не сделано пока)