📄 a.c
字号:
srand( j ); //不知到干啥的先放在这里
//-----------------
PDisplayflag.word = 0;
PedometerKeyFlag = 0;
PedometerState = PEDOMETER_STOP;
PedometerTimerCfgFunc(PEDOMETER_TMR_CHANNEL, PedometerTmrFunc, 0);
PedometerTimerCfgFunc(PEDOMETER_TMR_CHANNEL2, PedometerKeyDlyFunc, 0);
////////////////////////////////////////////////////////////////////////////
for(i=0;i<10;i++)
{
PedometerRecordStep[i]=1000+i*100;
PedometerRecordTime[i]=1000+i*100;
}
}
PEDOMETER_APP_CODE
void DIV10Conver16To10Display(unsigned long nSource,unsigned int *nTagert)//nTagert最好设置8成员个大小
{
unsigned long score_tmp;
score_tmp = nSource/10;
nTagert[0] = score_tmp/100000+'0';
if(nTagert[0]>'9')nTagert[0]='9';//防止溢出
score_tmp = score_tmp%100000;
nTagert[1] = score_tmp/10000+'0';
score_tmp = score_tmp%10000;
nTagert[2] = score_tmp/1000 +'0';
score_tmp = score_tmp%1000;
nTagert[3] = score_tmp/100 +'0';
nTagert[4] = '.';
score_tmp = score_tmp%100;
nTagert[5] = score_tmp/10 +'0';
score_tmp = score_tmp%10 +'0';
nTagert[6] = score_tmp;
nTagert[7] = 0;
}PEDOMETER_APP_CODE
void DIV100Conver16To10Display(unsigned long nSource,unsigned int *nTagert)//nTagert最好设置8成员个大小
{
unsigned long score_tmp;
score_tmp = nSource/100;
nTagert[0] = score_tmp/100000+'0';
if(nTagert[0]>'9')nTagert[0]='9';//防止溢出
score_tmp = score_tmp%100000;
nTagert[1] = score_tmp/10000+'0';
score_tmp = score_tmp%10000;
nTagert[2] = score_tmp/1000 +'0';
score_tmp = score_tmp%1000;
nTagert[3] = score_tmp/100 +'0';
score_tmp = score_tmp%100;
nTagert[4] = score_tmp/10 +'0';
nTagert[5] = '.';
score_tmp = score_tmp%10 +'0';
nTagert[6] = score_tmp;
nTagert[7] = 0;
}
PEDOMETER_APP_CODE
void Conver16To10Display(unsigned long nSource,unsigned int *nTagert)//nTagert最好设置8成员个大小
{
unsigned long score_tmp;
score_tmp = nSource;
nTagert[0] = score_tmp/10000+'0';
score_tmp = score_tmp%10000;
nTagert[1] = score_tmp/1000 +'0';
score_tmp = score_tmp%1000;
nTagert[2] = score_tmp/100 +'0';
score_tmp = score_tmp%100;
nTagert[3] = score_tmp/10 +'0';
score_tmp = score_tmp%10 +'0';
nTagert[4] = score_tmp;
nTagert[5] = 0;
}
PEDOMETER_APP_CODE
void PedometerDispInit(void)
{
unsigned int tmpbuf[8];
unsigned long score_tmp;
//------------------------------------------------------------------------------
// 以下为界面相关的初始化(测试用的简单)
//------------------------------------------------------------------------------
pcolor_tmp = LCD_GetColor();
LCD_SetColor(0xFFFF);
#ifndef TEST_PEDOMETER_UI
DisplayPicture(0, 0, PEDOMETER_BACK_XSIZE, PEDOMETER_BACK_YSIZE, NFA_PEDOMETER_BACK);
DisplayPicture(PLAY_BATT_X, PLAY_BATT_Y, PLAY_BATT_XSIZE, PLAY_BATT_YSIZE, NFA_PLAY_BATT + (unsigned long)(PLAY_BATT_XSIZE*PLAY_BATT_YSIZE*2*(BatteryLevel)));
#endif
#ifdef TEST_PEDOMETER_UI
LCD_NFDispStringAt(PEDOMETER_TEXT_BODY_WEIGHT_X,PEDOMETER_TEXT_BODY_WEIGHT_Y, "WEIGHT:");
LCD_NFDispStringAt(PEDOMETER_TEXT_STEP_SIZE_X,PEDOMETER_TEXT_STEP_SIZE_Y, "STEP_SIZE:");
LCD_NFDispStringAt(PEDOMETER_TEXT_STEP_X,PEDOMETER_TEXT_STEP_Y, "STEP:");
LCD_NFDispStringAt(PEDOMETER_TEXT_XNUMBER_X,PEDOMETER_TEXT_XNUMBER_Y, "X:");
LCD_NFDispStringAt(PEDOMETER_TEXT_YNUMBER_X,PEDOMETER_TEXT_YNUMBER_Y, "Y:");
LCD_NFDispStringAt(PEDOMETER_TEXT_DISTANCE_X,PEDOMETER_TEXT_DISTANCE_Y, "DISTANCE:");
LCD_NFDispStringAt(PEDOMETER_TEXT_CONSUME_X,PEDOMETER_TEXT_CONSUME_Y, "CONSUME:");
LCD_NFDispStringAt(PEDOMETER_TEXT_TIMER_X,PEDOMETER_TEXT_TIMER_Y, "TIMER:");
LCD_NFDispStringAt(PEDOMETER_TEXT_CONSUMEPHOUR_X,PEDOMETER_TEXT_CONSUMEPHOUR_Y, "CONSUME/H:");
LCD_NFDispStringAt(PEDOMETER_TEXT_STEPPMINUTE_X,PEDOMETER_TEXT_STEPPMINUTE_Y, "STEPF/M:");
#endif
GetAcceleration();
///////////////////////////////////////////////
#ifdef TEST_PEDOMETER_UI
Xnumber=MXC6202DataOut.Bytes.XaccMSB;
Xnumber=MXC6202DataOut.Bytes.XaccLSB+(Xnumber<<8);
Ynumber=MXC6202DataOut.Bytes.YaccMSB;
Ynumber=MXC6202DataOut.Bytes.YaccLSB+(Ynumber<<8);
PDisplayBodyWeight(BodyWeight);
PDisplayBodyHeight(BodyHeight);
PDisplayStepCounter(StepCounter);
PDisplayTotalConsume(TotalConsume);
PDisplayDistance(Distance);
PDisplayTimeCounter(TimeCounter);
PDisplayConsumeRate(ConsumeRate);
PDisplayStepFreqency(StepFreqency);
PDisplayXnumber(Xnumber);
PDisplayYnumber(Ynumber);
PDisplayPauseRun(PEDOMETER_DISP_PAUSE);
#else
PDisplayTime(TimeCounter);
PDisplayStepCounter(StepCounter);
PDisplayTotalConsume(TotalConsume);
PDisplayDistance(Distance);
#endif
}
PEDOMETER_APP_CODE
void PedometerSettingDisplay(void)
{
unsigned long tempDistance;
unsigned long tempConsume;
unsigned long tempTime;
unsigned int tmpbuf[8];
unsigned int i;
unsigned int Hour;
unsigned int Minute;
unsigned int Second;
if(PDisplayflag.bit.bMenuinital)
{
PDisplayflag.bit.bMenuinital=0;
PDisplayflag.bit.bInSetMode=1;
AdjustTempWeight=BodyWeight;
AdjustTempBodyHeight=BodyHeight;
AdjustTempConsume=TargertConsume;
AdjustPosition = 0;
DisplayPicture(0, 0, PEDOMETERSET_BACK_XSIZE, PEDOMETERSET_BACK_YSIZE, NFA_PEDOMETERSET_BACK);
DisplayPicture(PLAY_BATT_X, PLAY_BATT_Y, PLAY_BATT_XSIZE, PLAY_BATT_YSIZE, NFA_PLAY_BATT + (unsigned long)(PLAY_BATT_XSIZE*PLAY_BATT_YSIZE*2*(BatteryLevel)));
//pcolor_tmp = LCD_GetColor();
//LCD_SetColor(0x00);//黑色
DisplayMenuStr(PEDOMETER_SET_TITLE_X,PEDOMETER_SET_TITLE_Y, 120, 16, LCD_TEXTALIGN_CENTER, NFA_PEDOMETER_RECORD_SETTING);
DisplayMenuStr(PEDOMETER_SET_WEIGHT_X, PEDOMETER_SET_WEIGHT_Y , 60+40, 16, LCD_TEXTALIGN_LEFT, NFA_PEDOMETER_WEIGHT);
DisplayMenuStr(PEDOMETER_SET_HIGHT_X, PEDOMETER_SET_HIGHT_Y , 60+40, 16, LCD_TEXTALIGN_LEFT, NFA_PEDOMETER_STEP_SIZE);
DisplayMenuStr(PEDOMETER_SET_CONSUME_X, PEDOMETER_SET_CONSUME_Y, 60+40, 16, LCD_TEXTALIGN_LEFT, NFA_PEDOMETER_CONSUME);
//LCD_SetColor(pcolor_tmp);
PDisplayBodyWeight(AdjustTempWeight);
PDisplayBodyHeight(AdjustTempBodyHeight);
PDisplayTargetConsume(AdjustTempConsume);
}
if(PDisplayflag.bit.bAdjustWeight)
{
PDisplayflag.bit.bAdjustWeight=0;
PDisplayBodyWeight(AdjustTempWeight);
}
if(PDisplayflag.bit.bAdjustBodyHeight)
{
PDisplayflag.bit.bAdjustBodyHeight=0;
PDisplayBodyHeight(AdjustTempBodyHeight);
}
if(PDisplayflag.bit.bAdjustConsume)
{
PDisplayflag.bit.bAdjustConsume=0;
PDisplayTargetConsume(AdjustTempConsume);
}
if(PDisplayflag.bit.bAdjustPosition)
{
PDisplayflag.bit.bAdjustPosition=0;
PDisplayAdjustPosition(AdjustPosition);
}
if(PDisplayflag.bit.bPRecordDisplayinital)
{
PDisplayflag.bit.bPRecordDisplayinital=0;
PDisplayflag.bit.bInRecordMode=1;
PDisplayflag.bit.bPRecordDisplay=1;
AdjustPosition = 0;//用于指示显示那一组
//DisplayPicture(0, 0, PEDOMETER_RECORD_BACK_XSIZE, PEDOMETER_RECORD_BACK_YSIZE, NFA_PEDOMETER_RECORD_BACK);
//DisplayPicture(PLAY_BATT_X, PLAY_BATT_Y, PLAY_BATT_XSIZE, PLAY_BATT_YSIZE, NFA_PLAY_BATT + (unsigned long)(PLAY_BATT_XSIZE*PLAY_BATT_YSIZE*2*(BatteryLevel)));
}
if(PDisplayflag.bit.bPRecordDisplay)
{
PDisplayflag.bit.bPRecordDisplay=0;
DisplayPicture(0, 0, PEDOMETER_RECORD_BACK_XSIZE, PEDOMETER_RECORD_BACK_YSIZE, NFA_PEDOMETER_RECORD_BACK);
DisplayPicture(PLAY_BATT_X, PLAY_BATT_Y, PLAY_BATT_XSIZE, PLAY_BATT_YSIZE, NFA_PLAY_BATT + (unsigned long)(PLAY_BATT_XSIZE*PLAY_BATT_YSIZE*2*(BatteryLevel)));
DisplayMenuStr(PEDOMETER_SET_TITLE_X,PEDOMETER_SET_TITLE_Y, 120, 16, LCD_TEXTALIGN_CENTER, NFA_PEDOMETER_RECORD+(AdjustPosition+1)*BytesPerMenu);
//////////////////////////////////////////////////////////////////////////////////////////////计算行走路程
tempDistance=BodyHeight*37/100;//身高步幅 37 -45%福尔摩斯发现身高脚长的比例是1:7,他根据这个来推断罪犯的身高的
tempDistance=tempDistance*PedometerRecordStep[AdjustPosition];
tempDistance=tempDistance/100;
//////////////////////////////////////////////////////////////////////////////////////////////计算消耗的
tempConsume=tempDistance*BodyWeight;
tempConsume=tempConsume+(tempConsume*36)/1000;//能量(卡路里 Calories)= 1.036x合共走路距离(km)x 预设体重(kg)
tempTime=PedometerRecordTime[AdjustPosition];
//////////////////////////////////////////////////////////////////////////////////////////////计算行走路程
DIV10Conver16To10Display(tempDistance,tmpbuf);
for(i=0;i<7;i++)
tmpbuf[i]=tmpbuf[i]-'0';
tmpbuf[4]=10;//显示'.'
for(i=1;i<7;i++)
{
DisplayPicture(51+((i-1)*(MIDDLENUMBER_XSIZE)), 38, MIDDLENUMBER_XSIZE, MIDDLENUMBER_YSIZE, NFA_MIDDLENUMBER_BASS+tmpbuf[i]*MIDDLENUMBER_XSIZE*MIDDLENUMBER_YSIZE*2);
// 每个数值的宽度 数字图片的地址
}
//////////////////////////////////////////////////////////////////////////////////////////////计算消耗的
DIV100Conver16To10Display(tempConsume,tmpbuf);
for(i=0;i<7;i++)
tmpbuf[i]=tmpbuf[i]-'0';
tmpbuf[5]=10;//显示'.'
for(i=1;i<7;i++)
{
DisplayPicture(51+((i-1)*(MIDDLENUMBER_XSIZE)), 68, MIDDLENUMBER_XSIZE, MIDDLENUMBER_YSIZE, NFA_MIDDLENUMBER_BASS+tmpbuf[i]*MIDDLENUMBER_XSIZE*MIDDLENUMBER_YSIZE*2);
// 每个数值的宽度 数字图片的地址
}
//////////////////////////////////////////////////////////////////////////////////////////////计算消耗的
tempTime=PedometerRecordTime[AdjustPosition];
Second=tempTime%60;
Minute=tempTime/60;
Hour=Minute/60;
Minute=Minute-Hour*60;
tmpbuf[0]=Hour/10;
tmpbuf[1]=Hour%10;
tmpbuf[2]=11;//显示':'
tmpbuf[3]=Minute/10;
tmpbuf[4]=Minute%10;
tmpbuf[5]=10;//显示'.'
tmpbuf[6]=Second/10;
tmpbuf[7]=Second%10;
for(i=0;i<8;i++)
{
DisplayPicture(51+((i)*(MIDDLENUMBER_XSIZE)), 98, MIDDLENUMBER_XSIZE, MIDDLENUMBER_YSIZE, NFA_MIDDLENUMBER_BASS+tmpbuf[i]*MIDDLENUMBER_XSIZE*MIDDLENUMBER_YSIZE*2);
// 每个数值的宽度+2 数字图片的地址
}
}
}
PEDOMETER_APP_CODE
int PedometerAdjustOneValue(bool UporDown,unsigned int temp)
{
if(UporDown)
{
if(temp>=9)
temp =0;
else
temp++;
}
else
{
if(temp<=0)
temp =9;
else
temp--;
}
return temp;
}
PEDOMETER_APP_CODE
void PedometerAdjustValue(bool UporDown)
{//这个函数是调整指定位置的值
unsigned long temp;
unsigned long a;
unsigned long *b;
unsigned long temp1[7]={1000000,100000,10000,1000,100,10,1};
if(AdjustPosition<=0)return;
if(AdjustPosition>11)return;
switch(AdjustPosition)
{
/////////////////////////////////////////////////AdjustTempWeight
case 1:
case 2:
case 3:
a=temp1[3+AdjustPosition];
b=&AdjustTempWeight;
PDisplayflag.bit.bAdjustWeight=1;
break;
/////////////////////////////////////////////////AdjustTempBodyHeight
case 4:
case 5:
case 6:
a=temp1[3+AdjustPosition-3];
b=&AdjustTempBodyHeight;
PDisplayflag.bit.bAdjustBodyHeight=1;
break;
/////////////////////////////////////////////////AdjustTempConsume
case 7:
case 8:
case 9:
case 10:
case 11:
a=temp1[AdjustPosition-7];
b=&AdjustTempConsume;
PDisplayflag.bit.bAdjustConsume=1;
break;
/////////////////////////////////////////////////AdjustTempConsume
default:
break;
}
temp=(*b)%(a*10);
temp=temp/a;
(*b)=(*b)-temp*a;
temp=PedometerAdjustOneValue(UporDown,temp);
(*b)=(*b)+temp*a;
}
PEDOMETER_APP_CODE
void PedometerSetting(void)
{
unsigned int tmpbuf[4];
PedometerSettingDisplay();
if(KeyFlag.bc.bKeyPressed == 0)
return;
KeyFlag.bc.bKeyPressed = 0;
if (SystemInfo.bc.bHoldOn) {
return;
}
switch(KeyVal){
case KEY_VAL_PLAY_SHORT_UP:
if(PedometerState == PEDOMETER_RUN)
{
PedometerState = PEDOMETER_PAUSE;
PedometerFreqDown();
PedometerTimerStop(PEDOMETER_TMR_CHANNEL);
#ifdef TEST_PEDOMETER_UI
PDisplayPauseRun(PEDOMETER_DISP_PAUSE);
#endif
}
else //if(PedometerState == PEDOMETER_STOP)
{
PedometerState = PEDOMETER_RUN;
PedometerFreqUp();
PedometerDispInit();
#ifdef TEST_PEDOMETER_UI
PDisplayPauseRun(PEDOMETER_DISP_RUN);
#endif
PedometerTimerSetTimer(PEDOMETER_TMR_CHANNEL, 2);//设置50ms的时间中断
PedometerTimerStart(PEDOMETER_TMR_CHANNEL);
PDisplayflag.word = 0;//不在显示菜单
}
break;
case KEY_VAL_MENU_PRESS_START://退出回到主菜单
PostFun2Message(MSG_FUNCTION2_PEDOMETER,MSG_FUNCTION2_PEDOMETER_END,0,0,0/*,0,0,0*/);
break;
case KEY_VAL_MENU_SHORT_UP:
if(PDisplayflag.bit.bInSetMode)
{
if(AdjustPosition!=0)
{
if(AdjustTempWeight>0&&AdjustTempWeight<150)
{
BodyWeight = AdjustTempWeight;
}
if(AdjustTempBodyHeight>0&&AdjustTempBodyHeight<250)
{
BodyHeight=AdjustTempBodyHeight;
}
if(AdjustTempConsume>0&&AdjustTempConsume<10000000)
{
TargertConsume=AdjustTempConsume;
}
}
{//重新进入检测状态
PedometerState = PEDOMETER_RUN;
PedometerFreqUp();
PedometerDispInit();
#ifdef TEST_PEDOMETER_UI
PDisplayPauseRun(PEDOMETER_DISP_RUN);
#endif
PedometerTimerSetTimer(PEDOMETER_TMR_CHANNEL, 2);//设置50ms的时间中断
PedometerTimerStart(PEDOMETER_TMR_CHANNEL);
}
PDisplayflag.word = 0;//不在显示菜单
}
else
{
PDisplayflag.word = 0;//不在显示菜单
PDisplayflag.bit.bMenuinital=1;
}
break;
case KEY_VAL_FFD_PRESS:
case KEY_VAL_FFD_SHORT_UP:
if(PDisplayflag.bit.bInSetMode)
{
AdjustPosition++;
if(AdjustPosition>11)
AdjustPosition =1;
PDisplayflag.bit.bAdjustPosition=1;
}
else if(PDisplayflag.bit.bInRecordMode)
{
AdjustPosition++;
if(AdjustPosition>9)
AdjustPosition =0;
PDisplayflag.bit.bPRecordDisplay=1;
}
break;
case KEY_VAL_FFW_PRESS:
case KEY_VAL_FFW_SHORT_UP:
if(PDisplayflag.bit.bInSetMode)
{
if(AdjustPosition<=1)
AdjustPosition =11;
else
AdjustPosition--;
PDisplayflag.bit.bAdjustPosition=1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -