#include "keys.h" #include "screen.h" #include "struct.h" #include "my.h" extern UserData_TypeDef currentData; extern bool menuItemIsEditable; extern bool kprEditable; extern int kprPointer; extern int menuPointer; extern uint16_t dvd; extern int ignoreOff_flag; uint16_t kpr_temp[6]; extern uint16_t correctedKu[13]; __IO uint16_t KEY_STATE = 0; void keysHandler(void){ uint16_t key = KEY_STATE; KEY_STATE = 0; if(HAL_GPIO_ReadPin(OFF_GPIO_Port, OFF_Pin) == GPIO_PIN_RESET)ignoreOff_flag=0; //как только кнопку включения отпустили, перестаём её игнорировать if((HAL_GPIO_ReadPin(OFF_GPIO_Port, OFF_Pin) == GPIO_PIN_SET)&&(ignoreOff_flag==0)){ // если кнопка нажата второй раз то выключаемся HAL_GPIO_WritePin(ON_GPIO_Port, ON_Pin , GPIO_PIN_SET); } // if(key==OK_BTN_Pin){ //По нажатию ОК if(menuPointer==KPR&&kprEditable==0){ //вваливаемся в редактирование KPR kprEditable=1; return; } if(menuPointer==KPR&&kprEditable==1){ //переходим к слудщующей цифре KPR kprPointer++; return; } if(menuItemIsEditable==0){ menuItemIsEditable=1; return; //вваливаемся в редактирование }else{menuItemIsEditable=0; wrPar(); return;} // вываливаемся из него } if(kprEditable){ switch (kprPointer) { case KPR0: if(key==UP_BTN_Pin) { if((currentData.IK0<9)&&(currentData.IK0>=0)) currentData.IK0++; else if(currentData.IK0=='~') currentData.IK0=0; else if(currentData.IK0==9) currentData.IK0='~'; }; if((key==DN_BTN_Pin)) { if(currentData.IK0==0) currentData.IK0='~'; else if ((currentData.IK0<=9)&&(currentData.IK0>0)) currentData.IK0--; else if(currentData.IK0='~') currentData.IK0=9; } break; case KPR1: if((key==UP_BTN_Pin)) { if((currentData.IK1<9)&&(currentData.IK1>=0)) currentData.IK1++; else if(currentData.IK1=='~') currentData.IK1=0; else if(currentData.IK1==9) currentData.IK1='~'; } if((key==DN_BTN_Pin)) { if(currentData.IK1==0) currentData.IK1='~'; else if ((currentData.IK1<=9)&&(currentData.IK1>0)) currentData.IK1--; else if(currentData.IK1='~') currentData.IK1=9; } break; case KPR2: if((key==UP_BTN_Pin)) { if((currentData.IK2<9)&&(currentData.IK2>=0)) currentData.IK2++; else if(currentData.IK2=='~') currentData.IK2=0; else if(currentData.IK2==9) currentData.IK2='~'; } if((key==DN_BTN_Pin)) { if(currentData.IK2==0) currentData.IK2='~'; else if ((currentData.IK2<=9)&&(currentData.IK2>0)) currentData.IK2--; else if(currentData.IK2='~') currentData.IK2=9; } break; case KPR3: if((key==UP_BTN_Pin)) { if((currentData.IK3<9)&&(currentData.IK3>=0)) currentData.IK3++; else if(currentData.IK3=='~') currentData.IK3=0; else if(currentData.IK3==9) currentData.IK3='~'; } if((key==DN_BTN_Pin)) { if(currentData.IK3==0) currentData.IK3='~'; else if ((currentData.IK3<=9)&&(currentData.IK3>0)) currentData.IK3--; else if(currentData.IK3='~') currentData.IK3=9; } break; case KPR4: if((key==UP_BTN_Pin)) { if((currentData.IK4<9)&&(currentData.IK4>=0)) currentData.IK4++; else if(currentData.IK4=='~') currentData.IK4=0; else if(currentData.IK4==9) currentData.IK4='~'; } if((key==DN_BTN_Pin)) { if(currentData.IK4==0) currentData.IK4='~'; else if ((currentData.IK4<=9)&&(currentData.IK4>0)) currentData.IK4--; else if(currentData.IK4='~') currentData.IK4=9; } break; case KPR5: if((key==UP_BTN_Pin)) { if((currentData.IK5<9)&&(currentData.IK5>=0)) currentData.IK5++; else if(currentData.IK5=='~') currentData.IK5=0; else if(currentData.IK5==9) currentData.IK5='~'; } if((key==DN_BTN_Pin)) { if(currentData.IK5==0) currentData.IK5='~'; else if ((currentData.IK5<=9)&&(currentData.IK5>0)) currentData.IK5--; else if(currentData.IK5='~') currentData.IK5=9; } break; default: kpr_temp[0]=currentData.IK0; kpr_temp[1]=currentData.IK1; kpr_temp[2]=currentData.IK2; kpr_temp[3]=currentData.IK3; kpr_temp[4]=currentData.IK4; kpr_temp[5]=currentData.IK5; if (asciiToFloat4(kpr_temp)||currentData.SENS<0.001||currentData.SENS>1000){ //введено некорректное значение currentData.IK0=kpr_temp[0]; currentData.IK1=kpr_temp[1]; currentData.IK2=kpr_temp[2]; currentData.IK3=kpr_temp[3]; currentData.IK4=kpr_temp[4]; currentData.IK5=kpr_temp[5]; kprPointer=KPR0; // ПЕРЕСКОЧИТ САМ //пишем что значения не верны //рисуем нули } else {sh_applysetting(¤tData); wrPar(); kprEditable=0; kprPointer=0;} break; } return; //если попали в этот иф не нужно отрабатывать дальнейшие кнопки } if(!menuItemIsEditable){ if(key==UP_BTN_Pin){ //По нажатию ОК if(menuPointer==KPR){menuPointer=GROUND;} //todo сделай сохранение //Если крайний пункт меню то возвращаемся else menuPointer--; //иначе следующий пункт } if(key==DN_BTN_Pin){ //По нажатию ОК if(menuPointer==GROUND){menuPointer=KPR;} //todo сделай сохранение //Если крайний пункт меню то возвращаемся else menuPointer++; //иначе следующий пункт } } if(menuItemIsEditable){ switch (menuPointer){ case UNITSELECT: if((key==UP_BTN_Pin)&&(currentData.UNITAccel)) {currentData.UNIT--; sh_applysetting(¤tData);} if((key==DN_BTN_Pin)&&(currentData.UNIT==Accel)) {currentData.UNIT=mV; sh_applysetting(¤tData);} break; case OUT: if((key==UP_BTN_Pin)&&(currentData.IKUKu0_1)) {currentData.IKU--; sh_applysetting(¤tData);} break; case FVCH: if((key==UP_BTN_Pin)&&(currentData.IFVHp0_2)) {currentData.IFV--; sh_applysetting(¤tData);} break; case FNCH: if((key==UP_BTN_Pin)&&(currentData.IFNLp100)) {currentData.IFN--; sh_applysetting(¤tData);} break; case GROUND: if((key==UP_BTN_Pin)) {currentData.IPZ=1; sh_applysetting(¤tData);} if((key==DN_BTN_Pin)) {currentData.IPZ=0; sh_applysetting(¤tData);} break; /* case SAVING: wrPar(); menuPointer=WORK; sh_applysetting(¤tData);//todo Сделать по нормальному. break; */ } //close switch } }; //close keysHandler void keysHandlerCallibration(void){ uint16_t key = KEY_STATE; KEY_STATE = 0; if(HAL_GPIO_ReadPin(OFF_GPIO_Port, OFF_Pin) == GPIO_PIN_RESET) ignoreOff_flag=0; //как только кнопку включения отпустили, перестаём её игнорировать if((HAL_GPIO_ReadPin(OFF_GPIO_Port, OFF_Pin) == GPIO_PIN_SET)&&(ignoreOff_flag==0)){ wrCor(); HAL_GPIO_WritePin(ON_GPIO_Port, ON_Pin , GPIO_PIN_SET); } // if(key==OK_BTN_Pin){ //По нажатию ОК //if(menuPointer==GROUND){menuPointer=WORK;} //todo сделай сохранение //Если крайний пункт меню то возвращаемся к работе sh_applysetting(¤tData); menuPointer++; //иначе следующий пункт } switch (menuPointer){ case KUSET: if((key==UP_BTN_Pin)&&(currentData.IKUKu0_1)) {currentData.IKU--; sh_applysetting(¤tData);} break; case DAC0SET: if(key==UP_BTN_Pin) { if((correctedKu[currentData.IKU]+1000<=4095)) correctedKu[currentData.IKU]=correctedKu[currentData.IKU]+1000; sh_applysetting(¤tData); }; if((key==DN_BTN_Pin)) { if((correctedKu[currentData.IKU]-1000>=1)) correctedKu[currentData.IKU]=correctedKu[currentData.IKU]-1000; sh_applysetting(¤tData); } break; case DAC1SET: if(key==UP_BTN_Pin) { if((correctedKu[currentData.IKU]+100<=4095)) correctedKu[currentData.IKU]=correctedKu[currentData.IKU]+100; sh_applysetting(¤tData); }; if((key==DN_BTN_Pin)) { if((correctedKu[currentData.IKU]-100>=1)) correctedKu[currentData.IKU]=correctedKu[currentData.IKU]-100; sh_applysetting(¤tData); } break; case DAC2SET: if(key==UP_BTN_Pin) { if((correctedKu[currentData.IKU]+10<=4095)) correctedKu[currentData.IKU]=correctedKu[currentData.IKU]+10; sh_applysetting(¤tData); }; if((key==DN_BTN_Pin)) { if((correctedKu[currentData.IKU]-10>=1)) correctedKu[currentData.IKU]=correctedKu[currentData.IKU]-10; sh_applysetting(¤tData); } break; case DAC3SET: if(key==UP_BTN_Pin) { if((correctedKu[currentData.IKU]+1<=4095)) correctedKu[currentData.IKU]=correctedKu[currentData.IKU]+1; sh_applysetting(¤tData); }; if((key==DN_BTN_Pin)) { if((correctedKu[currentData.IKU]-1>=1)) correctedKu[currentData.IKU]=correctedKu[currentData.IKU]-1; sh_applysetting(¤tData); } break; case SAVE: wrCor(); sh_applysetting(¤tData);//todo Сделать по нормальному. menuPointer=KUSET; break; } //close switch }; //close keysHandlerCallibration