Skip to content

Commit

Permalink
Update the examples
Browse files Browse the repository at this point in the history
  • Loading branch information
mairas committed Feb 7, 2024
1 parent e6f9dcd commit a81dd0d
Show file tree
Hide file tree
Showing 19 changed files with 29 additions and 82 deletions.
6 changes: 2 additions & 4 deletions examples/analog_input.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

#include "sensesp/sensors/analog_input.h"

#include <Arduino.h>

#include "sensesp/sensors/analog_input.h"
#include "sensesp/signalk/signalk_output.h"
#include "sensesp/transforms/linear.h"
#include "sensesp_app.h"
Expand Down Expand Up @@ -90,9 +91,6 @@ void setup() {
analog_input->connect_to(new Linear(multiplier, offset, linear_config_path))
->connect_to(new SKOutputFloat(sk_path, "",
new SKMetadata("ratio", "Indoor light")));

// Start the SensESP application running
sensesp_app->start();
}

// The loop function is called in an endless loop during program execution.
Expand Down
3 changes: 0 additions & 3 deletions examples/async_repeat_sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ void setup() {
// Connect the output of the digital input to the SKOutput object which
// transmits the results to the Signal K server.
digital->connect_to(new SKOutputFloat(sk_path, ""));

// Start the SensESP application running
sensesp_app->start();
}

// The loop function is called in an endless loop during program execution.
Expand Down
11 changes: 4 additions & 7 deletions examples/chain_counter.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include "sensesp_app.h"
#include "sensesp_app_builder.h"
#include "sensesp/sensors/digital_input.h"
#include "sensesp/signalk/signalk_output.h"
#include "sensesp/system/lambda_consumer.h"
#include "sensesp/transforms/debounce.h"
#include "sensesp/transforms/integrator.h"
#include "sensesp_app.h"
#include "sensesp_app_builder.h"

using namespace sensesp;

Expand Down Expand Up @@ -96,8 +96,8 @@ void setup() {
*/
int read_delay = 10;
String read_delay_config_path = "/button_watcher/read_delay";
auto* button_watcher = new DigitalInputChange(
BUTTON_PIN, INPUT, read_delay, read_delay_config_path);
auto* button_watcher = new DigitalInputChange(BUTTON_PIN, INPUT, read_delay,
read_delay_config_path);

/**
* Create a DebounceInt to make sure we get a nice, clean signal from the
Expand Down Expand Up @@ -144,9 +144,6 @@ void setup() {

/* Connect the button_watcher to the debounce to the button_consumer. */
button_watcher->connect_to(debounce)->connect_to(button_consumer);

/* Finally, start the SensESPApp */
sensesp_app->start();
}

// The loop function is called in an endless loop during program execution.
Expand Down
4 changes: 1 addition & 3 deletions examples/constant_sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/

#include "sensesp/sensors/constant_sensor.h"

#include "sensesp_app_builder.h"

using namespace sensesp;
Expand All @@ -37,9 +38,6 @@ void setup() {
constant_sensor->connect_to(
new SKOutputFloat("tanks.freshWater.capacity", "",
new SKMetadata("m3", "Fresh Water Tank Capacity")));

// Start the SensESP application running
sensesp_app->start();
}

void loop() { app.tick(); }
17 changes: 5 additions & 12 deletions examples/freertos_tasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ void setup() {
SensESPMinimalAppBuilder builder;
SensESPMinimalApp *sensesp_app = builder.set_hostname("async")->get_app();

auto *networking = new Networking(
"/system/net", "", "", SensESPBaseApp::get_hostname(), "thisisfine");
auto *networking = new Networking("/system/net", "", "");
auto *http_server = new HTTPServer();

// create the SK delta object
Expand All @@ -65,7 +64,7 @@ void setup() {
auto *system_status_led = new SystemStatusLed(LED_BUILTIN);

system_status_controller->connect_to(system_status_led);
ws_client_->get_delta_count_producer().connect_to(system_status_led);
ws_client_->get_delta_tx_count_producer().connect_to(system_status_led);

// create a new task for toggling the output pin

Expand All @@ -88,17 +87,11 @@ void setup() {
// create a new SKListener for navigation.headingMagnetic

auto hdg = new SKValueListener<float>("navigation.headingMagnetic");
hdg->connect_to(new LambdaConsumer<float>([](float input) {
debugD("Heading: %f", input);
}));
hdg->connect_to(new LambdaConsumer<float>(
[](float input) { debugD("Heading: %f", input); }));

// print out free heap
app.onRepeat(2000, []() {
debugD("Free heap: %d", ESP.getFreeHeap());
});

// Start the SensESP application running
sensesp_app->start();
app.onRepeat(2000, []() { debugD("Free heap: %d", ESP.getFreeHeap()); });
}

// The loop function is called in an endless loop during program execution.
Expand Down
8 changes: 2 additions & 6 deletions examples/fuel_level_sensor/fuel_level_sensor_example.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "sensesp_app_builder.h"
#include "sensesp/sensors/analog_input.h"
#include "sensesp/signalk/signalk_output.h"
#include "sensesp/transforms/moving_average.h"
#include "sensesp_app_builder.h"

#define SERIAL_DEBUG_DISABLED = true

Expand Down Expand Up @@ -37,12 +37,8 @@ void setup() {
// https://signalk.org/specification/1.4.0/doc/vesselsBranch.html#vesselsregexptanks
input->connect_to(avg)->connect_to(
new SKOutputFloat("tanks.fuel.0.currentLevel"));

sensesp_app->start();
}

// The loop function is called in an endless loop during program execution.
// It simply calls `app.tick()` which will then execute all reactions as needed.
void loop() {
app.tick();
}
void loop() { app.tick(); }
5 changes: 2 additions & 3 deletions examples/hysteresis.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@

#include "sensesp/transforms/hysteresis.h"

#include <math.h>

#include "sensesp/sensors/analog_input.h"
#include "sensesp/signalk/signalk_output.h"
#include "sensesp/transforms/hysteresis.h"
#include "sensesp_app_builder.h"

using namespace sensesp;
Expand Down Expand Up @@ -44,8 +45,6 @@ void setup() {
->connect_to(new Hysteresis<float, bool>(0.3, 0.5, false, true,
"/transforms/hysteresis"))
->connect_to(new SKOutputBool(sk_path));

sensesp_app->start();
}

// The loop function is called in an endless loop during program execution.
Expand Down
5 changes: 2 additions & 3 deletions examples/lambda_transform.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include "sensesp/transforms/lambda_transform.h"

#include <math.h>

#include "sensesp/sensors/analog_input.h"
#include "sensesp/signalk/signalk_output.h"
#include "sensesp/transforms/lambda_transform.h"
#include "sensesp_app_builder.h"

using namespace sensesp;
Expand Down Expand Up @@ -89,8 +90,6 @@ void setup() {

analog_input->connect_to(log_transform)
->connect_to(new SKOutputFloat(sk_path));

sensesp_app->start();
}

// The loop function is called in an endless loop during program execution.
Expand Down
2 changes: 0 additions & 2 deletions examples/manual_networking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ void setup() {
}));

digin->connect_to(new SKOutputBool("electrical.switches.0.state", "/digin/state"));

sensesp_app->start();
}

// The loop function is called in an endless loop during program execution.
Expand Down
3 changes: 0 additions & 3 deletions examples/milone_level_sensor/milone_level_sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,6 @@ void setup() {
"/freshWaterTank_starboard/samples"))
->connect_to(
new SKOutputFloat("tanks.freshwater.starboard.currentLevel"));

// Start the SensESP application running
sensesp_app->start();
}

// The loop function is called in an endless loop during program execution.
Expand Down
5 changes: 1 addition & 4 deletions examples/minimal_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ void setup() {
// manually create Networking and HTTPServer objects to enable
// the HTTP configuration interface

auto* networking = new Networking(
"/system/net", "", "", SensESPBaseApp::get_hostname(), "thisisfine");
auto* networking = new Networking("/system/net", "", "");
auto* http_server = new HTTPServer();

auto* digin1 = new DigitalInputCounter(input_pin1, INPUT, RISING, read_delay);
Expand Down Expand Up @@ -67,8 +66,6 @@ void setup() {
pinMode(output_pin2, OUTPUT);
app.onRepeat(100,
[]() { digitalWrite(output_pin2, !digitalRead(output_pin2)); });

sensesp_app->start();
}

// The loop function is called in an endless loop during program execution.
Expand Down
2 changes: 0 additions & 2 deletions examples/raw_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ void setup() {

const char *sk_path = "environment.json.pin15";
jsonify->connect_to(new SKOutputRawJson(sk_path, ""));

sensesp_app->start();
}

void loop() { app.tick(); }
3 changes: 0 additions & 3 deletions examples/relay_control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ void setup() {
auto* listener = new FloatSKListener(sk_path);
listener->connect_to(new FloatThreshold(0.0f, 100.0f, true, config_path))
->connect_to(new DigitalOutput(5));

// Start the SensESP application running
sensesp_app->start();
}

// The loop function is called in an endless loop during program execution.
Expand Down
3 changes: 0 additions & 3 deletions examples/repeat_sensor_analog_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ void setup() {
// consumer that displays it, is "Indoor light".
analog_input->connect_to(
new SKOutputFloat(sk_path, "", new SKMetadata("ratio", "Indoor light")));

// Start the SensESP application running
sensesp_app->start();
}

// The loop function is called in an endless loop during program execution.
Expand Down
5 changes: 0 additions & 5 deletions examples/rpm_counter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,6 @@ void setup() {
->connect_to(new SKOutputFloat(
sk_path, config_path_skpath)); // connect the output of Frequency()
// to a Signal K Output as a number

// Start the SensESP application running. Because of everything that's been
// set up above, it constantly monitors the interrupt pin, and every
// read_delay ms, it sends the calculated frequency to Signal K.
sensesp_app->start();
}

// The loop function is called in an endless loop during program execution.
Expand Down
3 changes: 0 additions & 3 deletions examples/smart_switch/remote_switch_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,6 @@ void setup() {
// confirms it has made the change in state.
auto* sk_listener = new SKValueListener<bool>(sk_path);
sk_listener->connect_to(controller);

// Start the SensESP application running
sensesp_app->start();
}

// The loop function is called in an endless loop during program execution.
Expand Down
3 changes: 0 additions & 3 deletions examples/smart_switch/smart_switch_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,6 @@ void setup() {
// lets the server know the switch is still alive.
load_switch->connect_to(new RepeatReport<bool>(10000, config_path_repeat))
->connect_to(new SKOutputBool(sk_path, config_path_sk_output));

// Start the SensESP application running
sensesp_app->start();
}

// The loop function is called in an endless loop during program execution.
Expand Down
20 changes: 10 additions & 10 deletions examples/temperature_sender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,30 +143,30 @@ void setup() {
const float R1 = 51.0;

// An AnalogInput gets the value from the microcontroller's AnalogIn pin,
// which is a value from 0 to 1023 and then scales it to the max pin voltage (max_analog_in_voltage), giving the pin voltage.
// which is a value from 0 to 1023 and then scales it to the max pin voltage
// (max_analog_in_voltage), giving the pin voltage.
const float max_analog_in_voltage = 3.3;
// ESP32 has many pins that can be used for AnalogIn, and they're
// expressed here as the XX in GPIOXX.
auto* analog_input = new AnalogInput(36, 1000, "/12V_alternator/temp/analog_in/", max_analog_in_voltage);
auto* analog_input = new AnalogInput(
36, 1000, "/12V_alternator/temp/analog_in/", max_analog_in_voltage);

/* Translating the number returned by AnalogInput into a temperature, and
sending it to Signal K, requires several transforms. Wire them up in
sequence:
/* Translating the number returned by AnalogInput into a temperature,
and sending it to Signal K, requires several transforms. Wire them
up in sequence:
- convert voltage into ohms with VoltageDividerR2()
- find the Kelvin value for the given ohms value with
TemperatureInterpreter()
- use Linear() in case you want to calibrate the output at runtime
- send calibrated Kelvin value to Signal K with SKOutputNumber()
*/
->connect_to(new VoltageDividerR2(R1, volt_div_v_in, "/12V_alternator/temp/sender"))
analog_input
->connect_to(new VoltageDividerR2(R1, volt_div_v_in,
"/12V_alternator/temp/sender"))
->connect_to(new TemperatureInterpreter("/12V_alternator/temp/curve"))
->connect_to(new Linear(1.0, 0.0, "/12V_alternator/temp/calibrate"))
->connect_to(
new SKOutputFloat(sk_path, "/12V_alternator/temp/sk", metadata));

// Start the SensESP application running, which simply activates everything
// that's been set up above
sensesp_app->start();
}

// The loop function is called in an endless loop during program execution.
Expand Down
3 changes: 0 additions & 3 deletions examples/time_counter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,6 @@ void setup() {
engine_hours->connect_to(
new SKOutput<float>("propulsion.main.runTime", "",
new SKMetadata("s", "Main Engine running time")));

// Start the SensESP application running
sensesp_app->start();
}

void loop() { app.tick(); }

0 comments on commit a81dd0d

Please sign in to comment.