🎨 format

This commit is contained in:
Rune Harlyk
2025-10-11 10:42:32 +02:00
parent 4d51b9f556
commit 91a7b170fe
139 changed files with 6645 additions and 6317 deletions
@@ -1,12 +1,12 @@
<script lang="ts">
import Servos from './servos.svelte'
import ServoTable from './ServoTable.svelte'
import Servos from './servos.svelte'
import ServoTable from './ServoTable.svelte'
let servoId = $state(0)
let pwm = $state(306)
let servoId = $state(0)
let pwm = $state(306)
</script>
<div class="mx-0 my-1 flex flex-col space-y-4 sm:mx-8 sm:my-8">
<Servos bind:servoId bind:pwm />
<ServoTable {servoId} {pwm} />
<Servos bind:servoId bind:pwm />
<ServoTable {servoId} {pwm} />
</div>
+5 -5
View File
@@ -1,7 +1,7 @@
import type { PageLoad } from './$types';
import type { PageLoad } from './$types'
export const load = (async () => {
return {
title: 'Servo'
};
}) satisfies PageLoad;
return {
title: 'Servo'
}
}) satisfies PageLoad
+107 -103
View File
@@ -1,113 +1,117 @@
<script lang="ts">
import { api } from '$lib/api'
import { onMount } from 'svelte'
import { RotateCw, RotateCcw } from '$lib/components/icons'
interface Props {
data?: any
servoId?: number
pwm?: number
}
let {
data = $bindable({
servos: []
}),
pwm = $bindable(306),
servoId = $bindable(0)
}: Props = $props()
const updateValue = (event: Event, index: number, key: string) => {
data.servos[index][key] = Number((event.target as HTMLInputElement).value)
}
const syncConfig = async () => {
await api.post('/api/servo/config', data)
}
const toggleDirection = async (index: number) => {
data.servos[index].direction = data.servos[index].direction === 1 ? -1 : 1
await syncConfig()
}
onMount(async () => {
const result = await api.get('/api/servo/config')
if (result.isOk()) {
data = result.inner
import { api } from '$lib/api'
import { onMount } from 'svelte'
import { RotateCw, RotateCcw } from '$lib/components/icons'
interface Props {
data?: any
servoId?: number
pwm?: number
}
})
const setCenterPWM = async () => {
console.log('setCenterPWM', servoId, pwm)
data.servos[servoId]['center_pwm'] = pwm
await syncConfig()
}
let {
data = $bindable({
servos: []
}),
pwm = $bindable(306),
servoId = $bindable(0)
}: Props = $props()
const updateValue = (event: Event, index: number, key: string) => {
data.servos[index][key] = Number((event.target as HTMLInputElement).value)
}
const syncConfig = async () => {
await api.post('/api/servo/config', data)
}
const toggleDirection = async (index: number) => {
data.servos[index].direction = data.servos[index].direction === 1 ? -1 : 1
await syncConfig()
}
onMount(async () => {
const result = await api.get('/api/servo/config')
if (result.isOk()) {
data = result.inner
}
})
const setCenterPWM = async () => {
console.log('setCenterPWM', servoId, pwm)
data.servos[servoId]['center_pwm'] = pwm
await syncConfig()
}
</script>
<div>
<button class="btn btn-sm btn-primary" onclick={() => setCenterPWM()}>Set center pwm</button>
<button class="btn btn-sm btn-primary" onclick={() => setCenterPWM()}>Set center pwm</button>
</div>
<div class="overflow-x-auto">
<table class="table table-xs">
<thead>
<tr>
<th>Servo</th>
<th>Center PWM</th>
<th>Center Angle</th>
<th>Direction</th>
<th>Conversion</th>
</tr>
</thead>
<tbody>
{#each data.servos as servo, index}
<tr class="hover:bg-base-200">
<td class="font-medium">Servo {index}</td>
<td>
<input
type="number"
class="input input-sm input-bordered w-20"
value={servo.center_pwm}
onblur={syncConfig}
oninput={event => updateValue(event, index, 'center_pwm')}
min="80"
max="600" />
</td>
<td>
<input
type="number"
step="0.1"
class="input input-sm input-bordered w-20"
value={servo.center_angle}
onblur={syncConfig}
oninput={event => updateValue(event, index, 'center_angle')}
min="-90"
max="90" />
</td>
<td>
<button
class="btn btn-sm btn-ghost"
title="Toggle direction {servo.direction}"
onclick={() => toggleDirection(index)}>
{#if servo.direction === 1}
<RotateCw class="w-4 h-4 text-green-500" />
{:else}
<RotateCcw class="w-4 h-4" />
{/if}
</button>
</td>
<td>
<input
type="number"
step="0.01"
class="input input-sm input-bordered w-20"
value={servo.conversion}
onblur={syncConfig}
oninput={event => updateValue(event, index, 'conversion')}
min="0"
max="10" />
</td>
</tr>
{/each}
</tbody>
</table>
<table class="table table-xs">
<thead>
<tr>
<th>Servo</th>
<th>Center PWM</th>
<th>Center Angle</th>
<th>Direction</th>
<th>Conversion</th>
</tr>
</thead>
<tbody>
{#each data.servos as servo, index}
<tr class="hover:bg-base-200">
<td class="font-medium">Servo {index}</td>
<td>
<input
type="number"
class="input input-sm input-bordered w-20"
value={servo.center_pwm}
onblur={syncConfig}
oninput={event => updateValue(event, index, 'center_pwm')}
min="80"
max="600"
/>
</td>
<td>
<input
type="number"
step="0.1"
class="input input-sm input-bordered w-20"
value={servo.center_angle}
onblur={syncConfig}
oninput={event => updateValue(event, index, 'center_angle')}
min="-90"
max="90"
/>
</td>
<td>
<button
class="btn btn-sm btn-ghost"
title="Toggle direction {servo.direction}"
onclick={() => toggleDirection(index)}
>
{#if servo.direction === 1}
<RotateCw class="w-4 h-4 text-green-500" />
{:else}
<RotateCcw class="w-4 h-4" />
{/if}
</button>
</td>
<td>
<input
type="number"
step="0.01"
class="input input-sm input-bordered w-20"
value={servo.conversion}
onblur={syncConfig}
oninput={event => updateValue(event, index, 'conversion')}
min="0"
max="10"
/>
</td>
</tr>
{/each}
</tbody>
</table>
</div>
+49 -47
View File
@@ -1,64 +1,66 @@
<script lang="ts">
import { socket } from '$lib/stores'
import { MessageTopic } from '$lib/types/models'
import { throttler as Throttler } from '$lib/utilities'
import { socket } from '$lib/stores'
import { MessageTopic } from '$lib/types/models'
import { throttler as Throttler } from '$lib/utilities'
let { servoId = $bindable(0), pwm = $bindable(306) } = $props()
let { servoId = $bindable(0), pwm = $bindable(306) } = $props()
let active = $state(false)
let active = $state(false)
let allServos = $state(false)
let allServos = $state(false)
const throttler = new Throttler()
const throttler = new Throttler()
const activateServo = () => {
socket.sendEvent(MessageTopic.servoState, { active: 1 })
}
const activateServo = () => {
socket.sendEvent(MessageTopic.servoState, { active: 1 })
}
const deactivateServo = () => {
socket.sendEvent(MessageTopic.servoState, { active: 0 })
}
const deactivateServo = () => {
socket.sendEvent(MessageTopic.servoState, { active: 0 })
}
const updatePWM = () => {
throttler.throttle(() => {
socket.sendEvent(MessageTopic.servoPWM, { servo_id: servoId, pwm })
}, 10)
}
const updatePWM = () => {
throttler.throttle(() => {
socket.sendEvent(MessageTopic.servoPWM, { servo_id: servoId, pwm })
}, 10)
}
const toggleMode = () => {
servoId = allServos ? -1 : 0
}
const toggleMode = () => {
servoId = allServos ? -1 : 0
}
</script>
<div class="flex flex-col">
<h2 class="text-lg">General servo configuration</h2>
<span>Servo</span>
<span>{pwm}</span>
<h2 class="text-lg">General servo configuration</h2>
<span>Servo</span>
<span>{pwm}</span>
</div>
<input
type="range"
min="80"
max="600"
bind:value={pwm}
oninput={updatePWM}
class="w-full h-2 bg-gray-200 rounded-lg appearance-none cursor-pointer dark:bg-gray-700" />
type="range"
min="80"
max="600"
bind:value={pwm}
oninput={updatePWM}
class="w-full h-2 bg-gray-200 rounded-lg appearance-none cursor-pointer dark:bg-gray-700"
/>
<div class="flex flex-col">
<h2 class="text-lg">General servo configuration</h2>
<span>
<label for="mode">All servoes</label>
<input type="checkbox" class="toggle" bind:checked={allServos} onchange={toggleMode} />
</span>
<span>
<label for="active">Active</label>
<input
type="checkbox"
class="toggle"
bind:checked={active}
onchange={active ? activateServo : deactivateServo} />
</span>
<span class="flex items-center gap-2">
<label for="servoId">Servo active {servoId}</label>
<input type="range" min="0" max="11" step="1" bind:value={servoId} />
</span>
<h2 class="text-lg">General servo configuration</h2>
<span>
<label for="mode">All servoes</label>
<input type="checkbox" class="toggle" bind:checked={allServos} onchange={toggleMode} />
</span>
<span>
<label for="active">Active</label>
<input
type="checkbox"
class="toggle"
bind:checked={active}
onchange={active ? activateServo : deactivateServo}
/>
</span>
<span class="flex items-center gap-2">
<label for="servoId">Servo active {servoId}</label>
<input type="range" min="0" max="11" step="1" bind:value={servoId} />
</span>
</div>