diff --git a/interface/src/network/NetworkSettingsForm.tsx b/interface/src/network/NetworkSettingsForm.tsx index 9e857dfdc..f83767f4f 100644 --- a/interface/src/network/NetworkSettingsForm.tsx +++ b/interface/src/network/NetworkSettingsForm.tsx @@ -1,5 +1,5 @@ import React, { Fragment } from 'react'; -import { TextValidator, SelectValidator, ValidatorForm } from 'react-material-ui-form-validator'; +import { TextValidator, ValidatorForm } from 'react-material-ui-form-validator'; import { Checkbox, List, ListItem, ListItemText, ListItemAvatar, ListItemSecondaryAction } from '@material-ui/core'; @@ -9,7 +9,6 @@ import LockIcon from '@material-ui/icons/Lock'; import LockOpenIcon from '@material-ui/icons/LockOpen'; import DeleteIcon from '@material-ui/icons/Delete'; import SaveIcon from '@material-ui/icons/Save'; -import MenuItem from '@material-ui/core/MenuItem'; import { RestFormProps, PasswordValidator, BlockFormControlLabel, FormActions, FormButton } from '../components'; import { isIP, isHostname, optional } from '../validators'; @@ -34,7 +33,6 @@ class NetworkSettingsForm extends React.Component { ssid: selectedNetwork.ssid, password: "", hostname: props.data.hostname, - ethernet_profile: 0, static_ip_config: false, } props.setData(networkSettings); @@ -119,17 +117,6 @@ class NetworkSettingsForm extends React.Component { onChange={handleValueChange('hostname')} margin="normal" /> - - None (wifi only) - Profile 1 (LAN8720) - Profile 2 (TLK110) - & function formatTemp(t: string) { if (t == null) { - return "(not available)"; + return "n/a"; } return t + " °C"; } - function formatUnit(u: string) { +function formatUnit(u: string) { if (u == null) { return u; } return " " + u; } -class EMSESPDevicesForm extends Component< - EMSESPDevicesFormProps, - EMSESPDevicesFormState - > { +class EMSESPDevicesForm extends Component { state: EMSESPDevicesFormState = { confirmScanDevices: false, processing: false, @@ -106,7 +82,7 @@ class EMSESPDevicesForm extends Component< return (this.state.deviceData?.data || []).length === 0; }; - createDeviceItems() { + renderDeviceItems() { const { width, data } = this.props; return ( @@ -186,7 +162,7 @@ class EMSESPDevicesForm extends Component< ); } - createSensorItems() { + renderSensorItems() { const { data } = this.props; return ( @@ -365,11 +341,11 @@ class EMSESPDevicesForm extends Component< )} {this.noDeviceData() && ( - - - No data available for this device - - + + + No data available for this device + + )} ); @@ -379,9 +355,9 @@ class EMSESPDevicesForm extends Component< return (

- {this.createDeviceItems()} + {this.renderDeviceItems()} {this.renderDeviceData()} - {this.createSensorItems()} + {this.renderSensorItems()}

diff --git a/interface/src/project/EMSESPSettingsController.tsx b/interface/src/project/EMSESPSettingsController.tsx index 7f43397de..286afd576 100644 --- a/interface/src/project/EMSESPSettingsController.tsx +++ b/interface/src/project/EMSESPSettingsController.tsx @@ -1,14 +1,10 @@ import React, { Component } from 'react'; -import { ValidatorForm, TextValidator, SelectValidator } from 'react-material-ui-form-validator'; - -import { Checkbox, Typography, Box, Link } from '@material-ui/core'; -import SaveIcon from '@material-ui/icons/Save'; -import MenuItem from '@material-ui/core/MenuItem'; +// import { Container } from '@material-ui/core'; import { ENDPOINT_ROOT } from '../api'; -import { restController, RestControllerProps, RestFormLoader, RestFormProps, FormActions, FormButton, BlockFormControlLabel, SectionContent } from '../components'; +import EMSESPSettingsForm from './EMSESPSettingsForm'; -import { isIP, optional } from '../validators'; +import { restController, RestControllerProps, RestFormLoader, SectionContent } from '../components'; import { EMSESPSettings } from './EMSESPtypes'; @@ -19,303 +15,24 @@ type EMSESPSettingsControllerProps = RestControllerProps; class EMSESPSettingsController extends Component { componentDidMount() { - ValidatorForm.addValidationRule('isOptionalIP', optional(isIP)); this.props.loadData(); } render() { return ( - + // + ( - + render={formProps => ( + )} /> + // ) } } export default restController(EMSESP_SETTINGS_ENDPOINT, EMSESPSettingsController); - -type EMSESPSettingsControllerFormProps = RestFormProps; - -function EMSESPSettingsControllerForm(props: EMSESPSettingsControllerFormProps) { - const { data, saveData, handleValueChange } = props; - return ( - - - - Change the default settings on this page. For help click {'here'}. - - -

- - EMS Bus - - - 0 - Off - 1 - Default - 2 - EMS+ - 3 - HT3 - 4 - Hardware - - - Service Key (0x0B) - Modem (0x0D) - Terminal (0x0A) - Time Module (0x0F) - Alarm Module (0x12) - - - - -

- - External Button - - -

- - Dallas Sensor - - - - } - label="Dallas Parasite Mode" - /> -

- - LED - - - - } - label="Invert/Hide LED" - /> -

- - Shower - - - } - label="Shower Timer" - /> - - } - label="Shower Alert" - /> -

- - API - - - } - label="Allow WEB API to write commands" - /> -

- - Syslog - - - } - label="Enable Syslog" - /> - - - - OFF - ERR - NOTICE - INFO - DEBUG - ALL - - - - } - label="Trace EMS telegrams in raw format" - /> -

- - Analog Input - - - } - label="Enable ADC" - /> -

- - } variant="contained" color="primary" type="submit"> - Save - - -
- ); -} diff --git a/interface/src/project/EMSESPSettingsForm.tsx b/interface/src/project/EMSESPSettingsForm.tsx new file mode 100644 index 000000000..44d03f4e6 --- /dev/null +++ b/interface/src/project/EMSESPSettingsForm.tsx @@ -0,0 +1,371 @@ +import React from 'react'; +import { ValidatorForm, TextValidator, SelectValidator } from 'react-material-ui-form-validator'; + +import { Checkbox, Typography, Box, Link, withWidth, WithWidthProps } from '@material-ui/core'; +import SaveIcon from '@material-ui/icons/Save'; +import MenuItem from '@material-ui/core/MenuItem'; + +import Grid from '@material-ui/core/Grid'; + + +import { RestFormProps, FormActions, FormButton, BlockFormControlLabel } from '../components'; + +import { isIP, optional } from '../validators'; + +import { EMSESPSettings } from './EMSESPtypes'; + +type EMSESPSettingsFormProps = RestFormProps & WithWidthProps; + +class EMSESPSettingsForm extends React.Component { + + componentDidMount() { + ValidatorForm.addValidationRule('isOptionalIP', optional(isIP)); + } + + /* + handleSliderChange = (name: keyof LedSettings) => (event: React.ChangeEvent<{}>, value: number | number[]) => { + const { setData } = this.props; + setData({ ...this.props.data!, [name]: value }); + } + */ + + render() { + const { data, saveData, handleValueChange } = this.props; + return ( + + + + Modify any EMS-ESP settings on this page. For help go to the {'wiki'}. + + + +

+ + EMS Bus + + + + + + + Off + EMS + EMS+ + HT3 + Hardware + + + + + Service Key (0x0B) + Modem (0x0D) + Terminal (0x0A) + Time Module (0x0F) + Alarm Module (0x12) + + + + + + + +

+ + Board Profile + + + + + Choose from a pre-configured board layout to automatically set the GPIO pins + + + + + Gateway S32 + Gateway E32 (LAN8720) + NodeMCU 32S + Lolin D32 + Olimex ESP32 Gateway (LAN8720) + Ethernet (TLK110) + Custom... + + + { (data.board_profile === 0) && + + + + + + + + + + + + + + + + + + + } + +

+ + Options + + + { data.dallas_gpio !== 0 && + + } + label="Enable Dallas parasite mode" + /> + } + { data.led_gpio !== 0 && + + } + label="Invert LED" + /> + } + + + + + } + label="Shower Timer" + /> + {/* + } + label="Shower Alert" + /> */} + + + } + label="Enable API write commands" + /> + + } + label="Enable ADC" + /> +

+ + Syslog + + + + } + label="Enable Syslog" + /> + + { data.syslog_enabled && + + + + + + + + + + OFF + ERR + NOTICE + INFO + DEBUG + ALL + + + + + + + } + label="Output EMS telegrams in raw format" + /> + + } + +

+ + } variant="contained" color="primary" type="submit"> + Save + + +
+ ); + } + +} + +export default withWidth()(EMSESPSettingsForm); diff --git a/interface/src/project/EMSESPtypes.ts b/interface/src/project/EMSESPtypes.ts index d79525c55..1d8d69785 100644 --- a/interface/src/project/EMSESPtypes.ts +++ b/interface/src/project/EMSESPtypes.ts @@ -20,6 +20,7 @@ export interface EMSESPSettings { analog_enabled: boolean; pbutton_gpio: number; trace_raw: boolean; + board_profile: number; } export enum busConnectionStatus { diff --git a/lib/framework/NetworkSettingsService.h b/lib/framework/NetworkSettingsService.h index 15fb43a90..64e11f498 100644 --- a/lib/framework/NetworkSettingsService.h +++ b/lib/framework/NetworkSettingsService.h @@ -31,7 +31,6 @@ class NetworkSettings { String password; String hostname; bool staticIPConfig; - uint8_t ethernet_profile; // optional configuration for static IP address IPAddress localIP; @@ -46,7 +45,6 @@ class NetworkSettings { root["password"] = settings.password; root["hostname"] = settings.hostname; root["static_ip_config"] = settings.staticIPConfig; - root["ethernet_profile"] = settings.ethernet_profile; // extended settings JsonUtils::writeIP(root, "local_ip", settings.localIP); @@ -61,7 +59,6 @@ class NetworkSettings { settings.password = root["password"] | FACTORY_WIFI_PASSWORD; settings.hostname = root["hostname"] | FACTORY_WIFI_HOSTNAME; settings.staticIPConfig = root["static_ip_config"] | false; - settings.ethernet_profile = root["ethernet_profile"] | 0; // no ethernet // extended settings JsonUtils::readIP(root, "local_ip", settings.localIP); diff --git a/lib_standalone/ESP8266React.h b/lib_standalone/ESP8266React.h index c882bc0a1..62aaddb82 100644 --- a/lib_standalone/ESP8266React.h +++ b/lib_standalone/ESP8266React.h @@ -49,7 +49,7 @@ class DummySettings { String staticIPConfig = ""; String dnsIP1 = ""; String dnsIP2 = ""; - uint8_t ethernet_profile = 0; + uint8_t board_profile = 0; uint16_t publish_time_boiler = 10; uint16_t publish_time_thermostat = 10; uint16_t publish_time_solar = 10; diff --git a/src/WebSettingsService.cpp b/src/WebSettingsService.cpp index e2da54b88..dc3fb096e 100644 --- a/src/WebSettingsService.cpp +++ b/src/WebSettingsService.cpp @@ -50,6 +50,7 @@ void WebSettings::read(WebSettings & settings, JsonObject & root) { root["api_enabled"] = settings.api_enabled; root["analog_enabled"] = settings.analog_enabled; root["pbutton_gpio"] = settings.pbutton_gpio; + root["board_profile"] = settings.board_profile; } StateUpdateResult WebSettings::update(JsonObject & root, WebSettings & settings) { @@ -132,6 +133,9 @@ StateUpdateResult WebSettings::update(JsonObject & root, WebSettings & settings) // doesn't need any follow-up actions settings.api_enabled = root["api_enabled"] | EMSESP_DEFAULT_API_ENABLED; + // board profiles + settings.board_profile = root["board_profile"] | EMSESP_DEFAULT_BOARD_PROFILE; + return StateUpdateResult::CHANGED; } diff --git a/src/WebSettingsService.h b/src/WebSettingsService.h index 310b818db..775b16954 100644 --- a/src/WebSettingsService.h +++ b/src/WebSettingsService.h @@ -42,6 +42,7 @@ #define EMSESP_DEFAULT_API_ENABLED false // turn off, because its insecure #define EMSESP_DEFAULT_BOOL_FORMAT 1 // on/off #define EMSESP_DEFAULT_ANALOG_ENABLED false +#define EMSESP_DEFAULT_BOARD_PROFILE 0 // default ESP32 // Default GPIO PIN definitions #if defined(ESP32) @@ -84,6 +85,7 @@ class WebSettings { bool api_enabled; bool analog_enabled; uint8_t pbutton_gpio; + uint8_t board_profile; static void read(WebSettings & settings, JsonObject & root); static StateUpdateResult update(JsonObject & root, WebSettings & settings); diff --git a/src/system.cpp b/src/system.cpp index 9377bbe4a..36dedb975 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -169,12 +169,14 @@ void System::get_settings() { // LED hide_led_ = settings.hide_led; led_gpio_ = settings.led_gpio; + + // BOARD profile + board_profile_ = settings.board_profile; }); EMSESP::esp8266React.getNetworkSettingsService()->read([&](NetworkSettings & networkSettings) { hostname(networkSettings.hostname.c_str()); LOG_INFO(F("System %s booted (EMS-ESP version %s)"), networkSettings.hostname.c_str(), EMSESP_APP_VERSION); // print boot message - ethernet_profile_ = networkSettings.ethernet_profile; }); } @@ -284,7 +286,6 @@ void System::button_init(bool refresh) { } // Allow 0 for Boot-button on NodeMCU-32s? - // if (pbutton_gpio_) { if (!myPButton_.init(pbutton_gpio_, HIGH)) { LOG_INFO(F("External multi-functional button not detected")); } else { @@ -295,7 +296,6 @@ void System::button_init(bool refresh) { myPButton_.onDblClick(BUTTON_DblClickDelay, button_OnDblClick); myPButton_.onLongPress(BUTTON_LongPressDelay, button_OnLongPress); myPButton_.onVLongPress(BUTTON_VLongPressDelay, button_OnVLongPress); - // } } // set the LED to on or off when in normal operating mode @@ -454,7 +454,7 @@ void System::network_init(bool refresh) { // check ethernet profile // ethernet uses lots of additional memory so we only start it when it's explicitly set in the config - if (ethernet_profile_ == 0) { + if (board_profile_ == 0) { return; } @@ -465,7 +465,7 @@ void System::network_init(bool refresh) { eth_phy_type_t type; // Type of the Ethernet PHY (LAN8720 or TLK110) eth_clock_mode_t clock_mode; // ETH_CLOCK_GPIO0_IN or ETH_CLOCK_GPIO0_OUT, ETH_CLOCK_GPIO16_OUT, ETH_CLOCK_GPIO17_OUT for 50Hz inverted clock - if (ethernet_profile_ == 1) { + if (board_profile_ == 1) { // LAN8720 phy_addr = 0; power = -1; @@ -473,7 +473,7 @@ void System::network_init(bool refresh) { mdio = 18; type = ETH_PHY_LAN8720; clock_mode = ETH_CLOCK_GPIO0_IN; - } else if (ethernet_profile_ == 2) { + } else if (board_profile_ == 2) { // TLK110 phy_addr = 31; power = -1; @@ -803,10 +803,10 @@ void System::console_commands(Shell & shell, unsigned int context) { [](Shell & shell, const std::vector & arguments) { uint8_t n = Helpers::hextoint(arguments.front().c_str()); if (n <= 2) { - EMSESP::esp8266React.getNetworkSettingsService()->update( - [&](NetworkSettings & networkSettings) { - networkSettings.ethernet_profile = n; - shell.printfln(F_(ethernet_option_fmt), networkSettings.ethernet_profile); + EMSESP::webSettingsService.update( + [&](WebSettings & settings) { + settings.board_profile = n; + shell.printfln(F_(ethernet_option_fmt), n); return StateUpdateResult::CHANGED; }, "local"); @@ -827,8 +827,6 @@ void System::console_commands(Shell & shell, unsigned int context) { shell.printfln(F_(wifi_ssid_fmt), networkSettings.ssid.isEmpty() ? uuid::read_flash_string(F_(unset)).c_str() : networkSettings.ssid.c_str()); shell.print(F(" ")); shell.printfln(F_(wifi_password_fmt), networkSettings.ssid.isEmpty() ? F_(unset) : F_(asterisks)); - shell.print(F(" ")); - shell.printfln(F_(ethernet_option_fmt), networkSettings.ethernet_profile); }); }); diff --git a/src/system.h b/src/system.h index b16a56f33..a4ca6658d 100644 --- a/src/system.h +++ b/src/system.h @@ -143,7 +143,7 @@ class System { uint8_t led_gpio_; bool syslog_enabled_; bool analog_enabled_; - uint8_t ethernet_profile_; + uint8_t board_profile_; uint8_t pbutton_gpio_; int8_t syslog_level_; uint32_t syslog_mark_interval_; diff --git a/src/version.h b/src/version.h index 7c6067f11..7ac3c2575 100644 --- a/src/version.h +++ b/src/version.h @@ -1,2 +1,2 @@ -#define EMSESP_APP_VERSION "3.0.1b1" +#define EMSESP_APP_VERSION "3.0.1b2" #define EMSESP_PLATFORM "ESP32"