-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a component to show AgIsoStack logs.
- Loading branch information
Showing
6 changed files
with
144 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
//================================================================================================ | ||
/// @file LoggerComponent.hpp | ||
/// | ||
/// @brief Defines a GUI component to draw log output. | ||
/// @author Adrian Del Grosso | ||
/// | ||
/// @copyright 2023 Adrian Del Grosso | ||
//================================================================================================ | ||
#ifndef LOGGER_COMPONENT_HPP | ||
#define LOGGER_COMPONENT_HPP | ||
|
||
#include "isobus/isobus/can_stack_logger.hpp" | ||
#include "isobus/isobus/isobus_virtual_terminal_objects.hpp" | ||
#include "isobus/isobus/isobus_virtual_terminal_server_managed_working_set.hpp" | ||
|
||
#include "JuceHeader.h" | ||
|
||
/// @brief Defines a GUI component that will draw log info sunk from the stack | ||
class LoggerComponent : public Component | ||
, public isobus::CANStackLogger | ||
{ | ||
public: | ||
LoggerComponent(); | ||
|
||
void paint(Graphics &g) override; | ||
|
||
void sink_CAN_stack_log(LoggingLevel level, const std::string &logText) override; | ||
|
||
private: | ||
struct LogData | ||
{ | ||
String logText; | ||
isobus::CANStackLogger::LoggingLevel logLevel; | ||
}; | ||
static constexpr std::size_t MAX_NUMBER_MESSAGES = 3000; | ||
std::deque<LogData> loggedMessages; | ||
|
||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(LoggerComponent); | ||
}; | ||
|
||
#endif // LOGGER_COMPONENT_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
//================================================================================================ | ||
/// @file LoggerComponent.cpp | ||
/// | ||
/// @brief Implements a GUI component to draw log output. | ||
/// @author Adrian Del Grosso | ||
/// | ||
/// @copyright 2023 Adrian Del Grosso | ||
//================================================================================================ | ||
#include "LoggerComponent.hpp" | ||
|
||
LoggerComponent::LoggerComponent() | ||
{ | ||
auto bounds = getLocalBounds(); | ||
setBounds(10, 10, bounds.getWidth() - 10, bounds.getHeight() - 10); | ||
} | ||
|
||
void LoggerComponent::paint(Graphics &g) | ||
{ | ||
g.fillAll(Colours::black); | ||
g.setFont(14.0f); | ||
|
||
int numberOfLinesFitted = getHeight() / 14; | ||
|
||
for (std::size_t i = 0; i < loggedMessages.size() && i < numberOfLinesFitted; i++) | ||
{ | ||
const auto &message = loggedMessages.at(i); | ||
|
||
switch (message.logLevel) | ||
{ | ||
case LoggingLevel::Info: | ||
{ | ||
g.setColour(Colours::white); | ||
} | ||
break; | ||
|
||
case LoggingLevel::Warning: | ||
{ | ||
g.setColour(Colours::yellow); | ||
} | ||
break; | ||
|
||
case LoggingLevel::Error: | ||
case LoggingLevel::Critical: | ||
{ | ||
g.setColour(Colours::red); | ||
} | ||
break; | ||
|
||
case LoggingLevel::Debug: | ||
{ | ||
g.setColour(Colours::blueviolet); | ||
} | ||
break; | ||
|
||
default: | ||
{ | ||
g.setColour(Colours::white); | ||
} | ||
break; | ||
} | ||
g.drawFittedText(message.logText, 0, i * 14, getWidth(), 14, Justification::centredLeft, 1); | ||
} | ||
} | ||
|
||
void LoggerComponent::sink_CAN_stack_log(LoggingLevel level, const std::string &logText) | ||
{ | ||
const auto mmLock = MessageManagerLock(); | ||
|
||
loggedMessages.push_front({ logText, level }); | ||
|
||
if (loggedMessages.size() > MAX_NUMBER_MESSAGES) | ||
{ | ||
loggedMessages.pop_back(); | ||
} | ||
|
||
int newSize = loggedMessages.size() * 14; | ||
|
||
if (newSize < 200) | ||
{ | ||
newSize = 200; | ||
} | ||
setSize(getWidth(), newSize); | ||
repaint(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters