Skip to content

Commit

Permalink
Plugin slots can be disabled or enabled. A disabled plugin slot will …
Browse files Browse the repository at this point in the history
…not be considered by the slot scheduler. If an active slot is disabled, it will be automatically move to the next slot. If a slot is sticky, it can't be disabled.

#197
  • Loading branch information
BlueAndi committed Oct 25, 2024
1 parent ebade06 commit 1aa91f4
Show file tree
Hide file tree
Showing 23 changed files with 1,096 additions and 250 deletions.
63 changes: 61 additions & 2 deletions data/display.html
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,8 @@ <h1 class="mt-5">Display</h1>
var $inputGroupAlias = null;
var $divDuration = null;
var $inputDuration = null;
var $buttonSlotStatus = null;
var $buttonStickyFlag = null;
var $divDuration = null;
var $durationUnit = null;
var $dragableSlot = null;
Expand Down Expand Up @@ -448,7 +450,7 @@ <h1 class="mt-5">Display</h1>
if (false === rsp.slots[index].isSticky) {
$divSlot.attr("class", "divSlot locked");
} else {
$divSlot.attr("class", "divSlot lockedAndsticky");
$divSlot.attr("class", "divSlot lockedAndSticky");
}
}

Expand All @@ -470,10 +472,25 @@ <h1 class="mt-5">Display</h1>
.attr("class", "input-group-text")
.append("[s]");

$buttonStickyFlag = $("<button>")
.attr("class", "btn btn-dark")
.attr("id", "sticky" + index)
.attr("onclick", "handleStickySlot(" + index + ")")
.text((false === rsp.slots[index].isSticky) ? "-" : "S");

$buttonSlotStatus = $("<button>")
.attr("class", "btn btn-dark")
.attr("id", "slotStatus" + index)
.attr("type", "button")
.attr("onclick", "handleSlotStatus(" + index + ")")
.text((false === rsp.slots[index].isDisabled) ? "✓" : "-");

$divDuration = $("<div>")
.attr("class", "input-group")
.append($inputDuration)
.append($durationUnit);
.append($durationUnit)
.append($buttonStickyFlag)
.append($buttonSlotStatus);

$header.append($divDuration);

Expand Down Expand Up @@ -592,6 +609,48 @@ <h1 class="mt-5">Display</h1>
});
}

function handleSlotStatus(slotId) {
var statusStr = $("#slotStatus" + slotId).text();
var isDisabled = ("✓" === statusStr) ? true : false;

disableUI();

return wsClient.setSlot({
slotId: slotId,
isDisabled: isDisabled
}).then(function(rsp) {
return updateSlotInfo();
}).catch(function(err) {
if ("undefined" !== typeof err) {
console.error(err);
}
return dialog.showError("<p>Failed.</p>");
}).finally(function() {
enableUI();
});
}

function handleStickySlot(slotId) {
var stickyStr = $("#sticky" + slotId).text();
var sticky = ("-" === stickyStr) ? true : false;

disableUI();

return wsClient.setSlot({
slotId: slotId,
sticky: sticky
}).then(function(rsp) {
return updateSlotInfo();
}).catch(function(err) {
if ("undefined" !== typeof err) {
console.error(err);
}
return dialog.showError("<p>Failed.</p>");
}).finally(function() {
enableUI();
});
}

function updateBrightness() {
var brightnessInPercent = (brightness * 100 / 255).toFixed(2);
$("#brightness").text("" + brightnessInPercent + " %");
Expand Down
51 changes: 49 additions & 2 deletions data/js/ws.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,18 +210,29 @@ pixelix.ws.Client.prototype._onMessage = function(msg) {
} else if ("SLOT_DURATION" === this._pendingCmd.name) {
rsp.duration = parseInt(data[0]);
this._pendingCmd.resolve(rsp);
} else if ("SLOT" === this._pendingCmd.name) {
rsp.slotId = parseInt(data[0]);
rsp.name = data[1].substring(1, data[1].length - 1),
rsp.uid = parseInt(data[2]),
rsp.alias = data[3].substring(1, data[3].length - 1),
rsp.isLocked = (0 == parseInt(data[4])) ? false : true,
rsp.isSticky = (0 == parseInt(data[5])) ? false : true,
rsp.isDisabled = (0 == parseInt(data[6])) ? false : true,
rsp.duration = parseInt(data[7])
this._pendingCmd.resolve(rsp);
} else if ("SLOTS" === this._pendingCmd.name) {
rsp.maxSlots = parseInt(data.shift());
rsp.slots = [];
elements = 6;
elements = 7;
for(index = 0; index < (data.length / elements); ++index) {
rsp.slots.push({
name: data[elements * index + 0].substring(1, data[elements * index + 0].length - 1),
uid: parseInt(data[elements * index + 1]),
alias: data[elements * index + 2].substring(1, data[elements * index + 2].length - 1),
isLocked: (0 == parseInt(data[elements * index + 3])) ? false : true,
isSticky: (0 == parseInt(data[elements * index + 4])) ? false : true,
duration: parseInt(data[elements * index + 5])
isDisabled: (0 == parseInt(data[elements * index + 5])) ? false : true,
duration: parseInt(data[elements * index + 6])
});
}
this._pendingCmd.resolve(rsp);
Expand Down Expand Up @@ -484,6 +495,42 @@ pixelix.ws.Client.prototype.setSlotDuration = function(options) {
}.bind(this));
};

pixelix.ws.Client.prototype.setSlot = function(options) {
return new Promise(function(resolve, reject) {
var par = "";
if (null === this._socket) {
reject();
} else if ("number" !== typeof options.slotId) {
reject();
} else {

par += options.slotId
par += ";";

if ("boolean" !== typeof options.sticky) {
par += "0";
} else {
par += (false === options.sticky) ? "1" : "2";
}

par += ";";

if ("boolean" !== typeof options.isDisabled) {
par += "0";
} else {
par += (false === options.isDisabled) ? "1" : "2";
}

this._sendCmd({
name: "SLOT",
par: par,
resolve: resolve,
reject: reject
});
}
}.bind(this));
};

pixelix.ws.Client.prototype.getIperf = function(options) {
return new Promise(function(resolve, reject) {
if (null === this._socket) {
Expand Down
156 changes: 96 additions & 60 deletions lib/Utilities/src/Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,94 +71,130 @@
* External Functions
*****************************************************************************/

extern bool Util::strToUInt8(const String& str, uint8_t& value)
extern bool Util::strToUInt8(const char* str, uint8_t& value)
{
bool success = false;
char* endPtr = nullptr;
unsigned long tmp = 0UL;

errno = 0;
tmp = strtoul(str.c_str(), &endPtr, 0);

if ((0 == errno) &&
(nullptr != endPtr) &&
('\0' == *endPtr) &&
(str.c_str() != endPtr) &&
(UINT8_MAX >= tmp))
bool success = false;

if (nullptr != str)
{
value = static_cast<uint8_t>(tmp);
success = true;
char* endPtr = nullptr;
unsigned long tmp = 0UL;

errno = 0;
tmp = strtoul(str, &endPtr, 0);

if ((0 == errno) &&
(nullptr != endPtr) &&
('\0' == *endPtr) &&
(str != endPtr) &&
(UINT8_MAX >= tmp))
{
value = static_cast<uint8_t>(tmp);
success = true;
}
}

return success;
}

extern bool Util::strToUInt16(const String& str, uint16_t& value)
extern bool Util::strToUInt8(const String& str, uint8_t& value)
{
return strToUInt8(str.c_str(), value);
}

extern bool Util::strToUInt16(const char* str, uint16_t& value)
{
bool success = false;
char* endPtr = nullptr;
unsigned long tmp = 0UL;

errno = 0;
tmp = strtoul(str.c_str(), &endPtr, 0);

if ((0 == errno) &&
(nullptr != endPtr) &&
('\0' == *endPtr) &&
(str.c_str() != endPtr) &&
(UINT16_MAX >= tmp))
bool success = false;

if (nullptr != str)
{
value = static_cast<uint16_t>(tmp);
success = true;
char* endPtr = nullptr;
unsigned long tmp = 0UL;

errno = 0;
tmp = strtoul(str, &endPtr, 0);

if ((0 == errno) &&
(nullptr != endPtr) &&
('\0' == *endPtr) &&
(str != endPtr) &&
(UINT16_MAX >= tmp))
{
value = static_cast<uint16_t>(tmp);
success = true;
}
}

return success;
}

extern bool Util::strToInt32(const String& str, int32_t& value)
extern bool Util::strToUInt16(const String& str, uint16_t& value)
{
return strToUInt16(str.c_str(), value);
}

extern bool Util::strToInt32(const char* str, int32_t& value)
{
bool success = false;
char* endPtr = nullptr;
long tmp = 0L;

errno = 0;
tmp = strtol(str.c_str(), &endPtr, 0);

if ((0 == errno) &&
(nullptr != endPtr) &&
('\0' == *endPtr) &&
(str.c_str() != endPtr) &&
(INT32_MAX >= tmp))
bool success = false;

if (nullptr != str)
{
value = static_cast<int32_t>(tmp);
success = true;
char* endPtr = nullptr;
long tmp = 0L;

errno = 0;
tmp = strtol(str, &endPtr, 0);

if ((0 == errno) &&
(nullptr != endPtr) &&
('\0' == *endPtr) &&
(str != endPtr) &&
(INT32_MAX >= tmp))
{
value = static_cast<int32_t>(tmp);
success = true;
}
}

return success;
}

extern bool Util::strToUInt32(const String& str, uint32_t& value)
extern bool Util::strToInt32(const String& str, int32_t& value)
{
return strToInt32(str.c_str(), value);
}

extern bool Util::strToUInt32(const char* str, uint32_t& value)
{
bool success = false;
char* endPtr = nullptr;
unsigned long tmp = 0UL;

errno = 0;
tmp = strtoul(str.c_str(), &endPtr, 0);

if ((0 == errno) &&
(nullptr != endPtr) &&
('\0' == *endPtr) &&
(str.c_str() != endPtr) &&
(UINT32_MAX >= tmp))
bool success = false;

if (nullptr != str)
{
value = static_cast<uint32_t>(tmp);
success = true;
char* endPtr = nullptr;
unsigned long tmp = 0UL;

errno = 0;
tmp = strtoul(str, &endPtr, 0);

if ((0 == errno) &&
(nullptr != endPtr) &&
('\0' == *endPtr) &&
(str != endPtr) &&
(UINT32_MAX >= tmp))
{
value = static_cast<uint32_t>(tmp);
success = true;
}
}

return success;
}

extern bool Util::strToUInt32(const String& str, uint32_t& value)
{
return strToUInt32(str.c_str(), value);
}

extern String Util::uint32ToHex(uint32_t value)
{
char buffer[9]; /* Contains a 32-bit value in hex */
Expand Down
Loading

0 comments on commit 1aa91f4

Please sign in to comment.