printer:avr: Fix startup behavior if in correction mode
Also introduce startup wait until 0xFF is received.
This commit is contained in:
parent
0ec64e6a39
commit
323fa68222
@ -294,6 +294,7 @@ static int lw35ioc_chardev_open(struct inode *inodep, struct file *filep) {
|
|||||||
lw35ioc_reset_ioc_hw(serdev);
|
lw35ioc_reset_ioc_hw(serdev);
|
||||||
usleep_range(2100000, 2210000);
|
usleep_range(2100000, 2210000);
|
||||||
dev_info(&serdev->dev, "Put ioc into active mode.\n");
|
dev_info(&serdev->dev, "Put ioc into active mode.\n");
|
||||||
|
serdev_device_write(serdev, "\xFF", 1, 0);
|
||||||
priv->state = ACTIVE;
|
priv->state = ACTIVE;
|
||||||
break;
|
break;
|
||||||
case ACTIVE:
|
case ACTIVE:
|
||||||
|
@ -112,7 +112,7 @@ void hardfault() {
|
|||||||
#define PRINTER_CONTROL_CHAR 56
|
#define PRINTER_CONTROL_CHAR 56
|
||||||
#define PRINTER_NO_CHAR 128
|
#define PRINTER_NO_CHAR 128
|
||||||
|
|
||||||
#define ASCII_TRANSLATION_TABLE_SIZE 128 + 12
|
#define ASCII_TRANSLATION_TABLE_SIZE (128 + 12)
|
||||||
const uint8_t ascii_translation_table[ASCII_TRANSLATION_TABLE_SIZE] PROGMEM = {
|
const uint8_t ascii_translation_table[ASCII_TRANSLATION_TABLE_SIZE] PROGMEM = {
|
||||||
PRINTER_CONTROL_CHAR,
|
PRINTER_CONTROL_CHAR,
|
||||||
PRINTER_CONTROL_CHAR,
|
PRINTER_CONTROL_CHAR,
|
||||||
@ -277,6 +277,9 @@ const uint8_t ascii_translation_table[ASCII_TRANSLATION_TABLE_SIZE] PROGMEM = {
|
|||||||
#define PIN_CORRECTION (1 << 1)
|
#define PIN_CORRECTION (1 << 1)
|
||||||
#define PIN_ARMHAMMER (1 << 0)
|
#define PIN_ARMHAMMER (1 << 0)
|
||||||
|
|
||||||
|
/* Misc I/O */
|
||||||
|
#define MISCIO(t) t##D
|
||||||
|
#define PIN_BACKLIGHT (1 << 2)
|
||||||
|
|
||||||
/* Stepper drive */
|
/* Stepper drive */
|
||||||
|
|
||||||
@ -671,11 +674,22 @@ void move_carriage_to_far_left(uint8_t reset)
|
|||||||
|
|
||||||
if (LIMITSWITCH) {
|
if (LIMITSWITCH) {
|
||||||
debug_write("[car] Clearing switch area...\r\n");
|
debug_write("[car] Clearing switch area...\r\n");
|
||||||
while (LIMITSWITCH) {
|
cnt = 32;
|
||||||
|
while (LIMITSWITCH && (cnt> 0)) {
|
||||||
if (block_for(TIM_CARRIAGE, STEPPER_CFG_CARRIAGE.delay)) {
|
if (block_for(TIM_CARRIAGE, STEPPER_CFG_CARRIAGE.delay)) {
|
||||||
STEPPER_NEXT(CARRIAGE, 1);
|
STEPPER_NEXT(CARRIAGE, 1);
|
||||||
|
cnt--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (LIMITSWITCH && !cnt) { // We're probably in correction mode
|
||||||
|
DCMOTOR_EN;
|
||||||
|
arm_correction();
|
||||||
|
_delay_ms(1000);
|
||||||
|
DCMOTOR_STOP;
|
||||||
|
}
|
||||||
|
if (LIMITSWITCH) { // If the switch is still not released, there's some problem we can't fix from SW
|
||||||
|
hardfault();
|
||||||
|
}
|
||||||
for (cnt = 0; cnt < 16; cnt++) {
|
for (cnt = 0; cnt < 16; cnt++) {
|
||||||
STEPPER_NEXT(CARRIAGE, 1);
|
STEPPER_NEXT(CARRIAGE, 1);
|
||||||
}
|
}
|
||||||
@ -911,7 +925,7 @@ void printer_process()
|
|||||||
|
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case IDLE:
|
case IDLE:
|
||||||
if (print_buffer_rd != print_buffer_wr) { // maybe add "|| current_is_linebreak"
|
if (print_buffer_rd != print_buffer_wr) { // TODO: maybe add "|| current_is_linebreak"
|
||||||
if (!DCMOTOR_ISACTIVE) {
|
if (!DCMOTOR_ISACTIVE) {
|
||||||
DCMOTOR_EN;
|
DCMOTOR_EN;
|
||||||
_delay_ms(100); /* Let the motor get up to speed */
|
_delay_ms(100); /* Let the motor get up to speed */
|
||||||
@ -1019,7 +1033,8 @@ void printer_process()
|
|||||||
// stepper_status_WHEEL.target_pos += 10;
|
// stepper_status_WHEEL.target_pos += 10;
|
||||||
// // -----------
|
// // -----------
|
||||||
|
|
||||||
if (stepper_status_CARRIAGE.target_pos > PRINTER_STOP_RIGHT) { // Right margin safety
|
if (stepper_status_CARRIAGE.target_pos > PRINTER_STOP_RIGHT ||
|
||||||
|
stepper_status_CARRIAGE.target_pos < 0) { // Margin safety
|
||||||
hardfault();
|
hardfault();
|
||||||
}
|
}
|
||||||
stepper_perform_movement(&stepper_status_LINEFEED, &STEPPER_CFG_LINEFEED);
|
stepper_perform_movement(&stepper_status_LINEFEED, &STEPPER_CFG_LINEFEED);
|
||||||
@ -1211,10 +1226,10 @@ static void system_test_auto()
|
|||||||
if (POSITION_REACHED(WHEEL) && POSITION_REACHED(CARRIAGE) && POSITION_REACHED(LINEFEED) && print_stat) {
|
if (POSITION_REACHED(WHEEL) && POSITION_REACHED(CARRIAGE) && POSITION_REACHED(LINEFEED) && print_stat) {
|
||||||
print_stat = 0;
|
print_stat = 0;
|
||||||
debug_printf("[pos] %uL %uC%c %uW\r\n",
|
debug_printf("[pos] %uL %uC%c %uW\r\n",
|
||||||
stepper_status_LINEFEED.pos,
|
stepper_status_LINEFEED.pos,
|
||||||
stepper_status_CARRIAGE.pos,
|
stepper_status_CARRIAGE.pos,
|
||||||
(LIMITSWITCH ? '*' : '+'),
|
(LIMITSWITCH ? '*' : '+'),
|
||||||
stepper_status_WHEEL.pos);
|
stepper_status_WHEEL.pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (do_it) {
|
if (do_it) {
|
||||||
@ -1274,6 +1289,10 @@ int main()
|
|||||||
STEPPER_SET_IO(WHEEL);
|
STEPPER_SET_IO(WHEEL);
|
||||||
STEPPER_SET_IO(LINEFEED);
|
STEPPER_SET_IO(LINEFEED);
|
||||||
|
|
||||||
|
/* Set up miscellaneous I/O */
|
||||||
|
MISCIO(DDR) |= PIN_BACKLIGHT;
|
||||||
|
MISCIO(PORT) |= PIN_BACKLIGHT; /* Permanently enable backlight */
|
||||||
|
|
||||||
/* Set up SysTick Timer */
|
/* Set up SysTick Timer */
|
||||||
TCCR1B = (1 << WGM12) | (1 << CS11); // f_tim = 8 MHz / 8
|
TCCR1B = (1 << WGM12) | (1 << CS11); // f_tim = 8 MHz / 8
|
||||||
OCR1A = 2000 / TIMESCALE;
|
OCR1A = 2000 / TIMESCALE;
|
||||||
@ -1283,6 +1302,11 @@ int main()
|
|||||||
sync_uart();
|
sync_uart();
|
||||||
update_status(0);
|
update_status(0);
|
||||||
debug_write("\n\n\r[sys] STARTING IO CONTROLLER...\r\n");
|
debug_write("\n\n\r[sys] STARTING IO CONTROLLER...\r\n");
|
||||||
|
#ifndef DEBUG_BUILD
|
||||||
|
while (!((UCSRA & (1 << RXC)) && (UDR == 0xFF))); /* Wait for init command from driver */
|
||||||
|
update_status(0);
|
||||||
|
_delay_ms(250);
|
||||||
|
#endif
|
||||||
debug_write("[sys] Enabling interrupts.\r\n");
|
debug_write("[sys] Enabling interrupts.\r\n");
|
||||||
sei();
|
sei();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user