Skip to content

Commit

Permalink
Minor compilation and formatting fixes
Browse files Browse the repository at this point in the history
Fixed some formatting and added some minor compilation fixes that were
missed from earlier.
  • Loading branch information
ad3154 committed Sep 10, 2023
1 parent b419d25 commit d2bab5d
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions examples/VirtualTerminal/VirtualTerminal.ino
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ std::shared_ptr<void> softKeyListener = nullptr;
std::shared_ptr<void> 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
Expand Down Expand Up @@ -45,7 +45,7 @@ public:

case LoggingLevel::Critical:
{
Serial.print("[Critical]: ");
Serial.print("[Critical]: ");
}
break;
}
Expand Down
1 change: 1 addition & 0 deletions src/can_hardware_interface_single_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "to_string.hpp"

#include <algorithm>
#include <limits>

namespace isobus
{
Expand Down
15 changes: 14 additions & 1 deletion src/event_dispatcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
#include <algorithm>
#include <functional>
#include <memory>
#include <mutex>
#include <vector>

#if !defined CAN_STACK_DISABLE_THREADS && !defined ARDUINO
#include <mutex>
#endif

namespace isobus
{
//================================================================================================
Expand All @@ -31,7 +34,9 @@ namespace isobus
/// @return A shared pointer to the callback.
std::shared_ptr<std::function<void(const E &...)>> add_listener(const std::function<void(const E &...)> &callback)
{
#if !defined CAN_STACK_DISABLE_THREADS && !defined ARDUINO
std::lock_guard<std::mutex> lock(callbacksMutex);
#endif
auto shared = std::make_shared<std::function<void(const E &...)>>(callback);
callbacks.push_back(shared);
return shared;
Expand Down Expand Up @@ -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<std::mutex> lock(callbacksMutex);
#endif
return callbacks.size();
}

Expand All @@ -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<std::mutex> lock(callbacksMutex);
#endif
remove_expired_listeners();

std::for_each(callbacks.begin(), callbacks.end(), [&args...](std::weak_ptr<std::function<void(const E &...)>> &callback) {
Expand All @@ -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<std::mutex> lock(callbacksMutex);
#endif
remove_expired_listeners();

std::for_each(callbacks.begin(), callbacks.end(), [&args...](std::weak_ptr<std::function<void(const E &...)>> &callback) {
Expand All @@ -117,7 +128,9 @@ namespace isobus

private:
std::vector<std::weak_ptr<std::function<void(const E &...)>>> 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

Expand Down
1 change: 1 addition & 0 deletions src/isobus_guidance_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <algorithm>
#include <cassert>
#include <cmath>
#include <limits>
#include <memory>

namespace isobus
Expand Down
1 change: 1 addition & 0 deletions src/isobus_virtual_terminal_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <cassert>
#include <cstring>
#include <functional>
#include <limits>
#include <map>
#include <unordered_map>

Expand Down

0 comments on commit d2bab5d

Please sign in to comment.