}
}
-void motor_on(u8 slot) {
+void set_motor(u8 slot) {
u8 row, col;
row = slot%10;
col = slot/10;
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;
}
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;
}
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;
}
}