Fix motor off by one errors.
[uccvend-snackrom.git] / ROM2 / main_basic.c
index f3bd010..ae25a79 100644 (file)
@@ -141,6 +141,8 @@ void ping_pong() {
 u16 last_coin_value;
 bool last_door_open;
 char display_buf[11];
+/* cur_motor[0] is 0 for nothing, or 1..10, or 0xff to say redraw.
+ * cur_motor[1] is 0..9 and only meaningful is cur_motor[0] != 0. */
 u8 cur_motor[2];
 
 int main() {
@@ -164,15 +166,13 @@ int main() {
        comm_init();
        coinmech_init();
        keypad_init();
+       last_coin_value = 0;
+       last_door_open = 0;
 
-       delay(500);
+       delay(1000);
 
        set_msg("  CRUEL   ");
 
-       last_coin_value = 0;
-       last_door_open = 0;
-
-       dispense_motor(22);
        delay(1000);
 
        set_msg("   WORLD  ");
@@ -180,7 +180,7 @@ int main() {
 
        chime_start();
 
-       cur_motor[0] = 0;
+       cur_motor[0] = 0xff;
        while(1) {
                if (cur_motor[0] == 0xff) { /* signal to say redraw screen */
                        set_msg("*5N4X0RZ* ");
@@ -190,15 +190,15 @@ int main() {
                if (door_open() != last_door_open) {
                        last_door_open = door_open();
                        send_door_msg(last_door_open);
+                       chime_start();
                        if (last_door_open) {
-                               chime_start();
                                set_msg("DOOR OPEND");
                        } else {
-                               chime_start();
                                set_msg("DOOR CLOSE");
                        }
                }
 
+               /*
                if (rx_queue_state) {
                        switch (msg_buf[0]) {
                                case 'V':
@@ -220,12 +220,13 @@ int main() {
                                        ping_pong();
                                        break;
                                default:
-                               /* shrug */
+                                       // shurg
                                        send_nack();
                                        break;
                        }
                        msg_clr();
                }
+               */
 
                keypad_read();
                if (keypad_pressed()) {
@@ -233,28 +234,47 @@ int main() {
                                cur_motor[0] = 0xff;
                        } else {
                                if (cur_motor[0]) {
+                                       u8 motor_num;
                                        cur_motor[1] = last_key%10;
-                                       display_buf[1] = cur_motor[0]+'0';
+                                       display_buf[1] = cur_motor[1]+'0';
                                        set_msg(display_buf);
-                                       dispense_motor(cur_motor[0]*10 + cur_motor[1]);
-                                       set_msg("   DONE   ");
+
+                                       motor_num = cur_motor[0]%10;
+                                       motor_num *= 10;
+                                       motor_num += cur_motor[1];
+                                       switch (dispense_motor(motor_num)) {
+                                               case MOTOR_HOME_FAIL:
+                                                       set_msg(" HOME FAIL ");
+                                                       break;
+                                               case MOTOR_CURRENT_FAIL:
+                                                       set_msg(" OVER CRNT ");
+                                                       break;
+                                               case MOTOR_SUCCESS:
+                                                       set_msg("THANK  YOU");
+                                                       break;
+                                               default:
+                                                       set_msg("ERRRRRRRR?");
+                                                       break;
+                                       }
+
                                        display_buf[0] = ' ';
                                        display_buf[1] = ' ';
                                        cur_motor[0] = 0xff;
-                                       delay(1000);
+                                       delay(500);
                                } else {
-                                       cur_motor[0] = last_key%10;
-                                       display_buf[0] = cur_motor[0]+'0';
+                                       cur_motor[0] = last_key;
+                                       display_buf[0] = (last_key%10)+'0';
                                        set_msg(display_buf);
                                }
                        }
                        send_keypress(last_key);
                }
 
+               /*
                if (coin_value != last_coin_value) {
                        send_balance();
                        last_coin_value = coin_value;
                }
+               */
        }
 }
-

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