# 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
*
*/
+#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 */
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;
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);
}
}
/* 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_ */
#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
return 1;
}
+void selection_menu() {
+ set_msg("ENTER SELECTION OR INSERT COINS", WRAP_SCROLL);
+}
+
int main() {
/* do stuff */
set_msg("UNIVERSITY", WRAP_NONE);
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 */
}
}
}
}
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--;
}
--- /dev/null
+#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 */
+}
--- /dev/null
+#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_ */