Функция рисования графика перенесена в gfx_lib и автоматизирована
This commit is contained in:
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user