feat: add OLED sleep settings and management to save the display from burn-in
This commit is contained in:
1 parent
87a0403735
commit
96a5e184dd
10 files changed
+159
-2
No files matched your search
@@ -69,6 +69,24 @@
|
||||
</select>
|
||||
</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>
|
||||
</div>
|
||||
|
||||
@@ -105,6 +123,43 @@
|
||||
.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', () => {
|
||||
const url = document.getElementById('filamanUrl').value;
|
||||
const code = document.getElementById('deviceCode').value;
|
||||
|
||||
Reference in new issue
Block a user