From aa512f0b26452854c9e8c79395362cb90d81315c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Mon, 15 Jan 2018 19:27:08 +0100 Subject: [PATCH] Secondary Serial RX port for H801 and H802 boards (thanks to Pablo Pousada Rial) --- code/espurna/config/general.h | 11 +++++++++++ code/espurna/config/hardware.h | 2 ++ code/espurna/settings.ino | 33 ++++++++++++++++++++++++++++++++- 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/code/espurna/config/general.h b/code/espurna/config/general.h index 57cf9c66..fb73e37d 100644 --- a/code/espurna/config/general.h +++ b/code/espurna/config/general.h @@ -64,6 +64,17 @@ #define SERIAL_BAUDRATE 115200 // Default baudrate #endif +// Second serial port (used for RX) + +//#define SERIAL_RX_PORT Serial // This setting is usually defined + // in the hardware.h file for those + // boards that require it + +#ifndef SERIAL_RX_BAUDRATE +#define SERIAL_RX_BAUDRATE 115200 // Default baudrate +#endif + +#define SERIAL_RX_BUFFER_SIZE 32 //------------------------------------------------------------------------------ diff --git a/code/espurna/config/hardware.h b/code/espurna/config/hardware.h index f19a3426..5053c775 100644 --- a/code/espurna/config/hardware.h +++ b/code/espurna/config/hardware.h @@ -927,6 +927,7 @@ #define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER #define DUMMY_RELAY_COUNT 1 #define DEBUG_PORT Serial1 + #define SERIAL_RX_PORT Serial // LEDs #define LED1_PIN 5 @@ -954,6 +955,7 @@ #define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER #define DUMMY_RELAY_COUNT 1 #define DEBUG_PORT Serial1 + #define SERIAL_RX_PORT Serial // Light #define LIGHT_CHANNELS 4 diff --git a/code/espurna/settings.ino b/code/espurna/settings.ino index 3e06865f..822d30fd 100644 --- a/code/espurna/settings.ino +++ b/code/espurna/settings.ino @@ -28,6 +28,13 @@ Copyright (C) 2016-2018 by Xose PĂ©rez #endif #endif +#if TERMINAL_SUPPORT +#ifdef SERIAL_RX_PORT + char _serial_rx_buffer[SERIAL_RX_BUFFER_SIZE]; + static unsigned char _serial_rx_pointer = 0; +#endif +#endif + bool _settings_save = false; // ----------------------------------------------------------------------------- @@ -403,14 +410,38 @@ void settingsSetup() { DEBUG_MSG_P(PSTR("[SETTINGS] EEPROM size: %d bytes\n"), SPI_FLASH_SEC_SIZE); DEBUG_MSG_P(PSTR("[SETTINGS] Settings size: %d bytes\n"), _settingsSize()); + #if TERMINAL_SUPPORT + #ifdef SERIAL_RX_PORT + SERIAL_RX_PORT.begin(SERIAL_RX_BAUDRATE); + #endif + #endif + } void settingsLoop() { + if (_settings_save) { EEPROM.commit(); _settings_save = false; } + #if TERMINAL_SUPPORT + embedis.process(); - #endif + + #ifdef SERIAL_RX_PORT + + while (SERIAL_RX_PORT.available() > 0) { + char rc = Serial.read(); + _serial_rx_buffer[_serial_rx_pointer++] = rc; + if ((_serial_rx_pointer == SERIAL_RX_BUFFER_SIZE) || (rc == 10)) { + settingsInject(_serial_rx_buffer, (size_t) _serial_rx_pointer); + _serial_rx_pointer = 0; + } + } + + #endif // SERIAL_RX_PORT + + #endif // TERMINAL_SUPPORT + }