More code
[uccvend-snackrom.git] / ROM2 / main.c
index 116704b..c275801 100644 (file)
@@ -1,11 +1,14 @@
 #include "display.h"
 #include "keypad.h"
 #include "chime.h"
+#include "server.h"
 #include "vend.h"
 
 u16 uid;
 u16 pin;
 
+u16 scroll_timer;
+
 bool uid_enter() {
        u8 uidpos;
        /* the user has started to type in his/her UID. grab the last key and continue
@@ -51,6 +54,10 @@ bool pin_enter() {
        return 1;
 }
 
+void selection_menu() {
+       set_msg("ENTER SELECTION OR INSERT COINS", WRAP_SCROLL);
+}
+
 int main() {
        /* do stuff */
        set_msg("UNIVERSITY", WRAP_NONE);
@@ -60,21 +67,38 @@ int main() {
        set_msg("   CLUB   ", WRAP_NONE);
        delay(1000);
 
-       set_msg("UCC *** INSERT COINS OR USER-ID", WRAP_SCROLL_L);
+       /* FIXME: want this message to be changeable from the server */
+       set_msg("UNIVERISTY COMPUTER CLUB *** INSERT COINS OR USER-ID ***",
+                       WRAP_SCROLL);
        while(1) {
                /* this needs to be a relatively tight loop to make sure we catch
-                * keypresses
+                * keypresses at the main menu
                 */
                keypad_read();
                if (keypad_pressed()) {
                        if (last_key != KEY_RESET) {
                                if (uid_enter() && pin_enter()) {
                                        /* authenticate them */
-                               } else {
-                                       uid = 0;
-                                       pin = 0;
-                                       /* move on */
+                                       switch (server_authenticate(uid, pin)) {
+                                               case AUTH_GOOD:
+                                                       selection_menu();
+                                               case AUTH_BAD:
+                                                       set_msg(" BAD USER ", WRAP_NONE);
+                                                       delay(1000);
+                                                       break;
+                                               case AUTH_NO_MONEY:
+                                                       set_msg(" NO MONEY ", WRAP_NONE);
+                                                       delay(1000);
+                                                       break;
+                                               case AUTH_LOCKED:
+                                                       set_msg("YOUR ACCOUNT IS LOCKED", WRAP_SCROLL);
+                                                       delay(1000);
+                                                       break;
+                                       }
                                }
+                               uid = 0;
+                               pin = 0;
+                               /* move on */
                        }
                }
        }
@@ -92,5 +116,12 @@ void _start() {
 }
 
 void rti() {
-       chime();
+       chime(); /* turn chime on or of as need be */
+
+       /* scroll the display if need be too */
+       if (scroll_timer == 0) {
+               display_shift();
+               scroll_timer = SCROLL_TIME;
+       }
+       scroll_timer--;
 }

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