void USI_Init(void){ userTextIndex = 0; UIF_userInputIndex = 0; memcpy_P((void*)userText, (void*)PIN_str, sizeof(PIN_str)); usi_print(); UCP_Lock(); }
// user input finitestate machine void USI_fsm(uint8_t button) { switch(button){ case LEFT: deleteStr(); USI_Init(); break; case UP: deleteStr(); usi_previous(); break; case RIGHT: deleteStr(); if(userTextIndex == (sizeof(LOCK)-2)) // real array elements (\0) { /* Device Unlocked */ //if(strcmp_P(userText+sizeof(PIN_str)-1, LOCK) == 0) if(USI_pinCheck(userText+sizeof(PIN_str)-1) == 1) { CRD_fsmStart(); UCP_Unlock(); } /* Device Locked */ else { printStr((void*)LOCKED_str,FLASH); userTextIndex = 0; UIF_userInputIndex = 0; memcpy_P((void*)userText, (void*)PIN_str, sizeof(PIN_str)); userText[sizeof(PIN_str)-1+userTextIndex] = pgm_read_byte(&USI_keys[UIF_userInputIndex]); userText[sizeof(PIN_str)-1+userTextIndex+1] = 0; } } else { userTextIndex++; usi_print(); } break; case DOWN: deleteStr(); usi_next(); break; default: break; } }
static void usi_next(void){ UIF_increment(&UIF_userInputIndex, sizeof(USI_keys)); usi_print(); }
static void usi_previous(void){ UIF_decrement(&UIF_userInputIndex, sizeof(USI_keys)); usi_print(); }