Skip to content

Commit

Permalink
Merge pull request #572 from MartinMueller2003/main
Browse files Browse the repository at this point in the history
Fixed bug that routed fseq channel data around zigzag and group pixel processing
  • Loading branch information
forkineye committed Oct 29, 2022
2 parents 2b2ad25 + 71e004f commit d0f1d48
Show file tree
Hide file tree
Showing 20 changed files with 1,322 additions and 1,091 deletions.
4 changes: 3 additions & 1 deletion ESPixelStick/ESPixelStick.ino
Expand Up @@ -92,6 +92,7 @@ bool ResetWiFi = false;
bool IsBooting = true; // Configuration initialization flag
bool ConfigLoadNeeded = false;
bool ConfigSaveNeeded = false;
uint32_t DiscardedRxData = 0;

/////////////////////////////////////////////////////////
//
Expand Down Expand Up @@ -340,7 +341,7 @@ void deserializeCoreHandler (DynamicJsonDocument & jsonDoc)

// extern void PrettyPrint(DynamicJsonDocument & jsonStuff, String Name);
// PrettyPrint(jsonDoc, "deserializeCoreHandler");

JsonObject json = jsonDoc.as<JsonObject>();
deserializeCore (json);

Expand Down Expand Up @@ -467,6 +468,7 @@ void loop()

// need to keep the rx pipeline empty
size_t BytesToDiscard = min (100, LOG_PORT.available ());
DiscardedRxData += BytesToDiscard;
while (0 < BytesToDiscard)
{
FeedWDT ();
Expand Down
1 change: 1 addition & 0 deletions ESPixelStick/src/ConstNames.cpp
Expand Up @@ -163,6 +163,7 @@ const CN_PROGMEM char CN_stars [] = "***";
const CN_PROGMEM char CN_state [] = "state";
const CN_PROGMEM char CN_status [] = "status";
const CN_PROGMEM char CN_status_name [] = "status_name";
const CN_PROGMEM char CN_StayInApMode [] = "StayInApMode";
const CN_PROGMEM char CN_subnet [] = "subnet";
const CN_PROGMEM char CN_SyncOffset [] = "SyncOffset";
const CN_PROGMEM char CN_system [] = "system";
Expand Down
1 change: 1 addition & 0 deletions ESPixelStick/src/ConstNames.hpp
Expand Up @@ -172,6 +172,7 @@ extern const CN_PROGMEM char CN_stars[];
extern const CN_PROGMEM char CN_state[];
extern const CN_PROGMEM char CN_status [];
extern const CN_PROGMEM char CN_status_name[];
extern const CN_PROGMEM char CN_StayInApMode [];
extern const CN_PROGMEM char CN_subnet[];
extern const CN_PROGMEM char CN_SyncOffset[];
extern const CN_PROGMEM char CN_system[];
Expand Down
1 change: 1 addition & 0 deletions ESPixelStick/src/ESPixelStick.h
Expand Up @@ -75,6 +75,7 @@ extern bool IsBooting;
extern bool ResetWiFi;
static const String ConfigFileName = "/config.json";
extern void FeedWDT ();
extern uint32_t DiscardedRxData;

template <typename J, typename N>
bool setFromJSON (float & OutValue, J& Json, N Name)
Expand Down
6 changes: 6 additions & 0 deletions ESPixelStick/src/GPIO_Defs.hpp
Expand Up @@ -102,6 +102,8 @@ typedef enum
# include "platformDefinitions/GPIO_Defs_ESP32_QUINLED_UNO.hpp"
#elif defined (BOARD_ESP32_QUINLED_UNO_AE_PLUS)
# include "platformDefinitions/GPIO_Defs_ESP32_QUINLED_UNO_AE_Plus.hpp"
#elif defined (BOARD_ESP32_QUINLED_UNO_ESPSV3)
# include "platformDefinitions/GPIO_Defs_ESP32_QUINLED_UNO_ESPSV3.hpp"
#elif defined (BOARD_ESP32_QUINLED_UNO_ETH_ESPSV3)
# include "platformDefinitions/GPIO_Defs_ESP32_QUINLED_UNO_ETH_ESPSV3.hpp"
#elif defined (BOARD_ESP32_TTGO_T8)
Expand All @@ -127,3 +129,7 @@ typedef enum
#else
# error "No valid platform definition"
#endif // ndef platform specific GPIO definitions

#if defined(SUPPORT_SD) || defined(SUPPORT_SD_MMC)
# define SUPPORT_FPP
#endif // defined(SUPPORT_SD) || defined(SUPPORT_SD_MMC)
1 change: 1 addition & 0 deletions ESPixelStick/src/WebMgr.cpp
Expand Up @@ -678,6 +678,7 @@ void c_WebMgr::ProcessXJRequest (AsyncWebSocketClient* client)
system[F ("freeheap")] = ESP.getFreeHeap ();
system[F ("uptime")] = millis ();
system[F ("SDinstalled")] = FileMgr.SdCardIsInstalled ();
system[F ("DiscardedRxData")] = DiscardedRxData;

// DEBUG_V ("");

Expand Down
2 changes: 1 addition & 1 deletion ESPixelStick/src/input/InputFPPRemotePlayFile.cpp
Expand Up @@ -470,7 +470,7 @@ void c_InputFPPRemotePlayFile::ClearFileInfo()
uint32_t c_InputFPPRemotePlayFile::ReadFile(uint32_t DestinationIntensityId, uint32_t NumBytesToRead, uint32_t FileOffset)
{
// DEBUG_START;
#define WRITE_DIRECT_TO_OUTPUT_BUFFER
// #define WRITE_DIRECT_TO_OUTPUT_BUFFER
#ifdef WRITE_DIRECT_TO_OUTPUT_BUFFER
uint32_t NumBytesRead = FileMgr.ReadSdFile(FileHandleForFileBeingPlayed,
OutputMgr.GetBufferAddress(),
Expand Down
4 changes: 0 additions & 4 deletions ESPixelStick/src/input/InputMgr.hpp
Expand Up @@ -63,10 +63,6 @@ class c_InputMgr
void RestartBlankTimer (c_InputMgr::e_InputChannelIds Selector) { BlankEndTime[int(Selector)] = (millis () / 1000) + config.BlankDelay; }
bool BlankTimerHasExpired (c_InputMgr::e_InputChannelIds Selector) { return !(BlankEndTime[int(Selector)] > (millis () / 1000)); }

#if defined(SUPPORT_SD) || defined(SUPPORT_SD_MMC)
# define SUPPORT_FPP
#endif // defined(SUPPORT_SD) || defined(SUPPORT_SD_MMC)

enum e_InputType
{
InputType_E1_31 = 0,
Expand Down
41 changes: 30 additions & 11 deletions ESPixelStick/src/network/WiFiDriver.cpp
Expand Up @@ -241,7 +241,7 @@ void c_WiFiDriver::connectWifi (const String & current_ssid, const String & curr
WiFi.enableAP(false);
// DEBUG_V();
WiFi.enableSTA(true);

#endif
// DEBUG_V (String (" ssid: ") + current_ssid);
// DEBUG_V (String ("passphrase: ") + current_passphrase);
Expand Down Expand Up @@ -319,11 +319,12 @@ void c_WiFiDriver::GetConfig (JsonObject& json)
json[CN_gateway] = gateway.toString ();
#endif // !def ARDUINO_ARCH_ESP8266

json[CN_dhcp] = UseDhcp;
json[CN_sta_timeout] = sta_timeout;
json[CN_ap_fallback] = ap_fallbackIsEnabled;
json[CN_ap_timeout] = ap_timeout;
json[CN_ap_reboot] = RebootOnWiFiFailureToConnect;
json[CN_StayInApMode] = StayInApMode;
json[CN_dhcp] = UseDhcp;
json[CN_sta_timeout] = sta_timeout;
json[CN_ap_fallback] = ap_fallbackIsEnabled;
json[CN_ap_timeout] = ap_timeout;
json[CN_ap_reboot] = RebootOnWiFiFailureToConnect;

// DEBUG_END;

Expand Down Expand Up @@ -475,6 +476,7 @@ bool c_WiFiDriver::SetConfig (JsonObject & json)
ConfigChanged |= setFromJSON (ap_fallbackIsEnabled, json, CN_ap_fallback);
ConfigChanged |= setFromJSON (ap_timeout, json, CN_ap_timeout);
ConfigChanged |= setFromJSON (RebootOnWiFiFailureToConnect, json, CN_ap_reboot);
ConfigChanged |= setFromJSON (StayInApMode, json, CN_StayInApMode);

// DEBUG_V (" ip: " + ip);
// DEBUG_V ("gateway: " + gateway);
Expand Down Expand Up @@ -762,8 +764,11 @@ void fsm_WiFi_state_ConnectingAsAP::Poll ()
{
if (millis () - pWiFiDriver->GetFsmStartTime () > (1000 * pWiFiDriver->Get_ap_timeout ()))
{
logcon (F ("WiFi STA Failed to connect"));
fsm_WiFi_state_ConnectionFailed_imp.Init ();
if( false == pWiFiDriver->Get_ap_StayInApMode())
{
logcon (F ("WiFi STA Failed to connect"));
fsm_WiFi_state_ConnectionFailed_imp.Init ();
}
}
}

Expand All @@ -779,7 +784,7 @@ void fsm_WiFi_state_ConnectingAsAP::Init ()
pWiFiDriver->SetFsmState (this);
pWiFiDriver->AnnounceState ();

if (true == pWiFiDriver->Get_ap_fallbackIsEnabled())
if (true == pWiFiDriver->Get_ap_fallbackIsEnabled() || pWiFiDriver->Get_ap_StayInApMode())
{
WiFi.enableSTA(false);
WiFi.enableAP(true);
Expand Down Expand Up @@ -880,7 +885,14 @@ void fsm_WiFi_state_ConnectedToSta::Poll ()
if (0 == WiFi.softAPgetStationNum ())
{
logcon (F ("WiFi Lost the connection to the STA"));
fsm_WiFi_state_ConnectionFailed_imp.Init ();
if(pWiFiDriver->Get_ap_StayInApMode())
{
fsm_WiFi_state_ConnectingAsAP_imp.Init ();
}
else
{
fsm_WiFi_state_ConnectionFailed_imp.Init ();
}
}

/// DEBUG_END;
Expand Down Expand Up @@ -915,7 +927,14 @@ void fsm_WiFi_state_ConnectedToSta::OnDisconnect ()
// DEBUG_START;

logcon (F ("WiFi STA Disconnected"));
fsm_WiFi_state_ConnectionFailed_imp.Init ();
if(pWiFiDriver->Get_ap_StayInApMode())
{
fsm_WiFi_state_ConnectingAsAP_imp.Init ();
}
else
{
fsm_WiFi_state_ConnectionFailed_imp.Init ();
}

// DEBUG_END;

Expand Down
3 changes: 3 additions & 0 deletions ESPixelStick/src/network/WiFiDriver.hpp
Expand Up @@ -77,6 +77,7 @@ class c_WiFiDriver
uint32_t Get_sta_timeout () { return sta_timeout; }
uint32_t Get_ap_timeout () { return ap_timeout; }
bool Get_ap_fallbackIsEnabled () { return ap_fallbackIsEnabled; }
bool Get_ap_StayInApMode () { return StayInApMode; }
bool Get_RebootOnWiFiFailureToConnect () { return RebootOnWiFiFailureToConnect; }
String GetConfig_ssid () { return ssid; }
String GetConfig_passphrase () { return passphrase; }
Expand Down Expand Up @@ -110,6 +111,8 @@ class c_WiFiDriver
bool ap_fallbackIsEnabled = true;
uint32_t ap_timeout = AP_TIMEOUT; ///< How long to wait in AP mode with no connection before rebooting
uint32_t sta_timeout = CLIENT_TIMEOUT; ///< Timeout when connection as client (station)
bool StayInApMode = false;

#ifdef SUPPORT_ETHERNET
bool RebootOnWiFiFailureToConnect = false;
#else
Expand Down
1 change: 1 addition & 0 deletions ESPixelStick/src/output/OutputCommon.hpp
Expand Up @@ -48,6 +48,7 @@ class c_OutputCommon
OID_t GetOutputChannelId () { return OutputChannelId; } ///< return the output channel number
uint8_t * GetBufferAddress () { return pOutputBuffer;} ///< Get the address of the buffer into which the E1.31 handler will stuff data
uint32_t GetBufferUsedSize () { return OutputBufferSize;} ///< Get the address of the buffer into which the E1.31 handler will stuff data
gpio_num_t GetOutputGpio () { return DataPin; }
OTYPE_t GetOutputType () { return OutputType; } ///< Have the instance report its type.
virtual void GetStatus (ArduinoJson::JsonObject & jsonStatus);
void SetOutputBufferAddress (uint8_t* pNewOutputBuffer) { pOutputBuffer = pNewOutputBuffer; }
Expand Down
47 changes: 47 additions & 0 deletions ESPixelStick/src/output/OutputMgr.cpp
Expand Up @@ -126,6 +126,10 @@ typedef struct
//-----------------------------------------------------------------------------
static const OutputChannelIdToGpioAndPortEntry_t OutputChannelIdToGpioAndPort[] =
{
#ifdef DEFAULT_UART_0_GPIO
{DEFAULT_UART_0_GPIO, UART_NUM_0, c_OutputMgr::OM_PortType_t::Uart},
#endif // def DEFAULT_UART_0_GPIO

#ifdef DEFAULT_UART_1_GPIO
{DEFAULT_UART_1_GPIO, UART_NUM_1, c_OutputMgr::OM_PortType_t::Uart},
#endif // def DEFAULT_UART_1_GPIO
Expand Down Expand Up @@ -514,6 +518,7 @@ void c_OutputMgr::InstantiateNewOutputChannel(DriverInfo_t & CurrentOutputChanne
{
logcon(String(F(" Shutting Down '")) + DriverName + String(F("' on Output: ")) + String(CurrentOutputChannelDriver.DriverId));
}

delete CurrentOutputChannelDriver.pOutputChannelDriver;
CurrentOutputChannelDriver.pOutputChannelDriver = nullptr;
// DEBUG_V ();
Expand Down Expand Up @@ -1120,6 +1125,8 @@ bool c_OutputMgr::ProcessJsonConfig (JsonObject& jsonConfig)

UpdateDisplayBufferReferences ();

SetSerialUart();

// DEBUG_END;
return Response;

Expand Down Expand Up @@ -1182,6 +1189,46 @@ void c_OutputMgr::SetConfig(ArduinoJson::JsonDocument & ConfigData)

} // SaveConfig

//-----------------------------------------------------------------------------
void c_OutputMgr::SetSerialUart()
{
// DEBUG_START;

bool NeedToTurnOffSerial = false;

for (auto & CurrentOutputChannelDriver : OutputChannelDrivers)
{
// DEBUG_V();
if(e_OutputType::OutputType_Disabled != CurrentOutputChannelDriver.pOutputChannelDriver->GetOutputType() &&
(ConsoleTxGpio == CurrentOutputChannelDriver.pOutputChannelDriver->GetOutputGpio() ||
ConsoleRxGpio == CurrentOutputChannelDriver.pOutputChannelDriver->GetOutputGpio()))
{
// DEBUG_V("Found port that needs Serial turned off");
NeedToTurnOffSerial = true;
}
} // end for each channel

// DEBUG_V(String("NeedToTurnOffSerial: ") + String(NeedToTurnOffSerial));
// DEBUG_V(String(" SerialUartIsActive: ") + String(SerialUartIsActive));
if(NeedToTurnOffSerial && SerialUartIsActive)
{
// DEBUG_V("Turn OFF Serial");
Serial.end();
SerialUartIsActive = false;
}
else if(!NeedToTurnOffSerial && !SerialUartIsActive)
{
Serial.begin(115200);
SerialUartIsActive = true;
// DEBUG_V("Turn ON Serial");
}
else
{
// DEBUG_V("Leave Serial Alone");
}

// DEBUG_END;
}
//-----------------------------------------------------------------------------
///< Called from loop(), renders output data
void c_OutputMgr::Render()
Expand Down
12 changes: 10 additions & 2 deletions ESPixelStick/src/output/OutputMgr.hpp
Expand Up @@ -51,8 +51,8 @@ class c_OutputMgr
void GetStatus (JsonObject & jsonStatus);
void GetPortCounts (uint16_t& PixelCount, uint16_t& SerialCount) {PixelCount = uint16_t(OutputChannelId_End); SerialCount = uint16_t(NUM_UARTS); }
uint8_t* GetBufferAddress () { return OutputBuffer; } ///< Get the address of the buffer into which the E1.31 handler will stuff data
uint32_t GetBufferUsedSize () { return UsedBufferSize; } ///< Get the size (in intensities) of the buffer into which the E1.31 handler will stuff data
uint32_t GetBufferSize () { return sizeof(OutputBuffer); } ///< Get the size (in intensities) of the buffer into which the E1.31 handler will stuff data
uint32_t GetBufferUsedSize () { return UsedBufferSize; } ///< Get the size (in intensities) of the buffer into which the E1.31 handler will stuff data
uint32_t GetBufferSize () { return sizeof(OutputBuffer); } ///< Get the size (in intensities) of the buffer into which the E1.31 handler will stuff data
void DeleteConfig () { FileMgr.DeleteConfigFile (ConfigFileName); }
void PauseOutputs (bool NewState);
void GetDriverName (String & Name) { Name = "OutputMgr"; }
Expand All @@ -63,6 +63,10 @@ class c_OutputMgr
// handles to determine which output channel we are dealing with
enum e_OutputChannelIds
{
#ifdef DEFAULT_UART_0_GPIO
OutputChannelId_UART_0,
#endif // def DEFAULT_UART_0_GPIO

#ifdef DEFAULT_UART_1_GPIO
OutputChannelId_UART_1,
#endif // def DEFAULT_UART_1_GPIO
Expand Down Expand Up @@ -235,11 +239,15 @@ class c_OutputMgr
void UpdateDisplayBufferReferences (void);
void InstantiateNewOutputChannel(DriverInfo_t &ChannelIndex, e_OutputType NewChannelType, bool StartDriver = true);
void CreateNewConfig();
void SetSerialUart();

String ConfigFileName;

uint8_t OutputBuffer[OM_MAX_NUM_CHANNELS];
uint32_t UsedBufferSize = 0;
gpio_num_t ConsoleTxGpio = gpio_num_t::GPIO_NUM_1;
gpio_num_t ConsoleRxGpio = gpio_num_t::GPIO_NUM_3;
bool SerialUartIsActive = true;

#define OM_IS_UART (CurrentOutputChannelDriver.PortType == OM_PortType_t::Uart)
#define OM_IS_RMT (CurrentOutputChannelDriver.PortType == OM_PortType_t::Rmt)
Expand Down
16 changes: 10 additions & 6 deletions ESPixelStick/src/output/OutputPixel.cpp
Expand Up @@ -636,29 +636,33 @@ inline uint32_t c_OutputPixel::CalculateIntensityOffset(uint32_t ChannelId)
{
// DEBUG_START;

// DEBUG_V(String(" ChannelId: 0x") + String(ChannelId, HEX));
// DEBUG_V(String(" ChannelId: ") + String(ChannelId));
uint32_t PixelId = ChannelId / uint32_t(NumIntensityBytesPerPixel);
// DEBUG_V(String(" PixelId: 0x") + String(PixelId, HEX));
// DEBUG_V(String(" PixelId0: ") + String(PixelId));

// are we doing a zig zag operation?
if ((zig_size > 1) && (PixelId >= zig_size))
{
// DEBUG_V(String(" zig_size: 0x") + String(zig_size, HEX));
// DEBUG_V(String(" PixelId1: ") + String(PixelId));
// DEBUG_V(String(" zig_size: ") + String(zig_size));
uint32_t ZigZagGroupId = PixelId / zig_size;
// DEBUG_V(String(" ZigZagGroupId: 0x") + String(ZigZagGroupId, HEX));
// DEBUG_V(String(" ZigZagGroupId: ") + String(ZigZagGroupId));

// is this a backwards group
if (0 != (ZigZagGroupId & 0x1))
{
// DEBUG_V("Backwards Group");
uint32_t zigoffset = PixelId % zig_size;
// DEBUG_V(String(" zigoffset: 0x") + String(zigoffset, HEX));
// DEBUG_V(String(" zigoffset: ") + String(zigoffset));
uint32_t BaseGroupPixelId = ZigZagGroupId * zig_size;
// DEBUG_V(String(" BaseGroupPixelId1: ") + String(BaseGroupPixelId));
PixelId = BaseGroupPixelId + (zig_size - 1) - zigoffset;
// DEBUG_V(String(" BaseGroupPixelId: 0x") + String(BaseGroupPixelId, HEX));
// DEBUG_V(String(" BaseGroupPixelId2: ") + String(BaseGroupPixelId));
// DEBUG_V(String(" PixelId: 0x") + String(PixelId, HEX));
}
// DEBUG_V(String(" PixelId2: ") + String(PixelId));
}
// DEBUG_V(String(" Final PixelId: ") + String(PixelId));

uint32_t ColorOrderIndex = ChannelId % NumIntensityBytesPerPixel;
if (uint32_t(NumIntensityBytesPerPixel) > ChannelId)
Expand Down

0 comments on commit d0f1d48

Please sign in to comment.