If the code hasn't been touched in this long, its probably release-worthy.

This commit is contained in:
2022-06-11 11:02:27 +02:00
parent 0c9eb831dd
commit d14fa7fde1
59 changed files with 1610 additions and 842 deletions

View File

@@ -2,99 +2,96 @@
#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";
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;
}
return s_valueBuf;
}
void
LogService::handleEvent(const InputEvent& evt) {
if (evt.intent != InputEvent::None) {
const char* sourceName;
switch(evt.intent) {
case InputEvent::PowerToggle:
sourceName = "power-toggle";
break;
case InputEvent::SetPower:
sourceName = "set-power";
break;
case InputEvent::PreviousPattern:
sourceName = "previous-pattern";
break;
case InputEvent::NextPattern:
sourceName = "next-pattern";
break;
case InputEvent::SetPattern:
sourceName = "set-pattern";
break;
case InputEvent::SetColor:
sourceName = "set-color";
break;
case InputEvent::Acceleration:
sourceName = "acceleration";
break;
case InputEvent::UserInput:
sourceName = "user";
break;
case InputEvent::SetBrightness:
sourceName = "set-brightness";
break;
case InputEvent::FirmwareUpdate:
sourceName = "firmware-update";
break;
case InputEvent::NetworkStatus:
sourceName = "network-status";
break;
case InputEvent::NetworkActivity:
sourceName = "network-activity";
break;
case InputEvent::StartThing:
sourceName = "start-thing";
break;
case InputEvent::StopThing:
sourceName = "stop-thing";
break;
case InputEvent::SetDisplayOffset:
sourceName = "set-display-offset";
break;
case InputEvent::SetDisplayLength:
sourceName = "set-display-length";
break;
case InputEvent::SaveConfigurationRequest:
sourceName = "save-configuration";
break;
default:
sourceName = 0;
break;
}
char valueBuf[255];
switch(evt.type) {
case InputEvent::Null:
snprintf(valueBuf, sizeof(valueBuf), "null");break;
case InputEvent::Integer:
snprintf(valueBuf, sizeof(valueBuf), "%d %02x", evt.asInt(), evt.asInt());break;
case InputEvent::String:
snprintf(valueBuf, sizeof(valueBuf), "\"%s\"", evt.asString());break;
case InputEvent::Color:
snprintf(valueBuf, sizeof(valueBuf), "[%d, %d, %d]", evt.asRGB().r, evt.asRGB().g, evt.asRGB().b);break;
}
char buf[255 * 2];
if (sourceName == 0) {
snprintf(buf, sizeof(buf), "{\"intent\": %d, \"value\": %s}", evt.intent, valueBuf);
} else {
snprintf(buf, sizeof(buf), "{\"intent\": \"%s\", \"value\": %s}", sourceName, valueBuf);
}
if (evt.intent != m_lastEvent.intent) {
if (m_duplicateEvents > 0) {
Log.notice("Suppressed reporting %d duplicate events.", m_duplicateEvents);
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);
}
Log.verbose("Event: %s", buf);
m_duplicateEvents = 0;
m_lastEvent = evt;
//Particle.publish("renderbug/event", buf, PRIVATE);
} else {
m_duplicateEvents++;
}
/*if (m_online) {
} else {
Log.info("[offline] Event: %s", buf);
}*/
}
}
STATIC_ALLOC(LogService);
STATIC_TASK(LogService);