mirror of
https://github.com/letscontrolit/ESPEasy.git
synced 2026-07-27 19:57:38 +00:00
[USB CDC] Support USB serial port for ESP32-S2/S3/C3
This commit is contained in:
@@ -23,7 +23,7 @@
|
||||
"arduino",
|
||||
"espidf"
|
||||
],
|
||||
"name": "Espressif Generic ESP32-C3 4M Flash ESPEasy 1810k Code/OTA 316k FS",
|
||||
"name": "Espressif Generic ESP32-C3 USB CDC 4M Flash ESPEasy 1810k Code/OTA 316k FS",
|
||||
"upload": {
|
||||
"flash_size": "4MB",
|
||||
"maximum_ram_size": 327680,
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
{
|
||||
"build": {
|
||||
"arduino":{
|
||||
"ldscript": "esp32s2_out.ld",
|
||||
"memory_type": "dio_qspi"
|
||||
},
|
||||
"core": "esp32",
|
||||
"extra_flags": "-DBOARD_HAS_PSRAM -DESP32_4M -DESP32S2 -DCONFIG_IDF_TARGET_ESP32S2=1 -DUSE_USB_CDC_CONSOLE",
|
||||
"f_cpu": "240000000L",
|
||||
"f_flash": "80000000L",
|
||||
"flash_mode": "dio",
|
||||
"mcu": "esp32s2",
|
||||
"variant": "esp32s2",
|
||||
"partitions": "esp32_partition_app1810k_spiffs316k.csv"
|
||||
},
|
||||
"connectivity": [
|
||||
"wifi"
|
||||
],
|
||||
"debug": {
|
||||
"openocd_target": "esp32s2.cfg"
|
||||
},
|
||||
"frameworks": [
|
||||
"espidf",
|
||||
"arduino"
|
||||
],
|
||||
"name": "Espressif Generic ESP32-S2 USB CDC 4M Flash ESPEasy 1810k Code/OTA 316k FS",
|
||||
"upload": {
|
||||
"flash_size": "4MB",
|
||||
"maximum_ram_size": 327680,
|
||||
"maximum_size": 4194304,
|
||||
"require_upload_port": true,
|
||||
"before_reset": "usb_reset",
|
||||
"after_reset": "no_reset",
|
||||
"speed": 460800
|
||||
},
|
||||
"url": "https://docs.espressif.com/projects/esp-idf/en/latest/esp32s2/hw-reference/esp32s2/user-guide-saola-1-v1.2.html",
|
||||
"vendor": "Espressif"
|
||||
}
|
||||
@@ -35,7 +35,7 @@
|
||||
"espidf",
|
||||
"arduino"
|
||||
],
|
||||
"name": "Espressif Generic ESP32-S3 >= 4M Flash OPI PSRAM, ESPEasy 1810k Code/OTA 316k FS",
|
||||
"name": "Espressif Generic ESP32-S3 USB CDC >= 4M Flash OPI PSRAM, ESPEasy 1810k Code/OTA 316k FS",
|
||||
"upload": {
|
||||
"flash_size": "4MB",
|
||||
"maximum_ram_size": 327680,
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
"espidf",
|
||||
"arduino"
|
||||
],
|
||||
"name": "Espressif Generic ESP32-S3 >= 4M Flash QSPI PSRAM, ESPEasy 1810k Code/OTA 316k FS",
|
||||
"name": "Espressif Generic ESP32-S3 USB CDC >= 4M Flash QSPI PSRAM, ESPEasy 1810k Code/OTA 316k FS",
|
||||
"upload": {
|
||||
"flash_size": "4MB",
|
||||
"maximum_ram_size": 327680,
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
|
||||
#define PZEM_BAUD_RATE 9600
|
||||
|
||||
extern HardwareSerial Serial;
|
||||
//extern HardwareSerial Serial;
|
||||
ESPeasySerial *swSerial = nullptr;
|
||||
|
||||
#define DEBUG
|
||||
|
||||
@@ -58,6 +58,12 @@ extra_scripts = ${esp32c3_common.extra_scripts}
|
||||
extends = esp32c3_common
|
||||
board = esp32c3
|
||||
|
||||
|
||||
[env:normal_ESP32c3_4M316k_CDC]
|
||||
extends = esp32c3_common
|
||||
board = esp32c3cdc
|
||||
|
||||
|
||||
[env:collection_A_ESP32c3_4M316k]
|
||||
extends = esp32c3_common
|
||||
board = esp32c3
|
||||
|
||||
@@ -31,6 +31,16 @@ build_flags = ${esp32s2_common.build_flags}
|
||||
extra_scripts = ${esp32s2_common.extra_scripts}
|
||||
pre:tools/pio/pre_custom_esp32.py
|
||||
|
||||
[env:custom_ESP32s2_USB_CDC_4M316k]
|
||||
extends = esp32s2_common
|
||||
board = esp32s2_cdc
|
||||
build_flags = ${esp32s2_common.build_flags}
|
||||
-DPLUGIN_BUILD_CUSTOM
|
||||
-DESP_CONSOLE_USB_CDC=y
|
||||
extra_scripts = ${esp32s2_common.extra_scripts}
|
||||
pre:tools/pio/pre_custom_esp32.py
|
||||
|
||||
|
||||
[env:neopixel_ESP32s2_4M316k]
|
||||
extends = esp32s2_common
|
||||
board = esp32s2
|
||||
@@ -58,6 +68,10 @@ extra_scripts = ${esp32s2_common.extra_scripts}
|
||||
extends = esp32s2_common
|
||||
board = esp32s2
|
||||
|
||||
[env:normal_ESP32s2_4M316k_CDC]
|
||||
extends = esp32s2_common
|
||||
board = esp32s2_cdc
|
||||
|
||||
[env:collection_A_ESP32s2_4M316k]
|
||||
extends = esp32s2_common
|
||||
board = esp32s2
|
||||
|
||||
@@ -150,3 +150,7 @@ extra_scripts = ${esp32_common.extra_scripts}
|
||||
board_build.filesystem = littlefs
|
||||
board_build.partitions = esp32_partition_app4096k_spiffs8124k.csv
|
||||
|
||||
|
||||
[env:max_ESP32s3_16M8M_LittleFS_PSRAM_CDC]
|
||||
extends = env:max_ESP32s3_16M8M_LittleFS_PSRAM
|
||||
board = esp32s3cdc-qio_opi
|
||||
|
||||
+4
-4
@@ -50,7 +50,7 @@ boolean Plugin_040(uint8_t function, struct EventStruct *event, String& string)
|
||||
case PLUGIN_INIT:
|
||||
{
|
||||
Plugin_040_init = true;
|
||||
Serial.begin(9600);
|
||||
ESPEASY_SERIAL_0.begin(9600);
|
||||
success = true;
|
||||
break;
|
||||
}
|
||||
@@ -77,12 +77,12 @@ boolean Plugin_040(uint8_t function, struct EventStruct *event, String& string)
|
||||
uint8_t bytesread = 0;
|
||||
uint8_t tempbyte = 0;
|
||||
|
||||
if ((val = Serial.read()) == 2)
|
||||
if ((val = ESPEASY_SERIAL_0.read()) == 2)
|
||||
{ // check for header
|
||||
bytesread = 0;
|
||||
while (bytesread < 12) { // read 10 digit code + 2 digit checksum
|
||||
if ( Serial.available() > 0) {
|
||||
val = Serial.read();
|
||||
if ( ESPEASY_SERIAL_0.available() > 0) {
|
||||
val = ESPEASY_SERIAL_0.read();
|
||||
if ((val == 0x0D) || (val == 0x0A) || (val == 0x03) || (val == 0x02)) {
|
||||
// if header or stop bytes before the 10 digit reading
|
||||
break;
|
||||
|
||||
+74
-74
@@ -223,13 +223,13 @@ boolean Plugin_091(uint8_t function, struct EventStruct *event, String& string)
|
||||
Plugin_091_ownindex = event->TaskIndex;
|
||||
Settings.UseSerial = true; // make sure that serial enabled
|
||||
Settings.SerialLogLevel = 0; // and logging disabled
|
||||
Serial.setDebugOutput(false); // really, disable it!
|
||||
ESPEASY_SERIAL_0.setDebugOutput(false); // really, disable it!
|
||||
log = F("SerSW : Init ");
|
||||
if (PCONFIG(0) == SER_SWITCH_YEWE)
|
||||
{
|
||||
Plugin_091_numrelay = PCONFIG(1);
|
||||
Serial.begin(9600, SERIAL_8N1);
|
||||
Serial.setRxBufferSize(BUFFER_SIZE); // Arduino core for ESP8266 WiFi chip 2.4.0
|
||||
ESPEASY_SERIAL_0.begin(9600, SERIAL_8N1);
|
||||
ESPEASY_SERIAL_0.setRxBufferSize(BUFFER_SIZE); // Arduino core for ESP8266 WiFi chip 2.4.0
|
||||
delay(1);
|
||||
getmcustate(); // request status on startup
|
||||
log += F(" Yewe ");
|
||||
@@ -239,7 +239,7 @@ boolean Plugin_091(uint8_t function, struct EventStruct *event, String& string)
|
||||
if (PCONFIG(0) == SER_SWITCH_SONOFFDUAL)
|
||||
{
|
||||
Plugin_091_numrelay = 3; // 3rd button is the "wifi" button
|
||||
Serial.begin(19230, SERIAL_8N1);
|
||||
ESPEASY_SERIAL_0.begin(19230, SERIAL_8N1);
|
||||
log += F(" Sonoff Dual");
|
||||
} else
|
||||
if (PCONFIG(0) == SER_SWITCH_LCTECH)
|
||||
@@ -278,7 +278,7 @@ boolean Plugin_091(uint8_t function, struct EventStruct *event, String& string)
|
||||
break;
|
||||
}
|
||||
}
|
||||
Serial.begin(Plugin_091_speed, SERIAL_8N1);
|
||||
ESPEASY_SERIAL_0.begin(Plugin_091_speed, SERIAL_8N1);
|
||||
log += F(" LCTech ");
|
||||
log += Plugin_091_speed;
|
||||
log += F(" baud ");
|
||||
@@ -290,7 +290,7 @@ boolean Plugin_091(uint8_t function, struct EventStruct *event, String& string)
|
||||
Plugin_091_numrelay = 2; // 2nd button is the dimvalue
|
||||
Plugin_091_switchstate[1] = 255;
|
||||
Plugin_091_ostate[1] = 255;
|
||||
Serial.begin(9600, SERIAL_8N1);
|
||||
ESPEASY_SERIAL_0.begin(9600, SERIAL_8N1);
|
||||
log += F(" Wifi Dimmer");
|
||||
}
|
||||
|
||||
@@ -327,10 +327,10 @@ boolean Plugin_091(uint8_t function, struct EventStruct *event, String& string)
|
||||
|
||||
if (Plugin_091_init)
|
||||
{
|
||||
while (Serial.available() > 0) {
|
||||
while (ESPEASY_SERIAL_0.available() > 0) {
|
||||
yield();
|
||||
if (bytes_read < BUFFER_SIZE) {
|
||||
serial_buf[bytes_read] = Serial.read();
|
||||
serial_buf[bytes_read] = ESPEASY_SERIAL_0.read();
|
||||
|
||||
if (bytes_read == 0) { // packet start
|
||||
|
||||
@@ -534,7 +534,7 @@ boolean Plugin_091(uint8_t function, struct EventStruct *event, String& string)
|
||||
bytes_read++;
|
||||
}
|
||||
} else
|
||||
Serial.read(); // if buffer full, dump incoming
|
||||
ESPEASY_SERIAL_0.read(); // if buffer full, dump incoming
|
||||
}
|
||||
} // plugin initialized end
|
||||
success = true;
|
||||
@@ -817,14 +817,14 @@ boolean Plugin_091(uint8_t function, struct EventStruct *event, String& string)
|
||||
}
|
||||
|
||||
void getmcustate() {
|
||||
Serial.write(0x55); // Tuya header 55AA
|
||||
Serial.write(0xAA);
|
||||
Serial.write(0x00); // version 00
|
||||
Serial.write(0x08); // Tuya command 08 - request status
|
||||
Serial.write(0x00);
|
||||
Serial.write(0x00);
|
||||
Serial.write(0x07);
|
||||
Serial.flush();
|
||||
ESPEASY_SERIAL_0.write(0x55); // Tuya header 55AA
|
||||
ESPEASY_SERIAL_0.write(0xAA);
|
||||
ESPEASY_SERIAL_0.write(0x00); // version 00
|
||||
ESPEASY_SERIAL_0.write(0x08); // Tuya command 08 - request status
|
||||
ESPEASY_SERIAL_0.write(0x00);
|
||||
ESPEASY_SERIAL_0.write(0x00);
|
||||
ESPEASY_SERIAL_0.write(0x07);
|
||||
ESPEASY_SERIAL_0.flush();
|
||||
}
|
||||
|
||||
void sendmcucommand(uint8_t btnnum, uint8_t state, uint8_t swtype, uint8_t btnum_mode) // btnnum=0,1,2, state=0/1
|
||||
@@ -835,19 +835,19 @@ void sendmcucommand(uint8_t btnnum, uint8_t state, uint8_t swtype, uint8_t btnum
|
||||
{
|
||||
case SER_SWITCH_YEWE:
|
||||
{
|
||||
Serial.write(0x55); // Tuya header 55AA
|
||||
Serial.write(0xAA);
|
||||
Serial.write(0x00); // version 00
|
||||
Serial.write(0x06); // Tuya command 06 - send order
|
||||
Serial.write(0x00);
|
||||
Serial.write(0x05); // following data length 0x05
|
||||
Serial.write( (btnnum + 1) ); // relay number 1,2,3
|
||||
Serial.write(0x01); // ?
|
||||
Serial.write(0x00); // ?
|
||||
Serial.write(0x01); // ?
|
||||
Serial.write( state ); // status
|
||||
Serial.write((13 + btnnum + state)); // checksum:sum of all bytes in packet mod 256
|
||||
Serial.flush();
|
||||
ESPEASY_SERIAL_0.write(0x55); // Tuya header 55AA
|
||||
ESPEASY_SERIAL_0.write(0xAA);
|
||||
ESPEASY_SERIAL_0.write(0x00); // version 00
|
||||
ESPEASY_SERIAL_0.write(0x06); // Tuya command 06 - send order
|
||||
ESPEASY_SERIAL_0.write(0x00);
|
||||
ESPEASY_SERIAL_0.write(0x05); // following data length 0x05
|
||||
ESPEASY_SERIAL_0.write( (btnnum + 1) ); // relay number 1,2,3
|
||||
ESPEASY_SERIAL_0.write(0x01); // ?
|
||||
ESPEASY_SERIAL_0.write(0x00); // ?
|
||||
ESPEASY_SERIAL_0.write(0x01); // ?
|
||||
ESPEASY_SERIAL_0.write( state ); // status
|
||||
ESPEASY_SERIAL_0.write((13 + btnnum + state)); // checksum:sum of all bytes in packet mod 256
|
||||
ESPEASY_SERIAL_0.flush();
|
||||
break;
|
||||
}
|
||||
case SER_SWITCH_SONOFFDUAL:
|
||||
@@ -863,11 +863,11 @@ void sendmcucommand(uint8_t btnnum, uint8_t state, uint8_t swtype, uint8_t btnum
|
||||
Plugin_091_switchstate[1] = state;
|
||||
}
|
||||
sstate = Plugin_091_switchstate[0] + (Plugin_091_switchstate[1] << 1) + (Plugin_091_switchstate[2] << 2);
|
||||
Serial.write(0xA0);
|
||||
Serial.write(0x04);
|
||||
Serial.write( sstate );
|
||||
Serial.write(0xA1);
|
||||
Serial.flush();
|
||||
ESPEASY_SERIAL_0.write(0xA0);
|
||||
ESPEASY_SERIAL_0.write(0x04);
|
||||
ESPEASY_SERIAL_0.write( sstate );
|
||||
ESPEASY_SERIAL_0.write(0xA1);
|
||||
ESPEASY_SERIAL_0.flush();
|
||||
break;
|
||||
}
|
||||
case SER_SWITCH_LCTECH:
|
||||
@@ -883,23 +883,23 @@ void sendmcucommand(uint8_t btnnum, uint8_t state, uint8_t swtype, uint8_t btnum
|
||||
delay(1);
|
||||
}
|
||||
if (Plugin_091_ipd) {
|
||||
Serial.write(0x0D);
|
||||
Serial.write(0x0A);
|
||||
Serial.write(0x2B);
|
||||
Serial.write(0x49);
|
||||
Serial.write(0x50);
|
||||
Serial.write(0x44);
|
||||
Serial.write(0x2C);
|
||||
Serial.write(0x30);
|
||||
Serial.write(0x2C);
|
||||
Serial.write(0x34);
|
||||
Serial.write(0x3A);
|
||||
ESPEASY_SERIAL_0.write(0x0D);
|
||||
ESPEASY_SERIAL_0.write(0x0A);
|
||||
ESPEASY_SERIAL_0.write(0x2B);
|
||||
ESPEASY_SERIAL_0.write(0x49);
|
||||
ESPEASY_SERIAL_0.write(0x50);
|
||||
ESPEASY_SERIAL_0.write(0x44);
|
||||
ESPEASY_SERIAL_0.write(0x2C);
|
||||
ESPEASY_SERIAL_0.write(0x30);
|
||||
ESPEASY_SERIAL_0.write(0x2C);
|
||||
ESPEASY_SERIAL_0.write(0x34);
|
||||
ESPEASY_SERIAL_0.write(0x3A);
|
||||
}
|
||||
Serial.write(0xA0);
|
||||
Serial.write((0x01 + btnnum));
|
||||
Serial.write((0x00 + state));
|
||||
Serial.write((0xA1 + state + btnnum));
|
||||
Serial.flush();
|
||||
ESPEASY_SERIAL_0.write(0xA0);
|
||||
ESPEASY_SERIAL_0.write((0x01 + btnnum));
|
||||
ESPEASY_SERIAL_0.write((0x00 + state));
|
||||
ESPEASY_SERIAL_0.write((0xA1 + state + btnnum));
|
||||
ESPEASY_SERIAL_0.flush();
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -943,33 +943,33 @@ void sendmcudim(uint8_t dimvalue, uint8_t swtype)
|
||||
{
|
||||
case SER_SWITCH_YEWE:
|
||||
{
|
||||
Serial.write(0x55); // Tuya header 55AA
|
||||
Serial.write(0xAA);
|
||||
Serial.write(0x00); // version 00
|
||||
Serial.write(0x06); // Tuya command 06 - send order
|
||||
Serial.write(0x00);
|
||||
Serial.write(0x08); // following data length 0x08
|
||||
Serial.write(Plugin_091_numrelay); // dimmer order-id? select it at plugin settings 2/3!!!
|
||||
Serial.write(0x02); // type=value
|
||||
Serial.write(0x00); // length hi
|
||||
Serial.write(0x04); // length low
|
||||
Serial.write(0x00); // ?
|
||||
Serial.write(0x00); // ?
|
||||
Serial.write(0x00); // ?
|
||||
Serial.write( dimvalue ); // dim value (0-255)
|
||||
Serial.write( uint8_t(19 + Plugin_091_numrelay + dimvalue) ); // checksum:sum of all bytes in packet mod 256
|
||||
Serial.flush();
|
||||
ESPEASY_SERIAL_0.write(0x55); // Tuya header 55AA
|
||||
ESPEASY_SERIAL_0.write(0xAA);
|
||||
ESPEASY_SERIAL_0.write(0x00); // version 00
|
||||
ESPEASY_SERIAL_0.write(0x06); // Tuya command 06 - send order
|
||||
ESPEASY_SERIAL_0.write(0x00);
|
||||
ESPEASY_SERIAL_0.write(0x08); // following data length 0x08
|
||||
ESPEASY_SERIAL_0.write(Plugin_091_numrelay); // dimmer order-id? select it at plugin settings 2/3!!!
|
||||
ESPEASY_SERIAL_0.write(0x02); // type=value
|
||||
ESPEASY_SERIAL_0.write(0x00); // length hi
|
||||
ESPEASY_SERIAL_0.write(0x04); // length low
|
||||
ESPEASY_SERIAL_0.write(0x00); // ?
|
||||
ESPEASY_SERIAL_0.write(0x00); // ?
|
||||
ESPEASY_SERIAL_0.write(0x00); // ?
|
||||
ESPEASY_SERIAL_0.write( dimvalue ); // dim value (0-255)
|
||||
ESPEASY_SERIAL_0.write( uint8_t(19 + Plugin_091_numrelay + dimvalue) ); // checksum:sum of all bytes in packet mod 256
|
||||
ESPEASY_SERIAL_0.flush();
|
||||
break;
|
||||
}
|
||||
case SER_SWITCH_WIFIDIMMER:
|
||||
{
|
||||
Serial.write(0xFF); // Wifidimmer header FF55
|
||||
Serial.write(0x55);
|
||||
Serial.write( dimvalue ); // dim value (0-255)
|
||||
Serial.write(0x05);
|
||||
Serial.write(0xDC);
|
||||
Serial.write(0x0A);
|
||||
Serial.flush();
|
||||
ESPEASY_SERIAL_0.write(0xFF); // Wifidimmer header FF55
|
||||
ESPEASY_SERIAL_0.write(0x55);
|
||||
ESPEASY_SERIAL_0.write( dimvalue ); // dim value (0-255)
|
||||
ESPEASY_SERIAL_0.write(0x05);
|
||||
ESPEASY_SERIAL_0.write(0xDC);
|
||||
ESPEASY_SERIAL_0.write(0x0A);
|
||||
ESPEASY_SERIAL_0.flush();
|
||||
Plugin_091_switchstate[1] = dimvalue;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
#include "src/ESPEasyCore/Controller.h"
|
||||
#include "src/ESPEasyCore/ESPEasy_Log.h"
|
||||
#include "src/ESPEasyCore/Serial.h"
|
||||
|
||||
#include "src/Globals/Cache.h"
|
||||
#include "src/Globals/Device.h"
|
||||
|
||||
@@ -2903,6 +2903,10 @@ To create/register a plugin, you have to :
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef FEATURE_DEFINE_SERIAL_CONSOLE_PORT
|
||||
#define FEATURE_DEFINE_SERIAL_CONSOLE_PORT 0
|
||||
#endif
|
||||
|
||||
#if !FEATURE_PLUGIN_PRIORITY && (defined(USES_P137) /*|| defined(USES_Pxxx)*/)
|
||||
#undef FEATURE_PLUGIN_PRIORITY
|
||||
#define FEATURE_PLUGIN_PRIORITY 1
|
||||
@@ -2958,5 +2962,9 @@ To create/register a plugin, you have to :
|
||||
#define ESPEASY_RULES_FLOAT_TYPE float
|
||||
#endif
|
||||
|
||||
#ifndef ESPEASY_SERIAL_0
|
||||
#define ESPEASY_SERIAL_0 Serial
|
||||
#endif
|
||||
|
||||
|
||||
#endif // CUSTOMBUILD_DEFINE_PLUGIN_SETS_H
|
||||
@@ -72,7 +72,7 @@ void Caches::updateActiveTaskUseSerial0() {
|
||||
if ((Device[DeviceIndex].Type == DEVICE_TYPE_SERIAL) ||
|
||||
(Device[DeviceIndex].Type == DEVICE_TYPE_SERIAL_PLUS1)) {
|
||||
const ESPEasySerialPort port = ESPeasySerialType::getSerialType(
|
||||
ESPEasySerialPort::not_set,
|
||||
static_cast<ESPEasySerialPort>(Settings.TaskDevicePort[task]),
|
||||
Settings.TaskDevicePin1[task],
|
||||
Settings.TaskDevicePin2[task]);
|
||||
if (port == ESPEasySerialPort::serial0_swap ||
|
||||
|
||||
@@ -399,12 +399,14 @@ public:
|
||||
|
||||
// Do not rename or move this checksum.
|
||||
// Checksum calculation will work "around" this
|
||||
uint8_t md5[16]{}; // Store checksum of the settings.
|
||||
|
||||
// uint8_t ProgmemMd5[16]; // crc of the binary that last saved the struct to file.
|
||||
|
||||
uint8_t md5[16]; // Store checksum of the settings.
|
||||
uint32_t VariousBits2 = 0;
|
||||
|
||||
uint8_t console_serial_port = 2; // ESPEasySerialPort::serial0
|
||||
int8_t console_serial_rxpin = 3;
|
||||
int8_t console_serial_txpin = 1;
|
||||
int8_t alignment_filler1 = 0; // can be reused
|
||||
|
||||
// Try to extend settings to make the checksum 4-uint8_t aligned.
|
||||
};
|
||||
|
||||
|
||||
@@ -432,6 +432,23 @@ void SettingsStruct_tmpl<N_TASKS>::validate() {
|
||||
if ((I2C_clockSpeed == 0) || (I2C_clockSpeed > 3400000)) { I2C_clockSpeed = DEFAULT_I2C_CLOCK_SPEED; }
|
||||
if (WebserverPort == 0) { WebserverPort = 80;}
|
||||
if (SyslogPort == 0) { SyslogPort = 514; }
|
||||
|
||||
#if FEATURE_DEFINE_SERIAL_CONSOLE_PORT
|
||||
if (console_serial_port == 0 && UseSerial) {
|
||||
console_serial_port = 2; // ESPEasySerialPort::serial0
|
||||
}
|
||||
if (console_serial_port == 2) {
|
||||
// Set default RX/TX pins for Serial0
|
||||
console_serial_rxpin = 3;
|
||||
console_serial_txpin = 1;
|
||||
#ifdef ESP8266
|
||||
} else if (console_serial_port == 3) {
|
||||
// Set default RX/TX pins for Serial0_swapped
|
||||
console_serial_rxpin = 13;
|
||||
console_serial_txpin = 15;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
template<unsigned int N_TASKS>
|
||||
@@ -558,8 +575,8 @@ void SettingsStruct_tmpl<N_TASKS>::clearMisc() {
|
||||
deepSleep_wakeTime = 0;
|
||||
CustomCSS = false;
|
||||
WDI2CAddress = 0;
|
||||
UseRules = false;
|
||||
UseSerial = true;
|
||||
UseRules = DEFAULT_USE_RULES;
|
||||
UseSerial = DEFAULT_USE_SERIAL;
|
||||
UseSSDP = false;
|
||||
WireClockStretchLimit = 0;
|
||||
I2C_clockSpeed = 400000;
|
||||
|
||||
@@ -227,7 +227,7 @@ bool WiFiConnected() {
|
||||
static uint32_t lastCheckedTime = 0;
|
||||
static bool lastState = false;
|
||||
|
||||
if (lastCheckedTime != 0 && timePassedSince(lastCheckedTime) < 10) {
|
||||
if (lastCheckedTime != 0 && timePassedSince(lastCheckedTime) < 100) {
|
||||
// Try to rate-limit the nr of calls to this function or else it will be called 1000's of times a second.
|
||||
return lastState;
|
||||
}
|
||||
@@ -674,7 +674,7 @@ void initWiFi()
|
||||
// ********************************************************************************
|
||||
#if FEATURE_SET_WIFI_TX_PWR
|
||||
void SetWiFiTXpower() {
|
||||
SetWiFiTXpower(0.0f); // Just some minimal value, will be adjusted in SetWiFiTXpower
|
||||
SetWiFiTXpower(0); // Just some minimal value, will be adjusted in SetWiFiTXpower
|
||||
}
|
||||
|
||||
void SetWiFiTXpower(float dBm) {
|
||||
@@ -691,11 +691,16 @@ void SetWiFiTXpower(float dBm, float rssi) {
|
||||
dBm = 30; // Just some max, will be limited later
|
||||
}
|
||||
|
||||
// Range ESP32 : 2dBm - 20dBm
|
||||
// Range ESP32 : -1dBm - 20dBm
|
||||
// Range ESP8266: 0dBm - 20.5dBm
|
||||
float maxTXpwr;
|
||||
float threshold = GetRSSIthreshold(maxTXpwr);
|
||||
float minTXpwr = 0;
|
||||
#ifdef ESP8266
|
||||
float minTXpwr{};
|
||||
#endif
|
||||
#ifdef ESP32
|
||||
float minTXpwr = -1.0f;
|
||||
#endif
|
||||
|
||||
threshold += Settings.WiFi_sensitivity_margin; // Margin in dBm on top of threshold
|
||||
|
||||
@@ -717,48 +722,12 @@ void SetWiFiTXpower(float dBm, float rssi) {
|
||||
}
|
||||
|
||||
#ifdef ESP32
|
||||
wifi_power_t val = WIFI_POWER_MINUS_1dBm;
|
||||
if (dBm < 0) {
|
||||
val = WIFI_POWER_MINUS_1dBm;
|
||||
dBm = -1;
|
||||
} else if (dBm < 3.5f) {
|
||||
val = WIFI_POWER_2dBm;
|
||||
dBm = 2;
|
||||
} else if (dBm < 6) {
|
||||
val = WIFI_POWER_5dBm;
|
||||
dBm = 5;
|
||||
} else if (dBm < 8) {
|
||||
val = WIFI_POWER_7dBm;
|
||||
dBm = 7;
|
||||
} else if (dBm < 10) {
|
||||
val = WIFI_POWER_8_5dBm;
|
||||
dBm = 8.5;
|
||||
} else if (dBm < 12) {
|
||||
val = WIFI_POWER_11dBm;
|
||||
dBm = 11;
|
||||
} else if (dBm < 14) {
|
||||
val = WIFI_POWER_13dBm;
|
||||
dBm = 13;
|
||||
} else if (dBm < 16) {
|
||||
val = WIFI_POWER_15dBm;
|
||||
dBm = 15;
|
||||
} else if (dBm < 17.75f) {
|
||||
val = WIFI_POWER_17dBm;
|
||||
dBm = 17;
|
||||
} else if (dBm < 18.75f) {
|
||||
val = WIFI_POWER_18_5dBm;
|
||||
dBm = 18.5;
|
||||
} else if (dBm < 19.25f) {
|
||||
val = WIFI_POWER_19dBm;
|
||||
dBm = 19;
|
||||
} else {
|
||||
val = WIFI_POWER_19_5dBm;
|
||||
dBm = 19.5f;
|
||||
int8_t power = dBm * 4;
|
||||
if (esp_wifi_set_max_tx_power(power) == ESP_OK) {
|
||||
if (esp_wifi_get_max_tx_power(&power) == ESP_OK) {
|
||||
dBm = power / 4;
|
||||
}
|
||||
}
|
||||
esp_wifi_set_max_tx_power(val);
|
||||
//esp_wifi_get_max_tx_power(&val);
|
||||
// dBm = static_cast<float>(val);
|
||||
// dBm /= 4.0f;
|
||||
#endif
|
||||
|
||||
#ifdef ESP8266
|
||||
|
||||
@@ -87,16 +87,17 @@ void setLogLevelFor(uint8_t destination, uint8_t logLevel) {
|
||||
|
||||
void updateLogLevelCache() {
|
||||
uint8_t max_lvl = 0;
|
||||
// FIXME TD-er: Must add check whether SW serial may be using the same pins as Serial0
|
||||
const bool useSerial = Settings.UseSerial && !activeTaskUseSerial0();
|
||||
if (log_to_serial_disabled) {
|
||||
if (useSerial) {
|
||||
Serial.setDebugOutput(false);
|
||||
ESPEASY_SERIAL_CONSOLE_PORT.setDebugOutput(false);
|
||||
}
|
||||
} else {
|
||||
max_lvl = _max(max_lvl, Settings.SerialLogLevel);
|
||||
#ifndef BUILD_NO_DEBUG
|
||||
if (useSerial && Settings.SerialLogLevel >= LOG_LEVEL_DEBUG_MORE) {
|
||||
Serial.setDebugOutput(true);
|
||||
ESPEASY_SERIAL_CONSOLE_PORT.setDebugOutput(true);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -115,7 +116,12 @@ bool loglevelActiveFor(uint8_t logLevel) {
|
||||
}
|
||||
|
||||
uint8_t getSerialLogLevel() {
|
||||
#if FEATURE_DEFINE_SERIAL_CONSOLE_PORT
|
||||
// FIXME TD-er: Must add check whether SW serial may be using the same pins as Serial0
|
||||
if (log_to_serial_disabled || !Settings.UseSerial) return 0;
|
||||
#else
|
||||
if (log_to_serial_disabled || !Settings.UseSerial || activeTaskUseSerial0()) return 0;
|
||||
#endif
|
||||
if (!(WiFiEventData.WiFiServicesInitialized())){
|
||||
if (Settings.SerialLogLevel < LOG_LEVEL_INFO) {
|
||||
return LOG_LEVEL_INFO;
|
||||
|
||||
@@ -104,6 +104,11 @@ void sw_watchdog_callback(void *arg)
|
||||
\*********************************************************************************************/
|
||||
void ESPEasy_setup()
|
||||
{
|
||||
#if FEATURE_DEFINE_SERIAL_CONSOLE_PORT
|
||||
// Init serial as first call to make sure the object exists.
|
||||
//ESPEASY_SERIAL_CONSOLE_PORT.setLowPriority();
|
||||
initSerial();
|
||||
#endif
|
||||
#if defined(ESP8266_DISABLE_EXTRA4K) || defined(USE_SECOND_HEAP)
|
||||
disable_extra4k_at_link_time();
|
||||
#endif
|
||||
@@ -169,8 +174,19 @@ void ESPEasy_setup()
|
||||
#ifndef BUILD_NO_RAM_TRACKER
|
||||
checkRAM(F("setup"));
|
||||
#endif // ifndef BUILD_NO_RAM_TRACKER
|
||||
|
||||
Serial.begin(115200);
|
||||
#ifdef ESP8266
|
||||
ESPEASY_SERIAL_CONSOLE_PORT.begin(115200);
|
||||
#endif
|
||||
#ifdef ESP32
|
||||
# if defined(USE_USB_CDC_CONSOLE) && ARDUINO_USB_MODE
|
||||
addLog(LOG_LEVEL_INFO, F("ESPEasy console using HWCDC"));
|
||||
# else
|
||||
delay(10); // When using USB CDC and not opening the USB serial port, the ESP may hang at boot.
|
||||
ESPEASY_SERIAL_CONSOLE_PORT.end();
|
||||
delay(10);
|
||||
ESPEASY_SERIAL_CONSOLE_PORT.begin(115200);
|
||||
# endif
|
||||
#endif
|
||||
|
||||
// serialPrint("\n\n\nBOOOTTT\n\n\n");
|
||||
|
||||
@@ -420,6 +436,16 @@ void ESPEasy_setup()
|
||||
}
|
||||
|
||||
initSerial();
|
||||
# ifdef ESP32
|
||||
# if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
|
||||
# ifdef USE_USB_CDC_CONSOLE
|
||||
# if ARDUINO_USB_MODE
|
||||
# else // No ARDUINO_USB_MODE
|
||||
USB.begin();
|
||||
# endif
|
||||
# endif
|
||||
# endif
|
||||
# endif
|
||||
#ifndef BUILD_NO_RAM_TRACKER
|
||||
logMemUsageAfter(F("initSerial()"));
|
||||
#endif
|
||||
@@ -432,7 +458,7 @@ void ESPEasy_setup()
|
||||
|
||||
# ifndef BUILD_NO_DEBUG
|
||||
if (Settings.UseSerial && (Settings.SerialLogLevel >= LOG_LEVEL_DEBUG_MORE)) {
|
||||
Serial.setDebugOutput(true);
|
||||
ESPEASY_SERIAL_CONSOLE_PORT.setDebugOutput(true);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -450,6 +476,9 @@ void ESPEasy_setup()
|
||||
#endif // if FEATURE_NOTIFIER
|
||||
|
||||
PluginInit();
|
||||
|
||||
initSerial(); // Plugins may have altered serial, so re-init serial
|
||||
|
||||
#ifndef BUILD_NO_RAM_TRACKER
|
||||
logMemUsageAfter(F("PluginInit()"));
|
||||
#endif
|
||||
|
||||
+275
-34
@@ -7,33 +7,265 @@
|
||||
#include "../Globals/Logging.h" // For serialWriteBuffer
|
||||
#include "../Globals/Settings.h"
|
||||
|
||||
#include "../Helpers/ESPEasy_time_calc.h"
|
||||
#include "../Helpers/Memory.h"
|
||||
|
||||
#if FEATURE_DEFINE_SERIAL_CONSOLE_PORT
|
||||
# include "../Helpers/_Plugin_Helper_serial.h"
|
||||
#endif // if FEATURE_DEFINE_SERIAL_CONSOLE_PORT
|
||||
|
||||
/********************************************************************************************\
|
||||
* Get data from Serial Interface
|
||||
\*********************************************************************************************/
|
||||
|
||||
uint8_t SerialInByte;
|
||||
int SerialInByteCounter = 0;
|
||||
char InputBuffer_Serial[INPUT_BUFFER_SIZE + 2];
|
||||
int SerialInByteCounter{};
|
||||
char InputBuffer_Serial[INPUT_BUFFER_SIZE + 2]{};
|
||||
|
||||
#if FEATURE_DEFINE_SERIAL_CONSOLE_PORT
|
||||
uint8_t console_serial_port = 2; // ESPEasySerialPort::serial0
|
||||
int8_t console_serial_rxpin = 3;
|
||||
int8_t console_serial_txpin = 1;
|
||||
|
||||
ESPeasySerial ESPEASY_SERIAL_CONSOLE_PORT(
|
||||
static_cast<ESPEasySerialPort>(console_serial_port),
|
||||
console_serial_rxpin,
|
||||
console_serial_txpin,
|
||||
false,
|
||||
64);
|
||||
|
||||
|
||||
// Check to see if console port may have a conflict with given parameters
|
||||
// If there is a conflict, disable console port.
|
||||
void checkSerialConflict(ESPEasySerialPort port,
|
||||
int receivePin,
|
||||
int transmitPin)
|
||||
{
|
||||
bool consolePortConflict = false;
|
||||
|
||||
if (port == ESPEasySerialPort::software) {
|
||||
consolePortConflict =
|
||||
receivePin == console_serial_rxpin ||
|
||||
transmitPin == console_serial_txpin ||
|
||||
receivePin == console_serial_txpin ||
|
||||
transmitPin == console_serial_rxpin;
|
||||
} else {
|
||||
if (static_cast<ESPEasySerialPort>(console_serial_port) == port) {
|
||||
consolePortConflict = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (consolePortConflict) {
|
||||
ESPEASY_SERIAL_CONSOLE_PORT.end();
|
||||
console_serial_port = static_cast<uint8_t>(ESPEasySerialPort::not_set);
|
||||
console_serial_rxpin = -1;
|
||||
console_serial_txpin = -1;
|
||||
ESPEASY_SERIAL_CONSOLE_PORT.resetConfig(ESPEasySerialPort::not_set, -1, -1);
|
||||
}
|
||||
}
|
||||
|
||||
#else // if FEATURE_DEFINE_SERIAL_CONSOLE_PORT
|
||||
|
||||
|
||||
# ifdef ESP32
|
||||
|
||||
/*
|
||||
#if CONFIG_IDF_TARGET_ESP32C3 || // support USB via HWCDC using JTAG interface
|
||||
CONFIG_IDF_TARGET_ESP32S2 || // support USB via USBCDC
|
||||
CONFIG_IDF_TARGET_ESP32S3 // support USB via HWCDC using JTAG interface or USBCDC
|
||||
*/
|
||||
# if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
|
||||
|
||||
// #if CONFIG_TINYUSB_CDC_ENABLED // This define is not recognized here so use USE_USB_CDC_CONSOLE
|
||||
# ifdef USE_USB_CDC_CONSOLE
|
||||
# if ARDUINO_USB_MODE
|
||||
|
||||
// ESP32C3/S3 embedded USB using JTAG interface
|
||||
HWCDC ESPEASY_SERIAL_CONSOLE_PORT;
|
||||
# warning **** ESPEasy_Console uses HWCDC ****
|
||||
# else // No ARDUINO_USB_MODE
|
||||
// ESP32Sx embedded USB interface
|
||||
USBCDC ESPEASY_SERIAL_CONSOLE_PORT;
|
||||
# warning **** ESPEasy_Console uses USBCDC ****
|
||||
# endif // ARDUINO_USB_MODE
|
||||
|
||||
# else // No USE_USB_CDC_CONSOLE
|
||||
// Fallback serial interface for ESP32C3, S2 and S3 if no USB_SERIAL defined
|
||||
# warning **** ESPEasy_Console uses Serial ****
|
||||
# endif // USE_USB_CDC_CONSOLE
|
||||
|
||||
# else // No ESP32C3, S2 or S3
|
||||
// Fallback serial interface for non ESP32C3, S2 and S3
|
||||
# warning **** ESPEasy_Console uses Serial ****
|
||||
# endif // ESP32C3, S2 or S3
|
||||
|
||||
# else // No ESP32
|
||||
// Using the standard Serial0 HW serial port.
|
||||
# warning **** ESPEasy_Console uses Serial ****
|
||||
# endif // ifdef ESP32
|
||||
|
||||
#endif // if FEATURE_DEFINE_SERIAL_CONSOLE_PORT
|
||||
|
||||
|
||||
void initSerial()
|
||||
{
|
||||
if (log_to_serial_disabled || !Settings.UseSerial || activeTaskUseSerial0()) {
|
||||
updateActiveTaskUseSerial0();
|
||||
|
||||
if (!Settings.UseSerial) {
|
||||
return;
|
||||
}
|
||||
|
||||
#if FEATURE_DEFINE_SERIAL_CONSOLE_PORT
|
||||
|
||||
// FIXME TD-er: Must detect whether we should swap software serial on pin 3&1 for HW serial if Serial0 is not being used anymore.
|
||||
const ESPEasySerialPort port = static_cast<ESPEasySerialPort>(Settings.console_serial_port);
|
||||
|
||||
if ((port == ESPEasySerialPort::serial0) || (port == ESPEasySerialPort::serial0_swap)) {
|
||||
if (activeTaskUseSerial0()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
#else // if FEATURE_DEFINE_SERIAL_CONSOLE_PORT
|
||||
|
||||
if (activeTaskUseSerial0()) {
|
||||
return;
|
||||
}
|
||||
#endif // if FEATURE_DEFINE_SERIAL_CONSOLE_PORT
|
||||
|
||||
if (log_to_serial_disabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
#if FEATURE_DEFINE_SERIAL_CONSOLE_PORT
|
||||
|
||||
// if (ESPEASY_SERIAL_CONSOLE_PORT.getSerialPortType() == ESPEasySerialPort::not_set)
|
||||
|
||||
/*
|
||||
if (Settings.console_serial_port != console_serial_port ||
|
||||
Settings.console_serial_rxpin != console_serial_rxpin ||
|
||||
Settings.console_serial_txpin != console_serial_txpin) {
|
||||
|
||||
const uint8_t current_console_serial_port = console_serial_port;
|
||||
// Update cached values
|
||||
console_serial_port = Settings.console_serial_port;
|
||||
console_serial_rxpin = Settings.console_serial_rxpin;
|
||||
console_serial_txpin = Settings.console_serial_txpin;
|
||||
|
||||
#ifdef ESP8266
|
||||
bool forceSWSerial = static_cast<ESPEasySerialPort>(Settings.console_serial_port) == ESPEasySerialPort::software;
|
||||
if (activeTaskUseSerial0()) {
|
||||
if (ESPEasySerialPort::sc16is752 != static_cast<ESPEasySerialPort>(console_serial_port)) {
|
||||
forceSWSerial = true;
|
||||
console_serial_port = static_cast<uint8_t>(ESPEasySerialPort::software);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (loglevelActiveFor(LOG_LEVEL_INFO)) {
|
||||
String log = F("Serial : Change serial console port from: ");
|
||||
log += ESPEasySerialPort_toString(static_cast<ESPEasySerialPort>(current_console_serial_port));
|
||||
log += F(" to: ");
|
||||
log += ESPEasySerialPort_toString(static_cast<ESPEasySerialPort>(console_serial_port));
|
||||
#ifdef ESP8266
|
||||
if (forceSWSerial) {
|
||||
log += F(" (force SW serial)");
|
||||
}
|
||||
#endif
|
||||
addLogMove(LOG_LEVEL_INFO, log);
|
||||
}
|
||||
process_serialWriteBuffer();
|
||||
|
||||
|
||||
ESPEASY_SERIAL_CONSOLE_PORT.resetConfig(
|
||||
static_cast<ESPEasySerialPort>(console_serial_port),
|
||||
console_serial_rxpin,
|
||||
console_serial_txpin,
|
||||
false,
|
||||
64
|
||||
#ifdef ESP8266
|
||||
, forceSWSerial
|
||||
#endif
|
||||
);
|
||||
}
|
||||
*/
|
||||
#endif // if FEATURE_DEFINE_SERIAL_CONSOLE_PORT
|
||||
|
||||
// make sure previous serial buffers are flushed before resetting baudrate
|
||||
Serial.flush();
|
||||
Serial.begin(Settings.BaudRate);
|
||||
#ifdef ESP8266
|
||||
ESPEASY_SERIAL_CONSOLE_PORT.begin(Settings.BaudRate);
|
||||
#endif
|
||||
#ifdef ESP32
|
||||
# if defined(USE_USB_CDC_CONSOLE) && ARDUINO_USB_MODE
|
||||
// addLog(LOG_LEVEL_INFO, F("ESPEasy console using HWCDC"));
|
||||
ESPEASY_SERIAL_CONSOLE_PORT.begin();
|
||||
# else
|
||||
// Allow to flush data from the serial buffers
|
||||
// When not opening the USB serial port, the ESP may hang at boot.
|
||||
delay(10);
|
||||
ESPEASY_SERIAL_CONSOLE_PORT.end();
|
||||
delay(10);
|
||||
ESPEASY_SERIAL_CONSOLE_PORT.begin(Settings.BaudRate);
|
||||
ESPEASY_SERIAL_CONSOLE_PORT.flush();
|
||||
# endif
|
||||
# if CONFIG_IDF_TARGET_ESP32S2
|
||||
# if defined(USE_USB_CDC_CONSOLE)
|
||||
ESPEASY_SERIAL_CONSOLE_PORT.setRxBufferSize(64);
|
||||
# endif
|
||||
# endif
|
||||
# if defined(USE_USB_CDC_CONSOLE) && ARDUINO_USB_MODE
|
||||
|
||||
# else
|
||||
ESPEASY_SERIAL_CONSOLE_PORT.begin(Settings.BaudRate);
|
||||
# endif
|
||||
#endif
|
||||
|
||||
// ESPEASY_SERIAL_CONSOLE_PORT.setDebugOutput(true);
|
||||
|
||||
#if FEATURE_DEFINE_SERIAL_CONSOLE_PORT
|
||||
# ifdef ESP32
|
||||
|
||||
/*
|
||||
#if CONFIG_IDF_TARGET_ESP32C3 || // support USB via HWCDC using JTAG interface
|
||||
CONFIG_IDF_TARGET_ESP32S2 || // support USB via USBCDC
|
||||
CONFIG_IDF_TARGET_ESP32S3 // support USB via HWCDC using JTAG interface or USBCDC
|
||||
*/
|
||||
# if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
|
||||
|
||||
// #if CONFIG_TINYUSB_CDC_ENABLED // This define is not recognized here so use USE_USB_CDC_CONSOLE
|
||||
# ifdef USE_USB_CDC_CONSOLE
|
||||
# if ARDUINO_USB_MODE
|
||||
|
||||
// ESP32C3/S3 embedded USB using JTAG interface
|
||||
# else // No ARDUINO_USB_MODE
|
||||
// ESP32Sx embedded USB interface
|
||||
// USB.begin();
|
||||
|
||||
# endif // ARDUINO_USB_MODE
|
||||
|
||||
# else // No USE_USB_CDC_CONSOLE
|
||||
// Fallback serial interface for ESP32C3, S2 and S3 if no USB_SERIAL defined
|
||||
# warning **** ESPEasy_Console uses Serial ****
|
||||
# endif // USE_USB_CDC_CONSOLE
|
||||
|
||||
# else // No ESP32C3, S2 or S3
|
||||
// Fallback serial interface for non ESP32C3, S2 and S3
|
||||
# warning **** ESPEasy_Console uses Serial ****
|
||||
# endif // ESP32C3, S2 or S3
|
||||
|
||||
# else // No ESP32
|
||||
// Using the standard Serial0 HW serial port.
|
||||
# warning **** ESPEasy_Console uses Serial ****
|
||||
# endif // ifdef ESP32
|
||||
|
||||
#endif // if FEATURE_DEFINE_SERIAL_CONSOLE_PORT
|
||||
|
||||
|
||||
|
||||
// Serial.setDebugOutput(true);
|
||||
}
|
||||
|
||||
void serial()
|
||||
{
|
||||
if (Serial.available())
|
||||
if (ESPEASY_SERIAL_CONSOLE_PORT.available())
|
||||
{
|
||||
String dummy;
|
||||
|
||||
@@ -41,17 +273,23 @@ void serial()
|
||||
return;
|
||||
}
|
||||
}
|
||||
#if FEATURE_DEFINE_SERIAL_CONSOLE_PORT
|
||||
|
||||
// FIXME TD-er: Must add check whether SW serial may be using the same pins as Serial0
|
||||
if (!Settings.UseSerial) { return; }
|
||||
#else // if FEATURE_DEFINE_SERIAL_CONSOLE_PORT
|
||||
|
||||
if (!Settings.UseSerial || activeTaskUseSerial0()) { return; }
|
||||
#endif // if FEATURE_DEFINE_SERIAL_CONSOLE_PORT
|
||||
|
||||
while (Serial.available())
|
||||
while (ESPEASY_SERIAL_CONSOLE_PORT.available())
|
||||
{
|
||||
delay(0);
|
||||
SerialInByte = Serial.read();
|
||||
const uint8_t SerialInByte = ESPEASY_SERIAL_CONSOLE_PORT.read();
|
||||
|
||||
if (SerialInByte == 255) // binary data...
|
||||
{
|
||||
Serial.flush();
|
||||
ESPEASY_SERIAL_CONSOLE_PORT.flush();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -68,7 +306,7 @@ void serial()
|
||||
break;
|
||||
}
|
||||
InputBuffer_Serial[SerialInByteCounter] = 0; // serial data completed
|
||||
Serial.write('>');
|
||||
ESPEASY_SERIAL_CONSOLE_PORT.write('>');
|
||||
serialPrintln(InputBuffer_Serial);
|
||||
ExecuteCommand_all(EventValueSource::Enum::VALUE_SOURCE_SERIAL, InputBuffer_Serial);
|
||||
SerialInByteCounter = 0;
|
||||
@@ -79,9 +317,10 @@ void serial()
|
||||
|
||||
int getRoomLeft() {
|
||||
#ifdef USE_SECOND_HEAP
|
||||
|
||||
// If stored in 2nd heap, we must check this for space
|
||||
HeapSelectIram ephemeral;
|
||||
#endif
|
||||
#endif // ifdef USE_SECOND_HEAP
|
||||
|
||||
int roomLeft = getMaxFreeBlock();
|
||||
|
||||
@@ -95,22 +334,28 @@ int getRoomLeft() {
|
||||
return roomLeft;
|
||||
}
|
||||
|
||||
void addToSerialBuffer(const __FlashStringHelper * line)
|
||||
void addToSerialBuffer(const __FlashStringHelper *line)
|
||||
{
|
||||
addToSerialBuffer(String(line));
|
||||
}
|
||||
|
||||
void addToSerialBuffer(const String& line) {
|
||||
process_serialWriteBuffer(); // Try to make some room first.
|
||||
// When the buffer is too full, try to dump at least the size of what we try to add.
|
||||
const bool mustPop = !process_serialWriteBuffer() && serialWriteBuffer.size() > 10000;
|
||||
{
|
||||
#ifdef USE_SECOND_HEAP
|
||||
|
||||
// Allow to store the logs in 2nd heap if present.
|
||||
HeapSelectIram ephemeral;
|
||||
#endif
|
||||
#endif // ifdef USE_SECOND_HEAP
|
||||
int roomLeft = getRoomLeft();
|
||||
|
||||
auto it = line.begin();
|
||||
|
||||
while (roomLeft > 0 && it != line.end()) {
|
||||
if (mustPop) {
|
||||
serialWriteBuffer.pop_front();
|
||||
}
|
||||
serialWriteBuffer.push_back(*it);
|
||||
--roomLeft;
|
||||
++it;
|
||||
@@ -120,41 +365,37 @@ void addToSerialBuffer(const String& line) {
|
||||
}
|
||||
|
||||
void addNewlineToSerialBuffer() {
|
||||
process_serialWriteBuffer(); // Try to make some room first.
|
||||
{
|
||||
#ifdef USE_SECOND_HEAP
|
||||
// Allow to store the logs in 2nd heap if present.
|
||||
HeapSelectIram ephemeral;
|
||||
#endif
|
||||
|
||||
serialWriteBuffer.push_back('\r');
|
||||
serialWriteBuffer.push_back('\n');
|
||||
}
|
||||
addToSerialBuffer(F("\r\n"));
|
||||
}
|
||||
|
||||
void process_serialWriteBuffer() {
|
||||
if (serialWriteBuffer.size() == 0) { return; }
|
||||
size_t snip = Serial.availableForWrite();
|
||||
bool process_serialWriteBuffer() {
|
||||
const size_t bufferSize = serialWriteBuffer.size();
|
||||
if (bufferSize == 0) {
|
||||
return true;
|
||||
}
|
||||
const size_t snip = ESPEASY_SERIAL_CONSOLE_PORT.availableForWrite();
|
||||
|
||||
if (snip > 0) {
|
||||
size_t bytes_to_write = serialWriteBuffer.size();
|
||||
|
||||
size_t bytes_to_write = bufferSize;
|
||||
if (snip < bytes_to_write) { bytes_to_write = snip; }
|
||||
|
||||
while (bytes_to_write > 0 && !serialWriteBuffer.empty()) {
|
||||
const char c = serialWriteBuffer.front();
|
||||
|
||||
if (Settings.UseSerial) {
|
||||
Serial.write(c);
|
||||
ESPEASY_SERIAL_CONSOLE_PORT.write(c);
|
||||
}
|
||||
serialWriteBuffer.pop_front();
|
||||
--bytes_to_write;
|
||||
}
|
||||
}
|
||||
|
||||
return bufferSize != serialWriteBuffer.size();
|
||||
}
|
||||
|
||||
// For now, only send it to the serial buffer and try to process it.
|
||||
// Later we may want to wrap it into a log.
|
||||
void serialPrint(const __FlashStringHelper * text) {
|
||||
void serialPrint(const __FlashStringHelper *text) {
|
||||
addToSerialBuffer(text);
|
||||
}
|
||||
|
||||
@@ -162,7 +403,7 @@ void serialPrint(const String& text) {
|
||||
addToSerialBuffer(text);
|
||||
}
|
||||
|
||||
void serialPrintln(const __FlashStringHelper * text) {
|
||||
void serialPrintln(const __FlashStringHelper *text) {
|
||||
addToSerialBuffer(text);
|
||||
serialPrintln();
|
||||
}
|
||||
|
||||
@@ -3,29 +3,87 @@
|
||||
|
||||
#include "../../ESPEasy_common.h"
|
||||
|
||||
#if FEATURE_DEFINE_SERIAL_CONSOLE_PORT
|
||||
# include <ESPeasySerial.h>
|
||||
#endif // if FEATURE_DEFINE_SERIAL_CONSOLE_PORT
|
||||
|
||||
|
||||
#define INPUT_BUFFER_SIZE 128
|
||||
|
||||
extern uint8_t SerialInByte;
|
||||
extern int SerialInByteCounter;
|
||||
extern char InputBuffer_Serial[INPUT_BUFFER_SIZE + 2];
|
||||
extern int SerialInByteCounter;
|
||||
extern char InputBuffer_Serial[INPUT_BUFFER_SIZE + 2];
|
||||
|
||||
#if FEATURE_DEFINE_SERIAL_CONSOLE_PORT
|
||||
|
||||
// Cache the used settings, so we can check whether to change the console serial
|
||||
extern uint8_t console_serial_port;
|
||||
extern int8_t console_serial_rxpin;
|
||||
extern int8_t console_serial_txpin;
|
||||
|
||||
extern ESPeasySerial ESPEASY_SERIAL_CONSOLE_PORT;
|
||||
|
||||
#else // if FEATURE_DEFINE_SERIAL_CONSOLE_PORT
|
||||
|
||||
|
||||
# ifdef ESP32
|
||||
|
||||
/*
|
||||
#if CONFIG_IDF_TARGET_ESP32C3 || // support USB via HWCDC using JTAG interface
|
||||
CONFIG_IDF_TARGET_ESP32S2 || // support USB via USBCDC
|
||||
CONFIG_IDF_TARGET_ESP32S3 // support USB via HWCDC using JTAG interface or USBCDC
|
||||
*/
|
||||
# if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
|
||||
|
||||
// #if CONFIG_TINYUSB_CDC_ENABLED // This define is not recognized here so use USE_USB_CDC_CONSOLE
|
||||
# ifdef USE_USB_CDC_CONSOLE
|
||||
# if ARDUINO_USB_MODE
|
||||
// ESP32C3/S3 embedded USB using JTAG interface
|
||||
extern HWCDC ESPEASY_SERIAL_CONSOLE_PORT;
|
||||
# else // No ARDUINO_USB_MODE
|
||||
# include "USB.h"
|
||||
# include "USBCDC.h"
|
||||
extern USBCDC ESPEASY_SERIAL_CONSOLE_PORT;
|
||||
# endif // ARDUINO_USB_MODE
|
||||
|
||||
# else // No USE_USB_CDC_CONSOLE
|
||||
# define ESPEASY_SERIAL_CONSOLE_PORT Serial // Fallback serial interface for ESP32C3, S2 and S3 if no USB_SERIAL defined
|
||||
# endif // USE_USB_CDC_CONSOLE
|
||||
|
||||
# else // No ESP32C3, S2 or S3
|
||||
# define ESPEASY_SERIAL_CONSOLE_PORT Serial // Fallback serial interface for non ESP32C3, S2 and S3
|
||||
# endif // ESP32C3, S2 or S3
|
||||
|
||||
# else // No ESP32
|
||||
// Using the standard Serial0 HW serial port.
|
||||
# define ESPEASY_SERIAL_CONSOLE_PORT Serial
|
||||
# endif // ifdef ESP32
|
||||
|
||||
#endif // if FEATURE_DEFINE_SERIAL_CONSOLE_PORT
|
||||
|
||||
#if FEATURE_DEFINE_SERIAL_CONSOLE_PORT
|
||||
void checkSerialConflict(ESPEasySerialPort port,
|
||||
int receivePin,
|
||||
int transmitPin);
|
||||
#endif // if FEATURE_DEFINE_SERIAL_CONSOLE_PORT
|
||||
|
||||
void initSerial();
|
||||
|
||||
void serial();
|
||||
|
||||
void addToSerialBuffer(const __FlashStringHelper * line);
|
||||
void addToSerialBuffer(const __FlashStringHelper *line);
|
||||
void addToSerialBuffer(const String& line);
|
||||
|
||||
void addNewlineToSerialBuffer();
|
||||
|
||||
void process_serialWriteBuffer();
|
||||
// Return true when something got written, or when the buffer was already empty
|
||||
bool process_serialWriteBuffer();
|
||||
|
||||
// For now, only send it to the serial buffer and try to process it.
|
||||
// Later we may want to wrap it into a log.
|
||||
void serialPrint(const __FlashStringHelper * text);
|
||||
void serialPrint(const __FlashStringHelper *text);
|
||||
void serialPrint(const String& text);
|
||||
|
||||
void serialPrintln(const __FlashStringHelper * text);
|
||||
void serialPrintln(const __FlashStringHelper *text);
|
||||
void serialPrintln(const String& text);
|
||||
|
||||
void serialPrintln();
|
||||
|
||||
@@ -21,6 +21,10 @@
|
||||
#include "../Globals/Settings.h"
|
||||
#include "../Globals/Statistics.h"
|
||||
|
||||
#if FEATURE_DEFINE_SERIAL_CONSOLE_PORT
|
||||
#include "../Helpers/_Plugin_Helper_serial.h"
|
||||
#endif
|
||||
|
||||
#include "../Helpers/ESPEasyRTC.h"
|
||||
#include "../Helpers/ESPEasy_Storage.h"
|
||||
#include "../Helpers/Hardware.h"
|
||||
@@ -795,6 +799,16 @@ bool PluginCall(uint8_t Function, struct EventStruct *event, String& str)
|
||||
) {
|
||||
// Make sure any task data is actually cleared.
|
||||
clearPluginTaskData(event->TaskIndex);
|
||||
/*
|
||||
#if FEATURE_DEFINE_SERIAL_CONSOLE_PORT
|
||||
if (Device[DeviceIndex].isSerial()) {
|
||||
checkSerialConflict(
|
||||
serialHelper_getSerialType(event),
|
||||
serialHelper_getRxPin(event),
|
||||
serialHelper_getTxPin(event));
|
||||
}
|
||||
#endif
|
||||
*/
|
||||
}
|
||||
|
||||
if (performPluginCall) {
|
||||
@@ -846,7 +860,7 @@ bool PluginCall(uint8_t Function, struct EventStruct *event, String& str)
|
||||
}
|
||||
if (Function == PLUGIN_EXIT) {
|
||||
clearPluginTaskData(event->TaskIndex);
|
||||
initSerial();
|
||||
// initSerial();
|
||||
queueTaskEvent(F("TaskExit"), event->TaskIndex, retval);
|
||||
updateActiveTaskUseSerial0();
|
||||
}
|
||||
|
||||
@@ -398,7 +398,6 @@ bool BuildFixes()
|
||||
Settings.Build = get_build_nr();
|
||||
Settings.StructSize = sizeof(Settings);
|
||||
|
||||
|
||||
// We may have changed the settings, so update checksum.
|
||||
// This way we save settings less often as these changes are always reproducible via this
|
||||
// settings transitions function.
|
||||
@@ -530,6 +529,7 @@ String SaveSettings()
|
||||
// FIXME @TD-er: As discussed in #1292, the CRC for the settings is now disabled.
|
||||
|
||||
Settings.validate();
|
||||
initSerial();
|
||||
|
||||
if (!COMPUTE_STRUCT_CHECKSUM_UPDATE(SettingsStruct, Settings)
|
||||
/*
|
||||
@@ -672,6 +672,7 @@ String LoadSettings()
|
||||
}
|
||||
|
||||
Settings.validate();
|
||||
initSerial();
|
||||
|
||||
err = LoadFromFile(SettingsType::getSettingsFileName(SettingsType::Enum::SecuritySettings_Type).c_str(), 0, reinterpret_cast<uint8_t *>(&SecuritySettings), sizeof(SecurityStruct));
|
||||
|
||||
|
||||
@@ -76,10 +76,10 @@ void run_compiletime_checks() {
|
||||
check_size<CRCStruct, 204u>();
|
||||
check_size<SecurityStruct, 593u>();
|
||||
#ifdef ESP32
|
||||
const unsigned int SettingsStructSize = (336 + 84 * TASKS_MAX);
|
||||
constexpr unsigned int SettingsStructSize = (340 + 84 * TASKS_MAX);
|
||||
#endif
|
||||
#ifdef ESP8266
|
||||
const unsigned int SettingsStructSize = (312 + 84 * TASKS_MAX);
|
||||
constexpr unsigned int SettingsStructSize = (316 + 84 * TASKS_MAX);
|
||||
#endif
|
||||
#if FEATURE_CUSTOM_PROVISIONING
|
||||
check_size<ProvisioningStruct, 256u>();
|
||||
|
||||
@@ -235,13 +235,13 @@ String getTaskValueName(taskIndex_t TaskIndex, uint8_t TaskValueIndex) {
|
||||
void emergencyReset()
|
||||
{
|
||||
// Direct Serial is allowed here, since this is only an emergency task.
|
||||
Serial.begin(115200);
|
||||
Serial.write(0xAA);
|
||||
Serial.write(0x55);
|
||||
ESPEASY_SERIAL_0.begin(115200);
|
||||
ESPEASY_SERIAL_0.write(0xAA);
|
||||
ESPEASY_SERIAL_0.write(0x55);
|
||||
delay(1);
|
||||
|
||||
if (Serial.available() == 2) {
|
||||
if ((Serial.read() == 0xAA) && (Serial.read() == 0x55))
|
||||
if (ESPEASY_SERIAL_0.available() == 2) {
|
||||
if ((ESPEASY_SERIAL_0.read() == 0xAA) && (ESPEASY_SERIAL_0.read() == 0x55))
|
||||
{
|
||||
serialPrintln(F("\n\n\rSystem will reset to factory defaults in 10 seconds..."));
|
||||
delay(10000);
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "../ESPEasyCore/ESPEasyEth.h"
|
||||
#include "../ESPEasyCore/ESPEasyNetwork.h"
|
||||
#include "../ESPEasyCore/ESPEasyWifi.h"
|
||||
#include "../ESPEasyCore/Serial.h"
|
||||
#include "../Globals/ESPEasyEthEvent.h"
|
||||
#include "../Globals/ESPEasyWiFiEvent.h"
|
||||
#include "../Globals/ESPEasy_Scheduler.h"
|
||||
@@ -913,7 +914,7 @@ bool hasIPaddr() {
|
||||
for (auto addr : addrList) {
|
||||
if ((configured = (!addr.isLocal() && (addr.ifnumber() == STATION_IF)))) {
|
||||
/*
|
||||
Serial.printf("STA: IF='%s' hostname='%s' addr= %s\n",
|
||||
ESPEASY_SERIAL_CONSOLE_PORT.printf("STA: IF='%s' hostname='%s' addr= %s\n",
|
||||
addr.ifname().c_str(),
|
||||
addr.ifhostname(),
|
||||
addr.toString().c_str());
|
||||
@@ -1354,7 +1355,7 @@ String getDigestAuth(const String& authReq,
|
||||
F("\", response=\"") + response +
|
||||
'"';
|
||||
|
||||
// Serial.println(authorization);
|
||||
// ESPEASY_SERIAL_CONSOLE_PORT.println(authorization);
|
||||
|
||||
return authorization;
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ void ArduinoOTAInit()
|
||||
});
|
||||
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
|
||||
if (Settings.UseSerial) {
|
||||
Serial.printf("OTA : Progress %u%%\r", (progress / (total / 100)));
|
||||
ESPEASY_SERIAL_CONSOLE_PORT.printf("OTA : Progress %u%%\r", (progress / (total / 100)));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -214,10 +214,12 @@ void runEach30Seconds()
|
||||
log += F(" ESPeasy internal wifi status: ");
|
||||
log += WiFiEventData.ESPeasyWifiStatusToString();
|
||||
}
|
||||
|
||||
// log += F(" ListenInterval ");
|
||||
// log += WiFi.getListenInterval();
|
||||
addLogMove(LOG_LEVEL_INFO, log);
|
||||
#if FEATURE_DEFINE_SERIAL_CONSOLE_PORT
|
||||
addLogMove(LOG_LEVEL_INFO, ESPEASY_SERIAL_CONSOLE_PORT.getLogString());
|
||||
#endif
|
||||
}
|
||||
WiFi_AP_Candidates.purge_expired();
|
||||
#if FEATURE_ESPEASY_P2P
|
||||
|
||||
@@ -247,6 +247,12 @@ const __FlashStringHelper* getConflictingUse(int gpio, PinSelectPurpose purpose)
|
||||
|
||||
bool includeI2C = true;
|
||||
bool includeSPI = true;
|
||||
#if FEATURE_DEFINE_SERIAL_CONSOLE_PORT
|
||||
// FIXME TD-er: Must check whether this can be a conflict.
|
||||
bool includeSerial = false;
|
||||
#else
|
||||
bool includeSerial = true;
|
||||
#endif
|
||||
|
||||
#if FEATURE_ETHERNET
|
||||
bool includeEthernet = true;
|
||||
@@ -260,6 +266,10 @@ const __FlashStringHelper* getConflictingUse(int gpio, PinSelectPurpose purpose)
|
||||
case PinSelectPurpose::SPI_MISO:
|
||||
includeSPI = false;
|
||||
break;
|
||||
case PinSelectPurpose::Serial_input:
|
||||
case PinSelectPurpose::Serial_output:
|
||||
includeSerial = false;
|
||||
break;
|
||||
case PinSelectPurpose::Ethernet:
|
||||
#if FEATURE_ETHERNET
|
||||
includeEthernet = false;
|
||||
@@ -280,6 +290,13 @@ const __FlashStringHelper* getConflictingUse(int gpio, PinSelectPurpose purpose)
|
||||
if (includeSPI && Settings.isSPI_pin(gpio)) {
|
||||
return F("SPI");
|
||||
}
|
||||
|
||||
if (includeSerial && Settings.UseSerial) {
|
||||
if (gpio == 1) { return F("TX0"); }
|
||||
|
||||
if (gpio == 3) { return F("RX0"); }
|
||||
}
|
||||
|
||||
#if FEATURE_ETHERNET
|
||||
|
||||
if (Settings.isEthernetPin(gpio)) {
|
||||
|
||||
@@ -25,6 +25,8 @@ enum class PinSelectPurpose : uint8_t {
|
||||
SPI,
|
||||
SPI_MISO,
|
||||
Ethernet,
|
||||
Serial_input,
|
||||
Serial_output,
|
||||
DAC
|
||||
|
||||
};
|
||||
|
||||
@@ -189,6 +189,10 @@ void serialHelper_webformLoad(ESPEasySerialPort port, int rxPinDef, int txPinDef
|
||||
false);
|
||||
#endif // ifdef ESP32
|
||||
|
||||
#if defined(DISABLE_SOFTWARE_SERIAL) || !defined(ESP8266)
|
||||
allowSoftwareSerial = false;
|
||||
#endif
|
||||
|
||||
String options[NR_ESPEASY_SERIAL_TYPES];
|
||||
int ids[NR_ESPEASY_SERIAL_TYPES];
|
||||
// String attr[NR_ESPEASY_SERIAL_TYPES];
|
||||
|
||||
@@ -226,7 +226,7 @@ CCS811Core::status CCS811::begin(void)
|
||||
delay(200);
|
||||
|
||||
// returnError = setDriveMode(1); //Read every second
|
||||
// Serial.println();
|
||||
// ESPEASY_SERIAL_0.println();
|
||||
|
||||
return returnError;
|
||||
} // CCS811::begin
|
||||
@@ -343,11 +343,11 @@ CCS811Core::status CCS811::enableInterrupts(void)
|
||||
return returnError;
|
||||
}
|
||||
|
||||
// Serial.println(value, HEX);
|
||||
// ESPEASY_SERIAL_0.println(value, HEX);
|
||||
value |= (1 << 3); // Set INTERRUPT bit
|
||||
writeRegister(CSS811_MEAS_MODE, value);
|
||||
|
||||
// Serial.println(value, HEX);
|
||||
// ESPEASY_SERIAL_0.println(value, HEX);
|
||||
return returnError;
|
||||
}
|
||||
|
||||
@@ -463,14 +463,14 @@ CCS811Core::status CCS811::readNTC(void)
|
||||
|
||||
vrefCounts = (static_cast<uint16_t>(data[CSS811_NTC + 0]) << 8) | data[CSS811_NTC + 1];
|
||||
|
||||
// Serial.print("vrefCounts: ");
|
||||
// Serial.println(vrefCounts);
|
||||
// ESPEASY_SERIAL_0.print("vrefCounts: ");
|
||||
// ESPEASY_SERIAL_0.println(vrefCounts);
|
||||
ntcCounts = (static_cast<uint16_t>(data[CSS811_NTC + 2]) << 8) | data[CSS811_NTC + 3];
|
||||
|
||||
// Serial.print("ntcCounts: ");
|
||||
// Serial.println(ntcCounts);
|
||||
// Serial.print("sum: ");
|
||||
// Serial.println(ntcCounts + vrefCounts);
|
||||
// ESPEASY_SERIAL_0.print("ntcCounts: ");
|
||||
// ESPEASY_SERIAL_0.println(ntcCounts);
|
||||
// ESPEASY_SERIAL_0.print("sum: ");
|
||||
// ESPEASY_SERIAL_0.println(ntcCounts + vrefCounts);
|
||||
resistance = (static_cast<float>(ntcCounts) * refResistance / static_cast<float>(vrefCounts));
|
||||
|
||||
// Code from Milan Malesevic and Zoran Stupic, 2011,
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "../Globals/Settings.h"
|
||||
#include "../Globals/TimeZone.h"
|
||||
|
||||
#include "../Helpers/_Plugin_Helper_serial.h"
|
||||
#include "../Helpers/ESPEasy_Storage.h"
|
||||
#include "../Helpers/ESPEasy_time.h"
|
||||
#include "../Helpers/Hardware.h"
|
||||
@@ -55,6 +56,16 @@ void handle_advanced() {
|
||||
Settings.SyslogFacility = getFormItemInt(F("syslogfacility"));
|
||||
Settings.SyslogPort = getFormItemInt(F("syslogport"));
|
||||
Settings.UseSerial = isFormItemChecked(F("useserial"));
|
||||
|
||||
#if FEATURE_DEFINE_SERIAL_CONSOLE_PORT
|
||||
Settings.console_serial_rxpin = getFormItemInt(F("taskdevicepin1"), Settings.console_serial_rxpin);
|
||||
Settings.console_serial_txpin = getFormItemInt(F("taskdevicepin2"), Settings.console_serial_txpin);
|
||||
|
||||
serialHelper_webformSave(
|
||||
Settings.console_serial_port,
|
||||
Settings.console_serial_rxpin,
|
||||
Settings.console_serial_txpin);
|
||||
#endif
|
||||
setLogLevelFor(LOG_TO_SYSLOG, LabelType::SYSLOG_LOG_LEVEL);
|
||||
setLogLevelFor(LOG_TO_SERIAL, LabelType::SERIAL_LOG_LEVEL);
|
||||
setLogLevelFor(LOG_TO_WEBLOG, LabelType::WEB_LOG_LEVEL);
|
||||
@@ -214,15 +225,38 @@ void handle_advanced() {
|
||||
#endif // if FEATURE_SD
|
||||
|
||||
|
||||
addFormSubHeader(F("Serial Settings"));
|
||||
addFormSubHeader(F("Serial Console Settings"));
|
||||
|
||||
addFormCheckBox(F("Enable Serial Port Console"), F("useserial"), Settings.UseSerial);
|
||||
|
||||
#if FEATURE_DEFINE_SERIAL_CONSOLE_PORT
|
||||
serialHelper_webformLoad(
|
||||
static_cast<ESPEasySerialPort>(Settings.console_serial_port),
|
||||
Settings.console_serial_rxpin,
|
||||
Settings.console_serial_txpin,
|
||||
true);
|
||||
|
||||
// Show serial port selection
|
||||
addFormPinSelect(
|
||||
PinSelectPurpose::Serial_input,
|
||||
formatGpioName_RX(false),
|
||||
F("taskdevicepin1"),
|
||||
Settings.console_serial_rxpin);
|
||||
addFormPinSelect(
|
||||
PinSelectPurpose::Serial_output,
|
||||
formatGpioName_TX(false),
|
||||
F("taskdevicepin2"),
|
||||
Settings.console_serial_txpin);
|
||||
|
||||
html_add_script(F("document.getElementById('serPort').onchange();"), false);
|
||||
#endif
|
||||
|
||||
addFormCheckBox(F("Enable Serial port"), F("useserial"), Settings.UseSerial);
|
||||
addFormNumericBox(F("Baud Rate"), F("baudrate"), Settings.BaudRate, 0, 1000000);
|
||||
|
||||
|
||||
addFormSubHeader(F("Inter-ESPEasy Network"));
|
||||
if (Settings.UDPPort != 8266 ) addFormNote(F("Preferred P2P port is 8266"));
|
||||
addFormNumericBox(F("UDP port"), F("udpport"), Settings.UDPPort, 0, 65535);
|
||||
addFormNumericBox(F("ESPEasy p2p UDP port"), F("udpport"), Settings.UDPPort, 0, 65535);
|
||||
|
||||
// TODO sort settings in groups or move to other pages/groups
|
||||
addFormSubHeader(F("Special and Experimental Settings"));
|
||||
|
||||
@@ -1093,7 +1093,7 @@ void devicePage_show_pin_config(taskIndex_t taskIndex, deviceIndex_t DeviceIndex
|
||||
if (Device[DeviceIndex].isSerial())
|
||||
{
|
||||
// Pin1 = GPIO <--- TX
|
||||
purpose = PinSelectPurpose::Generic_input;
|
||||
purpose = PinSelectPurpose::Serial_input;
|
||||
} else if (Device[DeviceIndex].isSPI())
|
||||
{
|
||||
// All selectable SPI pins are output only
|
||||
@@ -1106,9 +1106,13 @@ void devicePage_show_pin_config(taskIndex_t taskIndex, deviceIndex_t DeviceIndex
|
||||
if (Device[DeviceIndex].usesTaskDevicePin(2)) {
|
||||
PinSelectPurpose purpose = PinSelectPurpose::Generic;
|
||||
|
||||
if (Device[DeviceIndex].isSerial() || Device[DeviceIndex].isSPI())
|
||||
if (Device[DeviceIndex].isSerial())
|
||||
{
|
||||
// Serial Pin2 = GPIO ---> RX
|
||||
purpose = PinSelectPurpose::Serial_output;
|
||||
}
|
||||
if (Device[DeviceIndex].isSPI())
|
||||
{
|
||||
// SPI only needs output pins
|
||||
purpose = PinSelectPurpose::Generic_output;
|
||||
}
|
||||
|
||||
@@ -276,6 +276,7 @@ void addPinSelector_Item(PinSelectPurpose purpose, const String& gpio_label, int
|
||||
if (getGpioInfo(gpio, pinnr, input, output, warning)) {
|
||||
bool includeI2C = true;
|
||||
bool includeSPI = true;
|
||||
bool includeSerial = true;
|
||||
#if FEATURE_ETHERNET
|
||||
bool includeEthernet = true;
|
||||
#endif // if FEATURE_ETHERNET
|
||||
@@ -326,13 +327,27 @@ void addPinSelector_Item(PinSelectPurpose purpose, const String& gpio_label, int
|
||||
return;
|
||||
}
|
||||
break;
|
||||
|
||||
case PinSelectPurpose::Serial_input:
|
||||
includeSerial = false;
|
||||
if (!input) {
|
||||
return;
|
||||
}
|
||||
break;
|
||||
|
||||
case PinSelectPurpose::Serial_output:
|
||||
includeSerial = false;
|
||||
if (!output) {
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (includeI2C && Settings.isI2C_pin(gpio)) {
|
||||
disabled = true;
|
||||
}
|
||||
|
||||
if (isSerialConsolePin(gpio)) {
|
||||
if (includeSerial && isSerialConsolePin(gpio)) {
|
||||
disabled = true;
|
||||
}
|
||||
|
||||
|
||||
+27
-26
@@ -13,6 +13,7 @@
|
||||
#include "../WebServer/Markup_Forms.h"
|
||||
|
||||
#include "../ESPEasyCore/ESPEasyRules.h"
|
||||
#include "../ESPEasyCore/Serial.h"
|
||||
|
||||
#include "../Globals/Settings.h"
|
||||
#include "../Helpers/ESPEasy_Storage.h"
|
||||
@@ -175,8 +176,8 @@ void handle_rules_new() {
|
||||
[/*&buffer,*/ &count, endIdx](fileInfo fi)
|
||||
{
|
||||
# ifdef WEBSERVER_RULES_DEBUG
|
||||
Serial.print(F("Start generation of: "));
|
||||
Serial.println(fi.Name);
|
||||
ESPEASY_SERIAL_0.print(F("Start generation of: "));
|
||||
ESPEASY_SERIAL_0.println(fi.Name);
|
||||
# endif // ifdef WEBSERVER_RULES_DEBUG
|
||||
|
||||
if (fi.isDirectory)
|
||||
@@ -227,8 +228,8 @@ void handle_rules_new() {
|
||||
}
|
||||
addHtml(F("</TD></TR>"));
|
||||
# ifdef WEBSERVER_RULES_DEBUG
|
||||
Serial.print(F("End generation of: "));
|
||||
Serial.println(fi.Name);
|
||||
ESPEASY_SERIAL_0.print(F("End generation of: "));
|
||||
ESPEASY_SERIAL_0.println(fi.Name);
|
||||
# endif // ifdef WEBSERVER_RULES_DEBUG
|
||||
|
||||
return count < endIdx;
|
||||
@@ -275,7 +276,7 @@ void handle_rules_backup() {
|
||||
}
|
||||
# ifdef WEBSERVER_NEW_RULES
|
||||
# ifdef WEBSERVER_RULES_DEBUG
|
||||
Serial.println(F("handle rules backup"));
|
||||
ESPEASY_SERIAL_0.println(F("handle rules backup"));
|
||||
# endif // ifdef WEBSERVER_RULES_DEBUG
|
||||
|
||||
if (!isLoggedIn() || !Settings.UseRules) { return; }
|
||||
@@ -347,9 +348,9 @@ void handle_rules_delete() {
|
||||
fileName = fileName.substring(0, fileName.length() - 4);
|
||||
bool removed = false;
|
||||
# ifdef WEBSERVER_RULES_DEBUG
|
||||
Serial.println(F("handle_rules_delete"));
|
||||
Serial.print(F("File name: "));
|
||||
Serial.println(fileName);
|
||||
ESPEASY_SERIAL_0.println(F("handle_rules_delete"));
|
||||
ESPEASY_SERIAL_0.print(F("File name: "));
|
||||
ESPEASY_SERIAL_0.println(fileName);
|
||||
# endif // ifdef WEBSERVER_RULES_DEBUG
|
||||
|
||||
if (fileName.length() > 0)
|
||||
@@ -392,8 +393,8 @@ bool handle_rules_edit(String originalUri, bool isAddNew) {
|
||||
bool handle = false;
|
||||
|
||||
# ifdef WEBSERVER_RULES_DEBUG
|
||||
Serial.println(originalUri);
|
||||
Serial.println(F("handle_rules_edit"));
|
||||
ESPEASY_SERIAL_0.println(originalUri);
|
||||
ESPEASY_SERIAL_0.println(F("handle_rules_edit"));
|
||||
# endif // ifdef WEBSERVER_RULES_DEBUG
|
||||
|
||||
if (isAddNew || (originalUri.startsWith(F("/rules/"))
|
||||
@@ -431,8 +432,8 @@ bool handle_rules_edit(String originalUri, bool isAddNew) {
|
||||
eventName = FileNameToEvent(fileName);
|
||||
}
|
||||
# ifdef WEBSERVER_RULES_DEBUG
|
||||
Serial.print(F("File name: "));
|
||||
Serial.println(fileName);
|
||||
ESPEASY_SERIAL_0.print(F("File name: "));
|
||||
ESPEASY_SERIAL_0.println(fileName);
|
||||
# endif // ifdef WEBSERVER_RULES_DEBUG
|
||||
bool isEdit = fileExists(fileName);
|
||||
|
||||
@@ -501,16 +502,16 @@ bool handle_rules_edit(String originalUri, bool isAddNew) {
|
||||
|
||||
bool isReadOnly = !isOverwrite && ((isEdit && !isAddNew && !isNew) || (isAddNew && isNew));
|
||||
# ifdef WEBSERVER_RULES_DEBUG
|
||||
Serial.print(F("Is Overwrite: "));
|
||||
Serial.println(isOverwrite);
|
||||
Serial.print(F("Is edit: "));
|
||||
Serial.println(isEdit);
|
||||
Serial.print(F("Is addnew: "));
|
||||
Serial.println(isAddNew);
|
||||
Serial.print(F("Is New: "));
|
||||
Serial.println(isNew);
|
||||
Serial.print(F("Is Read Only: "));
|
||||
Serial.println(isReadOnly);
|
||||
ESPEASY_SERIAL_0.print(F("Is Overwrite: "));
|
||||
ESPEASY_SERIAL_0.println(isOverwrite);
|
||||
ESPEASY_SERIAL_0.print(F("Is edit: "));
|
||||
ESPEASY_SERIAL_0.println(isEdit);
|
||||
ESPEASY_SERIAL_0.print(F("Is addnew: "));
|
||||
ESPEASY_SERIAL_0.println(isAddNew);
|
||||
ESPEASY_SERIAL_0.print(F("Is New: "));
|
||||
ESPEASY_SERIAL_0.println(isNew);
|
||||
ESPEASY_SERIAL_0.print(F("Is Read Only: "));
|
||||
ESPEASY_SERIAL_0.println(isReadOnly);
|
||||
# endif // ifdef WEBSERVER_RULES_DEBUG
|
||||
|
||||
addFormTextBox(F("Event name") // Label
|
||||
@@ -571,8 +572,8 @@ void Rule_showRuleTextArea(const String& fileName) {
|
||||
bool Rule_Download(const String& path)
|
||||
{
|
||||
# ifdef WEBSERVER_RULES_DEBUG
|
||||
Serial.print(F("Rule_Download path: "));
|
||||
Serial.println(path);
|
||||
ESPEASY_SERIAL_0.print(F("Rule_Download path: "));
|
||||
ESPEASY_SERIAL_0.println(path);
|
||||
# endif // ifdef WEBSERVER_RULES_DEBUG
|
||||
fs::File dataFile = tryOpenFile(path, "r");
|
||||
|
||||
@@ -609,8 +610,8 @@ bool EnumerateFileAndDirectory(String & rootPath
|
||||
|
||||
# ifdef ESP8266
|
||||
fs::Dir dir = ESPEASY_FS.openDir(rootPath);
|
||||
Serial.print(F("Enumerate files of "));
|
||||
Serial.println(rootPath);
|
||||
ESPEASY_SERIAL_0.print(F("Enumerate files of "));
|
||||
ESPEASY_SERIAL_0.println(rootPath);
|
||||
|
||||
while (next && dir.next()) {
|
||||
// Skip files
|
||||
|
||||
@@ -134,6 +134,11 @@ def parse_filename(file, version, variant, file_suffix):
|
||||
elif 'collection' in variant:
|
||||
variant_split = variant.split('_')
|
||||
group = 'Collection{}'.format(variant_split[1])
|
||||
# Select based on "4M1M" here to keep any occasional "4M2M" build
|
||||
# separated in another group
|
||||
if '_4M1M' in variant:
|
||||
main_group = '4M Flash Collection Builds'
|
||||
|
||||
|
||||
if 'NotSet' not in group:
|
||||
sub_group_spit = group.split('_')
|
||||
@@ -154,6 +159,9 @@ def parse_filename(file, version, variant, file_suffix):
|
||||
specials.append('VCC')
|
||||
if '_ETH' in variant:
|
||||
specials.append('ETH')
|
||||
if 'solo1' in variant:
|
||||
specials.append('Solo1')
|
||||
|
||||
|
||||
for sp in specials:
|
||||
sub_group_spit.append(sp)
|
||||
@@ -167,6 +175,10 @@ def parse_filename(file, version, variant, file_suffix):
|
||||
state = "No Group"
|
||||
main_group = 'Misc'
|
||||
|
||||
if 'collection' in variant:
|
||||
if '4M Flash' in main_group:
|
||||
main_group = '4M Flash Collection Builds'
|
||||
|
||||
if 'custom_' in variant:
|
||||
if 'Misc' in main_group:
|
||||
main_group = 'Custom Misc'
|
||||
@@ -175,6 +187,14 @@ def parse_filename(file, version, variant, file_suffix):
|
||||
if 'hard_' in variant:
|
||||
main_group = 'Device Specific'
|
||||
|
||||
if 'solo1' in variant:
|
||||
# Web flasher cannot detect whether it is an ESP32-classic or ESP32-solo1
|
||||
# Thus make a separate group for the solo1
|
||||
main_group = '4M Flash ESP32-solo1'
|
||||
|
||||
if 'CDC' in variant:
|
||||
main_group = '{} USB CDC'.format(main_group)
|
||||
|
||||
if ".factory.bin" in file_suffix or 'ESP32' not in file:
|
||||
#print('{:10s}: {:34s}\t{:10s} {} / {}'.format(state, sub_group, chipFamily, version, file))
|
||||
|
||||
@@ -244,12 +264,20 @@ def generate_manifest_files(bin_folder, output_prefix):
|
||||
# the main grouping in the combo box on the web flasher page
|
||||
main_group_list = [
|
||||
'4M Flash',
|
||||
'4M Flash USB CDC',
|
||||
'4M Flash ESP32-solo1',
|
||||
'4M Flash Collection Builds',
|
||||
'4M Flash Collection Builds USB CDC',
|
||||
'16M Flash',
|
||||
'16M Flash USB CDC',
|
||||
'2M Flash',
|
||||
'1M Flash',
|
||||
'Device Specific',
|
||||
'Custom',
|
||||
'Custom USB CDC',
|
||||
'Custom Misc',
|
||||
'Custom Misc USB CDC',
|
||||
'Misc USB CDC',
|
||||
'Misc']
|
||||
|
||||
for main_group in main_group_list:
|
||||
|
||||
@@ -69,6 +69,7 @@ else:
|
||||
"-DFEATURE_CHART_JS=1",
|
||||
|
||||
"-DFEATURE_SETTINGS_ARCHIVE=1",
|
||||
"-DFEATURE_DEFINE_SERIAL_CONSOLE_PORT=0",
|
||||
"-DFEATURE_ESPEASY_P2P=1",
|
||||
"-DFEATURE_CUSTOM_PROVISIONING=1"
|
||||
]
|
||||
|
||||
@@ -63,6 +63,7 @@ else:
|
||||
"-DFEATURE_I2CMULTIPLEXER=1",
|
||||
"-DFEATURE_TRIGONOMETRIC_FUNCTIONS_RULES=1",
|
||||
"-DFEATURE_CUSTOM_PROVISIONING=1",
|
||||
"-DFEATURE_DEFINE_SERIAL_CONSOLE_PORT=0",
|
||||
|
||||
"-DFEATURE_ESPEASY_P2P=1",
|
||||
|
||||
|
||||
Reference in New Issue
Block a user