2 * main_basic.c - a simplified main procedure that relies upon a ersver to do
3 * anything smart. Just be a dumb interface to a display, keypad, coin mech
7 #include "display_basic.h"
15 void motor_reply(char* slotptr, u8 code) {
16 /* returns a message of the form MXYY - X is return code, YY is motor */
19 tx_buffer[1] = code + '0';
20 tx_buffer[2] = *slotptr;
21 tx_buffer[3] = *(slotptr+1);
27 void dispense_something() {
28 /* process a message VXX in msg_buf where XX is motor number */
31 if ((msg_buf[1] < '0') || (msg_buf[1] > '9') ||
32 (msg_buf[2] < '0') || (msg_buf[2] > '9')) {
33 msg_buf[1] = msg_buf[2] = '0';
34 motor_reply((char*)&msg_buf[1], MOTOR_NOSLOT);
38 slot = (msg_buf[1] - '0') * 10;
39 slot += msg_buf[2] - '0';
41 motor_reply((char*)&msg_buf[1], dispense_motor(slot));
44 void write_to_display() {
45 /* process a message in the form DXXXXXXXXXXX to send to display */
48 for (i = 0; i < 10; i++)
50 buf[i] = msg_buf[i+1];
54 for (; i < 10; i++) /* pad the rest out with spaces */
64 tx_buffer[1] = have_change?'0':'1';
65 tx_buffer[2] = (coin_value/10000)%10;
66 tx_buffer[3] = (coin_value/1000)%10;
67 tx_buffer[4] = (coin_value/100)%10;
68 tx_buffer[5] = (coin_value/10)%10;
69 tx_buffer[6] = coin_value%10;
78 if ((msg_buf[1] < '0') || (msg_buf[1] > '9') ||
79 (msg_buf[2] < '0') || (msg_buf[2] > '9') ||
80 (msg_buf[3] < '0') || (msg_buf[3] > '9') ||
81 (msg_buf[4] < '0') || (msg_buf[4] > '9') ||
82 (msg_buf[5] < '0') || (msg_buf[5] > '9')) {
85 cost = msg_buf[1] - '0';
86 cost *= 10; cost = msg_buf[2] - '0';
87 cost *= 10; cost = msg_buf[3] - '0';
88 cost *= 10; cost = msg_buf[4] - '0';
89 cost *= 10; cost = msg_buf[5] - '0';
95 void send_keypress(u8 key) {
96 /* send a packet of the form KX with X being the key, or R for reset */
102 tx_buffer[1] = (key%10)+'0';
108 void send_door_msg(bool open) {
111 tx_buffer[1] = open?'1':'0';
123 /* make sure it's really a ping */
124 if (msg_buf[1] != 'I' ||
130 /* respond with ack & pong */
146 char display_buf[11];
147 for (display_pos = 0; display_pos < 11; display_pos++)
148 display_buf[display_pos] = '\0';
154 for (i = 0; i < 40000; i++) {}
156 for (i = 0; i < 20000; i++) {}
158 for (i = 0; i < 60000; i++) {}
160 changer_output = 0x7f;
161 //_io_ports[M6811_PORTA] = 0xc8; /* for talking to coin mech */
162 _io_ports[M6811_PORTA] = 0xc0; /* for talking to serial port */
163 _io_ports[M6811_DDRA] = 0xfc;
164 _io_ports[M6811_DDRD] = 0x3e;
165 _io_ports[M6811_SPCR] = 0x12;
166 set_misc_output(0x00);
168 chime_off(); /* mainly for debugging */
173 unlock(); /* enable interrupts */
180 while (chime_count != 0);
190 while (chime_count != 0);
194 set_msg("*5N4X0RZ* ");
198 if (door_open() != last_door_open) {
199 last_door_open = door_open();
200 send_door_msg(last_door_open);
201 if (last_door_open) {
203 set_msg("DOOR OPEND");
208 set_msg("DOOR CLOSE");
214 if (rx_queue_state) {
215 switch (msg_buf[0]) {
217 dispense_something();
243 if (keypad_pressed()) {
244 if (last_key == KEY_RESET)
245 display_buf[display_pos] = 'R';
247 display_buf[display_pos] = '0'+(last_key%10);
250 set_msg(display_buf);
251 send_keypress(last_key);
254 if (coin_value != last_coin_value) {
256 last_coin_value = coin_value;