Reading data received from Nextion on Serial Monitor

I made a library to handle Serial, that supports CRLF as well as the Nextion's 0xFFs.

This is a simple sketch that allows you to play with a Nextion via command line/Serial monitor.

#include <WhandallSerial.h>  // https://github.com/whandall/WhandallSerial

// simple handler just prints some infos about the received line

void processLine(const char* buf) {
  Serial.print(F("len = "));
  Serial.print((uint8_t)buf[-1]);
  Serial.print(F(", strlen = "));
  Serial.print(strlen(buf));
  Serial.print(F(", "));
  dump(buf, buf[-1]);
}

void processConsoleLine(const char* buf) {
  Serial.print(F("sent \""));
  Serial.print(buf);
  Serial.println(F("\""));
  Serial1.print(buf);
  Serial1.write(0xFF);
  Serial1.write(0xFF);
  Serial1.write(0xFF);
}

SSerial console(Serial, processConsoleLine); // used serial and handler
SSerial nextionSerial(Serial1, processLine); // used serial and handler

void setup() {
  Serial.begin(250000);
  console.begin(64, optIgnoreLF); // buffer size and options
  Serial1.begin(115200);
  nextionSerial.begin(64, optTripleFF | optKeepDlm); // buffer size and options
}

void loop() {
  console.loop();         // collect chars and call handler for each line
  nextionSerial.loop();   // collect chars and call handler for each line
}

void dump(const void* ptr, int len) {
  const byte* adr = (const byte*) ptr;
  byte idx;
  if (len) {
    for (; len > 0; len -= 16, adr += 16) {
      for (idx = 0; (idx < 16) && (idx < len); idx++) {
        phByte(adr[idx]);
        Serial.write(' ');
      }
      Serial.write('"');
      for (idx = 0; (idx < 16) && (idx < len); idx++) {
        Serial.write(adr[idx] < 0x20 ? '.' : adr[idx]);
      }
      Serial.write('"');
      Serial.println();
    }
  }
}

void phByte(byte byt) {
  if (byt < 16) {
    Serial.write('0');
  }
  Serial.print(byt, HEX);
}

You will probably have to adjust the baud rates.