Multiple serial ports (e.g. real serial & usb) connected to console tty

This commit is contained in:
folkert van heusden 2023-03-22 14:32:12 +01:00
parent 9137e7dd3d
commit d34d1ad299
Signed by untrusted user who does not match committer: folkert
GPG key ID: 6B6455EDFEED3BD1
3 changed files with 15 additions and 9 deletions

View file

@ -10,9 +10,9 @@
#define NEOPIXELS_PIN 25 #define NEOPIXELS_PIN 25
console_esp32::console_esp32(std::atomic_uint32_t *const stop_event, bus *const b, Stream & io_port) : console_esp32::console_esp32(std::atomic_uint32_t *const stop_event, bus *const b, std::vector<Stream *> & io_ports) :
console(stop_event, b), console(stop_event, b),
io_port(io_port) io_ports(io_ports)
{ {
} }
@ -24,8 +24,10 @@ console_esp32::~console_esp32()
int console_esp32::wait_for_char_ll(const short timeout) int console_esp32::wait_for_char_ll(const short timeout)
{ {
for(short i=0; i<timeout / 10; i++) { for(short i=0; i<timeout / 10; i++) {
if (io_port.available()) for(auto port : io_ports) {
return io_port.read(); if (port->available())
return port->read();
}
delay(10); delay(10);
} }
@ -35,7 +37,8 @@ int console_esp32::wait_for_char_ll(const short timeout)
void console_esp32::put_char_ll(const char c) void console_esp32::put_char_ll(const char c)
{ {
io_port.print(c); for(auto & port : io_ports)
port->print(c);
} }
void console_esp32::put_string_lf(const std::string & what) void console_esp32::put_string_lf(const std::string & what)
@ -55,7 +58,7 @@ void console_esp32::refresh_virtual_terminal()
void console_esp32::panel_update_thread() void console_esp32::panel_update_thread()
{ {
io_port.println(F("panel task started")); Serial.println(F("panel task started"));
cpu *const c = b->getCpu(); cpu *const c = b->getCpu();

View file

@ -1,4 +1,5 @@
#include <Arduino.h> #include <Arduino.h>
#include <vector>
#include "console.h" #include "console.h"
@ -6,7 +7,7 @@
class console_esp32 : public console class console_esp32 : public console
{ {
private: private:
Stream & io_port; std::vector<Stream *> io_ports;
protected: protected:
int wait_for_char_ll(const short timeout) override; int wait_for_char_ll(const short timeout) override;
@ -14,7 +15,7 @@ protected:
void put_char_ll(const char c) override; void put_char_ll(const char c) override;
public: public:
console_esp32(std::atomic_uint32_t *const stop_event, bus *const b, Stream & io_port); console_esp32(std::atomic_uint32_t *const stop_event, bus *const b, std::vector<Stream *> & io_ports);
virtual ~console_esp32(); virtual ~console_esp32();
void put_string_lf(const std::string & what) override; void put_string_lf(const std::string & what) override;

View file

@ -1,5 +1,6 @@
// (C) 2018-2023 by Folkert van Heusden // (C) 2018-2023 by Folkert van Heusden
// Released under Apache License v2.0 // Released under Apache License v2.0
#include <Arduino.h>
#include <atomic> #include <atomic>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
@ -317,7 +318,8 @@ void setup() {
b->add_cpu(c); b->add_cpu(c);
Serial.println(F("Init console")); Serial.println(F("Init console"));
cnsl = new console_esp32(&stop_event, b, Serial); std::vector<Stream *> serial_ports { &Serial, &Serial1 };
cnsl = new console_esp32(&stop_event, b, serial_ports);
Serial.println(F("Start line-frequency interrupt")); Serial.println(F("Start line-frequency interrupt"));
kw11_l *lf = new kw11_l(b, cnsl); kw11_l *lf = new kw11_l(b, cnsl);