Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
20ab21dae5 | ||
|
|
a14ab8fa55 | ||
|
|
96a5e184dd | ||
|
|
bc0d586c9e | ||
|
|
ddf981b971 | ||
|
|
1b7a71b617 | ||
|
|
87a0403735 | ||
|
|
97a2ecca41 | ||
|
|
fe768cf631 |
No files matched your search
@@ -69,6 +69,24 @@
|
|||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="fm-card">
|
||||||
|
<h2>Display Settings</h2>
|
||||||
|
|
||||||
|
<div class="fm-form-group" style="margin-top: 1rem;">
|
||||||
|
<label class="fm-label" for="sleepTimeoutSelect">OLED Sleep Timeout</label>
|
||||||
|
<select id="sleepTimeoutSelect" class="fm-input">
|
||||||
|
<option value="0">Disabled (always on)</option>
|
||||||
|
<option value="30">30 seconds</option>
|
||||||
|
<option value="60">1 minute</option>
|
||||||
|
<option value="120">2 minutes</option>
|
||||||
|
<option value="300">5 minutes</option>
|
||||||
|
<option value="600">10 minutes</option>
|
||||||
|
</select>
|
||||||
|
<p style="font-size: 0.8rem; margin-top: 0.5rem;">Display wakes automatically on weight change or NFC tag read.</p>
|
||||||
|
</div>
|
||||||
|
<div id="sleepStatusMessage" style="margin-top: 0.5rem;"></div>
|
||||||
|
</div>
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -105,6 +123,43 @@
|
|||||||
.catch(error => console.error('Error saving language:', error));
|
.catch(error => console.error('Error saving language:', error));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Display sleep timeout setting
|
||||||
|
fetch('/api/display')
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
const sel = document.getElementById('sleepTimeoutSelect');
|
||||||
|
const val = String(data.sleepTimeout);
|
||||||
|
// Select closest matching option
|
||||||
|
let matched = false;
|
||||||
|
for (let i = 0; i < sel.options.length; i++) {
|
||||||
|
if (sel.options[i].value === val) { sel.value = val; matched = true; break; }
|
||||||
|
}
|
||||||
|
if (!matched) sel.value = '0';
|
||||||
|
})
|
||||||
|
.catch(error => console.error('Error fetching display settings:', error));
|
||||||
|
|
||||||
|
document.getElementById('sleepTimeoutSelect').addEventListener('change', function() {
|
||||||
|
const msg = document.getElementById('sleepStatusMessage');
|
||||||
|
fetch('/api/display', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({ sleepTimeout: parseInt(this.value) })
|
||||||
|
})
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
if (data.success) {
|
||||||
|
msg.textContent = 'Saved.';
|
||||||
|
msg.style.color = 'var(--success-text)';
|
||||||
|
setTimeout(() => { msg.textContent = ''; }, 2000);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
msg.textContent = 'Error saving setting.';
|
||||||
|
msg.style.color = 'var(--error-text)';
|
||||||
|
console.error('Error saving display settings:', error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
document.getElementById('registerBtn').addEventListener('click', () => {
|
document.getElementById('registerBtn').addEventListener('click', () => {
|
||||||
const url = document.getElementById('filamanUrl').value;
|
const url = document.getElementById('filamanUrl').value;
|
||||||
const code = document.getElementById('deviceCode').value;
|
const code = document.getElementById('deviceCode').value;
|
||||||
|
|||||||
+2
-2
@@ -9,12 +9,12 @@
|
|||||||
; https://docs.platformio.org/page/projectconf.html
|
; https://docs.platformio.org/page/projectconf.html
|
||||||
|
|
||||||
[common]
|
[common]
|
||||||
version = "3.2.5"
|
version = "3.2.7"
|
||||||
to_old_version = "3.0.9"
|
to_old_version = "3.0.9"
|
||||||
|
|
||||||
##
|
##
|
||||||
[env:esp32dev]
|
[env:esp32dev]
|
||||||
platform = espressif32
|
platform = espressif32@^6.0.0
|
||||||
board = esp32dev
|
board = esp32dev
|
||||||
framework = arduino
|
framework = arduino
|
||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
||||||
|
|||||||
+3
-1
@@ -42,7 +42,9 @@ String filamanToken = "";
|
|||||||
bool filamanRegistered = false;
|
bool filamanRegistered = false;
|
||||||
// ***** API
|
// ***** API
|
||||||
|
|
||||||
// ***** Bambu Auto Set Spool
|
// ***** Display Sleep
|
||||||
|
uint16_t oledSleepTimeout = 60; // Default 60 seconds (0 = disabled)
|
||||||
|
// ***** Display Sleep
|
||||||
|
|
||||||
// ***** Task Prios
|
// ***** Task Prios
|
||||||
uint8_t rfidTaskCore = 1;
|
uint8_t rfidTaskCore = 1;
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
#define NVS_NAMESPACE_SETTINGS "settings"
|
#define NVS_NAMESPACE_SETTINGS "settings"
|
||||||
#define NVS_KEY_LANGUAGE "language"
|
#define NVS_KEY_LANGUAGE "language"
|
||||||
|
#define NVS_KEY_OLED_SLEEP "oled_sleep"
|
||||||
#define SCALE_DEFAULT_CALIBRATION_VALUE 430.0f;
|
#define SCALE_DEFAULT_CALIBRATION_VALUE 430.0f;
|
||||||
|
|
||||||
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
|
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
|
||||||
@@ -70,4 +71,5 @@ extern uint8_t scaleTaskCore;
|
|||||||
extern uint8_t scaleTaskPrio;
|
extern uint8_t scaleTaskPrio;
|
||||||
|
|
||||||
extern uint16_t defaultScaleCalibrationValue;
|
extern uint16_t defaultScaleCalibrationValue;
|
||||||
|
extern uint16_t oledSleepTimeout;
|
||||||
#endif
|
#endif
|
||||||
@@ -5,6 +5,7 @@
|
|||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include "lang.h"
|
#include "lang.h"
|
||||||
|
#include <Preferences.h>
|
||||||
|
|
||||||
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
|
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
|
||||||
|
|
||||||
@@ -16,6 +17,60 @@ static DisplayPriority currentPriority = DISPLAY_PRIORITY_NONE;
|
|||||||
static unsigned long prioritySetTime = 0;
|
static unsigned long prioritySetTime = 0;
|
||||||
static unsigned long priorityMinDuration = 0;
|
static unsigned long priorityMinDuration = 0;
|
||||||
|
|
||||||
|
// Display sleep management
|
||||||
|
static bool oledAsleep = false;
|
||||||
|
static unsigned long lastActivityMillis = 0;
|
||||||
|
|
||||||
|
void oledWake() {
|
||||||
|
if (oledAsleep) {
|
||||||
|
display.ssd1306_command(SSD1306_DISPLAYON);
|
||||||
|
oledAsleep = false;
|
||||||
|
}
|
||||||
|
lastActivityMillis = millis();
|
||||||
|
}
|
||||||
|
|
||||||
|
void oledSleep() {
|
||||||
|
if (!oledAsleep) {
|
||||||
|
display.ssd1306_command(SSD1306_DISPLAYOFF);
|
||||||
|
oledAsleep = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void oledResetActivityTimer() {
|
||||||
|
lastActivityMillis = millis();
|
||||||
|
if (oledAsleep) {
|
||||||
|
oledWake();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void oledCheckSleep() {
|
||||||
|
if (oledSleepTimeout == 0 || oledAsleep) return;
|
||||||
|
if (millis() - lastActivityMillis >= (unsigned long)oledSleepTimeout * 1000UL) {
|
||||||
|
oledSleep();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isOledAsleep() {
|
||||||
|
return oledAsleep;
|
||||||
|
}
|
||||||
|
|
||||||
|
void loadOledSleepTimeout() {
|
||||||
|
Preferences preferences;
|
||||||
|
preferences.begin(NVS_NAMESPACE_SETTINGS, true);
|
||||||
|
oledSleepTimeout = preferences.getUShort(NVS_KEY_OLED_SLEEP, 60);
|
||||||
|
preferences.end();
|
||||||
|
Serial.print("OLED sleep timeout loaded: ");
|
||||||
|
Serial.println(oledSleepTimeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
void saveOledSleepTimeout(uint16_t timeoutSecs) {
|
||||||
|
oledSleepTimeout = timeoutSecs;
|
||||||
|
Preferences preferences;
|
||||||
|
preferences.begin(NVS_NAMESPACE_SETTINGS, false);
|
||||||
|
preferences.putUShort(NVS_KEY_OLED_SLEEP, timeoutSecs);
|
||||||
|
preferences.end();
|
||||||
|
}
|
||||||
|
|
||||||
bool oledCanUpdate(DisplayPriority newPriority) {
|
bool oledCanUpdate(DisplayPriority newPriority) {
|
||||||
if (currentPriority == DISPLAY_PRIORITY_NONE) return true;
|
if (currentPriority == DISPLAY_PRIORITY_NONE) return true;
|
||||||
// Higher priority can always preempt
|
// Higher priority can always preempt
|
||||||
@@ -55,6 +110,9 @@ void setupDisplay() {
|
|||||||
display.setTextColor(WHITE);
|
display.setTextColor(WHITE);
|
||||||
display.clearDisplay();
|
display.clearDisplay();
|
||||||
|
|
||||||
|
// Load sleep timeout from NVS
|
||||||
|
loadOledSleepTimeout();
|
||||||
|
lastActivityMillis = millis();
|
||||||
|
|
||||||
oledShowTopRow();
|
oledShowTopRow();
|
||||||
oledShowProgressBar(0, 7, DISPLAY_BOOT_TEXT, tr(STR_DISPLAY_INIT));
|
oledShowProgressBar(0, 7, DISPLAY_BOOT_TEXT, tr(STR_DISPLAY_INIT));
|
||||||
|
|||||||
@@ -30,6 +30,15 @@ void oledcleardata();
|
|||||||
int oled_center_h(const String &text);
|
int oled_center_h(const String &text);
|
||||||
int oled_center_v(const String &text);
|
int oled_center_v(const String &text);
|
||||||
|
|
||||||
|
// Display sleep management
|
||||||
|
void oledWake();
|
||||||
|
void oledSleep();
|
||||||
|
void oledResetActivityTimer();
|
||||||
|
void oledCheckSleep();
|
||||||
|
bool isOledAsleep();
|
||||||
|
void loadOledSleepTimeout();
|
||||||
|
void saveOledSleepTimeout(uint16_t timeoutSecs);
|
||||||
|
|
||||||
void oledShowProgressBar(const uint8_t step, const uint8_t numSteps, const char* largeText, const char* statusMessage);
|
void oledShowProgressBar(const uint8_t step, const uint8_t numSteps, const char* largeText, const char* statusMessage);
|
||||||
|
|
||||||
void oledShowWeight(int16_t weight);
|
void oledShowWeight(int16_t weight);
|
||||||
|
|||||||
@@ -127,6 +127,7 @@ void loop() {
|
|||||||
{
|
{
|
||||||
lastButtonPress = currentMillis;
|
lastButtonPress = currentMillis;
|
||||||
scaleTareRequest = true;
|
scaleTareRequest = true;
|
||||||
|
oledResetActivityTimer(); // Wake display on touch press
|
||||||
}
|
}
|
||||||
|
|
||||||
// Überprüfe regelmäßig die WLAN-Verbindung
|
// Überprüfe regelmäßig die WLAN-Verbindung
|
||||||
@@ -139,6 +140,7 @@ void loop() {
|
|||||||
if (intervalElapsed(currentMillis, lastTopRowUpdateTime, DISPLAY_UPDATE_INTERVAL))
|
if (intervalElapsed(currentMillis, lastTopRowUpdateTime, DISPLAY_UPDATE_INTERVAL))
|
||||||
{
|
{
|
||||||
oledShowTopRow();
|
oledShowTopRow();
|
||||||
|
oledCheckSleep(); // Put display to sleep if timeout elapsed
|
||||||
// Clean up dead websocket clients periodically instead of on connect
|
// Clean up dead websocket clients periodically instead of on connect
|
||||||
if(currentMillis % 10000 < 50) ws.cleanupClients();
|
if(currentMillis % 10000 < 50) ws.cleanupClients();
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-4
@@ -1900,19 +1900,27 @@ String optimizeJsonForFastPath(const char* payload) {
|
|||||||
JsonDocument optimizedDoc;
|
JsonDocument optimizedDoc;
|
||||||
|
|
||||||
// Always add sm_id first (even if it's "0" for brand filaments)
|
// Always add sm_id first (even if it's "0" for brand filaments)
|
||||||
if (inputDoc["sm_id"].is<String>()) {
|
// Also convert spool_id to sm_id if present (backend may send either)
|
||||||
|
if (inputDoc["sm_id"].is<String>() && inputDoc["sm_id"].as<String>() != "0" && inputDoc["sm_id"].as<String>() != "") {
|
||||||
optimizedDoc["sm_id"] = inputDoc["sm_id"].as<String>();
|
optimizedDoc["sm_id"] = inputDoc["sm_id"].as<String>();
|
||||||
Serial.print("Optimizing JSON: sm_id found = ");
|
Serial.print("Optimizing JSON: sm_id found = ");
|
||||||
Serial.println(inputDoc["sm_id"].as<String>());
|
Serial.println(inputDoc["sm_id"].as<String>());
|
||||||
|
} else if (inputDoc["spool_id"].is<int>() && inputDoc["spool_id"].as<int>() > 0) {
|
||||||
|
optimizedDoc["sm_id"] = String(inputDoc["spool_id"].as<int>());
|
||||||
|
Serial.print("Optimizing JSON: Converted spool_id to sm_id = ");
|
||||||
|
Serial.println(inputDoc["spool_id"].as<int>());
|
||||||
|
} else if (inputDoc["spool_id"].is<String>() && inputDoc["spool_id"].as<String>() != "0" && inputDoc["spool_id"].as<String>() != "") {
|
||||||
|
optimizedDoc["sm_id"] = inputDoc["spool_id"].as<String>();
|
||||||
|
Serial.print("Optimizing JSON: Converted spool_id (string) to sm_id = ");
|
||||||
|
Serial.println(inputDoc["spool_id"].as<String>());
|
||||||
} else {
|
} else {
|
||||||
optimizedDoc["sm_id"] = "0"; // Default for brand filaments
|
optimizedDoc["sm_id"] = "0"; // Default for brand filaments
|
||||||
Serial.println("Optimizing JSON: No sm_id found, setting to '0'");
|
Serial.println("Optimizing JSON: No sm_id or spool_id found, setting sm_id to '0'");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add all other keys in original order
|
|
||||||
for (JsonPair kv : inputDoc.as<JsonObject>()) {
|
for (JsonPair kv : inputDoc.as<JsonObject>()) {
|
||||||
String key = kv.key().c_str();
|
String key = kv.key().c_str();
|
||||||
if (key != "sm_id") { // Skip sm_id as it's already added first
|
if (key != "sm_id" && key != "spool_id") {
|
||||||
optimizedDoc[key] = kv.value();
|
optimizedDoc[key] = kv.value();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2042,6 +2050,9 @@ void scanRfidTask(void * parameter) {
|
|||||||
// Set the current tag as not processed
|
// Set the current tag as not processed
|
||||||
tagProcessed = false;
|
tagProcessed = false;
|
||||||
|
|
||||||
|
// Wake display when a tag is detected
|
||||||
|
oledResetActivityTimer();
|
||||||
|
|
||||||
// Display some basic information about the card
|
// Display some basic information about the card
|
||||||
Serial.println("Found an ISO14443A card");
|
Serial.println("Found an ISO14443A card");
|
||||||
|
|
||||||
|
|||||||
@@ -196,6 +196,7 @@ void scale_loop(void * parameter) {
|
|||||||
// Update global weight variable only if it changed significantly (for API actions)
|
// Update global weight variable only if it changed significantly (for API actions)
|
||||||
if (stabilizedWeight != weight) {
|
if (stabilizedWeight != weight) {
|
||||||
weight = stabilizedWeight;
|
weight = stabilizedWeight;
|
||||||
|
oledResetActivityTimer(); // Wake display on weight change
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prüfen ob die Waage korrekt genullt ist
|
// Prüfen ob die Waage korrekt genullt ist
|
||||||
|
|||||||
+30
-2
@@ -227,11 +227,14 @@ void setupWebserver(AsyncWebServer &server) {
|
|||||||
String payloadString;
|
String payloadString;
|
||||||
serializeJson(doc, payloadString);
|
serializeJson(doc, payloadString);
|
||||||
|
|
||||||
|
bool hasSpoolId = !doc["spool_id"].isNull() || !doc["sm_id"].isNull();
|
||||||
int spoolId = doc["spool_id"] | 0;
|
int spoolId = doc["spool_id"] | 0;
|
||||||
|
if (spoolId == 0 && doc["sm_id"].is<String>()) {
|
||||||
|
spoolId = doc["sm_id"].as<String>().toInt();
|
||||||
|
}
|
||||||
int locationId = doc["location_id"] | 0;
|
int locationId = doc["location_id"] | 0;
|
||||||
|
|
||||||
// Start write task (fire and forget)
|
startWriteJsonToTag(hasSpoolId, payloadString.c_str(), spoolId, locationId);
|
||||||
startWriteJsonToTag(!doc["spool_id"].isNull(), payloadString.c_str(), spoolId, locationId);
|
|
||||||
|
|
||||||
// Respond immediately
|
// Respond immediately
|
||||||
request->send(200, "application/json", "{\"success\": true, \"message\": \"Schreibvorgang wurde gestartet. Bitte Tag bereit halten...\"}");
|
request->send(200, "application/json", "{\"success\": true, \"message\": \"Schreibvorgang wurde gestartet. Bitte Tag bereit halten...\"}");
|
||||||
@@ -269,6 +272,31 @@ void setupWebserver(AsyncWebServer &server) {
|
|||||||
request->send(200, "application/json", "{\"success\": true}");
|
request->send(200, "application/json", "{\"success\": true}");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Display Settings API
|
||||||
|
server.on("/api/display", HTTP_GET, [](AsyncWebServerRequest *request){
|
||||||
|
JsonDocument doc;
|
||||||
|
doc["sleepTimeout"] = oledSleepTimeout;
|
||||||
|
String response;
|
||||||
|
serializeJson(doc, response);
|
||||||
|
request->send(200, "application/json", response);
|
||||||
|
});
|
||||||
|
|
||||||
|
server.on("/api/display", HTTP_POST, [](AsyncWebServerRequest *request){}, NULL, [](AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total){
|
||||||
|
JsonDocument doc;
|
||||||
|
DeserializationError error = deserializeJson(doc, (const uint8_t*)data, len);
|
||||||
|
if (error) {
|
||||||
|
request->send(400, "application/json", "{\"success\": false, \"error\": \"Invalid JSON\"}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!doc["sleepTimeout"].is<int>()) {
|
||||||
|
request->send(400, "application/json", "{\"success\": false, \"error\": \"Missing sleepTimeout\"}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
uint16_t timeout = (uint16_t)constrain((int)doc["sleepTimeout"], 0, 3600);
|
||||||
|
saveOledSleepTimeout(timeout);
|
||||||
|
request->send(200, "application/json", "{\"success\": true}");
|
||||||
|
});
|
||||||
|
|
||||||
server.on("/reboot", HTTP_GET, [](AsyncWebServerRequest *request){
|
server.on("/reboot", HTTP_GET, [](AsyncWebServerRequest *request){
|
||||||
request->send(200, "text/plain", "Rebooting...");
|
request->send(200, "text/plain", "Rebooting...");
|
||||||
delay(500);
|
delay(500);
|
||||||
|
|||||||
Reference in new issue
Block a user