SensESP 3.0.1
Universal Signal K sensor toolkit ESP32
Loading...
Searching...
No Matches
voltage_multiplier.cpp
Go to the documentation of this file.
2
3namespace sensesp {
4
5VoltageMultiplier::VoltageMultiplier(uint16_t R1, uint16_t R2,
6 const String& config_path)
7 : FloatTransform(config_path), R1_{R1}, R2_{R2} {}
8
9void VoltageMultiplier::set(const float& input) {
10 // Ohms Law at work!
11 this->emit(input * (((float)R1_ + (float)R2_) / (float)R2_));
12}
13
14bool VoltageMultiplier::to_json(JsonObject& root) {
15 root["R1"] = R1_;
16 root["R2"] = R2_;
17 return true;
18};
19
20bool VoltageMultiplier::from_json(const JsonObject& config) {
21 String const expected[] = {"R1", "R2"};
22 for (auto str : expected) {
23 if (!config[str].is<JsonVariant>()) {
24 return false;
25 }
26 }
27 R1_ = config["R1"];
28 R2_ = config["R2"];
29 return true;
30}
31
32const String ConfigSchema(const VoltageMultiplier& obj) {
33 return R"({"type":"object","properties":{"R1":{"title":"R1","type":"number","description":"The measured value of resistor R1"},"R2":{"title":"R2","type":"number","description":"The measured value of resistor R2"}}})";
34}
35
36} // namespace sensesp
void emit(const float &new_value)
OBSOLETE: Since you can now apply an "output_scale" to the AnalogInput sensor, you don't need this tr...
virtual void set(const float &input)
VoltageMultiplier(uint16_t R1, uint16_t R2, const String &config_path="")
const String ConfigSchema(const SmartSwitchController &obj)