SensESP 2.7.2
Universal Signal K sensor toolkit ESP32
Loading...
Searching...
No Matches
voltagedivider.cpp
Go to the documentation of this file.
1#include "voltagedivider.h"
2
3namespace sensesp {
4
9
11 this->emit((Vin_ - Vout) * R2_ / Vout);
12}
13
15 root["Vin"] = Vin_;
16 root["R2"] = R2_;
17}
18
19static const char SCHEMA_R1[] PROGMEM = R"({
20 "type": "object",
21 "properties": {
22 "Vin": { "title": "Voltage in", "type": "number" },
23 "R2": { "title": "Resistance (ohms) of R2", "type": "number" }
24 }
25 })";
26
28
30 String expected[] = {"Vin", "R2"};
31 for (auto str : expected) {
32 if (!config.containsKey(str)) {
33 debugE(
34 "Cannot set VoltageDividerR1: configuration: missing json field %s\n",
35 str.c_str());
36 return false;
37 }
38 }
39
40 Vin_ = config["Vin"];
41 R2_ = config["R2"];
42
43 return true;
44}
45
50
52 this->emit((Vout * R1_) / (Vin_ - Vout));
53}
54
56 root["Vin"] = Vin_;
57 root["R1"] = R1_;
58}
59
60static const char SCHEMA_R2[] PROGMEM = R"({
61 "type": "object",
62 "properties": {
63 "Vin": { "title": "Voltage in", "type": "number" },
64 "R1": { "title": "Resistance (ohms) of R1", "type": "number" }
65 }
66 })";
67
69
71 String expected[] = {"Vin", "R1"};
72 for (auto str : expected) {
73 if (!config.containsKey(str)) {
74 debugE(
75 "Cannot set VoltageDividerR2: configuration: missing json field %s\n",
76 str.c_str());
77 return false;
78 }
79 }
80
81 Vin_ = config["Vin"];
82 R1_ = config["R1"];
83
84 return true;
85}
86
87} // namespace sensesp
virtual void load_configuration()
Construct a new transform based on a single function.
A common type of transform that consumes, transforms, then outputs values of the same data type.
Definition transform.h:95
virtual void set_input(float Vout, uint8_t ignored=0) override
virtual String get_config_schema() override
virtual bool set_configuration(const JsonObject &config) override
VoltageDividerR1(float R2, float Vin=3.3, String config_path="")
virtual void get_configuration(JsonObject &doc) override
virtual void set_input(float Vout, uint8_t ignored=0) override
virtual void get_configuration(JsonObject &doc) override
virtual bool set_configuration(const JsonObject &config) override
virtual String get_config_schema() override
VoltageDividerR2(float R1, float Vin=3.3, String config_path="")
const uint8_t PAGE_css_bootstrap[] PROGMEM
#define debugE(fmt,...)
Definition local_debug.h:50