Tearsback's picture
download
raw
6.75 kB
/*********************************************************************************************************
* ģ�����ƣ�GraphWidget.c
* ժ Ҫ�����οؼ�ģ��
* ��ǰ�汾��1.0.0
* �� �ߣ�Leyutek(COPYRIGHT 2018 - 2021 Leyutek. All rights reserved.)
* ������ڣ�2021��07��01��
* �� �ݣ�
* ע �⣺
**********************************************************************************************************
* ȡ���汾��
* �� �ߣ�
* ������ڣ�
* �޸����ݣ�
* �޸��ļ���
*********************************************************************************************************/
/*********************************************************************************************************
* ����ͷ�ļ�
*********************************************************************************************************/
#include "GraphWidget.h"
#include "TLILCD.h"
#include <math.h>
/*********************************************************************************************************
* �궨��
*********************************************************************************************************/
/*********************************************************************************************************
* ö�ٽṹ�嶨��
*********************************************************************************************************/
/*********************************************************************************************************
* �ڲ�����
*********************************************************************************************************/
/*********************************************************************************************************
* �ڲ���������
*********************************************************************************************************/
/*********************************************************************************************************
* �ڲ�����ʵ��
*********************************************************************************************************/
/*********************************************************************************************************
* API����ʵ��
*********************************************************************************************************/
/*********************************************************************************************************
* ��������: CreateGraphWidget
* ��������: �½����λ��ƿؼ�
* �������: x0,y0����ʼ���꣨���Ͻǣ���xSize�����ȣ�ySize���߶ȣ�graph�����οؼ��ṹ��
* �������: void
* �� �� ֵ: void
* ��������: 2021��07��01��
* ע ��: graph���Ǿ�̬�ṹ��
*********************************************************************************************************/
void InitGraphWidgetStruct(StructGraphObj* graph)
{
graph->backColor = 0x0000; //����Ĭ��Ϊ��ɫ
graph->penColor = 0x07E0; //������ɫĬ��Ϊ��ɫ
graph->curPos = 0; //��ǰ���Ƶ�ĺ�����
graph->WaveRatio = 1; //���ò��α���
graph->WaveSpeed = 1; //ÿ��һ�����ص㻭һ����
graph->WavePos = 0; //Ĭ����ֱ������ƫ����
graph->callBack = NULL; //��ͼ�ص�����Ĭ��Ϊ��
graph->hasCreate = 0; //δ����ʼ��
graph->firstFlag = 0; //δ���Ƶ�һ����
}
/*********************************************************************************************************
* ��������: CreateGraphWidget
* ��������: �½����λ��ƿؼ�
* �������: x0,y0����ʼ���꣨���Ͻǣ���xSize�����ȣ�ySize���߶ȣ�graph�����οؼ��ṹ��
* �������: void
* �� �� ֵ: void
* ��������: 2021��07��01��
* ע ��: graph���Ǿ�̬�ṹ��
*********************************************************************************************************/
void CreateGraphWidget(int x0, int y0, int xSize, int ySize, StructGraphObj* graph)
{
int x1,y1;
//����������յ�
x1 = x0 + xSize - 1;
//�����������յ�
y1 = y0 + ySize - 1;
graph->x0 = x0; //��¼�������
graph->y0 = y0; //��¼�������
graph->x1 = x1; //��¼�յ�����
graph->y1 = y1; //��¼�յ�����
//���Ʊ���
LCDFillPixel(graph->x0, graph->y0, graph->x1, graph->y1, graph->backColor);
//����Ѿ���ʼ��
graph->hasCreate = 1;
//δ��ʼ��ͼ
graph->startDraw = 0;
//δ���Ƶ�һ����
graph->firstFlag = 0;
}
/*********************************************************************************************************
* ��������: GraphWidgetAddData
* ��������: �������ӵ�
* �������: graph���ؼ��ṹ�壬data���������꣨���ص㣩
* �������: void
* �� �� ֵ: void
* ��������: 2021��07��01��
* ע ��: graph���Ǿ�̬�ṹ��
*********************************************************************************************************/
void GraphWidgetAddData(StructGraphObj* graph, unsigned int data)
{
unsigned int x; //���ڼ�����һ����ĺ�����
unsigned int y; //���ڼ�����һ�����������
//����δ��ʼ������ֱ���˳�
if(0 == graph->hasCreate || 0 == graph->startDraw)
{
return;
}
//���η�ֵ����
data = data / graph->WaveRatio;
//�����ƶ�
data = data + graph->WavePos * (graph->y1 - graph->y0) / 8;
//��������ƶ�������ݣ����ݷ�ΧΪ0~(graph->y1 - graph->y0)��
if(data > (graph->y1 - graph->y0 - 1))
{
data = graph->y1 - graph->y0 - 1;
}
//���·�ת����Ϊ���㺯��ԭ�������Ͻǣ�һ�㻭ͼԭ�������½�
data = graph->y1 - data;
//���Ƶ�һ����
if(0 == graph->firstFlag)
{
graph->firstFlag = 1;
graph->xOld = graph->x0;
graph->yOld = data;
}
else
{
//��ǰ���λ������Ų
graph->curPos = graph->curPos + graph->WaveSpeed;
}
//��ǰλ�ó�����ͼ����ѭ������
if(graph->curPos > (graph->x1 - graph->x0 - 1))
{
graph->curPos = 0;
}
//����ǰһ������
if(0 == graph->curPos)
{
graph->xOld = graph->x0;
//ɾ��ԭ�㴦�ĵ㣬����ԭ�����ĵ��޷����
LCDDrawLine(graph->x0, graph->y0,graph->x0, graph->y1, graph->backColor);
}
//�ٴμ�飬��ֹ����Խ��
if(data > graph->y1)
{
data = graph->y1;
}
if(data < (graph->y0))
{
data = graph->y0;
}
//�����յ�λ��
x = graph->x0 + graph->curPos;
y = data;
//����
LCDDrawLine(graph->xOld, graph->yOld, x, y, graph->penColor);
graph->xOld = x;
graph->yOld = y;
//��ȱ�ڣ�˳�����֮ǰԤ�������ĵ�
LCDFillPixel(x + 1, graph->y0, x + 10 > graph->x1 ? graph->x1 :x + 10, graph->y1, graph->backColor);
//ִ�лص�����
if(NULL != graph->callBack)
{
graph->callBack();
}
}

Xet Storage Details

Size:
6.75 kB
·
Xet hash:
a5422988db6aadd147e1982521df0c251a664eaa9e16b10471f78f6bcc4655f8

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.