SensESP 2.7.2
Universal Signal K sensor toolkit ESP32
Loading...
Searching...
No Matches
analogvoltage.cpp
Go to the documentation of this file.
1#include "analogvoltage.h"
2
3namespace sensesp {
4
8 max_voltage_{max_voltage},
9 multiplier_{multiplier},
10 offset_{offset} {
12}
13
15 this->emit(((input * (max_voltage_ / MAX_ANALOG_OUTPUT)) * multiplier_) +
16 offset_);
17}
18
20 root["max_voltage"] = max_voltage_;
21 root["multiplier"] = multiplier_;
22 root["offset"] = offset_;
23}
24
25static const char SCHEMA[] PROGMEM = R"({
26 "type": "object",
27 "properties": {
28 "max_voltage": { "title": "Max voltage", "type": "number", "description": "The maximum voltage allowed into your ESP's Analog Input pin" },
29 "multiplier": { "title": "Mulitplier", "type": "number", "description": "Output will be multiplied by this before sending to SK" },
30 "offsest": { "title": "Offset", "type": "number", "description": "This will be added to output before sending to SK" }
31 }
32 })";
33
35
37 String expected[] = {"max_voltage", "multiplier", "offset"};
38 for (auto str : expected) {
39 if (!config.containsKey(str)) {
40 return false;
41 }
42 }
43 max_voltage_ = config["max_voltage"];
44 multiplier_ = config["multiplier"];
45 offset_ = config["offset"];
46 return true;
47}
48
49} // namespace sensesp
#define MAX_ANALOG_OUTPUT
virtual bool set_configuration(const JsonObject &config) override
AnalogVoltage(float max_voltage=3.3, float multiplier=1.0, float offset=0.0, String config_path="")
virtual void set_input(float input, uint8_t inputChannel=0) override
virtual String get_config_schema() override
virtual void get_configuration(JsonObject &doc) override
virtual void load_configuration()
Construct a new transform based on a single function.
const uint8_t PAGE_css_bootstrap[] PROGMEM