cleanup main.cpp, split platform code into a Platform object

This commit is contained in:
2021-03-31 11:50:00 -07:00
parent a6534bcb20
commit 10bbcd6786
21 changed files with 768 additions and 408 deletions

View File

@@ -57,108 +57,12 @@ PhotonTelemetry::loop()
void
PhotonTelemetry::handleEvent(const InputEvent &evt)
{
Serial.flush();
if (evt.intent == InputEvent::NetworkStatus) {
onConnected();
}
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 (m_online) {
if (evt.intent != m_lastEvent.intent) {
if (m_duplicateEvents > 0) {
Log.info("Suppressed reporting %ld duplicate events.", m_duplicateEvents);
}
Log.info("Event: %s", buf);
m_duplicateEvents = 0;
m_lastEvent = evt;
Particle.publish("renderbug/event", buf, PRIVATE);
} else {
m_duplicateEvents++;
}
} else {
Log.info("[offline] Event: %s", buf);
}
if (evt.intent == InputEvent::SetColor) {
NSFastLED::CRGB rgb {evt.asRGB()};
uint32_t color = (rgb.r << 16) + (rgb.g << 8) + (rgb.b << 0);
m_ledStatus.setColor(color);
m_ledStatus.setActive(true);
m_rgbPulseFrame = 1000;
}
if (evt.intent == InputEvent::SetColor) {
NSFastLED::CRGB rgb {evt.asRGB()};
uint32_t color = (rgb.r << 16) + (rgb.g << 8) + (rgb.b << 0);
m_ledStatus.setColor(color);
m_ledStatus.setActive(true);
m_rgbPulseFrame = 1000;
}
}