📄 pedometer.c
字号:
LCD_NFDispStringAt(31+26,84+4, "SETTING");
LCD_SetColor(pcolor_tmp);
}
}
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];
unsigned int i;
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.word==0)//已经退出菜单显示,但没有开始
{
PDisplayflag.word = 0;//不在显示菜单
//PDisplayflag.bit.bMenuinital=1;
PDisplayflag.bit.bPInStartSwitchintal=1;
}
else
{
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;
}
}
}
else if(PDisplayflag.bit.bPInStartSwitchMode)
{
switch(AdjustPosition)
{
case PEDOMETER_CONTINUE://Continue
StepCounter=PedometerStepRecord[0];
TimeCounter=PedometerTimeRecord[0];
TimeInterCounter =TimeCounter*20;
break;
case PEDOMETER_CLEAR_RECORD://Clear Record
for(i=0;i<10;i++)
{
PedometerStepRecord[i]=0;
PedometerTimeRecord[i]=0;
}
break;
case PEDOMETER_SETTING://Setting menu
PDisplayflag.word = 0;//不在显示菜单
PDisplayflag.bit.bMenuinital=1;
break;
case PEDOMETER_NEW://Start New
//TotalConsume=0;//在初始化已经值0
//TimeCounter=0;
default:
break;
}
}
if(AdjustPosition!=PEDOMETER_SETTING)
{
PDisplayflag.word = 0;//不在显示菜单
PedometerDispInit();
}
}
break;
case KEY_VAL_FFW_PRESS:
case KEY_VAL_FFW_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;
}
else if(PDisplayflag.bit.bPInStartSwitchMode)
{
AdjustPosition++;
if(AdjustPosition>3)
AdjustPosition =0;
PDisplayflag.bit.bPInStartSwitchDisplay=1;
}
break;
case KEY_VAL_FFD_PRESS:
case KEY_VAL_FFD_SHORT_UP:
if(PDisplayflag.bit.bInSetMode)
{
if(AdjustPosition<=1)
AdjustPosition =11;
else
AdjustPosition--;
PDisplayflag.bit.bAdjustPosition=1;
}
else if(PDisplayflag.bit.bInRecordMode)
{
if(AdjustPosition<=0)
AdjustPosition =9;
else
AdjustPosition--;
PDisplayflag.bit.bPRecordDisplay=1;
}
else if(PDisplayflag.bit.bPInStartSwitchMode)
{
if(AdjustPosition<=0)
AdjustPosition =3;
else
AdjustPosition--;
PDisplayflag.bit.bPInStartSwitchDisplay=1;
}
break;
case KEY_VAL_UP_PRESS:
case KEY_VAL_UP_SHORT_UP:
if(PDisplayflag.bit.bInSetMode)
{
PedometerAdjustValue(1);
}
break;
case KEY_VAL_DOWN_PRESS:
case KEY_VAL_DOWN_SHORT_UP:
if(PDisplayflag.bit.bInSetMode)
{
PedometerAdjustValue(0);
}
break;
case KEY_VAL_REC_SHORT_UP:
if(!PDisplayflag.bit.bInRecordMode)
{
PDisplayflag.word = 0;//不在显示菜单
PDisplayflag.bit.bPRecordDisplayinital=1;
}
break;
default:
break;
}
}
PEDOMETER_APP_CODE
void PedometerProcess(void)
{
unsigned int imask_tmp;
unsigned int KeyValue;
unsigned int KeyState;
unsigned int tmpbuf[8];
if(PedometerState != PEDOMETER_RUN)
{
if(KeyFlag.bc.bKeyPressed)
KeyFlag.bc.bKeyPressed = 0;
return;
if (SystemInfo.bc.bHoldOn)
{
return;
}
}
if(PedometerReadFlag != 0)
{//50ms的时间中断判断一有没有Step
read_creg(%imask, imask_tmp);
bitclear_creg(%imask, 15);
PedometerReadFlag = 0;
write_creg(%imask, imask_tmp);
StepLoops();//检测有没有Step
}
if(PDisplayflag.bit.bBatt==1)
{
PDisplayflag.bit.bBatt=0;
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(TimeInterCounter%10==0)
{//0.5秒钟计算,刷新一次
//////////////////////////////////////////////////////////////////////////////////////////////读取相关数值
#ifdef TEST_PEDOMETER_UI
Xnumber=MXC6202DataOut.Bytes.XaccMSB;
Xnumber=MXC6202DataOut.Bytes.XaccLSB+(Xnumber<<8);
Ynumber=MXC6202DataOut.Bytes.YaccMSB;
Ynumber=MXC6202DataOut.Bytes.YaccLSB+(Ynumber<<8);
#endif
CalculaterCaluliAndDistance();
#ifdef TEST_PEDOMETER_UI
PDisplayXnumber(Xnumber);
PDisplayYnumber(Ynumber);
PDisplayStepCounter(StepCounter);
PDisplayBodyWeight(BodyWeight);
PDisplayBodyHeight(BodyHeight);
PDisplayDistance(Distance);
PDisplayTotalConsume(TotalConsume);
if(TimeInterCounter%20==0)
PDisplayTimeCounter(TimeCounter);
PDisplayConsumeRate(ConsumeRate);
PDisplayStepFreqency(StepFreqency);
#else
//////////////////////////////////////////////////////////////////////////////////////////////
if(SaveStepCounter!=StepCounter)
{
PDisplayStepCounter(StepCounter);
PDisplayTotalConsume(TotalConsume);//已千卡为单位
PDisplayDistance(Distance);
SaveStepCounter=StepCounter;
PDisplayConsumeBar(TotalConsume,TargertConsume);
}
if(TimeInterCounter%20==0)
{//一秒钟刷新一次
PDisplayTime(TimeCounter);
}
#endif
//////////////////////////////////////////////////////////////////////////////////////////////
}
if(KeyFlag.bc.bKeyPressed == 0)
return;
else
KeyFlag.bc.bKeyPressed = 0;
switch(KeyVal)
{
case KEY_VAL_PLAY_SHORT_UP:
if(PedometerState != PEDOMETER_RUN)
{
PedometerState = PEDOMETER_RUN;
PedometerFreqUp();
#ifdef TEST_PEDOMETER_UI
PDisplayXnumber(Xnumber);
PDisplayPauseRun(PEDOMETER_DISP_RUN);
#endif
PedometerTimerSetTimer(PEDOMETER_TMR_CHANNEL, 2);//根据 等级来设定时间
PedometerTimerStart(PEDOMETER_TMR_CHANNEL);
PedometerTimerReset(PEDOMETER_TMR_CHANNEL2);
PedometerTimerStart(PEDOMETER_TMR_CHANNEL2);
}
else
case KEY_VAL_REC_SHORT_UP:
case KEY_VAL_MENU_SHORT_UP:
{
PedometerState = PEDOMETER_PAUSE;
PedometerFreqDown();
PedometerTimerStop(PEDOMETER_TMR_CHANNEL);
PedometerTimerStop(PEDOMETER_TMR_CHANNEL2);
PedometerKeyFlag = 0;
PedometerKeyValue = KEY_VAL_NONE;
#ifdef TEST_PEDOMETER_UI
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -