More changes
[uccvend-snackrom.git] / ROM2 / main.c
index ffeb9d2..2960c52 100644 (file)
@@ -6,6 +6,7 @@
 
 u16 uid;
 u16 pin;
+u8 selection;
 
 u16 scroll_timer;
 
@@ -41,8 +42,9 @@ bool pin_enter() {
         *
         * Also display X's on screen as the pin is entered.
         */
+       pin = 0;
        set_msg("PIN?      ", WRAP_NONE);
-       for (pinpos = 1; pinpos <= 5; pinpos++) {
+       for (pinpos = 1; pinpos <= 4; pinpos++) {
                keypad_getkey();
                if (last_key == KEY_RESET) {
                        pin = 0;
@@ -54,8 +56,98 @@ bool pin_enter() {
        return 1;
 }
 
+void make_request(u8 selection) {
+       switch(server_request(uid, pin, selection)) {
+               case REQUEST_OK:
+                       set_msg("THANK YOU!", WRAP_NONE);
+                       break;
+               case REQUEST_NO_MONEY:
+                       set_msg("NO MONEY!", WRAP_NONE);
+                       break;
+               case REQUEST_SERVFAIL:
+                       set_msg("SERV FAIL!", WRAP_NONE);
+                       break;
+               case REQUEST_EMPTY:
+                       set_msg("NONE LEFT!", WRAP_NONE);
+                       break;
+               case REQUEST_INVAL:
+                       set_msg(" BAD SELN ", WRAP_NONE);
+                       break;
+       }
+       delay(1000);
+}
+
 void selection_menu() {
-       set_msg("ENTER SELECTION OR INSERT COINS", WRAP_SCROLL);
+       /* we have a valid username & PIN number */
+       /* either ask for a 2-digit selection, or wait for coins to be entered */
+       /* get the username somehow? */
+       set_msg("ENTER SELECTION OR INSERT COINS  ", WRAP_SCROLL);
+       selection = 0;
+       while(1) {
+               if (coin_value) {
+                       int prev_coin = 0;
+                       /* alternate between the price and a confirm message */
+                       while (coin_value) {
+                               if (prev_coin != coin_value) {
+                                       print_amount(coin_value);
+                                       append_msg("0: CONFIRM", WRAP_ALTERNATE);
+                                       prev_coin = coin_value;
+                               }
+                               keypad_read();
+                               if (keypad_pressed()) {
+                                       switch (last_key) {
+                                               case KEY_RESET:
+                                                       coin_refund();
+                                                       goto reset;
+                                               case KEY_0:
+                                                       switch (server_credit_account(uid, pin, coin_value)) {
+                                                               case CREDIT_OK:
+                                                                       coin_eat();
+                                                                       set_msg(" SUCCESS! ");
+                                                                       delay(1000);
+                                                                       break;
+                                                               case CREDIT_FAIL:
+                                                                       coin_refund();
+                                                                       set_msg("  FAILED! ");
+                                                                       delay(1000);
+                                                                       break;
+                                                       }
+                                                       break;
+                                       }
+                               }
+                       }
+                       /* coins were refunded */
+               }
+
+               if (selection) { /* half way through a selection */
+                       keypad_read();
+                       if (keypad_pressed()) {
+                               switch (last_key) {
+                                       case KEY_RESET:
+                                               selection = 0;
+                                               break;
+                                       case 0:
+                                               break;
+                                       default:
+                                               selection = selection * 10 + (last_key%10);
+                                               make_request(uid, pin, selection);
+                                               selection = 0;
+                               }
+                       }
+               } else { /* else listen for the first key of a selection */
+                       keypad_read();
+                       if (keypad_pressed()) {
+                               switch (last_key) {
+                                       case KEY_RESET:
+                                               return;
+                                       case 0:
+                                               break;
+                                       default:
+                                               selection = last_key%10;
+                               }
+                       }
+               }
+       }
 }
 
 void load_default_msg() {

UCC git Repository :: git.ucc.asn.au