From: Bernard Blackham Date: Wed, 6 Aug 2003 17:04:29 +0000 (+0000) Subject: More code X-Git-Tag: ROMW~97 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=3781ef6863f304c8242fc1216cddbdbb0c74bebe;p=uccvend-snackrom.git More code --- diff --git a/ROM2/Makefile b/ROM2/Makefile index e79afb2..440d4cf 100644 --- a/ROM2/Makefile +++ b/ROM2/Makefile @@ -1,7 +1,7 @@ # muchly stolen from m68hc1x's example.tar.gz's Makefile OBJS = \ - motors.o keypad.o display.o coinmech.o chime.o helpers.o main.o \ + motors.o keypad.o display.o coinmech.o chime.o helpers.o server.o main.o \ vectors.o INCLUDES = vend.h keypad.h chime.h asm.h display.h ports.h types.h diff --git a/ROM2/display.c b/ROM2/display.c index af96921..da51973 100644 --- a/ROM2/display.c +++ b/ROM2/display.c @@ -9,10 +9,12 @@ * */ +#include "display.h" #include "vend.h" char display_buffer[10]; /* what each byte on the display reads */ char current_message[256]; /* message that is scrolled or switched between */ +u8 msg_length; /* length of current_message */ u8 wrap_mode; /* whether to scroll or alternate between msgs */ u8 scroll_point; /* how far through the message we have scrolled */ @@ -25,16 +27,35 @@ void set_msg(char* newmsg, u8 wrap) { char* dest = current_message; /* equivalent of a string copy */ /* while (dest++ = newmsg++); */ + msg_length = 0; while (newmsg) { dest = newmsg; dest++; newmsg++; + msg_length++; } wrap_mode = wrap; scroll_point = 0; display_update(); } +void display_shift() { + /* update the display for WRAP_SCROLL or WRAP_ALTERNATE modes */ + switch (wrap_mode) { + case WRAP_SCROLL: + scroll_point++; + if (scroll_point >= msg_length) scroll_point = 0; + display_update(); + break; + case WRAP_ALTERNATE: + scroll_point += 10; + if (scroll_point >= msg_length) scroll_point = 0; + /* the above means that only sets of multiples of 10 characters + * are shown (excess ones are not) */ + display_update(); + } +} + void set_char(char c, u8 pos) { /* sets a single character */ display_buffer[pos] = c; @@ -67,15 +88,16 @@ void display_reset() { void display_update() { u8 i; + + for (i=0; i < 10; i++) { + display_buffer[i] = current_message[(i+scroll_point)%msg_length]; + } + + /* hmmm, will this cause some flickering of the display? */ display_reset(); for (i=0; i < 10; i++) { - /* FIXME: we may need to fiddle with the character codes sent to the - * controller. It doesn't seem like we have to, but datasheets for - * the "pin-for-pin" compatible MSC1937 from OKI suggest a different - * character set - */ - display_send_byte(i[display_buffer]&0x7f); + display_send_byte(display_buffer[i]&0x7f); } } diff --git a/ROM2/display.h b/ROM2/display.h index 384ef8d..96f666e 100644 --- a/ROM2/display.h +++ b/ROM2/display.h @@ -5,16 +5,20 @@ /* scrolling modes */ #define WRAP_NONE 0 /* trailing chars get left off */ -#define WRAP_SCROLL_L 1 /* scroll to the left */ -#define WRAP_SCROLL_R 2 /* scroll to the right */ -#define WRAP_ALTERNATE 3 /* alternate between text */ +#define WRAP_SCROLL 1 /* scroll to the left */ +#define WRAP_ALTERNATE 2 /* alternate between text */ + +/* number of RTI events between scrolling letters */ +#define SCROLL_TIME 8 extern char current_message[256]; +extern void display_init(); void set_msg(char* newmsg, u8 wrap); void set_char(char c, u8 pos); void set_wrap_mode(u8 new_wrap_mode); void display_refresh(); +void display_shift(); #endif /* _DISPLAY_H_ */ diff --git a/ROM2/main.c b/ROM2/main.c index 116704b..c275801 100644 --- a/ROM2/main.c +++ b/ROM2/main.c @@ -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--; } diff --git a/ROM2/server.c b/ROM2/server.c new file mode 100644 index 0000000..d121168 --- /dev/null +++ b/ROM2/server.c @@ -0,0 +1,8 @@ +#include "display.h" +#include "server.h" + +u8 server_authenticate(u16 uid, u16 pin) { + set_msg("VERIFYING ", WRAP_NONE); + /* send msgs to server and stuff */ + return AUTH_GOOD; /* for now */ +} diff --git a/ROM2/server.h b/ROM2/server.h new file mode 100644 index 0000000..f07ee54 --- /dev/null +++ b/ROM2/server.h @@ -0,0 +1,11 @@ +#ifndef _SERVER_H_ +#define _SERVER_H_ + +#define AUTH_GOOD 1 +#define AUTH_BAD -1 +#define AUTH_NO_MONEY -2 +#define AUTH_LOCKED -3 + +u8 server_authenticate(u16 uid, u16 pin); + +#endif /* _SERVER_H_ */