added hide_led - #463

This commit is contained in:
proddy
2020-08-26 16:05:27 +02:00
parent f7e592f74e
commit 896063d798
6 changed files with 45 additions and 26 deletions

View File

@@ -76,6 +76,16 @@ function EMSESPSettingsControllerForm(props: EMSESPSettingsControllerFormProps)
<MenuItem value={0x0F}>Time Module (0x0F)</MenuItem>
<MenuItem value={0x12}>Alarm Module (0x12)</MenuItem>
</SelectValidator>
<BlockFormControlLabel
control={
<Checkbox
checked={data.hide_led}
onChange={handleValueChange('hide_led')}
value="hide_led"
/>
}
label="Hide LED"
/>
<BlockFormControlLabel
control={
<Checkbox

View File

@@ -22,6 +22,7 @@ class DummySettings {
uint8_t master_thermostat = 0;
bool shower_timer = false;
bool shower_alert = false;
bool hide_led = false;
uint16_t publish_time = 10; // seconds
uint8_t mqtt_format = 1; // 1=single, 2=nested, 3=ha, 4=custom
uint8_t mqtt_qos = 0;

View File

@@ -36,6 +36,7 @@ void EMSESPSettings::read(EMSESPSettings & settings, JsonObject & root) {
root["master_thermostat"] = settings.master_thermostat;
root["shower_timer"] = settings.shower_timer;
root["shower_alert"] = settings.shower_alert;
root["hide_led"] = settings.hide_led;
}
StateUpdateResult EMSESPSettings::update(JsonObject & root, EMSESPSettings & settings) {
@@ -47,6 +48,7 @@ StateUpdateResult EMSESPSettings::update(JsonObject & root, EMSESPSettings & set
settings.master_thermostat = root["master_thermostat"] | EMSESP_DEFAULT_MASTER_THERMOSTAT;
settings.shower_timer = root["shower_timer"] | EMSESP_DEFAULT_SHOWER_TIMER;
settings.shower_alert = root["shower_alert"] | EMSESP_DEFAULT_SHOWER_ALERT;
settings.hide_led = root["hide_led"] | EMSESP_DEFAULT_HIDE_LED;
return StateUpdateResult::CHANGED;
}
@@ -56,7 +58,8 @@ StateUpdateResult EMSESPSettings::update(JsonObject & root, EMSESPSettings & set
void EMSESPSettingsService::onUpdate() {
EMSESP::shower_.start();
// EMSESP::system_.syslog_init(); // changing SysLog will require a restart
EMSESP::reset_tx();
EMSESP::init_tx();
System::set_led();
}
void EMSESPSettingsService::begin() {

View File

@@ -27,14 +27,13 @@
#define EMSESP_DEFAULT_TX_MODE 1 // EMS1.0
#define EMSESP_DEFAULT_EMS_BUS_ID 0x0B // service key
#define EMSESP_DEFAULT_SYSLOG_LEVEL -1 // OFF
#define EMSESP_DEFAULT_SYSLOG_MARK_INTERVAL 0
#define EMSESP_DEFAULT_SYSLOG_HOST ""
#define EMSESP_DEFAULT_MASTER_THERMOSTAT 0 // not set
#define EMSESP_DEFAULT_SHOWER_TIMER false
#define EMSESP_DEFAULT_SHOWER_ALERT false
#define EMSESP_DEFAULT_HIDE_LED false
namespace emsesp {
@@ -42,13 +41,12 @@ enum MQTT_format : uint8_t { SINGLE = 1, NESTED, HA, CUSTOM };
class EMSESPSettings {
public:
uint8_t tx_mode;
uint8_t ems_bus_id;
uint8_t master_thermostat;
bool shower_timer;
bool shower_alert;
// syslog
uint8_t tx_mode;
uint8_t ems_bus_id;
uint8_t master_thermostat;
bool shower_timer;
bool shower_alert;
bool hide_led;
int8_t syslog_level; // uuid::log::Level
uint32_t syslog_mark_interval;
String syslog_host;

View File

@@ -33,6 +33,7 @@ uuid::syslog::SyslogService System::syslog_;
uint32_t System::heap_start_ = 0;
int System::reset_counter_ = 0;
bool System::upload_status_ = false;
bool System::hide_led_ = false;
// send on/off to a gpio pin
// value: true = HIGH, false = LOW
@@ -145,16 +146,20 @@ void System::start() {
EMSESP::esp8266React.getWiFiSettingsService()->read(
[&](WiFiSettings & wifiSettings) { LOG_INFO(F("System %s booted (EMS-ESP version %s)"), wifiSettings.hostname.c_str(), EMSESP_APP_VERSION); });
syslog_init(); // init SysLog
syslog_init(); // init SysLog
set_led(); // init LED
EMSESP::init_tx(); // start UART
}
if (LED_GPIO) {
pinMode(LED_GPIO, OUTPUT); // LED pin, 0 means disabled
}
EMSESP::emsespSettingsService.read([&](EMSESPSettings & settings) { tx_mode_ = settings.tx_mode; });
#ifndef EMSESP_FORCE_SERIAL
EMSuart::start(tx_mode_); // start UART
#endif
// set the LED to on or off when in normal operating mode
void System::set_led() {
EMSESP::emsespSettingsService.read([&](EMSESPSettings & settings) {
hide_led_ = settings.hide_led;
if (LED_GPIO) {
pinMode(LED_GPIO, OUTPUT); // LED_GPIO 0 means disabled
digitalWrite(LED_GPIO, hide_led_ ? !LED_ON : LED_ON); // LED on, for ever
}
});
}
// returns true if OTA is uploading
@@ -261,7 +266,7 @@ void System::system_check() {
if (!system_healthy_) {
system_healthy_ = true;
if (LED_GPIO) {
digitalWrite(LED_GPIO, LED_ON); // LED on, for ever
digitalWrite(LED_GPIO, hide_led_ ? !LED_ON : LED_ON); // LED on, for ever
}
}
}
@@ -555,7 +560,7 @@ void System::console_commands(Shell & shell, unsigned int context) {
shell.printfln(F_(wifi_password_fmt), wifiSettings.ssid.isEmpty() ? F_(unset) : F_(asterisks));
});
});
/*
/*
EMSESPShell::commands->add_command(ShellContext::SYSTEM,
CommandFlags::USER,
flash_string_vector{F_(show), F_(mqtt)},

View File

@@ -63,6 +63,8 @@ class System {
static void show_mem(const char * note);
static void set_led();
void check_upgrade();
private:
@@ -115,11 +117,11 @@ class System {
static bool upload_status_; // true if we're in the middle of a OTA firmware upload
// settings
uint8_t tx_mode_;
bool system_heartbeat_;
uint8_t syslog_level_;
uint32_t syslog_mark_interval_;
String syslog_host_;
bool system_heartbeat_;
static bool hide_led_;
uint8_t syslog_level_;
uint32_t syslog_mark_interval_;
String syslog_host_;
};
} // namespace emsesp