#include "LogService.h" #include "Static.h" #include 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.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);