104 lines
3.4 KiB
C++
104 lines
3.4 KiB
C++
#include "LogService.h"
|
|
#include "Static.h"
|
|
#include <ArduinoLog.h>
|
|
|
|
static const char* eventValue(const InputEvent& evt);
|
|
|
|
const char*
|
|
LogService::intentName(InputEvent::Intent intent)
|
|
{
|
|
switch(intent) {
|
|
case InputEvent::BeatDetect:
|
|
return "beat-detection";
|
|
case InputEvent::Beat:
|
|
return "beat";
|
|
case InputEvent::ReadyToRoll:
|
|
return "ready-to-roll";
|
|
case InputEvent::PowerToggle:
|
|
return "power-toggle";
|
|
case InputEvent::SetPower:
|
|
return "set-power";
|
|
case InputEvent::PreviousPattern:
|
|
return "previous-pattern";
|
|
case InputEvent::NextPattern:
|
|
return "next-pattern";
|
|
case InputEvent::SetPattern:
|
|
return "set-pattern";
|
|
case InputEvent::SetColor:
|
|
return "set-color";
|
|
case InputEvent::Acceleration:
|
|
return "acceleration";
|
|
case InputEvent::UserInput:
|
|
return "user";
|
|
case InputEvent::SetBrightness:
|
|
return "set-brightness";
|
|
case InputEvent::FirmwareUpdate:
|
|
return "firmware-update";
|
|
case InputEvent::NetworkStatus:
|
|
return "network-status";
|
|
case InputEvent::NetworkActivity:
|
|
return "network-activity";
|
|
case InputEvent::StartThing:
|
|
return "start-thing";
|
|
case InputEvent::StopThing:
|
|
return "stop-thing";
|
|
case InputEvent::SetDisplayOffset:
|
|
return "set-display-offset";
|
|
case InputEvent::SetDisplayLength:
|
|
return "set-display-length";
|
|
case InputEvent::SaveConfigurationRequest:
|
|
return "save-configuration";
|
|
case InputEvent::ConfigurationChanged:
|
|
return "configuration-changed";
|
|
default:
|
|
return NULL;
|
|
}
|
|
}
|
|
|
|
char LogService::s_valueBuf[255];
|
|
|
|
const char*
|
|
LogService::eventValue(const InputEvent& evt)
|
|
{
|
|
switch(evt.type) {
|
|
case InputEvent::Null:
|
|
snprintf(s_valueBuf, sizeof(s_valueBuf), "null");break;
|
|
case InputEvent::Integer:
|
|
snprintf(s_valueBuf, sizeof(s_valueBuf), "%d %02x", evt.asInt(), evt.asInt());break;
|
|
case InputEvent::String:
|
|
snprintf(s_valueBuf, sizeof(s_valueBuf), "\"%s\"", evt.asString());break;
|
|
case InputEvent::Color:
|
|
snprintf(s_valueBuf, sizeof(s_valueBuf), "[%d, %d, %d]", evt.asRGB().r, evt.asRGB().g, evt.asRGB().b);break;
|
|
case InputEvent::Pointer:
|
|
snprintf(s_valueBuf, sizeof(s_valueBuf), "*%p", evt.as<void*>());break;
|
|
default:
|
|
snprintf(s_valueBuf, sizeof(s_valueBuf), "CORRUPTED");break;
|
|
}
|
|
return s_valueBuf;
|
|
}
|
|
|
|
void
|
|
LogService::handleEvent(const InputEvent& evt) {
|
|
if (evt.intent != InputEvent::None) {
|
|
if (evt.intent != m_lastEvent.intent) {
|
|
if (m_duplicateEvents > 0) {
|
|
Log.trace("Suppressed reporting %d duplicate events.", m_duplicateEvents);
|
|
}
|
|
const char* sourceName = intentName(evt.intent);;
|
|
const char* valueBuf = eventValue(evt);
|
|
if (sourceName == 0) {
|
|
Log.trace("Event: intent: %d value: %s", evt.intent, valueBuf);
|
|
} else {
|
|
Log.trace("Event: intent: %s value: %s", sourceName, valueBuf);
|
|
}
|
|
m_duplicateEvents = 0;
|
|
m_lastEvent = evt;
|
|
} else {
|
|
m_duplicateEvents++;
|
|
}
|
|
}
|
|
}
|
|
|
|
STATIC_ALLOC(LogService);
|
|
STATIC_TASK(LogService);
|