SensESP 3.0.0-beta.1
Universal Signal K sensor toolkit ESP32
Loading...
Searching...
No Matches
frequency.cpp
Go to the documentation of this file.
1#include "frequency.h"
2
3namespace sensesp {
4
5// Frequency
6
8 : Transform<int, float>(config_path), multiplier_{multiplier} {
10
11 last_update_ = millis();
12}
13
14void Frequency::set(const int& input) {
15 unsigned long cur_millis = millis();
16 unsigned long elapsed_millis = cur_millis - last_update_;
17 last_update_ = cur_millis;
18 this->emit(multiplier_ * input / (elapsed_millis / 1000.));
19}
20
22 root["multiplier"] = multiplier_;
23}
24
25static const char SCHEMA[] PROGMEM = R"###({
26 "type": "object",
27 "properties": {
28 "multiplier": { "title": "Multiplier", "type": "number" }
29 }
30 })###";
31
33
35 String expected[] = {"multiplier"};
36 for (auto str : expected) {
37 if (!config.containsKey(str)) {
38 return false;
39 }
40 }
41 multiplier_ = config["multiplier"];
42 return true;
43}
44
45} // namespace sensesp
virtual void load_configuration()
On/off switch for signals: input is emitted as-is if the enable flag is set in the web UI.
Definition enable.h:25
virtual void set(const int &input) override
Definition frequency.cpp:14
virtual String get_config_schema() override
Definition frequency.cpp:32
Frequency(float multiplier=1, String config_path="")
Definition frequency.cpp:7
virtual bool set_configuration(const JsonObject &config) override
Definition frequency.cpp:34
virtual void get_configuration(JsonObject &doc) override
Definition frequency.cpp:21
The main Transform class. A transform is identified primarily by the type of value that is produces (...
Definition transform.h:53
void emit(const T &new_value)
const uint8_t PAGE_css_bootstrap[] PROGMEM