uart: add label

This commit is contained in:
Zihao Yu 2024-01-10 02:58:41 +08:00
parent 5e099ea6db
commit eb3f526890
2 changed files with 24 additions and 1 deletions

View File

@ -13,7 +13,7 @@ private:
uint8_t tx_data, rx_data;
std::string rx_input;
std::string rx_sending_str;
static constexpr const char *rx_input_prompt = "UART RX (Press Enter to issue): ";
static constexpr const char *rx_input_prompt = "(Press Enter to issue): ";
bool tx_update_gui, rx_update_gui;
uint8_t *p_tx;
public:

View File

@ -133,7 +133,30 @@ void UART::rx_term_focus(bool v) {
rx_term->set_cursor_visibility(v);
}
static void init_render_local(SDL_Renderer *renderer) {
// draw line
SDL_SetRenderDrawColor(renderer, 0xff, 0xff, 0xff, 0);
SDL_Point p[5];
int x_pad = 20;
p[0] = Point(WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2);
p[1] = p[0] - Point(10, 10);
p[2] = p[1] - Point(0, 10);
p[3] = p[2] - Point(x_pad - 10, 0);
p[4] = p[3] - Point(0, 6);
draw_thicker_line(renderer, p, 5);
p[0].y = p[4].y - CH_HEIGHT * 3 / 2;
p[1] = p[0] - Point(x_pad - CH_WIDTH, 0);
draw_thicker_line(renderer, p, 2);
// draw label
draw_str(renderer, "RX", p[4].x - CH_WIDTH, p[4].y - CH_HEIGHT, 0xffffff);
draw_str(renderer, "TX", p[1].x - 2 * CH_WIDTH, p[1].y - CH_HEIGHT / 2, 0xffffff);
draw_str(renderer, "UART-[", p[1].x - 8 * CH_WIDTH, p[1].y, 0xffffff);
}
void init_uart(SDL_Renderer *renderer) {
init_render_local(renderer);
int x = WINDOW_WIDTH / 2, y = 0, w = WINDOW_WIDTH / 2, h = WINDOW_HEIGHT / 2;
uart = new UART(renderer, 1, 0, UART_TYPE, x, y, w, h);
uart->add_pin(UART_TX);