Skip to content

Commit

Permalink
Merge pull request forkineye#354 from MartinMueller2003/main
Browse files Browse the repository at this point in the history
Added / Fixed blank input support.
  • Loading branch information
forkineye authored Sep 22, 2021
2 parents dfd3389 + 84e6ddd commit 6a7752f
Show file tree
Hide file tree
Showing 30 changed files with 116 additions and 140 deletions.
31 changes: 17 additions & 14 deletions ESPixelStick/ESPixelStick.ino
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ void setup()
config.netmask = IPAddress ((uint32_t)0);
config.gateway = IPAddress ((uint32_t)0);
config.UseDhcp = true;
config.BlankDelay = 5;
config.ap_fallbackIsEnabled = true;
config.RebootOnWiFiFailureToConnect = true;
config.ap_timeout = AP_TIMEOUT;
Expand Down Expand Up @@ -213,9 +214,18 @@ bool dsDevice(JsonObject & json)
{
JsonObject JsonDeviceConfig = json[CN_device];

//TODO: Add configuration upgrade handling - cfgver moved to root level
String TempVersion;
setFromJSON (TempVersion, JsonDeviceConfig, CN_cfgver);
if (TempVersion != CurrentConfigVersion)
{
//TODO: Add configuration update handler
logcon (String (F ("Incorrect Config Version ID")));
}

//TODO: Add configuration upgrade handling - move cfgver to root level

ConfigChanged |= setFromJSON (config.id, JsonDeviceConfig, CN_id);
ConfigChanged |= setFromJSON (config.id, JsonDeviceConfig, CN_id);
ConfigChanged |= setFromJSON (config.BlankDelay, JsonDeviceConfig, CN_blanktime);
}
else
{
Expand Down Expand Up @@ -305,14 +315,6 @@ bool deserializeCore (JsonObject & json)

do // once
{
String TempVersion;
setFromJSON (TempVersion, json, CN_cfgver);
if (TempVersion != CurrentConfigVersion)
{
//TODO: Add configuration update handler
logcon (String (F ("Incorrect Config Version ID")));
}

dsDevice (json);
FileMgr.SetConfig (json);
ResetWiFi = dsNetwork (json);
Expand Down Expand Up @@ -380,19 +382,20 @@ void GetConfig (JsonObject & json)
// DEBUG_START;

// Config Version
json[CN_cfgver] = CurrentConfigVersion;

// Device
JsonObject device = json.createNestedObject(CN_device);
device[CN_id] = config.id;
JsonObject device = json.createNestedObject(CN_device);
device[CN_cfgver] = CurrentConfigVersion;
device[CN_id] = config.id;
device[CN_blanktime] = config.BlankDelay;

FileMgr.GetConfig (device);

// Network
JsonObject network = json.createNestedObject(CN_network);
network[CN_ssid] = config.ssid;
network[CN_passphrase] = config.passphrase;
network[CN_hostname] = config.hostname;
network[CN_hostname] = config.hostname;
#ifdef ARDUINO_ARCH_ESP8266
IPAddress Temp = config.ip;
network[CN_ip] = Temp.toString ();
Expand Down
1 change: 0 additions & 1 deletion ESPixelStick/src/ConstNames.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ const char CN_duration [] = "duration";
const char CN_effect [] = "effect";
const char CN_effect_list [] = "effect_list";
const char CN_EffectAllLeds [] = "EffectAllLeds";
const char CN_EffectBlankTime [] = "EffectBlankTime";
const char CN_EffectBrightness [] = "EffectBrightness";
const char CN_EffectColor [] = "EffectColor";
const char CN_EffectMirror [] = "EffectMirror";
Expand Down
1 change: 0 additions & 1 deletion ESPixelStick/src/ConstNames.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ extern const char CN_duration[];
extern const char CN_effect[];
extern const char CN_effect_list[];
extern const char CN_EffectAllLeds[];
extern const char CN_EffectBlankTime[];
extern const char CN_EffectBrightness[];
extern const char CN_EffectColor[];
extern const char CN_EffectMirror[];
Expand Down
1 change: 1 addition & 0 deletions ESPixelStick/src/ESPixelStick.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ typedef struct {
IPAddress ip = (uint32_t)0;
IPAddress netmask = (uint32_t)0;
IPAddress gateway = (uint32_t)0;
time_t BlankDelay = time_t(5);
bool UseDhcp = true; ///< Use DHCP?
bool ap_fallbackIsEnabled = true; ///< Fallback to AP if fail to associate?
uint32_t ap_timeout = AP_TIMEOUT; ///< How long to wait in AP mode with no connection before rebooting
Expand Down
2 changes: 1 addition & 1 deletion ESPixelStick/src/input/InputAlexa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void c_InputAlexa::Begin()
}
HasBeenInitialized = true;

pEffectsEngine = new c_InputEffectEngine (c_InputMgr::e_InputChannelIds::InputChannelId_1, c_InputMgr::e_InputType::InputType_Effects, InputDataBuffer, InputDataBufferSize);
pEffectsEngine = new c_InputEffectEngine (c_InputMgr::e_InputChannelIds::InputSecondaryChannelId, c_InputMgr::e_InputType::InputType_Effects, InputDataBuffer, InputDataBufferSize);
pEffectsEngine->SetOperationalState (false);

WebMgr.RegisterAlexaCallback ([this](EspalexaDevice* pDevice) {this->onMessage (pDevice); });
Expand Down
2 changes: 1 addition & 1 deletion ESPixelStick/src/input/InputArtnet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ void c_InputArtnet::onDmxFrame (uint16_t CurrentUniverseId,
&data[CurrentUniverse.SourceDataOffset],
min (CurrentUniverse.BytesToCopy, length));

InputMgr.ResetBlankTimer ();
InputMgr.RestartBlankTimer (GetInputChannelId ());
}
else
{
Expand Down
1 change: 0 additions & 1 deletion ESPixelStick/src/input/InputCommon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class c_InputCommon
virtual void GetDriverName (String & sDriverName) = 0; ///< get the name for the instantiated driver
virtual void SetBufferInfo (uint8_t * BufferStart, uint16_t BufferSize) = 0;
virtual void SetOperationalState (bool ActiveFlag) { IsInputChannelActive = ActiveFlag; }
virtual void ResetBlankTimer () {}; // only implemented by Effects Engine to delay return to operation
virtual void NetworkStateChanged (bool IsConnected) {}; // used by poorly designed rx functions
virtual bool isShutDownRebootNeeded () { return false; }

Expand Down
2 changes: 1 addition & 1 deletion ESPixelStick/src/input/InputDDP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ void c_InputDDP::ProcessReceivedData (DDP_packet_t & Packet)
// DEBUG_V (String (" InputBufferOffset: ") + String (InputBufferOffset));
memcpy (&InputDataBuffer[InputBufferOffset], &Data[0], AdjPacketDataLength);

InputMgr.ResetBlankTimer ();
InputMgr.RestartBlankTimer (GetInputChannelId ());

} while (false);

Expand Down
8 changes: 4 additions & 4 deletions ESPixelStick/src/input/InputE131.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ void c_InputE131::GetStatus (JsonObject & jsonStatus)
// DEBUG_START;

JsonObject e131Status = jsonStatus.createNestedObject (F ("e131"));
e131Status[CN_id] = InputChannelId;
e131Status[CN_unifirst] = startUniverse;
e131Status[CN_unilast ] = LastUniverse;
e131Status[CN_id] = InputChannelId;
e131Status[CN_unifirst] = startUniverse;
e131Status[CN_unilast ] = LastUniverse;
e131Status[CN_unichanlim] = ChannelsPerUniverse;

e131Status[CN_num_packets] = e131->stats.num_packets;
Expand Down Expand Up @@ -176,7 +176,7 @@ void c_InputE131::ProcessIncomingE131Data (e131_packet_t * packet)
&E131Data[CurrentUniverse.SourceDataOffset],
min (CurrentUniverse.BytesToCopy, NumBytesOfE131Data));

InputMgr.ResetBlankTimer ();
InputMgr.RestartBlankTimer (GetInputChannelId ());
}
else
{
Expand Down
26 changes: 4 additions & 22 deletions ESPixelStick/src/input/InputEffectEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ c_InputEffectEngine::c_InputEffectEngine (c_InputMgr::e_InputChannelIds NewInput

//-----------------------------------------------------------------------------
c_InputEffectEngine::c_InputEffectEngine () :
c_InputCommon (c_InputMgr::e_InputChannelIds::InputChannelId_1,
c_InputCommon (c_InputMgr::e_InputChannelIds::InputPrimaryChannelId,
c_InputMgr::e_InputType::InputType_Effects,
nullptr, 0)
{
Expand Down Expand Up @@ -109,7 +109,6 @@ void c_InputEffectEngine::GetConfig (JsonObject& jsonConfig)
jsonConfig[CN_EffectMirror] = EffectMirror;
jsonConfig[CN_EffectAllLeds] = EffectAllLeds;
jsonConfig[CN_EffectBrightness] = uint32_t(EffectBrightness * 100.0);
jsonConfig[CN_EffectBlankTime] = EffectBlankTime;
jsonConfig[CN_EffectWhiteChannel] = EffectWhiteChannel;
jsonConfig[CN_EffectColor] = HexColor;
// DEBUG_V ("");
Expand Down Expand Up @@ -149,7 +148,6 @@ void c_InputEffectEngine::GetMqttConfig (MQTTConfiguration_s & mqttConfig)
mqttConfig.mirror = EffectMirror;
mqttConfig.allLeds = EffectAllLeds;
mqttConfig.brightness = uint8_t(EffectBrightness * 255.0);
mqttConfig.blankTime = EffectBlankTime;
mqttConfig.whiteChannel = EffectWhiteChannel;

mqttConfig.color.r = EffectColor.r;
Expand Down Expand Up @@ -230,12 +228,6 @@ void c_InputEffectEngine::Process ()
}
// DEBUG_V ("Pixel Count OK");

if (millis () < EffectBlankEnd)
{
break;
}
// DEBUG_V ("");

if (millis () < (EffectLastRun + EffectWait))
{
break;
Expand All @@ -246,6 +238,7 @@ void c_InputEffectEngine::Process ()
uint16_t wait = (this->*ActiveEffect->func)();
EffectWait = max ((int)wait, MIN_EFFECT_DELAY);
EffectCounter++;
InputMgr.RestartBlankTimer (GetInputChannelId ());

} while (false);

Expand Down Expand Up @@ -289,7 +282,6 @@ bool c_InputEffectEngine::SetConfig (ArduinoJson::JsonObject& jsonConfig)
setFromJSON (EffectMirror, jsonConfig, CN_EffectMirror);
setFromJSON (EffectAllLeds, jsonConfig, CN_EffectAllLeds);
setFromJSON (EffectBrightness, jsonConfig, CN_EffectBrightness);
setFromJSON (EffectBlankTime, jsonConfig, CN_EffectBlankTime);
setFromJSON (EffectWhiteChannel, jsonConfig, CN_EffectWhiteChannel);
setFromJSON (effectName, jsonConfig, CN_currenteffect);
setFromJSON (effectColor, jsonConfig, CN_EffectColor);
Expand Down Expand Up @@ -322,7 +314,6 @@ void c_InputEffectEngine::SetMqttConfig (MQTTConfiguration_s& mqttConfig)
effectName = mqttConfig.effect;
EffectMirror = mqttConfig.mirror;
EffectAllLeds = mqttConfig.allLeds;
EffectBlankTime = mqttConfig.blankTime;
EffectWhiteChannel = mqttConfig.whiteChannel;

uint16_t tempBrightness = uint8_t(EffectBrightness * 255.0);
Expand Down Expand Up @@ -388,15 +379,6 @@ void c_InputEffectEngine::setDelay (uint16_t delay)
// DEBUG_END;
} // setDelay

//-----------------------------------------------------------------------------
void c_InputEffectEngine::ResetBlankTimer ()
{
// DEBUG_START;
EffectBlankEnd = millis () + (EffectBlankTime * 1000);
// DEBUG_END;

} // ResetBlankTimer

//-----------------------------------------------------------------------------
void c_InputEffectEngine::setEffect (const String & effectName)
{
Expand Down Expand Up @@ -759,7 +741,8 @@ uint16_t c_InputEffectEngine::effectLightning ()
}

//-----------------------------------------------------------------------------
uint16_t c_InputEffectEngine::effectBreathe () {
uint16_t c_InputEffectEngine::effectBreathe ()
{
/*
* Subtle "breathing" effect, works best with gamma correction on.
*
Expand Down Expand Up @@ -900,4 +883,3 @@ c_InputEffectEngine::CRGB c_InputEffectEngine::hsv2rgb (dCHSV in)
out_int = { uint8_t (255 * out.r), uint8_t (255 * out.g), uint8_t (255 * out.b) };
return out_int;
}

4 changes: 0 additions & 4 deletions ESPixelStick/src/input/InputEffectEngine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ class c_InputEffectEngine : public c_InputCommon
bool mirror;
bool allLeds;
uint8_t brightness;
uint8_t blankTime;
bool whiteChannel;
CRGB color;
} MQTTConfiguration_s;
Expand All @@ -90,7 +89,6 @@ class c_InputEffectEngine : public c_InputCommon
void Process (); ///< Call from loop(), renders Input data
void GetDriverName (String & sDriverName) { sDriverName = "Effects"; } ///< get the name for the instantiated driver
void SetBufferInfo (uint8_t * BufferStart, uint16_t BufferSize);
void ResetBlankTimer ();
void NextEffect ();

// Effect functions
Expand Down Expand Up @@ -120,7 +118,6 @@ class c_InputEffectEngine : public c_InputCommon

uint32_t EffectWait = 32; /* How long to wait for the effect to run again */
timeType EffectLastRun = 0; /* When did the effect last run ? in millis() */
timeType EffectBlankEnd = 0; /* When does the blankout period end */
uint32_t EffectCounter = 0; /* Counter for the number of calls to the active effect */
uint16_t EffectSpeed = 6; /* Externally controlled effect speed 1..10 */
uint16_t EffectDelay = DEFAULT_EFFECT_DELAY; /* Internal representation of speed */
Expand All @@ -129,7 +126,6 @@ class c_InputEffectEngine : public c_InputCommon
bool EffectAllLeds = false; /* Externally controlled effect all leds = 1st led */
bool EffectWhiteChannel = false;
float EffectBrightness = 1.0; /* Externally controlled effect brightness [0, 255] */
uint8_t EffectBlankTime = 0;
CRGB EffectColor = { 183, 0, 255 }; /* Externally controlled effect color */

uint32_t EffectStep = 0; /* Shared mutable effect step counter */
Expand Down
4 changes: 2 additions & 2 deletions ESPixelStick/src/input/InputFPPRemote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,13 @@ void c_InputFPPRemote::StartPlaying (String & FileName)
if (-1 != FileName.indexOf (".pl"))
{
// DEBUG_V ("Start Playlist");
pInputFPPRemotePlayItem = new c_InputFPPRemotePlayList ();
pInputFPPRemotePlayItem = new c_InputFPPRemotePlayList (GetInputChannelId ());
StatusType = F ("PlayList");
}
else
{
// DEBUG_V ("Start Local FSEQ file player");
pInputFPPRemotePlayItem = new c_InputFPPRemotePlayFile ();
pInputFPPRemotePlayItem = new c_InputFPPRemotePlayFile (GetInputChannelId ());
pInputFPPRemotePlayItem->SetSyncOffsetMS (SyncOffsetMS);
StatusType = CN_File;
}
Expand Down
4 changes: 2 additions & 2 deletions ESPixelStick/src/input/InputFPPRemotePlayEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
#include "InputEffectEngine.hpp"

//-----------------------------------------------------------------------------
c_InputFPPRemotePlayEffect::c_InputFPPRemotePlayEffect () :
c_InputFPPRemotePlayItem ()
c_InputFPPRemotePlayEffect::c_InputFPPRemotePlayEffect (c_InputMgr::e_InputChannelIds InputChannelId) :
c_InputFPPRemotePlayItem (InputChannelId)
{
// DEBUG_START;

Expand Down
2 changes: 1 addition & 1 deletion ESPixelStick/src/input/InputFPPRemotePlayEffect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
class c_InputFPPRemotePlayEffect : public c_InputFPPRemotePlayItem
{
public:
c_InputFPPRemotePlayEffect ();
c_InputFPPRemotePlayEffect (c_InputMgr::e_InputChannelIds InputChannelId);
~c_InputFPPRemotePlayEffect ();

virtual void Start (String & FileName, uint32_t duration, uint32_t PlayCount);
Expand Down
4 changes: 2 additions & 2 deletions ESPixelStick/src/input/InputFPPRemotePlayFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
#include "../service/FPPDiscovery.h"

//-----------------------------------------------------------------------------
c_InputFPPRemotePlayFile::c_InputFPPRemotePlayFile () :
c_InputFPPRemotePlayItem ()
c_InputFPPRemotePlayFile::c_InputFPPRemotePlayFile (c_InputMgr::e_InputChannelIds InputChannelId) :
c_InputFPPRemotePlayItem (InputChannelId)
{
// DEBUG_START;

Expand Down
2 changes: 1 addition & 1 deletion ESPixelStick/src/input/InputFPPRemotePlayFile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
class c_InputFPPRemotePlayFile : public c_InputFPPRemotePlayItem
{
public:
c_InputFPPRemotePlayFile ();
c_InputFPPRemotePlayFile (c_InputMgr::e_InputChannelIds InputChannelId);
~c_InputFPPRemotePlayFile ();

virtual void Start (String & FileName, uint32_t FrameId, uint32_t RemainingPlayCount);
Expand Down
2 changes: 1 addition & 1 deletion ESPixelStick/src/input/InputFPPRemotePlayFileFsm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ void fsm_PlayFile_state_PlayingFile::Poll (uint8_t* Buffer, size_t BufferSize)
}
}

InputMgr.ResetBlankTimer ();
InputMgr.RestartBlankTimer (p_InputFPPRemotePlayFile->GetInputChannelId ());

} while (false);

Expand Down
4 changes: 3 additions & 1 deletion ESPixelStick/src/input/InputFPPRemotePlayItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
#include "InputFPPRemotePlayItem.hpp"

//-----------------------------------------------------------------------------
c_InputFPPRemotePlayItem::c_InputFPPRemotePlayItem ()
c_InputFPPRemotePlayItem::c_InputFPPRemotePlayItem (c_InputMgr::e_InputChannelIds _InputChannelId)

{
// DEBUG_START;

InputChannelId = _InputChannelId;

// DEBUG_END;
} // c_InputFPPRemotePlayItem
Expand Down
5 changes: 4 additions & 1 deletion ESPixelStick/src/input/InputFPPRemotePlayItem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@
*/

#include "../ESPixelStick.h"
#include "InputMgr.hpp"

class c_InputFPPRemotePlayItem
{
public:
c_InputFPPRemotePlayItem ();
c_InputFPPRemotePlayItem (c_InputMgr::e_InputChannelIds InputChannelId);
virtual ~c_InputFPPRemotePlayItem ();

virtual void Poll (uint8_t * Buffer, size_t BufferSize) = 0;
Expand All @@ -39,12 +40,14 @@ class c_InputFPPRemotePlayItem
void GetDriverName (String& Name) { Name = "InputMgr"; }
int32_t GetSyncOffsetMS () { return SyncOffsetMS; }
void SetSyncOffsetMS (int32_t value) { SyncOffsetMS = value; }
c_InputMgr::e_InputChannelIds GetInputChannelId () { return InputChannelId; }
protected:
String PlayItemName;
uint32_t RemainingPlayCount = 0;
time_t PlayDurationSec = 0;

private:
int32_t SyncOffsetMS = 0;
c_InputMgr::e_InputChannelIds InputChannelId = c_InputMgr::e_InputChannelIds::InputChannelId_ALL;

}; // c_InputFPPRemotePlayItem
4 changes: 2 additions & 2 deletions ESPixelStick/src/input/InputFPPRemotePlayList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
#include "../service/FPPDiscovery.h"

//-----------------------------------------------------------------------------
c_InputFPPRemotePlayList::c_InputFPPRemotePlayList () :
c_InputFPPRemotePlayItem()
c_InputFPPRemotePlayList::c_InputFPPRemotePlayList (c_InputMgr::e_InputChannelIds InputChannelId) :
c_InputFPPRemotePlayItem(InputChannelId)
{
// DEBUG_START;

Expand Down
Loading

0 comments on commit 6a7752f

Please sign in to comment.