Browse Source

Secondary Serial RX port for H801 and H802 boards (thanks to Pablo Pousada Rial)

i18n
Xose Pérez 6 years ago
parent
commit
aa512f0b26
3 changed files with 45 additions and 1 deletions
  1. +11
    -0
      code/espurna/config/general.h
  2. +2
    -0
      code/espurna/config/hardware.h
  3. +32
    -1
      code/espurna/settings.ino

+ 11
- 0
code/espurna/config/general.h View File

@ -64,6 +64,17 @@
#define SERIAL_BAUDRATE 115200 // Default baudrate #define SERIAL_BAUDRATE 115200 // Default baudrate
#endif #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
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------


+ 2
- 0
code/espurna/config/hardware.h View File

@ -927,6 +927,7 @@
#define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER #define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER
#define DUMMY_RELAY_COUNT 1 #define DUMMY_RELAY_COUNT 1
#define DEBUG_PORT Serial1 #define DEBUG_PORT Serial1
#define SERIAL_RX_PORT Serial
// LEDs // LEDs
#define LED1_PIN 5 #define LED1_PIN 5
@ -954,6 +955,7 @@
#define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER #define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER
#define DUMMY_RELAY_COUNT 1 #define DUMMY_RELAY_COUNT 1
#define DEBUG_PORT Serial1 #define DEBUG_PORT Serial1
#define SERIAL_RX_PORT Serial
// Light // Light
#define LIGHT_CHANNELS 4 #define LIGHT_CHANNELS 4


+ 32
- 1
code/espurna/settings.ino View File

@ -28,6 +28,13 @@ Copyright (C) 2016-2018 by Xose Pérez <xose dot perez at gmail dot com>
#endif #endif
#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; 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] EEPROM size: %d bytes\n"), SPI_FLASH_SEC_SIZE);
DEBUG_MSG_P(PSTR("[SETTINGS] Settings size: %d bytes\n"), _settingsSize()); 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() { void settingsLoop() {
if (_settings_save) { if (_settings_save) {
EEPROM.commit(); EEPROM.commit();
_settings_save = false; _settings_save = false;
} }
#if TERMINAL_SUPPORT #if TERMINAL_SUPPORT
embedis.process(); 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
} }

Loading…
Cancel
Save