/**************************/ /* main() */ /**************************/ int main() { global RFID_flag; global LCDmod_flag; global keypress_flag; LCDinit() while (1) { // check flags if (RFID_flag == 1) { // RFID was received HandleRFID(); } if (LCDmod_flag == 1) { // LCD needs to be updated UpdateLCD(); } if (keypress_flag == 1) { // key was pressed PollKeypad(); } } } /**************************/ /* HandleRFID() */ /**************************/ void HandleRFID() { global item_name; global item_desc; global item_price; global cust_name; global cust_pin; global cust_email; global total; global keystate; int pin_try = 0; // RFID scanned is in memory at addr 0x__ // query DB to check if RFID was valid valid = DBCheck() if (valid == 1 and item == 1) { // valid item was scanned // item name, description, and weight stored in memory at addr 0x__ UpdateLCD() // show item name, description, cost wait (3 sec) // hold info on screen for 3 seconds // add item to shopping cart total += total + item_price; UpdateLCD() // show new shopping cart with most recent item added } else if (valid == 1 and item == 0) { // valid person was scanned // person name, PIN, email address stored in memory at addr 0x__ UpdateLCD() // show welcome with person's name, prompt for PIN entry // get 4 keypresses good_pin = ComparePIN() while (pin_try < 3) { // get 4 keypresses, store to pin_attempt // compare entered PIN with one cust_pin good_pin = ComparePIN() if (good_pin) { keystate++; UpdateLCD() // show screen to prompt user to scan first item return; } else { // increment pin count pin_try++; UpdateLCD() // show "incorrect PIN.. please try again" } } // once here, pin_try = 3 and attempts are up UpdateLCD() // show "sorry, you have maximized PIN attempts, please come back later" wait (3 secs) // hold info on screen for 3 seconds UpdateLCD() // show logo screen with prompt to swipe keyfob } else if (valid == 0 and item == 1) { // invalid item was scanned UpdateLCD() // display "item not recognized" wait (3 sec) // hold info on screen for 3 seconds UpdateLCD() // show original shopping cart } else { // invalid person scanned keyfob UpdateLCD() // display "person not recognized" wait (3 sec) // hold info on screen for 3 seconds UpdateLCD() // show logo screen with prompt to swipe keyfob } return; } /**************************/ /* PollKeypad() */ /**************************/ void PollKeypad() { global keystate; // 0 = idle // 1 = PIN entered, user is swiping // 2 = user completed checkout // 3 = final // key was pressed if (keystate == 0) { // first use in this session, so user needs to swipe keyfob UpdateLCD() // show "you must first swipe your keyfob" wait (3 secs) UpdateLCD() // show logo screen with prompt to swipe keyfob } if (keystate == 1) { // PIN already entered... check press: if (key == numberpad OR key == cancel) { UpdateLCD() // show "I'm sorry, that function is not recognized" wait (3 secs) UpdateLCD() // show unmodified shopping cart } else if (key == '?') { UpdateLCD() // show some help (probably tell them to scan tag on item wait (3 secs) UpdateLCD() // show unmodified shopping cart } else if (key == 'clear') { // user wants to remove last item if (item_cnt < 1) { UpdateLCD() // show "sorry, you have no items in your cart. Swipe tag to begin checkout" wait (3 secs) UpdateLCD() // show empty shopping cart } else { UpdateLCD() // show "Are you sure you want to delete the last item, press enter to confirm, cancel to quit" // wait for keypress received if (key == 'enter') { // remove most recent item from shopping cart UpdateLCD() // show updated shopping cart } else if (key == 'cancel') { UpdateLCD() // show unmodified shopping cart } else { // do nothing } } else if (key == 'enter') { // user is finished shopping UpdateLCD() // show "Are you sure you are finished shopping, enter to confirm, cancel to return" // wait for keypress received if (key == 'enter') { UpdateLCD() // show "Would you like a printed receipt?" // wait for keypress received if (key == 'enter') { PrintReceipt() EmailReceipt() } else if (key == 'cancel') { EmailReceipt() } } else if (key == 'cancel') { UpdateLCD() // show unmodified shopping cart } else { UpdateLCD() // show "I'm sorry, that function is not recognized" wait (3 secs) UpdateLCD() // show unmodified shopping cart } } } return; } /**************************/ /* PrintReceipt() */ /**************************/ void PrintReceipt() { UpdateLCD() // show "printing receipt" // print data UpdateLCD() // show "please take your receipt" return; } /**************************/ /* EmailReceipt() */ /**************************/ void EmailReceipt() { UpdateLCD() // show "emailing receipt to *cust_email*" // email receipt // wait for confirmation // if confirmation received, UpdateLCD() // show "email sent. Thank you for shopping RFID Xpr3ss. Have a Nice Day." return; }