more status values

Signed-off-by: Peter Siegmund <developer@mars3142.org>
This commit is contained in:
2026-01-18 22:41:20 +01:00
parent a12dfe7760
commit 3ec7bf7acb
6 changed files with 49 additions and 11 deletions

View File

@@ -3,6 +3,7 @@
#include <stdbool.h>
#include "persistence_manager.h"
#include <time.h>
// Gibt ein cJSON-Objekt with dem aktuellen Lichtstatus zurück
cJSON *create_light_status_json(void)
@@ -35,6 +36,14 @@ cJSON *create_light_status_json(void)
cJSON_AddNumberToObject(color, "b", 220);
cJSON_AddItemToObject(json, "color", color);
// Add current time as HH:MM only (suffix is handled in the frontend)
time_t now = time(NULL);
struct tm tm_info;
localtime_r(&now, &tm_info);
char time_str[8];
strftime(time_str, sizeof(time_str), "%H:%M", &tm_info);
cJSON_AddStringToObject(json, "clock", time_str);
persistence_manager_deinit(&pm);
return json;

View File

@@ -557,6 +557,11 @@ body {
align-items: center;
padding: 10px 0;
border-bottom: 1px solid var(--border);
display: none;
}
.status-item.visible {
display: flex;
}
.status-item:last-child {

View File

@@ -92,18 +92,18 @@
<div class="control-section">
<h3 data-i18n="control.status.title">Aktueller Status</h3>
<div class="status-display">
<div class="status-item">
<div class="status-item visible">
<span class="status-label" data-i18n="control.status.mode">Modus</span>
<span class="status-value" id="current-mode" data-i18n="mode.simulation">Simulation</span>
</div>
<div class="status-item">
<span class="status-label" data-i18n="control.status.schema">Schema</span>
<span class="status-value" id="current-schema">Schema 1</span>
</div>
<div class="status-item">
<div class="status-item visible">
<span class="status-label" data-i18n="control.status.color">Aktuelle Farbe</span>
<div class="current-color-preview" id="current-color"></div>
</div>
<div class="status-item">
<span class="status-label" data-i18n="control.status.clock">Uhrzeit</span>
<span class="status-value" id="current-clock">--:-- Uhr</span>
</div>
</div>
</div>
</div>

View File

@@ -40,7 +40,6 @@ document.addEventListener('touchend', (e) => {
lastTouchEnd = now;
}, false);
// Initialization
document.addEventListener('DOMContentLoaded', async () => {
initI18n();
initTheme();

View File

@@ -41,6 +41,7 @@ const translations = {
'control.status.mode': 'Modus',
'control.status.schema': 'Schema',
'control.status.color': 'Aktuelle Farbe',
'control.status.clock': 'Uhrzeit',
// Common
'common.on': 'AN',
@@ -174,7 +175,8 @@ const translations = {
// General
'loading': 'Laden...',
'error': 'Fehler',
'success': 'Erfolg'
'success': 'Erfolg',
'clock.suffix': 'Uhr'
},
en: {
@@ -216,6 +218,7 @@ const translations = {
'control.status.mode': 'Mode',
'control.status.schema': 'Schema',
'control.status.color': 'Current Color',
'control.status.clock': "Time",
// Common
'common.on': 'ON',
@@ -349,7 +352,8 @@ const translations = {
// General
'loading': 'Loading...',
'error': 'Error',
'success': 'Success'
'success': 'Success',
'clock.suffix': "o'clock"
}
};

View File

@@ -115,6 +115,20 @@ function updateSimulationOptions() {
} else {
options.classList.remove('visible');
}
[
'control.status.clock'
].forEach(i18nKey => {
const label = document.querySelector(`.status-item .status-label[data-i18n="${i18nKey}"]`);
const item = label ? label.closest('.status-item') : null;
if (item) {
if (currentMode === 'simulation') {
item.classList.add('visible');
} else {
item.classList.remove('visible');
}
}
});
}
async function setActiveSchema() {
@@ -173,8 +187,6 @@ async function loadLightStatus() {
// Update schema
if (status.schema) {
document.getElementById('active-schema').value = status.schema;
const schemaNum = status.schema.replace('schema_0', '').replace('.csv', '');
document.getElementById('current-schema').textContent = t(`schema.name.${schemaNum}`);
}
// Update current color
@@ -184,6 +196,15 @@ async function loadLightStatus() {
colorPreview.style.backgroundColor = `rgb(${status.color.r}, ${status.color.g}, ${status.color.b})`;
}
}
// Update clock/time
if (status.clock) {
const clockEl = document.getElementById('current-clock');
if (clockEl) {
// Use one translation key for the suffix, language is handled by t()
clockEl.textContent = status.clock + ' ' + t('clock.suffix');
}
}
}
} catch (error) {
console.log('Light status not available');