From 7e3c16893f30ce3ba1c0c0df4ad5d34be659e726 Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Thu, 10 Oct 2024 16:39:09 +0300 Subject: [PATCH] Fix examples --- examples/freertos_tasks.cpp | 25 +++++++------ examples/join_and_zip.cpp | 2 +- examples/minimal_app.cpp | 35 +++++++++++-------- examples/raw_json.cpp | 6 ++-- examples/repeat_transform.cpp | 2 +- .../smart_switch/remote_switch_example.cpp | 6 ++-- .../smart_switch/smart_switch_example.cpp | 14 ++++---- 7 files changed, 50 insertions(+), 40 deletions(-) diff --git a/examples/freertos_tasks.cpp b/examples/freertos_tasks.cpp index ae204e601..6183dbb42 100644 --- a/examples/freertos_tasks.cpp +++ b/examples/freertos_tasks.cpp @@ -36,29 +36,32 @@ void setup() { SetupLogging(); SensESPMinimalAppBuilder builder; - SensESPMinimalApp *sensesp_app = builder.set_hostname("async")->get_app(); + auto sensesp_app = builder.set_hostname("async")->get_app(); - auto *networking = new Networking("/system/networking", "", ""); - auto *http_server = new HTTPServer(); + auto networking = std::make_shared("/system/networking", "", ""); + auto http_server = std::make_shared(); // create the SK delta object - auto sk_delta_queue_ = new SKDeltaQueue(); + auto sk_delta_queue_ = std::make_shared(); // create the websocket client - auto ws_client_ = new SKWSClient("/system/sk", sk_delta_queue_, "", 0); + auto ws_client_ = + std::make_shared("/system/sk", sk_delta_queue_, "", 0); - ws_client_->connect_to( - new LambdaConsumer([](SKWSConnectionState input) { + auto output_consumer = std::make_shared>( + [](SKWSConnectionState input) { ESP_LOGD("Example", "SKWSConnectionState: %d", input); - })); + }); + + ws_client_->connect_to(output_consumer); // create the MDNS discovery object - auto mdns_discovery_ = new MDNSDiscovery(); + auto mdns_discovery_ = std::make_shared(); // create a system status controller and a led blinker - auto system_status_controller = new SystemStatusController(); - auto system_status_led = new SystemStatusLed(LED_BUILTIN); + auto system_status_controller = std::make_shared(); + auto system_status_led = std::make_shared(LED_BUILTIN); system_status_controller->connect_to( system_status_led->get_system_status_consumer()); diff --git a/examples/join_and_zip.cpp b/examples/join_and_zip.cpp index 29a1ada64..937ae5dff 100644 --- a/examples/join_and_zip.cpp +++ b/examples/join_and_zip.cpp @@ -24,7 +24,7 @@ using namespace sensesp; -SensESPMinimalApp* sensesp_app; +std::shared_ptr sensesp_app; void setup() { SetupLogging(); diff --git a/examples/minimal_app.cpp b/examples/minimal_app.cpp index d492734f3..2f614619a 100644 --- a/examples/minimal_app.cpp +++ b/examples/minimal_app.cpp @@ -35,27 +35,32 @@ void setup() { // manually create Networking and HTTPServer objects to enable // the HTTP configuration interface - auto* networking = new Networking("/system/networking", "", ""); - auto* http_server = new HTTPServer(); + auto networking = std::make_shared("/system/networking", "", ""); + auto http_server = std::make_shared(); - auto* digin1 = new DigitalInputCounter(input_pin1, INPUT, RISING, read_delay); - auto* digin2 = new DigitalInputCounter(input_pin2, INPUT, CHANGE, read_delay); + auto digin1 = std::make_shared(input_pin1, INPUT, RISING, + read_delay); + auto digin2 = std::make_shared(input_pin2, INPUT, CHANGE, + read_delay); - auto* scaled1 = new Linear(2, 1, "/digin1/scale"); - auto* scaled2 = new Linear(4, -1, "/digin2/scale"); + auto scaled1 = std::make_shared(2, 1, "/digin1/scale"); + auto scaled2 = std::make_shared(4, -1, "/digin2/scale"); digin1->connect_to(scaled1); - scaled1->connect_to(new LambdaTransform([](int input) { - Serial.printf("millis: %d\n", millis()); - Serial.printf("Counter 1: %d\n", input); - return input; - })); - - digin2->connect_to(scaled2)->connect_to( - new LambdaTransform([](int input) { + auto lambda_transform1 = + std::make_shared>([](int input) { + Serial.printf("millis: %d\n", millis()); + Serial.printf("Counter 1: %d\n", input); + return input; + }); + scaled1->connect_to(lambda_transform1); + auto lambda_transform2 = + std::make_shared>([](int input) { Serial.printf("Counter 2: %d\n", input); return input; - })); + }); + + digin2->connect_to(scaled2)->connect_to(lambda_transform2); pinMode(output_pin1, OUTPUT); event_loop()->onRepeat( diff --git a/examples/raw_json.cpp b/examples/raw_json.cpp index f5d384c61..bc0110d2c 100644 --- a/examples/raw_json.cpp +++ b/examples/raw_json.cpp @@ -15,9 +15,9 @@ void setup() { SetupLogging(); SensESPAppBuilder builder; - SensESPApp *sensesp_app = builder.set_hostname("json_demo") - ->set_wifi_client("Hat Labs Sensors", "kanneluuri2406") - ->get_app(); + auto sensesp_app = builder.set_hostname("json_demo") + ->set_wifi_client("Hat Labs Sensors", "kanneluuri2406") + ->get_app(); event_loop()->onRepeat(1000, []() { toggler.set(!toggler.get()); }); diff --git a/examples/repeat_transform.cpp b/examples/repeat_transform.cpp index f4081fcc6..0cd328a16 100644 --- a/examples/repeat_transform.cpp +++ b/examples/repeat_transform.cpp @@ -24,7 +24,7 @@ using namespace sensesp; -SensESPMinimalApp* sensesp_app; +std::shared_ptr sensesp_app; void setup() { SetupLogging(); diff --git a/examples/smart_switch/remote_switch_example.cpp b/examples/smart_switch/remote_switch_example.cpp index bcee09512..ca2b9b15f 100644 --- a/examples/smart_switch/remote_switch_example.cpp +++ b/examples/smart_switch/remote_switch_example.cpp @@ -78,7 +78,7 @@ void setup() { controller->connect_to(new BoolSKPutRequest(sk_path)); // Also connect the controller to an onboard LED... - controller->connect_to(led); + controller->connect_to(led->on_off_consumer_); // Connect a physical button that will feed manual click types into the // controller... @@ -92,7 +92,7 @@ void setup() { ->set_title("Click Type") ->set_sort_order(1000); - pr->connect_to(click_type)->connect_to(controller); + pr->connect_to(click_type)->connect_to(controller->click_consumer_); // In addition to the manual button "click types", a // SmartSwitchController accepts explicit state settings via @@ -105,7 +105,7 @@ void setup() { // sent across the Signal K network when the controlling device // confirms it has made the change in state. auto* sk_listener = new SKValueListener(sk_path); - sk_listener->connect_to(controller); + sk_listener->connect_to(controller->swich_consumer_); } void loop() { event_loop()->tick(); } diff --git a/examples/smart_switch/smart_switch_example.cpp b/examples/smart_switch/smart_switch_example.cpp index 2ecc59c6d..ebb37020e 100644 --- a/examples/smart_switch/smart_switch_example.cpp +++ b/examples/smart_switch/smart_switch_example.cpp @@ -47,7 +47,7 @@ void setup() { // Create the global SensESPApp() object. sensesp_app = builder.set_hostname("sk-engine-lights") ->set_sk_server("192.168.10.3", 3000) - ->set_wifi_client(client("YOUR_WIFI_SSID", "YOUR_WIFI_PASSWORD") + ->set_wifi_client("YOUR_WIFI_SSID", "YOUR_WIFI_PASSWORD") ->get_app(); // Define the SK Path that represents the load this device controls. @@ -73,9 +73,10 @@ void setup() { // electric light. Also connect this pin's state to an LED to get // a visual indicator of load's state. auto* load_switch = new DigitalOutput(PIN_RELAY); - load_switch->connect_to(new RgbLed(PIN_LED_R, PIN_LED_G, PIN_LED_B, - config_path_status_light, LED_ON_COLOR, - LED_OFF_COLOR)); + load_switch->connect_to( + (new RgbLed(PIN_LED_R, PIN_LED_G, PIN_LED_B, config_path_status_light, + LED_ON_COLOR, LED_OFF_COLOR)) + ->on_off_consumer_); // Create a switch controller to handle the user press logic and // connect it to the load switch... @@ -87,7 +88,8 @@ void setup() { DigitalInputState* btn = new DigitalInputState(PIN_BUTTON, INPUT, 100); PressRepeater* pr = new PressRepeater(); btn->connect_to(pr); - pr->connect_to(new ClickType(config_path_button_c))->connect_to(controller); + pr->connect_to(new ClickType(config_path_button_c)) + ->connect_to(controller->click_consumer_); // In addition to the manual button "click types", a // SmartSwitchController accepts explicit state settings via @@ -98,7 +100,7 @@ void setup() { // This allows any device on the SignalK network that can make // such a request to also control the state of our switch. auto* sk_listener = new StringSKPutRequestListener(sk_path); - sk_listener->connect_to(controller); + sk_listener->connect_to(controller->truthy_string_consumer_); // Finally, connect the load switch to an SKOutput so it reports its state // to the Signal K server. Since the load switch only reports its state