Skip to content

Commit

Permalink
Rename redundant *T and *Template classes
Browse files Browse the repository at this point in the history
  • Loading branch information
mairas committed Mar 8, 2024
1 parent bdbf7b6 commit c256244
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 47 deletions.
6 changes: 3 additions & 3 deletions examples/chain_counter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ void setup() {
counter_read_delay, counter_config_path);

/**
* An IntegratorT<int, float> called "accumulator" adds up all the counts it
* An Integrator<int, float> called "accumulator" adds up all the counts it
* receives (which are ints) and multiplies each count by gypsy_circum, which
* is the amount of chain, in meters, that is moved by each revolution of the
* windlass. (Since gypsy_circum is a float, the output of this transform must
* be a float, which is why we use IntegratorT<int, float>). It can be
* be a float, which is why we use Integrator<int, float>). It can be
* configured in the Config UI at accum_config_path.
*/
float gypsy_circum = 0.32;
String accum_config_path = "/accumulator/circum";
auto* accumulator =
new IntegratorT<int, float>(gypsy_circum, 0.0, accum_config_path);
new Integrator<int, float>(gypsy_circum, 0.0, accum_config_path);

/**
* There is no path for the amount of anchor rode deployed in the current
Expand Down
4 changes: 2 additions & 2 deletions src/sensesp/net/ws_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ class WSClient : public Configurable,
/// @brief Emits the number of deltas sent since last report
TaskQueueProducer<int> delta_tx_tick_producer_ =
TaskQueueProducer<int>(0, ReactESP::app, 5, 990);
IntegratorT<int, int> delta_tx_count_producer_{1, 0, ""};
IntegratorT<int, int> delta_rx_count_producer_{1, 0, ""};
Integrator<int, int> delta_tx_count_producer_{1, 0, ""};
Integrator<int, int> delta_rx_count_producer_{1, 0, ""};

SemaphoreHandle_t received_updates_semaphore_ =
xSemaphoreCreateRecursiveMutex();
Expand Down
4 changes: 2 additions & 2 deletions src/sensesp/sensors/constant_sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ static const char SCHEMA_CONSTANT_SENSOR[] PROGMEM = R"###({
* @brief Base class for constant value sensors.
*/
template <class T>
class ConstantSensor : public SensorT<T> {
class ConstantSensor : public Sensor<T> {
public:
ConstantSensor(T value, int send_interval = 30, String config_path = "")
: SensorT<T>(config_path), value_{value}, send_interval_{send_interval} {
: Sensor<T>(config_path), value_{value}, send_interval_{send_interval} {
this->load_configuration();

ReactESP::app->onRepeat(send_interval_ * 1000,
Expand Down
12 changes: 6 additions & 6 deletions src/sensesp/sensors/digital_input.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ class DigitalInput {
* @param config_path The path to configuring read_delay in the Config UI.
*
* */
class DigitalInputState : public DigitalInput, public SensorT<bool> {
class DigitalInputState : public DigitalInput, public Sensor<bool> {
public:
DigitalInputState(uint8_t pin, int pin_mode, int read_delay = 1000,
String config_path = "")
: DigitalInput{pin, pin_mode},
SensorT<bool>(config_path),
Sensor<bool>(config_path),
read_delay_{read_delay},
triggered_{false} {
load_configuration();
Expand Down Expand Up @@ -84,7 +84,7 @@ class DigitalInputState : public DigitalInput, public SensorT<bool> {
* @param config_path The path to configuring read_delay in the Config UI
*
* */
class DigitalInputCounter : public DigitalInput, public SensorT<int> {
class DigitalInputCounter : public DigitalInput, public Sensor<int> {
public:
DigitalInputCounter(uint8_t pin, int pin_mode, int interrupt_type,
unsigned int read_delay, String config_path = "")
Expand All @@ -106,7 +106,7 @@ class DigitalInputCounter : public DigitalInput, public SensorT<int> {
unsigned int read_delay, String config_path,
std::function<void()> interrupt_handler)
: DigitalInput{pin, pin_mode},
SensorT<int>(config_path),
Sensor<int>(config_path),
interrupt_type_{interrupt_type},
interrupt_handler_{interrupt_handler},
read_delay_{read_delay} {
Expand Down Expand Up @@ -185,12 +185,12 @@ class DigitalInputDebounceCounter : public DigitalInputCounter {
*
* @see Debounce
* */
class DigitalInputChange : public DigitalInput, public SensorT<bool> {
class DigitalInputChange : public DigitalInput, public Sensor<bool> {
public:
DigitalInputChange(uint8_t pin, int pin_mode, int interrupt_type,
String config_path = "")
: DigitalInput{pin, pin_mode},
SensorT<bool>(config_path),
Sensor<bool>(config_path),
interrupt_type_{interrupt_type},
triggered_{true} {
load_configuration();
Expand Down
4 changes: 2 additions & 2 deletions src/sensesp/sensors/sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace sensesp {

std::set<Sensor*> Sensor::sensors_;
std::set<SensorConfig*> SensorConfig::sensors_;

Sensor::Sensor(String config_path) : Configurable{config_path} {
SensorConfig::SensorConfig(String config_path) : Configurable{config_path} {
sensors_.insert(this);
}

Expand Down
28 changes: 14 additions & 14 deletions src/sensesp/sensors/sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,34 @@ namespace sensesp {
* variable to be configurable at run-time in your project, don't provide a
* config_path when you construct the class.
*/
class Sensor : virtual public Observable, public Configurable {
class SensorConfig : virtual public Observable, public Configurable {
public:
Sensor(String config_path = "");
SensorConfig(String config_path = "");

static const std::set<Sensor*>& get_sensors() { return sensors_; }
static const std::set<SensorConfig*>& get_sensors() { return sensors_; }

private:
static std::set<Sensor*> sensors_;
static std::set<SensorConfig*> sensors_;
};

/**
* @brief Sensor template class for any sensor producing actual values.
*
**/
template <typename T>
class SensorT : public Sensor, public ValueProducer<T> {
class Sensor : public ValueProducer<T> {
public:
SensorT<T>(String config_path = "")
: Sensor(config_path), ValueProducer<T>() {}
Sensor<T>(String config_path = "")
: SensorConfig(config_path), ValueProducer<T>() {}
};

typedef SensorT<float> FloatSensor;
typedef SensorT<int> IntSensor;
typedef SensorT<bool> BoolSensor;
typedef SensorT<String> StringSensor;
typedef Sensor<float> FloatSensor;
typedef Sensor<int> IntSensor;
typedef Sensor<bool> BoolSensor;
typedef Sensor<String> StringSensor;

template <class T>
class RepeatSensor : public SensorT<T> {
class RepeatSensor : public Sensor<T> {
public:
/**
* @brief Construct a new RepeatSensor object.
Expand All @@ -66,7 +66,7 @@ class RepeatSensor : public SensorT<T> {
* @tparam T The type of the value returned by the callback function.
*/
RepeatSensor<T>(unsigned int repeat_interval_ms, std::function<T()> callback)
: SensorT<T>(""),
: Sensor<T>(""),
repeat_interval_ms_(repeat_interval_ms),
returning_callback_(callback) {
ReactESP::app->onRepeat(repeat_interval_ms_, [this]() {
Expand All @@ -89,7 +89,7 @@ class RepeatSensor : public SensorT<T> {
*/
RepeatSensor<T>(unsigned int repeat_interval_ms,
std::function<void(RepeatSensor<T>*)> callback)
: SensorT<T>(""),
: Sensor<T>(""),
repeat_interval_ms_(repeat_interval_ms),
emitting_callback_(callback) {
ReactESP::app->onRepeat(repeat_interval_ms_,
Expand Down
2 changes: 1 addition & 1 deletion src/sensesp/sensors/system_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace sensesp {
* @brief Connect a system information sensor to SKOutput
**/
template <typename T>
void connect_system_info_sensor(SensorT<T>* sensor, String prefix,
void connect_system_info_sensor(Sensor<T>* sensor, String prefix,
String name) {
auto hostname_obs = SensESPBaseApp::get()->get_hostname_observable();
String hostname = hostname_obs->get();
Expand Down
20 changes: 8 additions & 12 deletions src/sensesp/transforms/debounce.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,14 @@ static const char DEBOUNCE_SCHEMA[] PROGMEM = R"###({
* @see DigitalInputChange
*/
template <class T>
class DebounceTemplate : public SymmetricTransform<T> {
class Debounce : public SymmetricTransform<T> {
public:
DebounceTemplate(int ms_min_delay = 15, String config_path = "")
: SymmetricTransform<T>(config_path),
ms_min_delay_{ms_min_delay} {
Debounce(int ms_min_delay = 15, String config_path = "")
: SymmetricTransform<T>(config_path), ms_min_delay_{ms_min_delay} {
this->load_configuration();
}

virtual void set(T input, uint8_t input_channel = 0) override {

// Input has changed since the last emit, or this is the first
// input since the program started to run.

Expand Down Expand Up @@ -87,13 +85,11 @@ class DebounceTemplate : public SymmetricTransform<T> {
virtual String get_config_schema() override { return FPSTR(DEBOUNCE_SCHEMA); }
};

typedef DebounceTemplate<bool> DebounceBool;
typedef DebounceTemplate<bool>
Debounce; // for backward-compatibility with original class
typedef DebounceTemplate<int> DebounceInt;
typedef DebounceTemplate<float>
DebounceFloat; // not sure this works - test it if you use it
typedef Debounce<bool> DebounceBool;
typedef Debounce<int> DebounceInt;
typedef Debounce<float>
DebounceFloat;

}
} // namespace sensesp

#endif
8 changes: 4 additions & 4 deletions src/sensesp/transforms/integrator.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ static const char INTEGRATOR_SCHEMA[] PROGMEM = R"({
* @tparam P Producer (output) data type
*/
template <class C, class P>
class IntegratorT : public Transform<C, P> {
class Integrator : public Transform<C, P> {
public:
/**
* @brief Construct a new Integrator T object
Expand All @@ -31,7 +31,7 @@ class IntegratorT : public Transform<C, P> {
* @param value Initial value of the accumulator
* @param config_path Configuration path
*/
IntegratorT(P k = 1, P value = 0, String config_path = "")
Integrator(P k = 1, P value = 0, String config_path = "")
: Transform<C, P>(config_path), k{k}, value{value} {
this->load_configuration();
this->emit(value);
Expand Down Expand Up @@ -66,8 +66,8 @@ class IntegratorT : public Transform<C, P> {
P value = 0;
};

typedef IntegratorT<float, float> Integrator;
typedef IntegratorT<int, int> Accumulator;
typedef Integrator<float, float> FloatIntegrator;
typedef Integrator<int, int> Accumulator;

} // namespace sensesp
#endif
2 changes: 1 addition & 1 deletion src/sensesp_app_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class SensESPAppBuilder : public SensESPBaseAppBuilder {
const SensESPAppBuilder* enable_wifi_watchdog() {
// create the wifi disconnect watchdog
app_->system_status_controller_
.connect_to(new DebounceTemplate<SystemStatus>(
.connect_to(new Debounce<SystemStatus>(
3 * 60 * 1000 // 180 s = 180000 ms = 3 minutes
))
->connect_to(new LambdaConsumer<SystemStatus>([](SystemStatus input) {
Expand Down

0 comments on commit c256244

Please sign in to comment.