More code
[uccvend-snackrom.git] / ROM2 / main.c
index 188fef0..c275801 100644 (file)
 #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
+        * reading. Returns true if a UID was entered successfully.
+        * The UID will be entered as 5 digits. (shorter uids should be pre-padded
+        * with zeros)
+        */
+       uid = last_key%10; /* 10 => 0, it was _not_ reset (hopefuly :) */
+       set_msg("UID?      ", WRAP_NONE);
+       set_char((last_key%10)+'0', 5);
+
+       for (uidpos = 2; uidpos <= 5; uidpos++) {
+               keypad_getkey();
+               if (last_key == KEY_RESET) {
+                       uid = 0;
+                       return 0;
+               }
+               uid = (uid*10) + (last_key%10);
+               set_char((last_key%10)+'0', 4+uidpos);
+       }
+       return 1;
+}
+
+
+bool pin_enter() {
+       u8 pinpos;
+       /* We ask for a pin, display a PIN: prompt. PINs must be a 4 digit number.
+        * Strictly, they must be 16-bit, but it's easier to use the guarantee that
+        * 4-digits numbers are < 65536
+        *
+        * Also display X's on screen as the pin is entered.
+        */
+       set_msg("PIN?      ", WRAP_NONE);
+       for (pinpos = 1; pinpos <= 5; pinpos++) {
+               keypad_getkey();
+               if (last_key == KEY_RESET) {
+                       pin = 0;
+                       return 0;
+               }
+               pin = (pin*10) + (last_key%10);
+               set_char('X', 4+pinpos);
+       }
+       return 1;
+}
+
+void selection_menu() {
+       set_msg("ENTER SELECTION OR INSERT COINS", WRAP_SCROLL);
+}
+
 int main() {
        /* do stuff */
-       set_msg("UNIVERSITY");
+       set_msg("UNIVERSITY", WRAP_NONE);
        delay(1000);
-       set_msg(" COMPUTER ");
+       set_msg(" COMPUTER ", WRAP_NONE);
        delay(1000);
-       set_msg("   CLUB   ");
+       set_msg("   CLUB   ", WRAP_NONE);
        delay(1000);
 
+       /* 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 at the main menu
+                */
+               keypad_read();
+               if (keypad_pressed()) {
+                       if (last_key != KEY_RESET) {
+                               if (uid_enter() && pin_enter()) {
+                                       /* authenticate them */
+                                       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 */
+                       }
+               }
        }
 }
 
@@ -20,6 +110,18 @@ void _start() {
         */
        display_init();
        set_bus_expanded();
+       /* enable RTI & set rate */
+       /* init coin mech */
        main();
 }
 
+void rti() {
+       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