Compare commits
No commits in common. "781a02dce68e924fed62f0bb60c6bc74e96dac78" and "97a9f9f4024a4b0b69412c74d0f2fa98e3f6e1c2" have entirely different histories.
781a02dce6
...
97a9f9f402
@ -80,7 +80,7 @@ struct lw35ioc_chardev {
|
|||||||
struct lw35ioc_printer_status{
|
struct lw35ioc_printer_status{
|
||||||
int buffer_free;
|
int buffer_free;
|
||||||
int status;
|
int status;
|
||||||
int rx_count;
|
int reserved0;
|
||||||
int reserved1;
|
int reserved1;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -106,9 +106,6 @@ struct lw35ioc_priv {
|
|||||||
|
|
||||||
enum lw35ioc_state state;
|
enum lw35ioc_state state;
|
||||||
struct lw35ioc_packet packet;
|
struct lw35ioc_packet packet;
|
||||||
|
|
||||||
u8 tx_count;
|
|
||||||
u8 tx_count_resync;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -167,16 +164,16 @@ static int lw35ioc_process_buf(struct serdev_device *serdev,
|
|||||||
priv->printer_status_temp.buffer_free = (int)c;
|
priv->printer_status_temp.buffer_free = (int)c;
|
||||||
break;
|
break;
|
||||||
case 2: /* Reserved */
|
case 2: /* Reserved */
|
||||||
priv->printer_status_temp.rx_count = (int)c;
|
priv->printer_status_temp.reserved0 = (int)c;
|
||||||
break;
|
break;
|
||||||
case 3: /* Reserved */
|
case 3: /* Reserved */
|
||||||
priv->printer_status_temp.reserved1 = (int)c;
|
priv->printer_status_temp.reserved1 = (int)c;
|
||||||
|
|
||||||
dev_info(&serdev->dev,
|
dev_info(&serdev->dev,
|
||||||
"New printer status. status=0x%02X buffer_free=0x%02X rx_count=0x%02X reserved=0x%02X.\n",
|
"New printer status. status=0x%02X buffer_free=0x%02X [0x%02X,0x%02X].\n",
|
||||||
priv->printer_status_temp.status,
|
priv->printer_status_temp.status,
|
||||||
priv->printer_status_temp.buffer_free,
|
priv->printer_status_temp.buffer_free,
|
||||||
priv->printer_status_temp.rx_count,
|
priv->printer_status_temp.reserved0,
|
||||||
priv->printer_status_temp.reserved1);
|
priv->printer_status_temp.reserved1);
|
||||||
if (priv->printer_status_temp.status == 0xFF) {
|
if (priv->printer_status_temp.status == 0xFF) {
|
||||||
dev_err(&serdev->dev,
|
dev_err(&serdev->dev,
|
||||||
@ -295,9 +292,6 @@ static int lw35ioc_chardev_open(struct inode *inodep, struct file *filep) {
|
|||||||
break;
|
break;
|
||||||
case INIT:
|
case INIT:
|
||||||
case PASSIVE:
|
case PASSIVE:
|
||||||
// TODO: locks
|
|
||||||
priv->pbuf_tail = 0;
|
|
||||||
priv->pbuf_head = 0;
|
|
||||||
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");
|
||||||
@ -318,7 +312,6 @@ static int lw35ioc_chardev_open(struct inode *inodep, struct file *filep) {
|
|||||||
//return -EBUSY; // TODO
|
//return -EBUSY; // TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
priv->tx_count_resync = 1;
|
|
||||||
priv->chardev.open_count++;
|
priv->chardev.open_count++;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -505,15 +498,6 @@ void pbuf_work_handler(struct work_struct *work)
|
|||||||
dev_warn(&serdev->dev, "Cannot transmit data to device. Device is not ready.\n");
|
dev_warn(&serdev->dev, "Cannot transmit data to device. Device is not ready.\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (priv->tx_count_resync) {
|
|
||||||
priv->tx_count = priv->printer_status.rx_count;
|
|
||||||
priv->tx_count_resync = 0;
|
|
||||||
}
|
|
||||||
if (priv->printer_status.rx_count != priv->tx_count) {
|
|
||||||
dev_info(&serdev->dev, "Not transmitting any data to device because rx is unconfirmed [tx=%d, rx=%d].\n",
|
|
||||||
priv->tx_count, priv->printer_status.rx_count);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (bsize > priv->printer_status.buffer_free)
|
if (bsize > priv->printer_status.buffer_free)
|
||||||
bsize = priv->printer_status.buffer_free;
|
bsize = priv->printer_status.buffer_free;
|
||||||
if (bsize > CIRC_CNT_TO_END(head, tail, PBUF_SIZE))
|
if (bsize > CIRC_CNT_TO_END(head, tail, PBUF_SIZE))
|
||||||
@ -531,7 +515,7 @@ void pbuf_work_handler(struct work_struct *work)
|
|||||||
dev_warn(&serdev->dev, "Cannot transmit data to device. Device buffer is full.\n");
|
dev_warn(&serdev->dev, "Cannot transmit data to device. Device buffer is full.\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
priv->tx_count += bsize;
|
|
||||||
serdev_device_write_buf(serdev,
|
serdev_device_write_buf(serdev,
|
||||||
priv->pbuf + tail,
|
priv->pbuf + tail,
|
||||||
bsize);
|
bsize);
|
||||||
@ -632,9 +616,6 @@ static int lw35ioc_probe(struct serdev_device *serdev)
|
|||||||
priv->printer_status.buffer_free = 0;
|
priv->printer_status.buffer_free = 0;
|
||||||
priv->printer_status.status = 0;
|
priv->printer_status.status = 0;
|
||||||
|
|
||||||
priv->tx_count = 0;
|
|
||||||
priv->tx_count_resync = 1;
|
|
||||||
|
|
||||||
priv->serdev = serdev;
|
priv->serdev = serdev;
|
||||||
static_serdev = serdev;
|
static_serdev = serdev;
|
||||||
priv->packet.state = SYNC;
|
priv->packet.state = SYNC;
|
||||||
|
@ -1,7 +1,4 @@
|
|||||||
// Known bugs:
|
#include <avr/io.h>
|
||||||
// When having linebreak at the auto-linebreak width, bad things will happen.
|
|
||||||
|
|
||||||
#include <avr/io.h>
|
|
||||||
#include <avr/interrupt.h>
|
#include <avr/interrupt.h>
|
||||||
#include <util/delay.h>
|
#include <util/delay.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -91,13 +88,7 @@ void debug_putc(char c) {};
|
|||||||
unsigned int debug_printf(char *format,...) {return 0;};
|
unsigned int debug_printf(char *format,...) {return 0;};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
enum hardfault_reason {HARDFAULT_REASON_NONE = 0,
|
void hardfault() {
|
||||||
HARDFAULT_REASON_MARGIN,
|
|
||||||
HARDFAULT_REASON_TXOVERFLOW,
|
|
||||||
HARDFAULT_REASON_USER,
|
|
||||||
HARDFAULT_REASON_LIMITSWITCH};
|
|
||||||
|
|
||||||
void hardfault(enum hardfault_reason reason) {
|
|
||||||
cli();
|
cli();
|
||||||
PORTB = 0;
|
PORTB = 0;
|
||||||
PORTC = 0;
|
PORTC = 0;
|
||||||
@ -113,7 +104,6 @@ void hardfault(enum hardfault_reason reason) {
|
|||||||
uart_putc(0x00);
|
uart_putc(0x00);
|
||||||
uart_putc(0x00);
|
uart_putc(0x00);
|
||||||
uart_putc(0x00);
|
uart_putc(0x00);
|
||||||
uart_putc(reason);
|
|
||||||
debug_write("HARDFAULT!\r\n");
|
debug_write("HARDFAULT!\r\n");
|
||||||
while(1);
|
while(1);
|
||||||
}
|
}
|
||||||
@ -626,7 +616,7 @@ void tx_buffer_putc(char c)
|
|||||||
{
|
{
|
||||||
if (tx_buffer_async) {
|
if (tx_buffer_async) {
|
||||||
if (tx_buffer_rd == tx_buffer_wr + 1) // implicit % 256
|
if (tx_buffer_rd == tx_buffer_wr + 1) // implicit % 256
|
||||||
hardfault(HARDFAULT_REASON_TXOVERFLOW);
|
hardfault();
|
||||||
tx_buffer[tx_buffer_wr++] = c; // implicit % 256
|
tx_buffer[tx_buffer_wr++] = c; // implicit % 256
|
||||||
} else {
|
} else {
|
||||||
uart_putc(c);
|
uart_putc(c);
|
||||||
@ -642,7 +632,7 @@ void tx_status()
|
|||||||
tx_buffer_putc(0xAA); /* Header[1] */
|
tx_buffer_putc(0xAA); /* Header[1] */
|
||||||
tx_buffer_putc((char) (global_status | local_status));
|
tx_buffer_putc((char) (global_status | local_status));
|
||||||
tx_buffer_putc(RINGBUF_FREE(print_buffer_wr, print_buffer_rd, PRINT_BUFFER_SIZE));
|
tx_buffer_putc(RINGBUF_FREE(print_buffer_wr, print_buffer_rd, PRINT_BUFFER_SIZE));
|
||||||
tx_buffer_putc(print_buffer_wr); /* RX byte count*/
|
tx_buffer_putc(0); /* RESERVED */
|
||||||
tx_buffer_putc(0); /* RESERVED */
|
tx_buffer_putc(0); /* RESERVED */
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -702,7 +692,7 @@ void move_carriage_to_far_left(uint8_t reset)
|
|||||||
DCMOTOR_STOP;
|
DCMOTOR_STOP;
|
||||||
}
|
}
|
||||||
if (LIMITSWITCH) { // If the switch is still not released, there's some problem we can't fix from SW
|
if (LIMITSWITCH) { // If the switch is still not released, there's some problem we can't fix from SW
|
||||||
hardfault(HARDFAULT_REASON_LIMITSWITCH);
|
hardfault();
|
||||||
}
|
}
|
||||||
for (cnt = 0; cnt < 16; cnt++) {
|
for (cnt = 0; cnt < 16; cnt++) {
|
||||||
STEPPER_NEXT(CARRIAGE, 1);
|
STEPPER_NEXT(CARRIAGE, 1);
|
||||||
@ -743,7 +733,7 @@ void align_daisy_wheel()
|
|||||||
stepper_status_WHEEL.target_pos = 0;
|
stepper_status_WHEEL.target_pos = 0;
|
||||||
stepper_status_WHEEL.ldir = 0;
|
stepper_status_WHEEL.ldir = 0;
|
||||||
|
|
||||||
/* Rotate right for two revolutions -> lock daisy wheel to assembly */
|
/* Rotate right for one revolution -> lock daisy wheel to assembly */
|
||||||
for (i = 0; i < (96 + 1) * 2; ) {
|
for (i = 0; i < (96 + 1) * 2; ) {
|
||||||
if (block_for(TIM_WHEEL, STEPPER_CFG_WHEEL.delay)) {
|
if (block_for(TIM_WHEEL, STEPPER_CFG_WHEEL.delay)) {
|
||||||
STEPPER_NEXT(WHEEL, 1);
|
STEPPER_NEXT(WHEEL, 1);
|
||||||
@ -825,7 +815,7 @@ enum printer_mode_t {MANUAL, INTELLIGENT};
|
|||||||
#define GET_PRINT_CODE(c) (pgm_read_byte(&ascii_translation_table[c]))
|
#define GET_PRINT_CODE(c) (pgm_read_byte(&ascii_translation_table[c]))
|
||||||
|
|
||||||
uint16_t print_margin_left = 100;
|
uint16_t print_margin_left = 100;
|
||||||
uint16_t print_margin_right = PRINTER_STOP_RIGHT - 90; // TODO: should be - 100; see top comment in this source file
|
uint16_t print_margin_right = PRINTER_STOP_RIGHT - 100;
|
||||||
|
|
||||||
int8_t move_one_character(uint8_t backward)
|
int8_t move_one_character(uint8_t backward)
|
||||||
{
|
{
|
||||||
@ -836,7 +826,7 @@ int8_t move_one_character(uint8_t backward)
|
|||||||
stepper_status_CARRIAGE.target_pos -= PRINT_CHARACTER_WIDTH;
|
stepper_status_CARRIAGE.target_pos -= PRINT_CHARACTER_WIDTH;
|
||||||
} else {
|
} else {
|
||||||
if (stepper_status_CARRIAGE.target_pos >= print_margin_right - PRINT_CHARACTER_WIDTH) {
|
if (stepper_status_CARRIAGE.target_pos >= print_margin_right - PRINT_CHARACTER_WIDTH) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
stepper_status_CARRIAGE.target_pos += PRINT_CHARACTER_WIDTH;
|
stepper_status_CARRIAGE.target_pos += PRINT_CHARACTER_WIDTH;
|
||||||
}
|
}
|
||||||
@ -859,7 +849,7 @@ inline int8_t simulate_print_run(uint8_t *start_end_index, uint8_t *recovery_ind
|
|||||||
uint16_t carriage_position;
|
uint16_t carriage_position;
|
||||||
uint8_t translated;
|
uint8_t translated;
|
||||||
uint8_t status = 0;
|
uint8_t status = 0;
|
||||||
uint8_t line_matters = 0; /* A printable character was somewhere on it */
|
uint8_t line_matters = 0;
|
||||||
|
|
||||||
index = *start_end_index;
|
index = *start_end_index;
|
||||||
carriage_position = print_margin_left;
|
carriage_position = print_margin_left;
|
||||||
@ -944,7 +934,7 @@ enum printer_state process_special_command(uint8_t command)
|
|||||||
return INIT;
|
return INIT;
|
||||||
|
|
||||||
case PRINT_COMMAND_HARDFAULLT:
|
case PRINT_COMMAND_HARDFAULLT:
|
||||||
hardfault(HARDFAULT_REASON_USER);
|
hardfault();
|
||||||
return INIT;
|
return INIT;
|
||||||
|
|
||||||
case PRINT_COMMAND_BACKLIGHT_ON:
|
case PRINT_COMMAND_BACKLIGHT_ON:
|
||||||
@ -1024,8 +1014,6 @@ void printer_process()
|
|||||||
static uint8_t print_buffer_recovery = 0;
|
static uint8_t print_buffer_recovery = 0;
|
||||||
|
|
||||||
static uint8_t current_is_linebreak = 0;
|
static uint8_t current_is_linebreak = 0;
|
||||||
static int8_t last_linebreak_was_auto = 0;
|
|
||||||
|
|
||||||
uint8_t current_char;
|
uint8_t current_char;
|
||||||
static uint8_t special_command;
|
static uint8_t special_command;
|
||||||
uint8_t translated;
|
uint8_t translated;
|
||||||
@ -1052,7 +1040,6 @@ void printer_process()
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Check whether the current character is a command or something to print */
|
/* Check whether the current character is a command or something to print */
|
||||||
//if (!last_linebreak_was_auto) FIXME: This doesn't work yet!!! Eat newlines (and doesn't work anyways)
|
|
||||||
current_is_linebreak += (current_char == '\n');
|
current_is_linebreak += (current_char == '\n');
|
||||||
if (current_is_linebreak) {
|
if (current_is_linebreak) {
|
||||||
if (backward) {
|
if (backward) {
|
||||||
@ -1094,8 +1081,7 @@ void printer_process()
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case PRINTER_NO_CHAR:
|
case PRINTER_NO_CHAR:
|
||||||
last_linebreak_was_auto = move_one_character(backward);
|
current_is_linebreak += move_one_character(backward);
|
||||||
current_is_linebreak += last_linebreak_was_auto;
|
|
||||||
if (!current_is_linebreak)
|
if (!current_is_linebreak)
|
||||||
debug_putc(' ');
|
debug_putc(' ');
|
||||||
break;
|
break;
|
||||||
@ -1105,8 +1091,6 @@ void printer_process()
|
|||||||
state = HAMMER;
|
state = HAMMER;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
last_linebreak_was_auto = 0;
|
|
||||||
} else { /* TODO: Special commands */
|
} else { /* TODO: Special commands */
|
||||||
special_command = current_char;
|
special_command = current_char;
|
||||||
state = SPECIAL_COMMAND;
|
state = SPECIAL_COMMAND;
|
||||||
@ -1133,16 +1117,13 @@ void printer_process()
|
|||||||
arm_hammer();
|
arm_hammer();
|
||||||
_delay_ms(50); // TODO: replace with timer
|
_delay_ms(50); // TODO: replace with timer
|
||||||
debug_putc(debug_character);
|
debug_putc(debug_character);
|
||||||
last_linebreak_was_auto = move_one_character(backward);
|
current_is_linebreak += move_one_character(backward);
|
||||||
current_is_linebreak += last_linebreak_was_auto;
|
|
||||||
state = IDLE;
|
state = IDLE;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SPECIAL_COMMAND:
|
case SPECIAL_COMMAND:
|
||||||
state = process_special_command(special_command);
|
state = process_special_command(special_command);
|
||||||
if (state != SPECIAL_COMMAND)
|
|
||||||
tx_status();
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case INIT:
|
case INIT:
|
||||||
@ -1164,7 +1145,7 @@ void printer_process()
|
|||||||
|
|
||||||
if (stepper_status_CARRIAGE.target_pos > PRINTER_STOP_RIGHT ||
|
if (stepper_status_CARRIAGE.target_pos > PRINTER_STOP_RIGHT ||
|
||||||
stepper_status_CARRIAGE.target_pos < 0) { // Margin safety
|
stepper_status_CARRIAGE.target_pos < 0) { // Margin safety
|
||||||
hardfault(HARDFAULT_REASON_MARGIN);
|
hardfault();
|
||||||
}
|
}
|
||||||
stepper_perform_movement(&stepper_status_LINEFEED, &STEPPER_CFG_LINEFEED);
|
stepper_perform_movement(&stepper_status_LINEFEED, &STEPPER_CFG_LINEFEED);
|
||||||
stepper_perform_movement(&stepper_status_CARRIAGE, &STEPPER_CFG_CARRIAGE);
|
stepper_perform_movement(&stepper_status_CARRIAGE, &STEPPER_CFG_CARRIAGE);
|
||||||
|
@ -1,29 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
source shared.sh
|
|
||||||
|
|
||||||
if [ "$1" == "" ]; then
|
|
||||||
echo "usage: $0 <file>"
|
|
||||||
exit;
|
|
||||||
fi
|
|
||||||
|
|
||||||
mkdir -p out
|
|
||||||
rm out/*
|
|
||||||
|
|
||||||
echo ".ll $LL" > out/header
|
|
||||||
cat "$1" | sed 's/\./\\\&./g' > out/text
|
|
||||||
echo ".sp 0" > out/footer
|
|
||||||
cat out/header out/text out/footer | nroff -Tascii > out/render
|
|
||||||
|
|
||||||
cline=0
|
|
||||||
page=1
|
|
||||||
while IFS="" read -r p || [ -n "$p" ]
|
|
||||||
do
|
|
||||||
cline=$(($cline + 1))
|
|
||||||
if [ $cline -eq $PL ]; then
|
|
||||||
page=$(($page + 1))
|
|
||||||
cline=0
|
|
||||||
fi
|
|
||||||
printf '%s\n' "$p" >> "out/out$page.txt"
|
|
||||||
done < out/render
|
|
||||||
|
|
||||||
echo "Created $page pages."
|
|
@ -1,39 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
source shared.sh
|
|
||||||
|
|
||||||
ML=$(( (110-$LL) / 2))
|
|
||||||
MT=$(( (64 - $PL) / 2 ))
|
|
||||||
echo "Margin left: $ML"
|
|
||||||
echo "Margin top : $MT"
|
|
||||||
echo "Page width : $LL"
|
|
||||||
echo "Page length: $PL"
|
|
||||||
|
|
||||||
if [ $MT -gt 127 ]; then
|
|
||||||
echo "Margin top > 127 not supported because I am lazy. Is $MT."
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
MT=$(( $MT + 128 )) # Set "move by n line bit"
|
|
||||||
#exit
|
|
||||||
echo -ne $(printf "\\\\x%02x\\\\x%02x" 224 $ML) > /dev/lw35
|
|
||||||
MR=$((ML + $LL + 2)); # Plus 2 because bug in FW in conjunction with manual newlines
|
|
||||||
echo -ne $(printf "\\\\x%02x\\\\x%02x" 225 $MR) > /dev/lw35
|
|
||||||
|
|
||||||
for file in ./out/out*; do
|
|
||||||
foo=""
|
|
||||||
while [ true ]; do
|
|
||||||
echo "Insert a piece of paper and press enter. When you're done, enter y."
|
|
||||||
read foo
|
|
||||||
if [ "$foo" == "y" ]; then
|
|
||||||
break;
|
|
||||||
fi
|
|
||||||
echo -ne "\xE3\x8C" > /dev/lw35 # Draw in until at top of paper
|
|
||||||
echo -ne $(printf "\\\\x%02x\\\\x%02x" 0xE3 $MT) > /dev/lw35 # Move over margin top
|
|
||||||
done
|
|
||||||
echo "Printing part $file..."
|
|
||||||
|
|
||||||
cat $file > /dev/lw35
|
|
||||||
echo "Part done."
|
|
||||||
done
|
|
||||||
|
|
||||||
echo "Done."
|
|
@ -1,6 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# Limits for A4 vertical
|
|
||||||
LL=80 # Max 90
|
|
||||||
PL=58 # Max 64
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user