Skip to content

Commit

Permalink
Merge pull request #544 from MartinMueller2003/main
Browse files Browse the repository at this point in the history
Added configurable "Blank" value support to the PWM driver
  • Loading branch information
forkineye authored Jul 1, 2022
2 parents 7ee646f + 5bc6b23 commit 110525c
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 21 deletions.
1 change: 1 addition & 0 deletions ESPixelStick/src/ConstNames.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ const CN_PROGMEM char CN_hadisco [] = "hadisco";
const CN_PROGMEM char CN_haprefix [] = "haprefix";
const CN_PROGMEM char CN_HostName [] = "HostName";
const CN_PROGMEM char CN_hostname [] = "hostname";
const CN_PROGMEM char CN_hv [] = "hv";
const CN_PROGMEM char CN_id [] = "id";
const CN_PROGMEM char CN_Idle [] = "Idle";
const CN_PROGMEM char CN_init [] = "init";
Expand Down
1 change: 1 addition & 0 deletions ESPixelStick/src/ConstNames.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ extern const CN_PROGMEM char CN_haprefix[];
extern const CN_PROGMEM char CN_Heap_colon [];
extern const CN_PROGMEM char CN_HostName [];
extern const CN_PROGMEM char CN_hostname [];
extern const CN_PROGMEM char CN_hv[];
extern const CN_PROGMEM char CN_id[];
extern const CN_PROGMEM char CN_Idle[];
extern const CN_PROGMEM char CN_init[];
Expand Down
4 changes: 0 additions & 4 deletions ESPixelStick/src/WebMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,6 @@ void c_WebMgr::init ()
DefaultHeaders::Instance ().addHeader (F ("Access-Control-Allow-Methods"), "GET, HEAD, POST, PUT, DELETE, CONNECT, OPTIONS, TRACE, PATCH");

// Setup WebSockets
// webSocket.onEvent ([this](AsyncWebSocket* server, AsyncWebSocketClient * client, AwsEventType type, void* arg, uint8_t * data, size_t len)
// {
// this->onWsEvent (server, client, type, arg, data, len);
// });
using namespace std::placeholders;
webSocket.onEvent (std::bind (&c_WebMgr::onWsEvent, this, _1, _2, _3, _4, _5, _6));
webServer.addHandler (&webSocket);
Expand Down
10 changes: 10 additions & 0 deletions ESPixelStick/src/output/OutputCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ c_OutputCommon::~c_OutputCommon ()
// DEBUG_END;
} // ~c_OutputCommon

//-----------------------------------------------------------------------------
void c_OutputCommon::ClearBuffer ()
{
// DEBUG_START;

memset(GetBufferAddress(), 0x00, GetBufferUsedSize());

// DEBUG_END;
} // ClearBuffer

//-----------------------------------------------------------------------------
void c_OutputCommon::GetStatus (JsonObject & jsonStatus)
{
Expand Down
1 change: 1 addition & 0 deletions ESPixelStick/src/output/OutputCommon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class c_OutputCommon
virtual void SetOutputBufferSize (size_t NewOutputBufferSize) { OutputBufferSize = NewOutputBufferSize; };
virtual size_t GetNumChannelsNeeded () = 0;
virtual void PauseOutput (bool State) {}
virtual void ClearBuffer ();
virtual void WriteChannelData (size_t StartChannelId, size_t ChannelCount, byte *pSourceData);
virtual void ReadChannelData (size_t StartChannelId, size_t ChannelCount, byte *pTargetData);

Expand Down
8 changes: 7 additions & 1 deletion ESPixelStick/src/output/OutputMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1392,7 +1392,13 @@ void c_OutputMgr::ClearBuffer()
{
// DEBUG_START;

memset(OutputBuffer, 0x00, sizeof(OutputBuffer));
for (auto & currentOutputChannelDriver : OutputChannelDrivers)
{
if(nullptr != currentOutputChannelDriver.pOutputChannelDriver)
{
currentOutputChannelDriver.pOutputChannelDriver->ClearBuffer();
}
}

// DEBUG_END;

Expand Down
22 changes: 21 additions & 1 deletion ESPixelStick/src/output/OutputServoPCA9685.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,18 @@ c_OutputServoPCA9685::c_OutputServoPCA9685 (c_OutputMgr::e_OutputChannelIds Outp
{
// DEBUG_START;

for (ServoPCA9685Channel_t & currentServoPCA9685Channel : OutputList)
uint32_t id = 0;
for (ServoPCA9685Channel_t &currentServoPCA9685Channel : OutputList)
{
currentServoPCA9685Channel.Id - id++;
currentServoPCA9685Channel.Enabled = false;
currentServoPCA9685Channel.MinLevel = SERVO_PCA9685_OUTPUT_MIN_PULSE_WIDTH;
currentServoPCA9685Channel.MaxLevel = SERVO_PCA9685_OUTPUT_MAX_PULSE_WIDTH;
currentServoPCA9685Channel.PreviousValue = 0;
currentServoPCA9685Channel.IsReversed = false;
currentServoPCA9685Channel.Is16Bit = false;
currentServoPCA9685Channel.IsScaled = true;
currentServoPCA9685Channel.HomeValue = 0;
}

// DEBUG_END;
Expand Down Expand Up @@ -82,6 +85,21 @@ void c_OutputServoPCA9685::Begin ()
// DEBUG_END;
} // Begin

//-----------------------------------------------------------------------------
void c_OutputServoPCA9685::ClearBuffer ()
{
// DEBUG_START;

// memset(GetBufferAddress(), 0x00, GetBufferUsedSize());
for (ServoPCA9685Channel_t & currentServoPCA9685Channel : OutputList)
{
GetBufferAddress()[currentServoPCA9685Channel.Id] =
currentServoPCA9685Channel.HomeValue;
}

// DEBUG_END;
} // ClearBuffer

//----------------------------------------------------------------------------
bool c_OutputServoPCA9685::validate ()
{
Expand Down Expand Up @@ -173,6 +191,7 @@ bool c_OutputServoPCA9685::SetConfig (ArduinoJson::JsonObject & jsonConfig)
setFromJSON (CurrentOutputChannel->IsReversed, JsonChannelData, OM_SERVO_PCA9685_CHANNEL_REVERSED);
setFromJSON (CurrentOutputChannel->Is16Bit, JsonChannelData, OM_SERVO_PCA9685_CHANNEL_16BITS);
setFromJSON (CurrentOutputChannel->IsScaled, JsonChannelData, OM_SERVO_PCA9685_CHANNEL_SCALED);
setFromJSON (CurrentOutputChannel->HomeValue, JsonChannelData, OM_SERVO_PCA9685_CHANNEL_HOME);

// DEBUG_V (String ("ChannelId: ") + String (ChannelId));
// DEBUG_V (String (" Enabled: ") + String (CurrentOutputChannel->Enabled));
Expand Down Expand Up @@ -213,6 +232,7 @@ void c_OutputServoPCA9685::GetConfig (ArduinoJson::JsonObject & jsonConfig)
JsonChannelData[OM_SERVO_PCA9685_CHANNEL_REVERSED] = currentServoPCA9685.IsReversed;
JsonChannelData[OM_SERVO_PCA9685_CHANNEL_16BITS] = currentServoPCA9685.Is16Bit;
JsonChannelData[OM_SERVO_PCA9685_CHANNEL_SCALED] = currentServoPCA9685.IsScaled;
JsonChannelData[OM_SERVO_PCA9685_CHANNEL_HOME] = currentServoPCA9685.HomeValue;

// DEBUG_V (String ("ChannelId: ") + String (ChannelId));
// DEBUG_V (String (" Enabled: ") + String (currentServoPCA9685.Enabled));
Expand Down
8 changes: 7 additions & 1 deletion ESPixelStick/src/output/OutputServoPCA9685.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,22 @@ class c_OutputServoPCA9685 : public c_OutputCommon
#define SERVO_PCA9685_OUTPUT_MIN_PULSE_WIDTH 650
#define SERVO_PCA9685_OUTPUT_MAX_PULSE_WIDTH 2350

public: typedef struct ServoPCA9685Channel_s
typedef struct ServoPCA9685Channel_s
{
uint8_t Id = -1;
bool Enabled = false;
uint16_t MinLevel = SERVO_PCA9685_OUTPUT_MIN_PULSE_WIDTH;
uint16_t MaxLevel = SERVO_PCA9685_OUTPUT_MAX_PULSE_WIDTH;
uint16_t PreviousValue = 0;
bool IsReversed = false;
bool Is16Bit = false;
bool IsScaled = true;
uint8_t HomeValue = 0;

} ServoPCA9685Channel_t;

public:

// These functions are inherited from c_OutputCommon
c_OutputServoPCA9685 (c_OutputMgr::e_OutputChannelIds OutputChannelId,
gpio_num_t outputGpio,
Expand All @@ -56,6 +60,7 @@ public: typedef struct ServoPCA9685Channel_s
void GetDriverName (String& sDriverName);
void GetStatus (ArduinoJson::JsonObject & jsonStatus) { c_OutputCommon::GetStatus (jsonStatus); }
size_t GetNumChannelsNeeded () { return Num_Channels; }
void ClearBuffer();

private:
# define OM_SERVO_PCA9685_CHANNEL_LIMIT 16
Expand All @@ -69,6 +74,7 @@ public: typedef struct ServoPCA9685Channel_s
# define OM_SERVO_PCA9685_CHANNEL_REVERSED CN_rev
# define OM_SERVO_PCA9685_CHANNEL_16BITS CN_b16
# define OM_SERVO_PCA9685_CHANNEL_SCALED CN_sca
# define OM_SERVO_PCA9685_CHANNEL_HOME CN_hv
# define SERVO_PCA9685_UPDATE_FREQUENCY 50

bool validate ();
Expand Down
33 changes: 19 additions & 14 deletions html/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -672,25 +672,29 @@ function ProcessModeConfigurationDataServoPCA9685(ServoConfig)
let EnabledPattern = '<td><input type="checkbox" id="ServoEnabled_' + (CurrentRowId) + '"></td>';
let MinLevelPattern = '<td><input type="number" id="ServoMinLevel_' + (CurrentRowId) + '"step="1" min="10" max="4095" value="0" class="form-control is-valid"></td>';
let MaxLevelPattern = '<td><input type="number" id="ServoMaxLevel_' + (CurrentRowId) + '"step="1" min="10" max="4095" value="0" class="form-control is-valid"></td>';
let RestingPattern = '<td><input type="number" id="ServoHomeValue_' + (CurrentRowId) + '"step="1" min="0" max="255" value="0" class="form-control is-valid"></td>';
let DataType = '<td><select class="form-control is-valid" id="ServoDataType_' + (CurrentRowId) + '" title="Effect to generate"></select></td>';

let rowPattern = '<tr>' + ChanIdPattern + EnabledPattern + MinLevelPattern + MaxLevelPattern + DataType + RestingPattern + '</tr>';

let rowPattern = '<tr>' + ChanIdPattern + EnabledPattern + MinLevelPattern + MaxLevelPattern + DataType + '</tr>';
$('#servo_pca9685channelconfigurationtable tr:last').after(rowPattern);

$('#ServoChanId_' + CurrentRowId).attr('style', $('#ServoChanId_hr').attr('style'));
$('#ServoEnabled_' + CurrentRowId).attr('style', $('#ServoEnabled_hr').attr('style'));
$('#ServoMinLevel_' + CurrentRowId).attr('style', $('#ServoMinLevel_hr').attr('style'));
$('#ServoMaxLevel_' + CurrentRowId).attr('style', $('#ServoMaxLevel_hr').attr('style'));
$('#ServoDataType_' + CurrentRowId).attr('style', $('#ServoDataType_hr').attr('style'));
$('#ServoChanId_' + CurrentRowId).attr('style', $('#ServoChanId_hr').attr('style'));
$('#ServoEnabled_' + CurrentRowId).attr('style', $('#ServoEnabled_hr').attr('style'));
$('#ServoMinLevel_' + CurrentRowId).attr('style', $('#ServoMinLevel_hr').attr('style'));
$('#ServoMaxLevel_' + CurrentRowId).attr('style', $('#ServoMaxLevel_hr').attr('style'));
$('#ServoHomeValue_' + CurrentRowId).attr('style', $('#ServoHomeValue_hr').attr('style'));
$('#ServoDataType_' + CurrentRowId).attr('style', $('#ServoDataType_hr').attr('style'));
}

$.each(ChannelConfigs, function (i, CurrentChannelConfig) {
// console.log("Current Channel Id = " + CurrentChannelConfig.id);
let currentChannelRowId = CurrentChannelConfig.id + 1;
$('#ServoChanId_' + (currentChannelRowId)).html(currentChannelRowId);
$('#ServoEnabled_' + (currentChannelRowId)).prop("checked", CurrentChannelConfig.en);
$('#ServoMinLevel_' + (currentChannelRowId)).val(CurrentChannelConfig.Min);
$('#ServoMaxLevel_' + (currentChannelRowId)).val(CurrentChannelConfig.Max);
$('#ServoChanId_' + (currentChannelRowId)).html(currentChannelRowId);
$('#ServoEnabled_' + (currentChannelRowId)).prop("checked", CurrentChannelConfig.en);
$('#ServoMinLevel_' + (currentChannelRowId)).val(CurrentChannelConfig.Min);
$('#ServoMaxLevel_' + (currentChannelRowId)).val(CurrentChannelConfig.Max);
$('#ServoHomeValue_' + (currentChannelRowId)).val(CurrentChannelConfig.hv);

let jqSelector = "#ServoDataType_" + (currentChannelRowId);

Expand Down Expand Up @@ -1115,11 +1119,12 @@ function ExtractChannelConfigFromHtmlPage(JsonConfig, SectionName)
ChannelConfig.updateinterval = parseInt($('#updateinterval').val(), 10);
$.each(ChannelConfig.channels, function (i, CurrentChannelConfig) {
// console.info("Current Channel Id = " + CurrentChannelConfig.id);
let currentChannelRowId = CurrentChannelConfig.id + 1;
let currentChannelRowId = CurrentChannelConfig.id + 1;
CurrentChannelConfig.en = $('#ServoEnabled_' + (currentChannelRowId)).prop("checked");
CurrentChannelConfig.Min = parseInt($('#ServoMinLevel_' + (currentChannelRowId)).val(), 10);
CurrentChannelConfig.Max = parseInt($('#ServoMaxLevel_' + (currentChannelRowId)).val(), 10);
let ServoDataType = parseInt($('#ServoDataType_' + (currentChannelRowId)).val(), 10);
CurrentChannelConfig.Min = parseInt($('#ServoMinLevel_' + (currentChannelRowId)).val(), 10);
CurrentChannelConfig.Max = parseInt($('#ServoMaxLevel_' + (currentChannelRowId)).val(), 10);
CurrentChannelConfig.hv = parseInt($('#ServoHomeValue_' + (currentChannelRowId)).val(), 10);
let ServoDataType = parseInt($('#ServoDataType_' + (currentChannelRowId)).val(), 10);

CurrentChannelConfig.rev = (ServoDataType & 0x01) ? true : false;
CurrentChannelConfig.sca = (ServoDataType & 0x02) ? true : false;
Expand Down
1 change: 1 addition & 0 deletions html/servo_pca9685.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<th id="ServoMinLevel_hr">Min Pulse Width</th>
<th id="ServoMaxLevel_hr">Max Pulse Width</th>
<th id="ServoDataType_hr">Input Data Type</th>
<th id="ServoHomeValue_hr">Resting Data value</th>
</tr>
</thead>
<tbody id="servo_pca9685channelconfigurationtable">
Expand Down

0 comments on commit 110525c

Please sign in to comment.