前面的帖子用板载的framebuffer HDMI输出显示了诸如文字/JPG图片/GIF图片等内容,这次来显示一下模拟和数字信号采集系统中常用的两种图表——波形图和折线图,波形图一般用于显示模拟信号,其特点是可以使用横纵坐标系表达时间-信号强度关系(即时分图)和频率-信号强度关系(频分图),其中时分图使用广泛,表达意思明确,而频分图需要时分图使用FFT算法进行转换,算是一种二次转换图,理解起来需要一定的信号基础,本帖我就简单描绘一个正弦波的时分图。绘制波形图和折线图,能很好地评测 arm开发板的GPU图形绘制性能。
先看代码:
- void LCD_Waveform_Graph_Whole_Add_Single(int x[WAVE_GRAPH_EDGE_TOTAL_WIDTH] , int color_back , int color_line ,
- int color_point , int point_size)
- {
- int i = 0 , j = 0;
- for(i = 0 ; i < WAVE_GRAPH_EDGE_TOTAL_WIDTH ; i ++)
- {
- if(x[i] < 0)
- x[i] = 0;
- if(x[i] > 399)
- x[i] = 399;
- }
- for(j = WAVE_GRAPH_EDGE_START_WIDTH ; j < WAVE_GRAPH_EDGE_END_WIDTH ; j++)
- for(i = WAVE_GRAPH_EDGE_START_HEIGHT ; i < WAVE_GRAPH_EDGE_END_HEIGHT ; i++)
- {
- framebuffer_lcd[i * LCD_WIDTH + j] = color_back;
- }
- LCD_Draw_Line(WAVE_GRAPH_EDGE_START_WIDTH , WAVE_GRAPH_EDGE_START_HEIGHT , WAVE_GRAPH_EDGE_END_WIDTH , WAVE_GRAPH_EDGE_START_HEIGHT , color_line , point_size);
- LCD_Draw_Line(WAVE_GRAPH_EDGE_START_WIDTH , WAVE_GRAPH_EDGE_START_HEIGHT + 100 , WAVE_GRAPH_EDGE_END_WIDTH , WAVE_GRAPH_EDGE_START_HEIGHT + 100 , color_line , point_size);
- LCD_Draw_Line(WAVE_GRAPH_EDGE_START_WIDTH , WAVE_GRAPH_EDGE_START_HEIGHT + 200 , WAVE_GRAPH_EDGE_END_WIDTH , WAVE_GRAPH_EDGE_START_HEIGHT + 200 , color_line , point_size);
- LCD_Draw_Line(WAVE_GRAPH_EDGE_START_WIDTH , WAVE_GRAPH_EDGE_START_HEIGHT + 300 , WAVE_GRAPH_EDGE_END_WIDTH , WAVE_GRAPH_EDGE_START_HEIGHT + 300 , color_line , point_size);
- LCD_Draw_Line(WAVE_GRAPH_EDGE_START_WIDTH , WAVE_GRAPH_EDGE_START_HEIGHT + 400 , WAVE_GRAPH_EDGE_END_WIDTH , WAVE_GRAPH_EDGE_START_HEIGHT + 400 , color_line , point_size);
- LCD_Draw_Line(WAVE_GRAPH_EDGE_START_WIDTH , WAVE_GRAPH_EDGE_START_HEIGHT , 100 , WAVE_GRAPH_EDGE_END_HEIGHT , color_line , point_size);
- LCD_Draw_Line(WAVE_GRAPH_EDGE_START_WIDTH + 100 , WAVE_GRAPH_EDGE_START_HEIGHT , 200 , WAVE_GRAPH_EDGE_END_HEIGHT , color_line , point_size);
- LCD_Draw_Line(WAVE_GRAPH_EDGE_START_WIDTH + 200 , WAVE_GRAPH_EDGE_START_HEIGHT , 300 , WAVE_GRAPH_EDGE_END_HEIGHT , color_line , point_size);
- LCD_Draw_Line(WAVE_GRAPH_EDGE_START_WIDTH + 300 , WAVE_GRAPH_EDGE_START_HEIGHT , 400 , WAVE_GRAPH_EDGE_END_HEIGHT , color_line , point_size);
- LCD_Draw_Line(WAVE_GRAPH_EDGE_START_WIDTH + 400 , WAVE_GRAPH_EDGE_START_HEIGHT , 500 , WAVE_GRAPH_EDGE_END_HEIGHT , color_line , point_size);
- LCD_Draw_Line(WAVE_GRAPH_EDGE_START_WIDTH + 500 , WAVE_GRAPH_EDGE_START_HEIGHT , 600 , WAVE_GRAPH_EDGE_END_HEIGHT , color_line , point_size);
- LCD_Draw_Line(WAVE_GRAPH_EDGE_START_WIDTH + 600 , WAVE_GRAPH_EDGE_START_HEIGHT , 700 , WAVE_GRAPH_EDGE_END_HEIGHT , color_line , point_size);
- LCD_Draw_Line(WAVE_GRAPH_EDGE_START_WIDTH + 700 , WAVE_GRAPH_EDGE_START_HEIGHT , 800 , WAVE_GRAPH_EDGE_END_HEIGHT , color_line , point_size);
- LCD_Draw_Line(WAVE_GRAPH_EDGE_START_WIDTH + 800 , WAVE_GRAPH_EDGE_START_HEIGHT , 900 , WAVE_GRAPH_EDGE_END_HEIGHT , color_line , point_size);
- LCD_Draw_Line(WAVE_GRAPH_EDGE_START_WIDTH + 900 , WAVE_GRAPH_EDGE_START_HEIGHT , 1000 , WAVE_GRAPH_EDGE_END_HEIGHT , color_line , point_size);
- LCD_Draw_Line(WAVE_GRAPH_EDGE_START_WIDTH + 1000 , WAVE_GRAPH_EDGE_START_HEIGHT , 1100 , WAVE_GRAPH_EDGE_END_HEIGHT , color_line , point_size);
- LCD_Draw_Line(WAVE_GRAPH_EDGE_START_WIDTH + 1100 , WAVE_GRAPH_EDGE_START_HEIGHT , 1200 , WAVE_GRAPH_EDGE_END_HEIGHT , color_line , point_size);
- LCD_Draw_Line(WAVE_GRAPH_EDGE_START_WIDTH + 1200 , WAVE_GRAPH_EDGE_START_HEIGHT , 1300 , WAVE_GRAPH_EDGE_END_HEIGHT , color_line , point_size);
- LCD_Draw_Line(WAVE_GRAPH_EDGE_START_WIDTH + 1300 , WAVE_GRAPH_EDGE_START_HEIGHT , 1400 , WAVE_GRAPH_EDGE_END_HEIGHT , color_line , point_size);
- LCD_Draw_Line(WAVE_GRAPH_EDGE_START_WIDTH + 1400 , WAVE_GRAPH_EDGE_START_HEIGHT , 1500 , WAVE_GRAPH_EDGE_END_HEIGHT , color_line , point_size);
- LCD_Draw_Line(WAVE_GRAPH_EDGE_START_WIDTH + 1500 , WAVE_GRAPH_EDGE_START_HEIGHT , 1600 , WAVE_GRAPH_EDGE_END_HEIGHT , color_line , point_size);
- LCD_Draw_Line(WAVE_GRAPH_EDGE_START_WIDTH + 1600 , WAVE_GRAPH_EDGE_START_HEIGHT , 1700 , WAVE_GRAPH_EDGE_END_HEIGHT , color_line , point_size);
- for(i = 0 ; i < WAVE_GRAPH_EDGE_TOTAL_WIDTH - 1 ; i++)
- {
- LCD_Draw_Pixel(i + WAVE_GRAPH_EDGE_START_WIDTH , WAVE_GRAPH_EDGE_END_HEIGHT - x[i] , color_point , point_size);
- LCD_Draw_Line(i + WAVE_GRAPH_EDGE_START_WIDTH , WAVE_GRAPH_EDGE_END_HEIGHT - x[i] ,
- i + WAVE_GRAPH_EDGE_START_WIDTH + 1 , WAVE_GRAPH_EDGE_END_HEIGHT - x[i + 1] , color_point , point_size);
- }
- }
复制代码
- void * Thread_ADC(void *arg)
- {
- LCD_Show_ASCII_32(100 , 400 , 0 , LCD_COLOR_CYAN_32 , '0');
- LCD_Show_ASCII_String_64(0 , 960 , 0 , LCD_COLOR_CYAN_32 , "0");
- LCD_Show_ASCII_String_64(0 , 850 , 0 , LCD_COLOR_CYAN_32 , "100");
- LCD_Show_ASCII_String_64(0 , 750 , 0 , LCD_COLOR_CYAN_32 , "200");
- LCD_Show_ASCII_String_64(0 , 650 , 0 , LCD_COLOR_CYAN_32 , "300");
- LCD_Show_ASCII_String_64(0 , 550 , 0 , LCD_COLOR_CYAN_32 , "400");
- while(1)
- {
- int buf[WAVE_GRAPH_EDGE_TOTAL_WIDTH] , i;
- for(i = 0 ; i < WAVE_GRAPH_EDGE_TOTAL_WIDTH ; i ++)
- {
- buf[i] = (int)(cos((i + count) * 3 / 180.0) * 200 + 200) % 400;
- }
- count ++;
- if(count == 10000)
- count = 0;
- LCD_Waveform_Graph_Whole_Add_Single(buf , 0 , LCD_COLOR_GREEN_32 , LCD_COLOR_RED_32 , 2);
- LCD_Line_Chart_Add_Double(dht11_temp , dht11_humi , LCD_COLOR_WHITE_32 , 0 , LCD_COLOR_PURPLE_32 , LCD_COLOR_RED_32 , 26 , LINE_CHART_EDGE_END_HEIGHT);
-
- LCD_Effect(FB_DEV);
- }
- }
复制代码
绘制波形图大概有三步:
-绘制矩形背景,使用背景色填充
-绘制横纵坐标系网格
-填入信号强度波形,可以选择从左至右填充或从右至左填充,一般人好理解的方式是从左至右填充,新数据从右边出现
而绘制波形图新增数据的方式又有两种:
-整帧填充,一下填充全部数据
-逐个填充,每填充一个就将前面的数据左移一格,最左边数据丢弃
我这次使用的新增数据的方式为第一种。查看效果:
然后是折线图,折线图的显示相比起波形图要简单很多,就是每次增加一个点的数据,然后每填充一个就将前面的数据左移一格,最左边数据丢弃,而折线图同时显示的数据量也不会很多,不像波形图那么多,十几个到二十几个就够了,折线图所描绘的数据一般是那种采集量不需要很大的数据如温度或者湿度:
- void LCD_Line_Chart_Add_Double(int x1 , int x2 , int color_back , int color_line , int color_point1 ,
- int color_point2 , int x_point_num , int y_edge)
- {
- int i = 0 , j = 0;
- if(x1<0)
- x1 = 0;
- if(x1>100)
- x1 = 100;
- if(x2<0)
- x2 = 0;
- if(x2>100)
- x2 = 100;
- for(j = LINE_CHART_EDGE_START_WIDTH ; j < LINE_CHART_EDGE_END_WIDTH ; j++)
- for(i = LINE_CHART_EDGE_START_HEIGHT ; i < LINE_CHART_EDGE_END_HEIGHT ; i++)
- {
- framebuffer_lcd[i * LCD_WIDTH + j] = color_back;
- }
- LCD_Draw_Line(LINE_CHART_EDGE_START_WIDTH , LINE_CHART_EDGE_START_HEIGHT , LINE_CHART_EDGE_START_WIDTH , y_edge , color_line , 1);
- LCD_Draw_Line(LINE_CHART_EDGE_START_WIDTH , y_edge , LINE_CHART_EDGE_END_WIDTH , y_edge , color_line , 1);
- for(i=0;i<=27;i++)
- line_chart_data1[i] = line_chart_data1[i+1];
- line_chart_data1[x_point_num] = x1;
- for(i=0;i<=27;i++)
- line_chart_data2[i] = line_chart_data2[i+1];
- line_chart_data2[x_point_num] = x2;
- for(i = 0 ; i <= x_point_num ; i++)
- {
- LCD_Draw_Pixel(5 + LINE_CHART_EDGE_START_WIDTH + 30 * i , y_edge - line_chart_data1[i] * 3 - 5 , color_point1 , 5);
- LCD_Draw_Pixel(5 + LINE_CHART_EDGE_START_WIDTH + 30 * i , y_edge - line_chart_data2[i] * 3 - 5 , color_point2 , 5);
- if(i != x_point_num)
- {
- LCD_Draw_Line(5 + LINE_CHART_EDGE_START_WIDTH + 30 * i ,
- y_edge - line_chart_data1[i] * 3 - 3 ,
- 5 + LINE_CHART_EDGE_START_WIDTH + 30*(i + 1),
- y_edge - line_chart_data1[i+1] * 3 - 3 ,
- color_point1 ,
- 1);
- LCD_Draw_Line(5 + LINE_CHART_EDGE_START_WIDTH + 30 * i ,
- y_edge - line_chart_data2[i] * 3 - 3 ,
- 5 + LINE_CHART_EDGE_START_WIDTH + 30 * (i + 1),
- y_edge - line_chart_data2[i+1] * 3 - 3 ,
- color_point2 ,
- 1);
- }
- }
- LCD_Show_ASCII_32(LINE_CHART_EDGE_END_WIDTH , y_edge - line_chart_data1[x_point_num] * 3 - 15 , color_point1 , LCD_COLOR_CYAN_32 , x1 / 10 + '0');
- LCD_Show_ASCII_32(LINE_CHART_EDGE_END_WIDTH + 16 , y_edge - line_chart_data1[x_point_num] * 3 - 15 , color_point1 , LCD_COLOR_CYAN_32 , x1 % 10 + '0');
- LCD_Show_ASCII_32(LINE_CHART_EDGE_END_WIDTH + 48 , y_edge - line_chart_data2[x_point_num] * 3 - 15 , color_point2 , LCD_COLOR_CYAN_32 , x2 / 10 + '0');
- LCD_Show_ASCII_32(LINE_CHART_EDGE_END_WIDTH + 64 , y_edge - line_chart_data2[x_point_num] * 3 - 15 , color_point2 , LCD_COLOR_CYAN_32 , x2 % 10 + '0');
- }
复制代码
如图所示,红色点为湿度数据,紫色点为温度数据。
0
|
|
|
|