From d2bab5d719965728c72c7ee8e8b686abb6816d06 Mon Sep 17 00:00:00 2001 From: Adrian Del Grosso <10929341+ad3154@users.noreply.github.com> Date: Sun, 10 Sep 2023 11:14:22 -0600 Subject: [PATCH] Minor compilation and formatting fixes Fixed some formatting and added some minor compilation fixes that were missed from earlier. --- README.md | 4 ++-- examples/VirtualTerminal/VirtualTerminal.ino | 4 ++-- src/can_hardware_interface_single_thread.cpp | 1 + src/event_dispatcher.hpp | 15 ++++++++++++++- src/isobus_guidance_interface.cpp | 1 + src/isobus_virtual_terminal_client.cpp | 1 + 6 files changed, 21 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 4824318..d5b4ba1 100644 --- a/README.md +++ b/README.md @@ -20,8 +20,8 @@ Currently this Arduino library is compatible with Teensy hardware only. ESP32 su ### Example -An example ino file for Arduino IDE is located in the main AgIsoStack++ repo. [Starting from here](https://github.com/Open-Agriculture/AgIsoStack-plus-plus/tree/main/examples/arduino_example) is recommended! -The example sketch loads a VT object pool to a virtual terminal, as long as your teensy is connected to an ISO11783 CAN network using the Teensy's CAN 1 pins and compatible CAN transceiver. +Examples are located [here](https://github.com/Open-Agriculture/AgIsoStack-Arduino/tree/main/examples). +The virtual terminal example sketch is a good starting point, and loads a VT object pool to a virtual terminal, as long as your teensy is connected to an ISO11783 CAN network using the Teensy's CAN 1 pins and compatible CAN transceiver. ### Troubleshooting diff --git a/examples/VirtualTerminal/VirtualTerminal.ino b/examples/VirtualTerminal/VirtualTerminal.ino index 8c83844..43f0278 100644 --- a/examples/VirtualTerminal/VirtualTerminal.ino +++ b/examples/VirtualTerminal/VirtualTerminal.ino @@ -12,7 +12,7 @@ std::shared_ptr softKeyListener = nullptr; std::shared_ptr buttonListener = nullptr; // A log sink for the CAN stack -class CustomLogger : public isobus::CANStackLogger +class CustomLogger : public CANStackLogger { public: void sink_CAN_stack_log(CANStackLogger::LoggingLevel level, const std::string &text) override @@ -45,7 +45,7 @@ public: case LoggingLevel::Critical: { - Serial.print("[Critical]: "); + Serial.print("[Critical]: "); } break; } diff --git a/src/can_hardware_interface_single_thread.cpp b/src/can_hardware_interface_single_thread.cpp index 6e4cfd5..136738e 100644 --- a/src/can_hardware_interface_single_thread.cpp +++ b/src/can_hardware_interface_single_thread.cpp @@ -12,6 +12,7 @@ #include "to_string.hpp" #include +#include namespace isobus { diff --git a/src/event_dispatcher.hpp b/src/event_dispatcher.hpp index 2fdfb7c..bb3cdca 100644 --- a/src/event_dispatcher.hpp +++ b/src/event_dispatcher.hpp @@ -12,9 +12,12 @@ #include #include #include -#include #include +#if !defined CAN_STACK_DISABLE_THREADS && !defined ARDUINO +#include +#endif + namespace isobus { //================================================================================================ @@ -31,7 +34,9 @@ namespace isobus /// @return A shared pointer to the callback. std::shared_ptr> add_listener(const std::function &callback) { +#if !defined CAN_STACK_DISABLE_THREADS && !defined ARDUINO std::lock_guard lock(callbacksMutex); +#endif auto shared = std::make_shared>(callback); callbacks.push_back(shared); return shared; @@ -70,7 +75,9 @@ namespace isobus /// @return The number of listeners std::size_t get_listener_count() { +#if !defined CAN_STACK_DISABLE_THREADS && !defined ARDUINO std::lock_guard lock(callbacksMutex); +#endif return callbacks.size(); } @@ -88,7 +95,9 @@ namespace isobus /// @return True if the event was successfully invoked, false otherwise. void invoke(E &&...args) { +#if !defined CAN_STACK_DISABLE_THREADS && !defined ARDUINO std::lock_guard lock(callbacksMutex); +#endif remove_expired_listeners(); std::for_each(callbacks.begin(), callbacks.end(), [&args...](std::weak_ptr> &callback) { @@ -104,7 +113,9 @@ namespace isobus /// @return True if the event was successfully invoked, false otherwise. void call(const E &...args) { +#if !defined CAN_STACK_DISABLE_THREADS && !defined ARDUINO std::lock_guard lock(callbacksMutex); +#endif remove_expired_listeners(); std::for_each(callbacks.begin(), callbacks.end(), [&args...](std::weak_ptr> &callback) { @@ -117,7 +128,9 @@ namespace isobus private: std::vector>> callbacks; ///< The callbacks to invoke +#if !defined CAN_STACK_DISABLE_THREADS && !defined ARDUINO std::mutex callbacksMutex; ///< The mutex to protect the callbacks +#endif }; } // namespace isobus diff --git a/src/isobus_guidance_interface.cpp b/src/isobus_guidance_interface.cpp index 22ae8f8..f1a959d 100644 --- a/src/isobus_guidance_interface.cpp +++ b/src/isobus_guidance_interface.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include namespace isobus diff --git a/src/isobus_virtual_terminal_client.cpp b/src/isobus_virtual_terminal_client.cpp index 5ec4c9e..9ccf162 100644 --- a/src/isobus_virtual_terminal_client.cpp +++ b/src/isobus_virtual_terminal_client.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include