UART code for a 16550.
[uccvend-snackrom.git] / ROM2 / main.c
index 2960c52..81919f0 100644 (file)
@@ -2,6 +2,7 @@
 #include "keypad.h"
 #include "chime.h"
 #include "server.h"
+#include "coinmech.h"
 #include "vend.h"
 
 u16 uid;
@@ -30,10 +31,9 @@ bool uid_enter() {
                uid = (uid*10) + (last_key%10);
                set_char((last_key%10)+'0', 4+uidpos);
        }
-       return 1;
+       return (uid!=0);
 }
 
-
 bool pin_enter() {
        u8 pinpos;
        /* We ask for a pin, display a PIN: prompt. PINs must be a 4 digit number.
@@ -57,6 +57,7 @@ bool pin_enter() {
 }
 
 void make_request(u8 selection) {
+       set_msg("REQUESTING", WRAP_NONE); /* XXX: maybe this isn't needed? */
        switch(server_request(uid, pin, selection)) {
                case REQUEST_OK:
                        set_msg("THANK YOU!", WRAP_NONE);
@@ -84,7 +85,7 @@ void selection_menu() {
        set_msg("ENTER SELECTION OR INSERT COINS  ", WRAP_SCROLL);
        selection = 0;
        while(1) {
-               if (coin_value) {
+               if (coin_value) { /* we have coins inserted */
                        int prev_coin = 0;
                        /* alternate between the price and a confirm message */
                        while (coin_value) {
@@ -97,19 +98,20 @@ void selection_menu() {
                                if (keypad_pressed()) {
                                        switch (last_key) {
                                                case KEY_RESET:
-                                                       coin_refund();
-                                                       goto reset;
+                                                       scroll_msg("PRESS COIN REFUND");
+                                                       while (coin_value);
+                                                       break;
                                                case KEY_0:
                                                        switch (server_credit_account(uid, pin, coin_value)) {
                                                                case CREDIT_OK:
                                                                        coin_eat();
-                                                                       set_msg(" SUCCESS! ");
+                                                                       set_msg(" SUCCESS! ", WRAP_NONE);
                                                                        delay(1000);
                                                                        break;
                                                                case CREDIT_FAIL:
-                                                                       coin_refund();
-                                                                       set_msg("  FAILED! ");
-                                                                       delay(1000);
+                                                                       set_msg(" FAILED!  " "PRESS COIN" "  REFUND  ",
+                                                                                       WRAP_ALTERNATE);
+                                                                       while (coin_value);
                                                                        break;
                                                        }
                                                        break;
@@ -130,7 +132,7 @@ void selection_menu() {
                                                break;
                                        default:
                                                selection = selection * 10 + (last_key%10);
-                                               make_request(uid, pin, selection);
+                                               make_request(selection);
                                                selection = 0;
                                }
                        }

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