add BROKEN_CR_WORKAROUND define

This commit is contained in:
informatic 2024-07-20 12:13:17 +02:00
parent 24f8ebef52
commit e3e600ed91
No known key found for this signature in database
3 changed files with 23 additions and 7 deletions

View file

@ -16,10 +16,10 @@ pio run -t upload -t monitor -e esp32dev
## Usage
ESP32 exposes plain TCP server on port 1337 (check USB-UART output for currently assigned IP address) and passes ASCII/Unicode input/output data through to TTY line. Multiple clients receive copy of all the data and can send data simultaneously. All data sent to the teletype is echoed back (to all clients).
ESP32 exposes plain TCP server on port 1337 (check USB-UART output for currently assigned IP address) and passes ASCII/Unicode input/output data through to TTY line. Multiple clients receive copy of all the data and can send data simultaneously.
Motor should start up only when there's an active TCP connection - wait a couple of seconds before sending data to ensure motor is up and running.
No text wrapping is implemented - limit to ~80 columns on client-side.
Basic text wrapping is implemented - ie. newline is automatically appended every 69 characters - handle this on client-side to properly support word wrap.
Check Baudot ↔ ASCII/Unicode conversion routines in `src/baudot.c` for supported characters.
Check Baudot ↔ ASCII/Unicode conversion routines in `src/baudot.c` for supported characters.

View file

@ -298,8 +298,15 @@ size_t unicode_to_baudot(baudot_context_t *ctx, uint8_t *input, uint8_t input_le
if (baudot_map[x] == c)
{
// switch to figures + workaround for broken carriage return on our machine :(
if (ctx->tx_figures != x >> 5 || (c == '\r' && !ctx->tx_figures))
bool needs_figure_switch = ctx->tx_figures != x >> 5;
#ifdef BROKEN_CR_WORKAROUND
// workaround for broken carriage return on our machine :(
if (c == '\r' && !ctx->tx_figures)
{
needs_figure_switch = true;
}
#endif
if (needs_figure_switch)
{
output[out_pos++] = ctx->tx_figures ? BAUDOT_LTRS : BAUDOT_FIGS;
ctx->tx_figures = !ctx->tx_figures;
@ -321,9 +328,14 @@ size_t unicode_to_baudot(baudot_context_t *ctx, uint8_t *input, uint8_t input_le
if (ctx->column >= 69)
{
#ifdef BROKEN_CR_WORKAROUND
if (!ctx->tx_figures)
{
output[out_pos++] = 0x1b;
ctx->tx_figures = 1;
}
#endif
// emit newline
output[out_pos++] = 0x1b;
ctx->tx_figures = 1;
output[out_pos++] = 0x08;
output[out_pos++] = 0x02;
ctx->column = 0;

View file

@ -2,6 +2,7 @@
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
typedef struct
{
@ -14,3 +15,6 @@ typedef struct
size_t baudot_to_unicode(baudot_context_t *ctx, uint8_t *input, uint8_t input_len, uint8_t *output, uint8_t output_len);
size_t unicode_to_baudot(baudot_context_t *ctx, uint8_t *input, uint8_t input_len, uint8_t *output, uint8_t output_len);
// Enable broken carriage return workaround - switch to figures before doing a carriage return
#define BROKEN_CR_WORKAROUND