port to platformio

This commit is contained in:
2021-03-29 01:10:55 -07:00
parent 9a3bf84214
commit a6534bcb20
131 changed files with 1537 additions and 1148 deletions

View File

@@ -0,0 +1,28 @@
#include "CloudStatus.h"
#include "../../../Static.h"
void
CloudStatus::onStart()
{
SINGLE_THREADED_BLOCK() {
if (Particle.connected()) {
initNetwork(0, cloud_status_connected);
} else {
System.on(cloud_status, &CloudStatus::initNetwork);
}
}
}
void
CloudStatus::initNetwork(system_event_t event, int param) {
if (param == cloud_status_connected) {
Log.info("Connected to T H E C L O U D");
MainLoop::instance()->dispatch(InputEvent{InputEvent::NetworkStatus, true});
} else if (param == cloud_status_disconnected) {
Log.info("Lost cloud connection!!");
MainLoop::instance()->dispatch(InputEvent{InputEvent::NetworkStatus, false});
}
}
STATIC_ALLOC(CloudStatus);

View File

@@ -0,0 +1,11 @@
#include "../../../Figments/Figments.h"
class CloudStatus: public Task {
public:
CloudStatus() : Task("Cloud") {}
void loop() override {}
void onStart() override;
private:
static void initNetwork(system_event_t event, int param);
};

View File

@@ -0,0 +1,187 @@
#include "Particle.h"
#include "../../../Figments/Figments.h"
#include "../../../colors.h"
#include "../../../Static.h"
#include "./Photon.h"
void
PhotonInput::onConnected()
{
Log.info("Connecting photon input...");
Particle.function("save", &PhotonInput::save, this);
Particle.function("power", &PhotonInput::setPower, this);
Particle.function("next", &PhotonInput::nextPattern, this);
Particle.function("input", &PhotonInput::input, this);
Particle.function("previous", &PhotonInput::previousPattern, this);
Particle.function("pattern", &PhotonInput::setPattern, this);
Particle.function("setHue", &PhotonInput::setHue, this);
Particle.function("brightness", &PhotonInput::setBrightness, this);
Particle.function("reboot", &PhotonInput::reboot, this);
Particle.function("start", &PhotonInput::startThing, this);
Particle.function("stop", &PhotonInput::stopThing, this);
//Log.info("Connecting photon configuration...");
Particle.function("pixelCount", &PhotonInput::setPixelCount, this);
Particle.function("startPixel", &PhotonInput::setStartPixel, this);
Particle.function("save", &PhotonInput::photonSave, this);
Particle.variable("pixelCount", m_pixelCountInt);
Particle.variable("startPixel", m_startPixelInt);
publishConfig();
}
int
PhotonInput::startThing(String command)
{
command.toCharArray(m_commandBuf, sizeof(m_commandBuf));
setEvent(InputEvent(InputEvent::StartThing, m_commandBuf));
return 0;
}
int
PhotonInput::stopThing(String command)
{
command.toCharArray(m_commandBuf, sizeof(m_commandBuf));
setEvent(InputEvent(InputEvent::StopThing, m_commandBuf));
return 0;
}
void
PhotonInput::onStart()
{
System.on(firmware_update, &PhotonInput::onFirmwareUpdate);
System.on(button_click, &PhotonInput::onButtonClick);
System.on(reset, &PhotonInput::onReset);
}
void
PhotonInput::handleEvent(const InputEvent &evt)
{
if (evt.intent == InputEvent::NetworkStatus) {
onConnected();
}
}
int
PhotonInput::reboot(String command)
{
System.reset();
return 0;
}
void
PhotonInput::onReset(system_event_t event, int param)
{
NSFastLED::FastLED.clear();
}
void
PhotonInput::onButtonClick(system_event_t event, int param)
{
Static<PhotonInput>::instance()->setEvent(InputEvent{InputEvent::NextPattern, param});
}
void
PhotonInput::onFirmwareUpdate(system_event_t event, int param)
{
Static<PhotonInput>::instance()->setEvent(InputEvent{InputEvent::FirmwareUpdate, param});
}
int
PhotonInput::input(String command)
{
command.toCharArray(m_commandBuf, sizeof(m_commandBuf));
setEvent(InputEvent(InputEvent::UserInput, m_commandBuf));
return 0;
}
int
PhotonInput::setPattern(String command)
{
command.toCharArray(m_commandBuf, sizeof(m_commandBuf));
setEvent(InputEvent(InputEvent::SetPattern, m_commandBuf));
return 0;
}
int
PhotonInput::setHue(String colorName)
{
ColorInfo nextColor = colorForName(colorName);
setEvent(InputEvent(InputEvent::SetColor, nextColor.rgb));
return 0;
}
int
PhotonInput::nextPattern(String command)
{
setEvent(InputEvent(InputEvent::NextPattern));
return 0;
}
int
PhotonInput::previousPattern(String command)
{
setEvent(InputEvent(InputEvent::PreviousPattern));
return 0;
}
int
PhotonInput::save(String command) {
setEvent(InputEvent::SaveConfigurationRequest);
}
int
PhotonInput::setPower(String command)
{
if (command == "off") {
setEvent(InputEvent(InputEvent::SetPower, 0));
} else if (command == "on") {
setEvent(InputEvent(InputEvent::SetPower, 1));
} else {
setEvent(InputEvent(InputEvent::PowerToggle));
}
return 0;
}
int
PhotonInput::setBrightness(String command)
{
setEvent(InputEvent(InputEvent::SetBrightness, command.toInt()));
return 0;
}
void
PhotonInput::publishConfig() const
{
char buf[255];
snprintf(buf, sizeof(buf), "{\"pixels\": \"%d\", \"offset\": \"%d\"}", m_config.data.pixelCount, m_config.data.startPixel);
Particle.publish("renderbug/config", buf, PRIVATE);
}
int
PhotonInput::photonSave(String command)
{
setEvent(InputEvent::SaveConfiguration);
return 0;
}
int
PhotonInput::setPixelCount(String command)
{
m_pixelCount = command.toInt();
setEvent(InputEvent{InputEvent::SetDisplayLength, m_pixelCount})
return 0;
}
int
PhotonInput::setStartPixel(String command)
{
m_startPixel = command.toInt();
setEvent(InputEvent{InputEvent::SetDisplayLength, m_startPixel})
return 0;
}
STATIC_ALLOC(PhotonInput);

View File

@@ -0,0 +1,38 @@
#include "Particle.h"
#include "../../../Figments/Figments.h"
class PhotonInput: public BufferedInputSource {
public:
PhotonInput() : BufferedInputSource("PhotonInput") {}
void onStart() override;
void handleEvent(const InputEvent &evt) override;
private:
char m_commandBuf[16];
void onConnected();
int reboot(String command);
int input(String command);
int setPattern(String command);
int setHue(String colorName);
int nextPattern(String command);
int previousPattern(String command);
int setPower(String command);
int setBrightness(String command);
int save(String command);
int startThing(String command);
int stopThing(String command);
void publishConfig() const;
int photonSave(String command);
int setPixelCount(String command);
int setStartPixel(String command);
static void onReset(system_event_t event, int param);
static void onButtonClick(system_event_t event, int param);
static void onFirmwareUpdate(system_event_t event, int param);
int m_startPixel;
int m_pixelCount;
};