Skip to content
This repository has been archived by the owner on Oct 4, 2021. It is now read-only.

Commit

Permalink
adc scaling, remove unused hostname in system
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDvP committed Jan 24, 2021
1 parent cdf6aae commit 37148f1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
22 changes: 15 additions & 7 deletions src/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
#include "emsesp.h" // for send_raw_telegram() command

#include "version.h" // firmware version of EMS-ESP
#if defined(ESP32)
#include "driver/adc.h"
#endif

#if defined(EMSESP_TEST)
#include "test/test.h"
Expand All @@ -41,7 +44,6 @@ uint8_t System::led_gpio_ = 0;
uint16_t System::analog_ = 0;
bool System::analog_enabled_ = false;
bool System::syslog_enabled_ = false;
std::string System::hostname_;

// send on/off to a gpio pin
// value: true = HIGH, false = LOW
Expand Down Expand Up @@ -219,6 +221,13 @@ void System::other_init() {
Helpers::bool_format(settings.bool_format);
analog_enabled_ = settings.analog_enabled;
});
#ifdef ESP32
if (analog_enabled_) {
adc_power_on();
} else {
adc_power_off();
}
#endif
}

// init stuff. This is called when settings are changed in the web
Expand All @@ -229,8 +238,6 @@ void System::init() {

syslog_init(); // init SysLog

EMSESP::esp8266React.getWiFiSettingsService()->read([&](WiFiSettings & settings) { hostname(settings.hostname.c_str()); });

EMSESP::init_tx(); // start UART
}

Expand Down Expand Up @@ -334,8 +341,8 @@ void System::send_heartbeat() {
doc["uptime"] = uuid::log::format_timestamp_ms(uuid::get_uptime_ms(), 3);
doc["uptime_sec"] = uuid::get_uptime_sec();
doc["mqtt_fails"] = Mqtt::publish_fails();
doc["txfails"] = EMSESP::txservice_.telegram_fail_count();
doc["rxfails"] = EMSESP::rxservice_.telegram_error_count();
doc["tx_fails"] = EMSESP::txservice_.telegram_fail_count();
doc["rx_fails"] = EMSESP::rxservice_.telegram_error_count();
doc["dallas_fails"] = EMSESP::sensor_fails();
doc["freemem"] = free_memory;
#if defined(ESP8266)
Expand All @@ -355,9 +362,10 @@ void System::measure_analog() {
if (!measure_last_ || (uint32_t)(uuid::get_uptime() - measure_last_) >= SYSTEM_MEASURE_ANALOG_INTERVAL) {
measure_last_ = uuid::get_uptime();
#if defined(ESP8266)
uint16_t a = analogRead(A0);
// uint16_t a = analogRead(A0); // 10 bit 3,2V
uint16_t a = ((analogRead(A0) * 27) / 8); // scale to esp32 result in mV
#elif defined(ESP32)
uint16_t a = analogRead(36);
uint16_t a = analogRead(36); // arduino scale mV
#else
uint16_t a = 0; // standalone
#endif
Expand Down
9 changes: 0 additions & 9 deletions src/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,6 @@ class System {
bool check_upgrade();
void send_heartbeat();

// static std::string hostname() {
// return hostname_;
// }

static void hostname(std::string hostname) {
hostname_ = hostname;
}

private:
static uuid::log::Logger logger_;

Expand Down Expand Up @@ -115,7 +107,6 @@ class System {
static uint16_t analog_;

// settings
static std::string hostname_;
static bool hide_led_;
static uint8_t led_gpio_;
static bool syslog_enabled_;
Expand Down

0 comments on commit 37148f1

Please sign in to comment.