Added option to control RGB LED brightness

This commit is contained in:
foorschtbar
2023-05-15 17:03:13 +02:00
parent 504d150e7b
commit 7b662dd65e
7 changed files with 48 additions and 10 deletions

View File

@@ -66,6 +66,16 @@
<option value="27">27</option>
</select>
</p>
<p>
<label for="apcfgledbrightness">LED Brightness</label>
<select id="apcfgledbrightness">
<option value="-1">off</option>
<option value="64">25%</option>
<option value="128">50%</option>
<option value="192">75%</option>
<option value="255">100%</option>
</select>
</p>
<p>
<input type="button" value="Save" id="apcfgsave">
</p>

View File

@@ -315,18 +315,20 @@ $('#apconfigbutton').onclick = function () {
table.deleteRow(i);
}
$('#apconfigbox').style.display = 'block'
fetch("/get_ap_list")
.then(response => response.json())
.then(data => {
$('#apcfgalias').value = data.alias;
$('#apcfgchid').value = data.channel;
})
fetch("/get_ap_list")
.then(response => response.json())
.then(data => {
$('#apcfgalias').value = data.alias;
$('#apcfgchid').value = data.channel;
$("#apcfgledbrightness").value = data.ledbrightness;
})
}
$('#apcfgsave').onclick = function () {
let formData = new FormData();
formData.append("alias", $('#apcfgalias').value);
formData.append("channel", $('#apcfgchid').value);
formData.append("channel", $('#apcfgchid').value);
formData.append('ledbrightness', $('#apcfgledbrightness').value);
fetch("/save_apcfg", {
method: "POST",
body: formData

View File

@@ -2,9 +2,11 @@
#ifdef HAS_RGB_LED
#include <FastLED.h>
#endif
#endif
void ledTask(void* parameter);
void setBrightness(int brightness);
void updateBrightnessFromConfig();
#ifdef HAS_RGB_LED
void shortBlink(CRGB cname);

View File

@@ -5,8 +5,10 @@
#endif
#include "settings.h"
#include "tag_db.h"
QueueHandle_t ledQueue;
int maxledbrightness = 255;
#ifdef HAS_RGB_LED
QueueHandle_t rgbLedQueue;
@@ -230,6 +232,23 @@ void monoIdleStep() {
}
}
void setBrightness(int brightness) {
maxledbrightness = brightness;
#ifdef HAS_RGB_LED
FastLED.setBrightness(maxledbrightness);
#endif
}
void updateBrightnessFromConfig() {
if (APconfig["ledbrightness"].as<int>() != 0) {
int newbrightness = APconfig["ledbrightness"].as<int>();
if (newbrightness < 0) newbrightness = 0;
if (newbrightness != maxledbrightness) {
setBrightness(newbrightness);
}
}
}
void ledTask(void* parameter) {
#ifdef HAS_RGB_LED
FastLED.addLeds<WS2812B, FLASHER_RGB_LED, GRB>(leds, 1); // GRB ordering is typical
@@ -285,7 +304,7 @@ void ledTask(void* parameter) {
if (rgbQueueFlush) {
delete rgb;
rgb=nullptr;
rgb = nullptr;
} else {
rgbInstructionFadeTime = rgb->fadeTime;
if (rgb->fadeTime <= 1) {

View File

@@ -87,6 +87,8 @@ void setup() {
initAPconfig();
updateBrightnessFromConfig();
init_web();
init_udp();

View File

@@ -227,10 +227,11 @@ void initAPconfig() {
LittleFS.begin(true);
File configFile = LittleFS.open("/current/apconfig.json", "r");
if (!configFile) {
//default values'
// default values'
Serial.println("APconfig not found");
APconfig["channel"] = 0;
APconfig["alias"] = String();
APconfig["ledbrightness"] = 100;
return;
}
DeserializationError error = deserializeJson(APconfig, configFile);

View File

@@ -308,6 +308,8 @@ void init_web() {
if (request->hasParam("alias", true) && request->hasParam("channel", true)) {
APconfig["alias"] = request->getParam("alias", true)->value();
APconfig["channel"] = request->getParam("channel", true)->value();
APconfig["ledbrightness"] = request->getParam("ledbrightness", true)->value();
updateBrightnessFromConfig();
saveAPconfig();
setAPchannel();
}