SensESP 3.0.1
Universal Signal K sensor toolkit ESP32
Loading...
Searching...
No Matches
truth_text.cpp
Go to the documentation of this file.
1#include "truth_text.h"
2
3#include <utility>
4
5namespace sensesp {
6
7bool TextToTruth::is_valid_true(const String& value) {
8 if (value.length() == 0) {
9 return false;
10 }
11
12 if (value.equalsIgnoreCase("On") || value.equalsIgnoreCase("Yes") ||
13 value.equalsIgnoreCase("True") || value.equalsIgnoreCase("T") ||
14 value.equalsIgnoreCase("Y")) {
15 return true;
16 }
17
18 if (value.toInt() != 0) {
19 return true;
20 }
21
22 return false;
23}
24
25bool TextToTruth::is_valid_false(const String& value) {
26 if (value.length() == 0) {
27 return false;
28 }
29
30 if (value.equalsIgnoreCase("Off") || value.equalsIgnoreCase("No") ||
31 value.equalsIgnoreCase("False") || value.equalsIgnoreCase("F") ||
32 value.equalsIgnoreCase("N") || value.equalsIgnoreCase("0") ||
33 value.equalsIgnoreCase("0.0")) {
34 return true;
35 }
36
37 return false;
38}
39
40void TextToTruth::set(const String& input) {
41 this->emit(TextToTruth::is_valid_true(input));
42}
43
44TruthToText::TruthToText(const String& true_value, const String& false_value)
45 : Transform<bool, String>(), truth_value_{false_value, true_value} {}
46
47void TruthToText::set(const bool& input) {
48 if (input) {
49 this->emit(truth_value_[1]);
50 } else {
51 this->emit(truth_value_[0]);
52 }
53}
54
55} // namespace sensesp
static bool is_valid_false(const String &value)
static bool is_valid_true(const String &value)
Definition truth_text.cpp:7
virtual void set(const String &input) override
The main Transform class. A transform is identified primarily by the type of value that is produces (...
Definition transform.h:53
String truth_value_[2]
Definition truth_text.h:56
TruthToText(const String &true_value="ON", const String &false_value="OFF")
virtual void set(const bool &input) override
void emit(const bool &new_value)