📄 measureinterfacehandler.c
字号:
#include "option.h"
#include "def.h"
#include "44b.h"
#include "44blib.h"
#include "GUI.H"
#include "GUI_Protected.H"
#include "define.h"
#include "LCD_ConfDefaults.h"
#include <math.h>
#include "ADC.h"
#define USE_BANDING_MEMDEV (0) /* Set to 0 for drawing without banding memory device */
#define true 1
#define false 0
extern const GUI_BITMAP bmreturnToMainFrame;//从测量界面返回主界面
extern const GUI_BITMAP bmMeasureControl;//测量界面中控制按钮
extern struct ConfigData configData;//配置数据
extern int status;
extern const GUI_BITMAP bmMainInterface;//主界面位图
struct MeasureData
{
int currentMinutes;//
int currentSeconds;
int currentSphygusTimes[6];
int timesPerMinute;
};
struct MeasureData measureData;
int working=0;//标志是否在工作
int startOrsStop=0;//标志
struct GraphData graphData;
#define YSIZE (100) //图形高度
#define DEG2RAD (3.1415926f / 180) // 弧度/角度
I16 *pStart;
int startMinute=0;
int startSecond=0;
//===============================================================================
void measureInit()
{
int i;
measureData.currentMinutes=0;
measureData.currentSeconds=0;
for(i=0;i<9;i++)
measureData.currentSphygusTimes[i]=0;
measureData.timesPerMinute=0;
}
//---------------------------------------------------------------------------------------
void GetCurrentMeasureValue()//得到当前测量数据
{
int i=0,total=0;
int shi=0,ge=0;
rRTCCON=0x1;
shi=rBCDMIN>>4;
ge=rBCDMIN&0xf;
measureData.currentMinutes=shi*10+ge;
shi=rBCDSEC>>4;
ge=rBCDSEC&0xf;
measureData.currentSeconds=shi*10+ge;
rRTCCON=0x0;
measureData.currentSphygusTimes[measureData.currentMinutes]=measureData.currentSeconds;
for(i=0;i<measureData.currentMinutes;i++)
total+=measureData.currentSphygusTimes[i];
if(measureData.currentMinutes>=1)
measureData.timesPerMinute=total/measureData.currentMinutes;
}
//---------------------------------------------------------------------------
static void DisplayFormatResult(void *pData)//显示
{
int i=0;
int total=0;
GUI_GotoXY(0,125);
GUI_SetColor(GUI_WHITE);
GUI_SetFont(&GUI_Font_HZK16);
GUI_DispString("时间:");
GUI_DispSDec(measureData.currentMinutes, 3);
GUI_GotoXY(80,125);
GUI_DispString("分");
GUI_GotoXY(100,125);
GUI_DispSDec(measureData.currentSeconds, 3);
GUI_GotoXY(140,125);
GUI_DispString("秒\n");
GUI_GotoXY(0,145);
GUI_DispString("次数:");
GUI_GotoXY(40,145);
for(i=0;i<configData.minutes;i++)
{
switch(i)
{
case 1: GUI_GotoXY(80,145);break;
case 2: GUI_GotoXY(120,145);break;
case 3: GUI_GotoXY(0,162);break;
case 4: GUI_GotoXY(40,162);break;
case 5: GUI_GotoXY(80,162);break;
case 6: GUI_GotoXY(120,162);break;
}
GUI_DispSDec(measureData.currentSphygusTimes[i], 4);
}
GUI_GotoXY(0,180);
GUI_DispString("总次数:");
for(i=0;i<measureData.currentMinutes;i++)
total+=measureData.currentSphygusTimes[i];
GUI_DispSDec(total,5);
GUI_GotoXY(0,200);
GUI_DispString("脉搏率:");
GUI_DispSDec(measureData.timesPerMinute,4);
GUI_GotoXY(120,200);
GUI_DispString("次/分");
}
//===============================================================================
static void DrawLabel()//绘制标签
{
int x, y;
int i=0;
GUI_SetBkColor(GUI_RED);
GUI_SetDrawMode(GUI_DRAWMODE_NORMAL);
GUI_SetPenSize(2);
GUI_SetColor(GUI_WHITE);
GUI_ClearRect(0,0,160, 100);//清除指定区域
GUI_DrawRect(18,0, (LCD_XSIZE - 2), (100 - 10));//绘制一个矩形
GUI_SetDrawMode(GUI_DRAWMODE_XOR);
GUI_SetFont(&GUI_Font6x8);
GUI_SetPenSize(1);
for (x = 0; x < (LCD_XSIZE - 20); x += 30)
{
int xPos = x + 18;
GUI_DrawVLine(xPos, 0,100-11);//绘制垂直线
GUI_DispDecAt(x /30, xPos - 2, (100 - 7), 1);//最下行显示十进制数字:0 1 2 3
}
for (y =(YSIZE-10)/2; y >0 ; y -= 10,i+=1)
{
int yPos;
GUI_DrawHLine(y, 13, 159);//绘制短水平指示线
GUI_GotoXY(1, y - 4);//设置读写位置
GUI_DispSDec(+i, 2);//最左列显示十进制数字:+3 +2 +1 0
yPos = (YSIZE-10) - y;
GUI_DrawHLine(yPos, 13, 159);//绘制短水平指示线
GUI_GotoXY(1, yPos - 4);
GUI_DispSDec(-i, 2);
}
GUI_DrawHLine(45, 13, 159);//绘制短水平指示线
GUI_SetDrawMode(GUI_DRAWMODE_NORMAL);
}
//==================================================================================
//-----------------------------------------------------------------------
static void GetSineData(I16 * paY, int n)
{
int i;
/* for (i = 0; i < n; i++)
{
float s = sin(i * DEG2RAD * 8);
paY[i] = s * (YSIZE-40) / 2 + (YSIZE-40) / 2;//得到对应Y坐标
}*/
for (i = 0; i < n; i++)
{
paY[i]=(I16)GetConvertData();//得到对应Y坐标
Uart_Printf("\n uc-gui demo%d",GetConvertData());
}
}
//--------------------------------------------------------------------
static void Draw(void * p) //绘制图形区域
{
int i;
struct GraphData * pParam = (struct GraphData *)p;
GUI_SetBkColor(GUI_BLACK);
GUI_SetColor(GUI_WHITE);
GUI_ClearRect(19,19, (LCD_XSIZE - 2), (YSIZE - 1));
if(working==1)
GetCurrentMeasureValue();
DrawLabel();
DisplayFormatResult(NULL);
GUI_DrawGraph(pParam->aY, (LCD_XSIZE - 20), 19, 19);//绘制图形
}
static void Draw2(void * p)
{
struct GraphData * pParam = (struct GraphData *)p;
Draw(p);
GUI_SetColor(GUI_WHITE);
GUI_DrawGraph(pParam->aY+15, (LCD_XSIZE - 20), 19, (LCD_YSIZE - 20) - YSIZE);
}
//------------------------------------------------------------------------------------
void DrawGraph()//显示脉搏波形图
{
struct GraphData Param;
int key=100;
I16 * pStart;
int t0, Cnt = 0;
GUI_RECT Rect = {0,0 , 160,240};
GUI_HMEM hMem = GUI_ALLOC_Alloc(280 * sizeof(I16));//分配内存空间
pStart = GUI_ALLOC_h2p(hMem);//内存设备转化为指针
GetSineData(pStart,280);//得到SIN图象数据
t0 = GUI_GetTime();
while((GUI_GetTime() - t0) < 10000)
{
int t1, tDiff2;
if (Cnt++ % 135)
{
Param.aY++;
}
else
{
Param.aY = pStart;
}
t1 = GUI_GetTime();
GUI_MEMDEV_Draw(&Rect, Draw, &Param, 0, 0);//绘图
tDiff2 = GUI_GetTime() - t1;
if (tDiff2 < 100)
{
GUI_Delay(100 - tDiff2);
}
GUI_Delay(1000);
key=GetKey();
if (key==1) //按下KEY1//停止测量
{
working=0;
}
else
if(key==0)//按下KEY1//开始测量
{
working=1;
rRTCCON=0x1;
rBCDMIN=0x00;
rBCDSEC=0x00;//记录当前秒数
rRTCCON=0x0;
measureInit();
}
else
if(key==2)
{
working=0;
rRTCCON=0x1;
rBCDMIN=0x00;
rBCDSEC=0x00;//记录当前秒数
rRTCCON=0x0;
measureInit();
status=1;//标志主界面
GUI_Clear();
GUI_SetDrawMode(GUI_DRAWMODE_NORMAL);
GUI_DrawBitmap(&bmMainInterface,0,0);//显示主界面
break;
}
if(measureData.currentMinutes==configData.minutes)
{
working=0;
}
//GetSineData(pStart,280);
}
GUI_Delay(1000);
GUI_ALLOC_Free(hMem);
}
//------------------------------------------------
//=============================================================================
void MeasureHandler()
{
rRTCCON=0x1;
rBCDMIN=0x00;
rBCDSEC=0x00;//记录当前秒数
rRTCCON=0x0;
measureInit();
//graphData.aY=(unsigned short *)malloc(160);
GUI_Clear();
DrawLabel();//绘制标签
GUI_DrawBitmap(&bmreturnToMainFrame,0,220);//显示"脉搏测量 "界面
GUI_DrawBitmap(&bmMeasureControl,0,100);//绘制控制按钮
//GetCurrentMeasureValue();
DisplayFormatResult(NULL);
DrawGraph();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -