Skip to content

Commit 7dab69b

Browse files
committed
Brightness Output Processor: allow Models instead of hard coded start channels
1 parent 70f38c3 commit 7dab69b

File tree

3 files changed

+85
-29
lines changed

3 files changed

+85
-29
lines changed

src/channeloutput/processors/BrightnessOutputProcessor.cpp

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,18 @@
1111
*/
1212

1313
#include "fpp-pch.h"
14+
#include "../../overlays/PixelOverlay.h"
15+
#include "../../overlays/PixelOverlayModel.h"
1416

1517
#include <math.h>
1618
#include <stdio.h>
1719

20+
#if __has_include(<jsoncpp/json/json.h>)
21+
#include <jsoncpp/json/json.h>
22+
#elif __has_include(<json/json.h>)
23+
#include <json/json.h>
24+
#endif
25+
1826
#include "../../log.h"
1927

2028
#include "BrightnessOutputProcessor.h"
@@ -26,9 +34,35 @@ BrightnessOutputProcessor::BrightnessOutputProcessor(const Json::Value& config)
2634
count = config["count"].asInt();
2735
brightness = config["brightness"].asInt();
2836
gamma = config["gamma"].asFloat();
29-
LogInfo(VB_CHANNELOUT, "Brightness: %d-%d => Brightness:%d Gamma: %f\n",
37+
38+
if (config.isMember("model")) {
39+
model = config["model"].asString();
40+
if (model != "&lt;Use Start Channel&gt;") {
41+
auto m_model = PixelOverlayManager::INSTANCE.getModel(model);
42+
if (!m_model) {
43+
LogErr(VB_CHANNELOUT, "Invalid Pixel Overlay Model: '%s'\n", model.c_str());
44+
} else {
45+
int m_channel = m_model->getChannelCount();
46+
LogDebug(VB_CHANNELOUT, "Before Model applied Brightness: %d-%d => Brightness:%d Gamma: %f Model: %s model\n",
47+
start, start + count - 1,
48+
brightness, gamma, model.c_str(),m_channel);
49+
int offset = start;
50+
start = m_model->getStartChannel() + start + 1;
51+
if (count > m_channel) {
52+
count = m_channel - offset;
53+
LogWarn(VB_CHANNELOUT, "Output processor tried to go past end channel of model. Restricting to %d channels\n", count);
54+
} else if (count < m_channel) {
55+
LogInfo(VB_CHANNELOUT, "Output processor tried to use less channels (%d) than overlay model has (%d). This may be intentional\n",count, m_channel);
56+
}
57+
}
58+
}
59+
} else {
60+
model = "";
61+
}
62+
63+
LogInfo(VB_CHANNELOUT, "Brightness: %d-%d => Brightness:%d Gamma: %f Model: %s\n",
3064
start, start + count - 1,
31-
brightness, gamma);
65+
brightness, gamma, model.c_str());
3266

3367
float bf = brightness;
3468
float maxB = bf * 2.55f;

src/channeloutput/processors/BrightnessOutputProcessor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@ class BrightnessOutputProcessor : public OutputProcessor {
3131
int count;
3232
int brightness;
3333
float gamma;
34+
std::string model;
3435
unsigned char table[256];
3536
};

www/outputprocessors.php

Lines changed: 48 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
<!DOCTYPE html>
22
<html lang="en">
3+
<?php
4+
require_once "common.php";
5+
?>
36

47
<head>
5-
<?php
6-
include 'common/htmlMeta.inc';
7-
require_once "common.php";
8-
include 'common/menuHead.inc'; ?>
9-
8+
<?php include 'common/menuHead.inc'; ?>
109
<script language="Javascript">
1110

1211
function outputOption(val, def) {
@@ -19,7 +18,7 @@ function outputOption(val, def) {
1918
return html;
2019
}
2120

22-
function HTMLForOutputProcessorConfig(output) {
21+
function HTMLForOutputProcessorConfig(output, models) {
2322
var html = "";
2423
var type = output.type;
2524

@@ -43,6 +42,15 @@ function HTMLForOutputProcessorConfig(output) {
4342
html += ">RGBW Pixels</option>";
4443
html += "</select>";
4544
} else if (type == "Brightness") {
45+
html += "Model: <select class='model'>";
46+
models.forEach(function(model) {
47+
html += "<option value='" + model + "'";
48+
if (output.model === model) {
49+
html += " selected";
50+
}
51+
html += ">" + model + "</option>";
52+
});
53+
html += "</select>&nbsp;";
4654
html += "Start Channel: <input class='start' type=text size='7' maxlength='7' value='" + output.start + "'/>&nbsp;"
4755
+ "Channel Count: <input class='count' type=text size='7' maxlength='7' value='" + output.count + "'/>&nbsp;"
4856
+ "Brightness: <input class='brightness' type=number value='" + output.brightness + "' min='0' max='100'/>"
@@ -100,7 +108,7 @@ function HTMLForOutputProcessorConfig(output) {
100108
return html;
101109
}
102110

103-
function PopulateOutputProcessorTable(data) {
111+
function PopulateOutputProcessorTable(data, models) {
104112
$('#outputProcessors tbody').html("");
105113

106114
for (var i = 0; i < data.outputProcessors.length; i++) {
@@ -119,16 +127,16 @@ function PopulateOutputProcessorTable(data) {
119127
+ "<td>" + type + "</td>"
120128
+ "<td><input class='description' type='text' size='32' maxlength='64' value='" + output.description + "'></td><td>";
121129

122-
html += HTMLForOutputProcessorConfig(output);
130+
html += HTMLForOutputProcessorConfig(output, models);
123131
html += "</td></tr>";
124132

125133
$('#outputProcessors tbody').append(html);
126134
}
127135
}
128136

129-
function GetOutputProcessors() {
137+
function GetOutputProcessors(models) {
130138
$.getJSON("api/channel/output/processors", function (data) {
131-
PopulateOutputProcessorTable(data);
139+
PopulateOutputProcessorTable(data, models);
132140
}).fail(function () {
133141
DialogError("Error", "Failed to load Output Processors");
134142
});
@@ -178,6 +186,7 @@ function SetOutputProcessors() {
178186
type: "Brightness",
179187
active: $this.find("input.active").is(':checked') ? 1 : 0,
180188
description: $this.find("input.description").val(),
189+
model: $this.find("select.model").val(),
181190
start: parseInt($this.find("input.start").val()),
182191
count: parseInt($this.find("input.count").val()),
183192
brightness: parseInt($this.find("input.brightness").val()),
@@ -188,7 +197,7 @@ function SetOutputProcessors() {
188197
processors.push(b);
189198
} else {
190199
dataError = 1;
191-
alert("Brightness settings of row " + rowNumber + " is not valid.");
200+
alert("Settings of row " + rowNumber + " is not valid.");
192201
return;
193202
}
194203
} else if (type == "Set Value") {
@@ -205,7 +214,7 @@ function SetOutputProcessors() {
205214
processors.push(b);
206215
} else {
207216
dataError = 1;
208-
alert("Set Value settings of row " + rowNumber + " is not valid.");
217+
alert("Settings of row " + rowNumber + " is not valid.");
209218
return;
210219
}
211220
} else if (type == "Hold Value") {
@@ -221,7 +230,7 @@ function SetOutputProcessors() {
221230
processors.push(b);
222231
} else {
223232
dataError = 1;
224-
alert("Hold Value settings of row " + rowNumber + " is not valid.");
233+
alert("Settings of row " + rowNumber + " is not valid.");
225234
return;
226235
}
227236
} else if (type == "Reorder Colors") {
@@ -238,7 +247,7 @@ function SetOutputProcessors() {
238247
processors.push(b);
239248
} else {
240249
dataError = 1;
241-
alert("Color Order settings of row " + rowNumber + " is not valid.");
250+
alert("Settings of row " + rowNumber + " is not valid.");
242251
return;
243252
}
244253
} else if (type == "Three to Four") {
@@ -256,7 +265,7 @@ function SetOutputProcessors() {
256265
processors.push(b);
257266
} else {
258267
dataError = 1;
259-
alert("Three to Four settings of row " + rowNumber + " is not valid.");
268+
alert("Settings of row " + rowNumber + " is not valid.");
260269
return;
261270
}
262271

@@ -274,7 +283,7 @@ function SetOutputProcessors() {
274283
processors.push(b);
275284
} else {
276285
dataError = 1;
277-
alert("Override Zero settings of row " + rowNumber + " is not valid.");
286+
alert("Settings of row " + rowNumber + " is not valid.");
278287
return;
279288
}
280289
} else if (type == "Fold") {
@@ -310,9 +319,9 @@ function SetOutputProcessors() {
310319
}
311320
).done(function (data) {
312321
$.jGrowl("Output Processors Table saved", { themeState: 'success' });
313-
PopulateOutputProcessorTable(data);
314322
SetRestartFlag(2);
315323
common_ViewPortChange();
324+
PopulateOutputProcessorTable(data,models);
316325
}).fail(function () {
317326
DialogError("Save Output Processors Table", "Save Failed");
318327
});
@@ -330,7 +339,7 @@ function AddOtherTypeOptions(row, type) {
330339
loops: 1,
331340
reverse: 0
332341
};
333-
config += HTMLForOutputProcessorConfig(b);
342+
config += HTMLForOutputProcessorConfig(b, models);
334343
} else if (type == "Brightness") {
335344
var b = {
336345
type: "Brightness",
@@ -339,30 +348,30 @@ function AddOtherTypeOptions(row, type) {
339348
brightness: 100,
340349
gamma: 1.0
341350
};
342-
config += HTMLForOutputProcessorConfig(b);
351+
config += HTMLForOutputProcessorConfig(b, models);
343352
} else if (type == "Set Value") {
344353
var b = {
345354
type: "Set Value",
346355
start: 1,
347356
count: 1,
348357
value: 255
349358
};
350-
config += HTMLForOutputProcessorConfig(b);
359+
config += HTMLForOutputProcessorConfig(b, models);
351360
} else if (type == "Hold Value") {
352361
var b = {
353362
type: "Hold Value",
354363
start: 1,
355364
count: 1,
356365
};
357-
config += HTMLForOutputProcessorConfig(b);
366+
config += HTMLForOutputProcessorConfig(b, models);
358367
} else if (type == "Reorder Colors") {
359368
var b = {
360369
type: "Reorder Colors",
361370
start: 1,
362371
count: 1,
363372
colorOrder: 132
364373
};
365-
config += HTMLForOutputProcessorConfig(b);
374+
config += HTMLForOutputProcessorConfig(b, models);
366375
} else if (type == "Three to Four") {
367376
var b = {
368377
type: "Three to Four",
@@ -371,7 +380,7 @@ function AddOtherTypeOptions(row, type) {
371380
colorOrder: 1234,
372381
algorithm: 1
373382
};
374-
config += HTMLForOutputProcessorConfig(b);
383+
config += HTMLForOutputProcessorConfig(b, models);
375384
}
376385
else if (type == "Override Zero") {
377386
var b = {
@@ -380,15 +389,15 @@ function AddOtherTypeOptions(row, type) {
380389
count: 1,
381390
value: 255
382391
};
383-
config += HTMLForOutputProcessorConfig(b);
392+
config += HTMLForOutputProcessorConfig(b, models);
384393
} else if (type == "Fold") {
385394
var b = {
386395
type: "Fold",
387396
source: 1,
388397
count: 1,
389398
node: 0
390399
};
391-
config += HTMLForOutputProcessorConfig(b);
400+
config += HTMLForOutputProcessorConfig(b, models);
392401
}
393402

394403

@@ -450,8 +459,20 @@ function DeleteSelectedProcessor() {
450459
}
451460

452461
$(document).ready(function () {
462+
$.ajax({
463+
url: "api/models?simple=true",
464+
method: "GET",
465+
dataType: "json",
466+
success: function(models) {
467+
models.unshift("&lt;Use Start Channel&gt;");
453468
SetupSelectableTableRow(tableInfo);
454-
GetOutputProcessors();
469+
GetOutputProcessors(models);
470+
},
471+
error: function() {
472+
console.error("Error fetching models");
473+
}
474+
});
475+
455476

456477
if (window.innerWidth > 600) {
457478
$('#outputProcessorsBody').sortable({
@@ -539,4 +560,4 @@ class='buttons btn-success ml-1'>
539560
</div>
540561
</body>
541562

542-
</html>
563+
</html>

0 commit comments

Comments
 (0)