SensESP 3.1.1
Universal Signal K sensor toolkit ESP32
Loading...
Searching...
No Matches
analog_input.cpp
Go to the documentation of this file.
1#include "sensesp.h"
2
3#include "analog_input.h"
4
5#include "Arduino.h"
6#include "sensesp_base_app.h"
7
8namespace sensesp {
9
11 const String& config_path, float output_scale)
12 : FloatSensor(config_path),
13 pin{pin},
16 analog_reader_ = std::unique_ptr<AnalogReader>(new AnalogReader(pin));
17 load();
18
19 event_loop()->onRepeat(read_delay, [this]() { this->update(); });
20}
21
23
24bool AnalogInput::to_json(JsonObject& root) {
25 root["read_delay"] = read_delay;
26 return true;
27};
28
29bool AnalogInput::from_json(const JsonObject& config) {
30 String const expected[] = {"read_delay"};
31 for (auto str : expected) {
32 if (!config[str].is<JsonVariant>()) {
33 return false;
34 }
35 }
36 read_delay = config["read_delay"];
37 return true;
38}
39
40const String ConfigSchema(AnalogInput& obj) {
41 return R"###({"type":"object","properties":{"read_delay":{"title":"Read delay","type":"number","description":"Number of milliseconds between each analogRead(A0)"}} })###";
42}
43
44} // namespace sensesp
Sensor for reading the MCU analog input pins.
std::unique_ptr< BaseAnalogReader > analog_reader_
virtual bool from_json(const JsonObject &config) override
virtual bool to_json(JsonObject &root) override
AnalogInput(uint8_t pin=A0, unsigned int read_delay=200, const String &config_path="", float output_scale=1024.)
unsigned int read_delay
virtual bool load() override
Load and populate the object from a persistent storage.
Definition saveable.cpp:8
void emit(const float &new_value)
const String ConfigSchema(const SmartSwitchController &obj)
std::shared_ptr< reactesp::EventLoop > event_loop()
Definition sensesp.cpp:9
ESP32AnalogReader AnalogReader
Sensor< float > FloatSensor
Definition sensor.h:46