Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slider for calibration #763

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/Controllers/StateController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,22 @@ public async Task<IActionResult> ResetCalibration()
return StatusCode(500, new { error = "An error occurred while resetting calibration" });
}
}

[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 });
}
}


9 changes: 3 additions & 6 deletions src/Services/MqttCoordinator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,20 +172,17 @@ private async Task OnMqttMessageReceived(MqttApplicationMessageReceivedEventArgs
}
catch (JsonSerializationException ex)
{
_logger.LogError(ex, "JSON deserialization error for topic {Topic}. Payload: {Payload}",
arg.ApplicationMessage.Topic, payload);
_logger.LogError(ex, "JSON deserialization error for topic {Topic}. Payload: {Payload}", arg.ApplicationMessage.Topic, payload);
MqttMessageMalformed?.Invoke(this, EventArgs.Empty);
}
catch (MqttMessageProcessingException ex)
{
_logger.LogError(ex, "Error processing {MessageType} message for topic {Topic}. Payload: {Payload}",
ex.MessageType, ex.Topic, ex.Payload);
_logger.LogError(ex, "Error processing {MessageType} message for topic {Topic}. Payload: {Payload}", ex.MessageType, ex.Topic, ex.Payload);
MqttMessageMalformed?.Invoke(this, EventArgs.Empty);
}
catch (Exception ex)
{
_logger.LogError(ex, "Unexpected error processing message for topic {Topic}. Payload: {Payload}",
arg.ApplicationMessage.Topic, payload);
_logger.LogError(ex, "Unexpected error processing message for topic {Topic}. Payload: {Payload}", arg.ApplicationMessage.Topic, payload);
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 @@ -5,6 +5,8 @@
import { getToastStore } from '@skeletonlabs/skeleton';
import { getModalStore } from '@skeletonlabs/skeleton';
import { base } from '$app/paths';
import { SlideToggle } from '@skeletonlabs/skeleton';
import { onMount } from 'svelte';

enum DataPoint {
ErrorPercent = 0,
Expand Down Expand Up @@ -96,6 +98,40 @@
});
}
}
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 Down Expand Up @@ -125,7 +161,11 @@
<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>
<button class="btn variant-filled-warning" on:click={resetCalibration}> Reset Calibration </button>
<div class="flex items-center space-x-2">
<span>Auto Optimization</span>
<SlideToggle name="auto-optimization" bind:checked={autoOptimization} on:change={toggleAutoOptimization} />
<button class="btn variant-filled-warning" on:click={resetCalibration}> Reset Calibration </button>
</div>
</div>
</header>
<section class="p-4 pt-0">
Expand Down
Loading