diff --git a/src/Controllers/StateController.cs b/src/Controllers/StateController.cs index 2206eac1..2cd77778 100644 --- a/src/Controllers/StateController.cs +++ b/src/Controllers/StateController.cs @@ -135,6 +135,22 @@ void OnDeviceChanged(object? sender, DeviceEventArgs e) _eventDispatcher.DeviceStateChanged -= OnDeviceChanged; } } + + [HttpGet("api/state/calibration/autoOptimize")] + public IActionResult GetAutoOptimize() + { + var c = _config.Config; + return Ok(new { autoOptimize = c?.Optimization.Enabled ?? false }); + } + + [HttpPost("api/state/calibration/autoOptimize")] + public IActionResult ToggleAutoOptimize([FromBody] bool enable) + { + var c = _config.Config; + if (c != null) c.Optimization.Enabled = enable; + + return Ok(new { autoOptimize = c?.Optimization.Enabled ?? false }); + } } diff --git a/src/Services/MqttCoordinator.cs b/src/Services/MqttCoordinator.cs index ace09128..fa7d4212 100644 --- a/src/Services/MqttCoordinator.cs +++ b/src/Services/MqttCoordinator.cs @@ -194,7 +194,7 @@ await DeviceConfigReceivedAsync(new DeviceSettingsEventArgs } catch (Exception ex) { - _logger.LogWarning(ex, "Error parsing mqtt message from {topic}", arg.ApplicationMessage.Topic); + _logger.LogWarning("Error parsing mqtt message from {topic}: {error}", arg.ApplicationMessage.Topic, ex.Message); MqttMessageMalformed?.Invoke(this, EventArgs.Empty); } } diff --git a/src/ui/src/lib/CalibrationMatrix.svelte b/src/ui/src/lib/CalibrationMatrix.svelte index d945deee..22243bd2 100644 --- a/src/ui/src/lib/CalibrationMatrix.svelte +++ b/src/ui/src/lib/CalibrationMatrix.svelte @@ -2,6 +2,8 @@ import { calibration } from '$lib/stores'; import { RadioGroup, RadioItem } from '@skeletonlabs/skeleton'; import { popup } from '@skeletonlabs/skeleton'; + import { SlideToggle } from '@skeletonlabs/skeleton'; + import { onMount } from 'svelte'; enum DataPoint { ErrorPercent = 0, @@ -56,6 +58,40 @@ } let data_point: DataPoint = 0; + let autoOptimization = false; + + async function fetchAutoOptimizationState() { + const response = await fetch('/api/state/calibration/autoOptimize'); + const data = await response.json(); + autoOptimization = data.autoOptimize; + } + + async function toggleAutoOptimization() { + try { + const newState = !autoOptimization; + const response = await fetch('/api/state/calibration/autoOptimize', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(newState), + }); + + if (response.ok) { + const data = await response.json(); + autoOptimization = data.autoOptimize; + console.log('Auto-optimization toggled:', autoOptimization); + } else { + console.error('Failed to toggle auto-optimization'); + } + } catch (error) { + console.error('Error toggling auto-optimization:', error); + } + } + + onMount(() => { + fetchAutoOptimizationState(); + }); {#if $calibration?.matrix} @@ -76,7 +112,7 @@
{#if $calibration?.matrix}
-
+
Error % Error (m) @@ -85,6 +121,10 @@ Tx Rssi Ref Variance (m) +
+ Auto Optimization + +