/*******************************************************************************
    PocketScreen "Serial Communication To ESP" Example
    written by Florian Keller
    last changed 30 Nov 20

    Allows you to direectly talk to the ESP via Serial Monitor.

    To create a WiFi access point, wait until the ESP serial is open, then
    type 'AT'. The ESP should respond with 'OK'; if not, try sending 'AT' again.
    Then, type 'AT+CWMODE=3', it then says either 'OK' or 'no change'.
    Now, type 'AT+CWSAP="[name]","[password]",1,4' with [name] and [password]
    replaced by whatever WiFi name and password you want. It should again answer
    with 'OK'.

    For more information, see:
    https://docs.espressif.com/projects/esp-at/en/latest/AT_Command_Set/
*******************************************************************************/

// include libraries
#include <PocketScreen.h>

void setup() {
    // wait a bit
    delay(2000);
    
    // enable ESP
    pinMode(PIN_ESP_ENABLE, OUTPUT);
    digitalWrite(PIN_ESP_ENABLE, HIGH);

    // open serial monitor
     don't forget to set your serial monitor baud rate to 115200, too!
    SerialUSB.begin(115200);
    while (!SerialUSB);
    SerialUSB.println("SerialUSB here.");

    // open serial communication to ESP
    SerialESP.begin(115200);
    while (!SerialESP);
    SerialUSB.println("ESP Serial open.");
}

void loop() {
    // send any text coming from the ESP to USB serial...
    while (SerialESP.available()) {
        SerialUSB.write((char) SerialESP.read());
    }

    // ...and vice versa
    while (SerialUSB.available()) {
        SerialESP.write((char) SerialUSB.read());
    }
    
    delay(10);
}
