Lots of changes! Takes us to rom S
[uccvend-snackrom.git] / ROM2 / motors.c
index e7cb6b5..efed7cc 100644 (file)
@@ -36,7 +36,7 @@ void motor_shift_send(u8 data) {
        }
 }
 
-void motor_on(u8 slot) {
+void set_motor(u8 slot) {
        u8 row, col;
        row = slot%10;
        col = slot/10;
@@ -61,30 +61,38 @@ void motor_on(u8 slot) {
        motor_shift_send(1 << (row-1)); /* rows from 1..8 here */
 
        bclr((void*)&_io_ports[M6811_PORTA], PORTA_MOTOR_CLOCK);
+}
+
+void motor_start() {
        bclr_changer_output(A3000_MOTOR_ROW_DISABLE);
 }
 
-void motors_off() {
+void motor_pause() {
+       bset_changer_output(A3000_MOTOR_ROW_DISABLE);
+}
+
+void motor_stop() {
        bset_changer_output(A3000_MOTOR_ROW_DISABLE);
-       delay(10); /* XXX cf motors_off */
        bset((void*)&_io_ports[M6811_PORTA], PORTA_MOTOR_COL_DISABLE);
        bclr_misc_output(A3800_MOTOR_COL8_ENABLE | A3800_MOTOR_COL9_ENABLE);
 }
 
 bool motor_here(u8 slot) {
        u8 i, c = 0;
+       set_motor(slot);
        for (i=0; i < 8; i++) {
-               motor_on(slot);
+               motor_start();
                delay(5);
                if ((_io_ports[M6811_PORTE] & PORTE_MOTOR_OVERVOLTAGE) == 0) {
                        c++;
                        if (c == 3) {
-                               motors_off();
+                               motor_stop();
                                return 1;
                        }
                }
-               motors_off();
+               motor_pause();
        }
+       motor_stop();
        return 0;
 }
 
@@ -98,14 +106,15 @@ bool start_motor(u8 slot) {
        u8 r = slot%10;
        if (r >= 5) r--; 
        r = 1 << (r-1);
-       motor_on(slot);
-       delay(100);
+       set_motor(slot);
+       motor_start();
+       delay(50);
        for (i = 0; i < 1000; i++) {
                if ((home_sensors & r) != 0) return 1;
                delay(1);
        }
        /* it never left */
-       motors_off();
+       motor_stop();
        return 0;
 }
 
@@ -139,15 +148,15 @@ bool motor_overcurrent() {
 u8 dispense_motor(u8 slot) {
        if (!is_motor(slot)) return MOTOR_NOSLOT;
        if (!start_motor(slot)) return MOTOR_HOME_FAIL;
+       delay(100);
 
        while (1) {
                if (motor_overcurrent()) {
-                       motors_off();
+                       motor_stop();
                        return MOTOR_CURRENT_FAIL;
                }
-               /* something should call motor_here? */
                if (back_home(slot)) {
-                       motors_off();
+                       motor_stop();
                        return MOTOR_SUCCESS;
                }
        }

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