Skip to content

Commit

Permalink
Slider for calibration
Browse files Browse the repository at this point in the history
  • Loading branch information
DTTerastar committed Oct 5, 2024
1 parent 5b55335 commit d33d70a
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
16 changes: 16 additions & 0 deletions src/Controllers/StateController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
}


2 changes: 1 addition & 1 deletion src/Services/MqttCoordinator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
42 changes: 41 additions & 1 deletion src/ui/src/lib/CalibrationMatrix.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();
});
</script>

{#if $calibration?.matrix}
Expand All @@ -76,7 +112,7 @@
<div class="card p-2">
{#if $calibration?.matrix}
<header>
<div class="flex justify-center p-2">
<div class="flex justify-between items-center p-2">
<RadioGroup active="variant-filled-primary" hover="hover:variant-soft-primary">
<RadioItem bind:group={data_point} name="justify" value={0}>Error %</RadioItem>
<RadioItem bind:group={data_point} name="justify" value={1}>Error (m)</RadioItem>
Expand All @@ -85,6 +121,10 @@
<RadioItem bind:group={data_point} name="justify" value={4}>Tx Rssi Ref</RadioItem>
<RadioItem bind:group={data_point} name="justify" value={5}>Variance (m)</RadioItem>
</RadioGroup>
<div class="flex items-center space-x-2">
<span>Auto Optimization</span>
<SlideToggle name="auto-optimization" bind:checked={autoOptimization} on:change={toggleAutoOptimization} />
</div>
</div>
</header>
<section class="p-4 pt-0">
Expand Down

0 comments on commit d33d70a

Please sign in to comment.