Skip to content

Commit

Permalink
AnsiTerminal: added option to communicate with USB Serial (thanks to …
Browse files Browse the repository at this point in the history
…Guido Lehwalder)
  • Loading branch information
fdivitto committed Apr 1, 2021
1 parent ce28b84 commit c4a4f93
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 9 deletions.
18 changes: 16 additions & 2 deletions examples/VGA/AnsiTerminal/AnsiTerminal.ino
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@
*/


/*
Credits:
- Guido Lehwalder, https://github.com/guidol70 : using USB-serial Port for ANSI-Terminal (https://github.com/fdivitto/FabGL/issues/110)
*/

#include "fabgl.h"


Expand All @@ -37,8 +44,15 @@ fabgl::Terminal Terminal;
// WARN!! Good for ESP32 with 3.3V voltage (ESP-WROOM-32). This will BRICK your ESP32 if the flash isn't 3.3V
// NOTE1: replace "/dev/cu.SLAB_USBtoUART" with your serial port
// NOTE2: espefuse.py is downloadable from https://github.com/espressif/esptool
#define UART_RX 34
#define UART_TX 2

// UART Pins for USB serial
#define UART_URX 3
#define UART_UTX 1

// UART Pins for normal serial Port
#define UART_SRX 34
#define UART_STX 2


#define RESET_PIN 12

Expand Down
29 changes: 22 additions & 7 deletions examples/VGA/AnsiTerminal/confdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ constexpr int BOOTINFO_DISABLED = 0;
constexpr int BOOTINFO_ENABLED = 1;
constexpr int BOOTINFO_TEMPDISABLED = 2;



constexpr int SERCTL_DISABLED = 0;
constexpr int SERCTL_ENABLED = 1;


struct ConfDialogApp : public uiApp {
Expand All @@ -140,6 +140,7 @@ struct ConfDialogApp : public uiApp {
uiComboBox * columnsComboBox;
uiComboBox * rowsComboBox;
uiCheckBox * infoCheckBox;
uiCheckBox * serctlCheckBox;

void init() {

Expand Down Expand Up @@ -268,8 +269,14 @@ struct ConfDialogApp : public uiApp {
infoCheckBox = new uiCheckBox(frame, Point(80, y - 2), Size(16, 16), uiCheckBoxKind::CheckBox, true, STYLE_CHECKBOX);
infoCheckBox->setChecked(getBootInfo() == BOOTINFO_ENABLED);

y += 24;

y += 48;
// set control to usb-serial
new uiLabel(frame, "USBSerial", Point(10, y), Size(0, 0), true, STYLE_LABEL);
serctlCheckBox = new uiCheckBox(frame, Point(80, y - 2), Size(16, 16), uiCheckBoxKind::CheckBox, true, STYLE_CHECKBOX);
serctlCheckBox->setChecked(getSerCtl() == SERCTL_ENABLED);

y += 24;

// exit without save button
auto exitNoSaveButton = new uiButton(frame, "Quit [ESC]", Point(10, y), Size(90, 20), uiButtonKind::Button, true, STYLE_BUTTON);
Expand Down Expand Up @@ -309,7 +316,8 @@ struct ConfDialogApp : public uiApp {
fontComboBox->selectedItem() != getFontIndex() ||
columnsComboBox->selectedItem() != getColumnsIndex() ||
rowsComboBox->selectedItem() != getRowsIndex() ||
bgColorComboBox->selectedColor() != getBGColor();
bgColorComboBox->selectedColor() != getBGColor() ||
serctlCheckBox->checked() != getSerCtl();

preferences.putInt("TermType", termComboBox->selectedItem());
preferences.putInt("KbdLayout", kbdComboBox->selectedItem());
Expand All @@ -325,6 +333,7 @@ struct ConfDialogApp : public uiApp {
preferences.putInt("Columns", columnsComboBox->selectedItem());
preferences.putInt("Rows", rowsComboBox->selectedItem());
preferences.putInt("BootInfo", infoCheckBox->checked() ? BOOTINFO_ENABLED : BOOTINFO_DISABLED);
preferences.putInt("SerCtl", serctlCheckBox->checked() ? SERCTL_ENABLED : SERCTL_DISABLED);

if (reboot) {
auto rebootDialog = new RebootDialog(frame);
Expand Down Expand Up @@ -403,6 +412,10 @@ struct ConfDialogApp : public uiApp {
return preferences.getInt("BootInfo", BOOTINFO_ENABLED);
}

static int getSerCtl() {
return preferences.getInt("SerCtl", SERCTL_DISABLED);
}

// if version in preferences doesn't match, reset preferences
static void checkVersion() {
if (preferences.getInt("VerMaj", 0) != TERMVERSION_MAJ || preferences.getInt("VerMin", 0) != TERMVERSION_MIN) {
Expand Down Expand Up @@ -458,11 +471,13 @@ struct ConfDialogApp : public uiApp {
static void loadConfiguration() {
Terminal.setTerminalType(getTermType());
Terminal.keyboard()->setLayout(SupportedLayouts::layouts()[getKbdLayoutIndex()]);
Terminal.connectSerialPort(BAUDRATES_INT[getBaudRateIndex()], fabgl::UARTConf(getParityIndex(), getDataLenIndex(), getStopBitsIndex()), UART_RX, UART_TX, getFlowCtrl());
Terminal.setBackgroundColor(getBGColor());
Terminal.setForegroundColor(getFGColor());
// configure serial port
bool serctl = (getSerCtl() == SERCTL_ENABLED);
auto rxPin = serctl ? UART_URX : UART_SRX;
auto txPin = serctl ? UART_UTX : UART_STX;
Terminal.connectSerialPort(BAUDRATES_INT[getBaudRateIndex()], fabgl::UARTConf(getParityIndex(), getDataLenIndex(), getStopBitsIndex()), rxPin, txPin, getFlowCtrl());
}

};


0 comments on commit c4a4f93

Please sign in to comment.