Merge pull request #620 from CheeseE/dev

Add support for Lolin C3 mini
This commit is contained in:
Proddy
2022-09-19 16:18:34 +05:30
committed by GitHub
14 changed files with 70 additions and 11 deletions

View File

@@ -124,13 +124,18 @@ const SettingsApplication: FC = () => {
name="board_profile"
label={LL.BOARD_PROFILE()}
value={data.board_profile}
disabled={processingBoard}
disabled={processingBoard || data.board_profile === 'C3MINI'}
variant="outlined"
onChange={changeBoardProfile}
margin="normal"
select
>
{boardProfileSelectItems()}
{data.board_profile === 'C3MINI' && (
<MenuItem key={'C3MINI'} value={'C3MINI'}>
C3 Mini
</MenuItem>
)}
<Divider />
<MenuItem key={'CUSTOM'} value={'CUSTOM'}>
Custom&hellip;

View File

@@ -7,7 +7,7 @@ export const GPIO_VALIDATOR = {
if (
value &&
(value === 1 ||
(value >= 6 && value <= 12) ||
(value >= 10 && value <= 12) ||
(value >= 14 && value <= 15) ||
value === 20 ||
value === 24 ||

View File

@@ -846,7 +846,7 @@ void AsyncWebSocketClient::binary(AsyncWebSocketMessageBuffer * buffer)
IPAddress AsyncWebSocketClient::remoteIP() {
if(!_client) {
return IPAddress(0U);
return IPAddress((uint32_t)0);
}
return _client->remoteIP();
}

View File

@@ -49,6 +49,9 @@ void APSettingsService::startAP() {
WiFi.softAPConfig(_state.localIP, _state.gatewayIP, _state.subnetMask);
esp_wifi_set_bandwidth((wifi_interface_t)ESP_IF_WIFI_AP, WIFI_BW_HT20);
WiFi.softAP(_state.ssid.c_str(), _state.password.c_str(), _state.channel, _state.ssidHidden, _state.maxClients);
#ifdef ARDUINO_LOLIN_C3_MINI
WiFi.setTxPower(WIFI_POWER_8_5dBm); //https://www.wemos.cc/en/latest/c3/c3_mini.html#about-wifi
#endif
if (!_dnsServer) {
IPAddress apIp = WiFi.softAPIP();
emsesp::EMSESP::logger().info(F("Starting Access Point with captive portal on %s"), apIp.toString().c_str());

View File

@@ -75,6 +75,9 @@ void NetworkSettingsService::manageSTA() {
});
WiFi.begin(_state.ssid.c_str(), _state.password.c_str()); // attempt to connect to the network
#ifdef ARDUINO_LOLIN_C3_MINI
WiFi.setTxPower(WIFI_POWER_8_5dBm); //https://www.wemos.cc/en/latest/c3/c3_mini.html#about-wifi
#endif
}
}

View File

@@ -1152,6 +1152,17 @@ rest_server.post(EMSESP_BOARDPROFILE_ENDPOINT, (req, res) => {
data.eth_power = 12
data.eth_phy_addr = 0
data.eth_clock_mode = 3
} else if (board_profile == 'C3MINI') {
// Lolin C3 mini
data.led_gpio = 7
data.dallas_gpio = 2
data.rx_gpio = 4
data.tx_gpio = 5
data.pbutton_gpio = 9
data.phy_type = 0
data.eth_power = 0
data.eth_phy_addr = 0
data.eth_clock_mode = 0
}
console.log('boardProfile POST. Sending back, profile: ' + board_profile + ', ' + 'data: ' + JSON.stringify(data))

View File

@@ -81,3 +81,14 @@ board_upload.flash_size = 16MB
board_build.partitions = esp32_partition_16M.csv
build_flags = ${common.build_flags}
build_unflags = ${common.unbuild_flags}
[env:lolin_c3_mini]
extra_scripts =
pre:scripts/build_interface.py
scripts/rename_fw.py
board = lolin_c3_mini
platform = espressif32
board_upload.flash_size = 4MB
board_build.partitions = esp32_partition_4M.csv
build_flags = ${common.build_flags}
build_unflags = ${common.unbuild_flags}

View File

@@ -128,9 +128,11 @@ void AnalogSensor::reload() {
} else if (sensor.type() == AnalogType::COUNTER) {
LOG_DEBUG(F("Adding analog I/O Counter sensor on GPIO%d"), sensor.gpio());
pinMode(sensor.gpio(), INPUT_PULLUP);
#ifndef ARDUINO_LOLIN_C3_MINI
if (sensor.gpio() == 25 || sensor.gpio() == 26) {
dacWrite(sensor.gpio(), 255);
}
#endif
sensor.polltime_ = 0;
sensor.poll_ = digitalRead(sensor.gpio());
publish_sensor(sensor);
@@ -160,7 +162,9 @@ void AnalogSensor::reload() {
} else if (sensor.offset() < 0) {
sensor.set_offset(0);
}
dacWrite(sensor.gpio(), sensor.offset());
#ifndef ARDUINO_LOLIN_C3_MINI
dacWrite(sensor.gpio(), sensor.offset());
#endif
sensor.set_value(sensor.offset());
} else {
digitalWrite(sensor.gpio(), sensor.offset() > 0 ? 1 : 0);
@@ -572,7 +576,9 @@ bool AnalogSensor::command_setvalue(const char * value, const int8_t gpio) {
sensor.set_offset(v);
sensor.set_value(v);
pinMode(sensor.gpio(), OUTPUT);
dacWrite(sensor.gpio(), sensor.offset());
#ifndef ARDUINO_LOLIN_C3_MINI
dacWrite(sensor.gpio(), sensor.offset());
#endif
publish_sensor(sensor);
return true;
} else if (v == 0 || v == 1) {

View File

@@ -691,7 +691,7 @@ void Console::load_system_commands(unsigned int context) {
std::vector<int8_t> data; // led, dallas, rx, tx, button, phy_type, eth_power, eth_phy_addr, eth_clock_mode
std::string board_profile = Helpers::toUpper(arguments.front());
if (!EMSESP::system_.load_board_profile(data, board_profile)) {
shell.println(F("Invalid board profile (S32, E32, MH-ET, NODEMCU, OLIMEX, OLIMEXPOE, CUSTOM)"));
shell.println(F("Invalid board profile (S32, E32, MH-ET, NODEMCU, OLIMEX, OLIMEXPOE, C3MINI, CUSTOM)"));
return;
}
EMSESP::webSettingsService.update(

View File

@@ -856,7 +856,7 @@ void EMSdevice::generate_values_web(JsonObject & output) {
if (dv.numeric_operator > 0) {
obj["s"] = Helpers::render_value(s, (float)1 / dv.numeric_operator, 1);
} else if (dv.numeric_operator < 0) {
obj["s"] = Helpers::render_value(s, (-1) * dv.numeric_operator, 0);
obj["s"] = Helpers::render_value(s, (float)(-1) * dv.numeric_operator, 0);
}
int16_t dv_set_min, dv_set_max;

View File

@@ -1321,8 +1321,8 @@ void Mqtt::publish_ha_climate_config(uint8_t tag, bool has_roomtemp, bool remove
doc["curr_temp_tpl"] = currtemp_s;
}
doc["min_temp"] = Helpers::render_value(min_s, 5, 0, EMSESP::system_.fahrenheit() ? 2 : 0);
doc["max_temp"] = Helpers::render_value(max_s, 30, 0, EMSESP::system_.fahrenheit() ? 2 : 0);
doc["min_temp"] = Helpers::render_value(min_s, (uint32_t)5, 0, EMSESP::system_.fahrenheit() ? 2 : 0);
doc["max_temp"] = Helpers::render_value(max_s, (uint32_t)30, 0, EMSESP::system_.fahrenheit() ? 2 : 0);
doc["temp_step"] = "0.5";
// the HA climate component only responds to auto, heat and off

View File

@@ -353,6 +353,15 @@ void System::wifi_tweak() {
#endif
}
#ifdef ARDUINO_LOLIN_C3_MINI
// https://www.wemos.cc/en/latest/c3/c3_mini.html
bool System::is_valid_gpio(uint8_t pin) {
if ((pin >= 11 && pin <= 19) || (pin > 21)) {
return false; // bad pin
}
return true;
}
#else
// check for valid ESP32 pins. This is very dependent on which ESP32 board is being used.
// Typically you can't use 1, 6-11, 12, 14, 15, 20, 24, 28-31 and 40+
// we allow 0 as it has a special function on the NodeMCU apparently
@@ -364,6 +373,7 @@ bool System::is_valid_gpio(uint8_t pin) {
}
return true;
}
#endif
// Starts up the UART Serial bridge
void System::start() {
@@ -1224,6 +1234,8 @@ bool System::load_board_profile(std::vector<int8_t> & data, const std::string &
data = {0, 0, 36, 4, 34, PHY_type::PHY_TYPE_LAN8720, -1, 0, 0}; // Olimex ESP32-EVB (uses U1TXD/U1RXD/BUTTON, no LED or Dallas)
} else if (board_profile == "OLIMEXPOE") {
data = {0, 0, 36, 4, 34, PHY_type::PHY_TYPE_LAN8720, 12, 0, 3}; // Olimex ESP32-POE
} else if (board_profile == "C3MINI") {
data = {7, 2, 4, 5, 9, PHY_type::PHY_TYPE_NONE, 0, 0, 0}; // Lolin C3 Mini
} else if (board_profile == "CUSTOM") {
// send back current values
data = {(int8_t)EMSESP::system_.led_gpio_,

View File

@@ -26,7 +26,11 @@
#define EMS_MAXBUFFERSIZE 33 // max size of the buffer. EMS packets are max 32 bytes, plus extra for BRK
#define EMSUART_NUM UART_NUM_2 // on the ESP32 we're using UART2
#ifdef ARDUINO_LOLIN_C3_MINI
#define EMSUART_NUM UART_NUM_1 // on C3 mini we're using UART1
#else
#define EMSUART_NUM UART_NUM_2 // on the ESP32 we're using UART2
#endif
#define EMSUART_BAUD 9600 // uart baud rate for the EMS circuit
#define EMS_TXMODE_DEFAULT 1

View File

@@ -81,7 +81,11 @@ void WebSettings::read(WebSettings & settings, JsonObject & root) {
StateUpdateResult WebSettings::update(JsonObject & root, WebSettings & settings) {
// load default GPIO configuration based on board profile
std::vector<int8_t> data; // // led, dallas, rx, tx, button, phy_type, eth_power, eth_phy_addr, eth_clock_mode
settings.board_profile = root["board_profile"] | EMSESP_DEFAULT_BOARD_PROFILE;
#ifdef ARDUINO_LOLIN_C3_MINI
settings.board_profile = "C3MINI";
#else
settings.board_profile = root["board_profile"] | EMSESP_DEFAULT_BOARD_PROFILE;
#endif
if (!System::load_board_profile(data, settings.board_profile.c_str())) {
settings.board_profile = "CUSTOM";
EMSESP::logger().info("No board profile found. Re-setting to %s", settings.board_profile.c_str());