Allow different Serial-port to be used on ESP32

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

View file

@ -10,8 +10,9 @@
#define NEOPIXELS_PIN 25 #define NEOPIXELS_PIN 25
console_esp32::console_esp32(std::atomic_uint32_t *const stop_event, bus *const b) : console_esp32::console_esp32(std::atomic_uint32_t *const stop_event, bus *const b, Stream & io_port) :
console(stop_event, b) console(stop_event, b),
io_port(io_port)
{ {
} }
@ -23,8 +24,8 @@ 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 (Serial.available()) if (io_port.available())
return Serial.read(); return io_port.read();
delay(10); delay(10);
} }
@ -34,7 +35,7 @@ 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)
{ {
Serial.print(c); io_port.print(c);
} }
void console_esp32::put_string_lf(const std::string & what) void console_esp32::put_string_lf(const std::string & what)
@ -54,7 +55,7 @@ void console_esp32::refresh_virtual_terminal()
void console_esp32::panel_update_thread() void console_esp32::panel_update_thread()
{ {
Serial.println(F("panel task started")); io_port.println(F("panel task started"));
cpu *const c = b->getCpu(); cpu *const c = b->getCpu();

View file

@ -5,13 +5,16 @@
class console_esp32 : public console class console_esp32 : public console
{ {
private:
Stream & io_port;
protected: protected:
int wait_for_char_ll(const short timeout) override; int wait_for_char_ll(const short timeout) override;
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); console_esp32(std::atomic_uint32_t *const stop_event, bus *const b, Stream & io_port);
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

@ -317,7 +317,7 @@ 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); cnsl = new console_esp32(&stop_event, b, Serial);
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);