🔋 Adds battery model

This commit is contained in:
Rune Harlyk
2024-07-14 23:10:39 +02:00
committed by Rune Harlyk
parent cfa3e58d09
commit c783793b5c
4 changed files with 15 additions and 15 deletions
@@ -6,20 +6,20 @@
import Battery100 from '~icons/tabler/battery-4'; import Battery100 from '~icons/tabler/battery-4';
import BatteryCharging from '~icons/tabler/battery-charging-2'; import BatteryCharging from '~icons/tabler/battery-charging-2';
export let charging = false; export let current = 0;
export let soc = 100; export let voltage = 0;
</script> </script>
<div class="tooltip tooltip-bottom" data-tip="{soc} %"> <div class="tooltip tooltip-left z-10" data-tip="{voltage}V {Math.floor(current*10)/10} mA">
{#if charging} {#if voltage == 0}
<BatteryCharging class="{$$props.class || ''} -rotate-90 animate-pulse" /> <BatteryCharging class="{$$props.class || ''} -rotate-90 animate-pulse" />
{:else if soc > 75} {:else if voltage > 8.2}
<Battery100 class="{$$props.class || ''} -rotate-90" /> <Battery100 class="{$$props.class || ''} -rotate-90" />
{:else if soc > 55} {:else if voltage > 8}
<Battery75 class="{$$props.class || ''} -rotate-90" /> <Battery75 class="{$$props.class || ''} -rotate-90" />
{:else if soc > 30} {:else if voltage > 7.8}
<Battery50 class="{$$props.class || ''} -rotate-90" /> <Battery50 class="{$$props.class || ''} -rotate-90" />
{:else if soc > 5} {:else if voltage > 7.6}
<Battery25 class="{$$props.class || ''} -rotate-90" /> <Battery25 class="{$$props.class || ''} -rotate-90" />
{:else} {:else}
<Battery0 class="{$$props.class || ''} text-error -rotate-90 animate-pulse" /> <Battery0 class="{$$props.class || ''} text-error -rotate-90 animate-pulse" />
+3 -3
View File
@@ -6,8 +6,8 @@ let telemetry_data = {
rssi: 0 rssi: 0
}, },
battery: { battery: {
soc: 100, voltage: 100,
charging: false current: false
}, },
download_ota: { download_ota: {
status: 'none', status: 'none',
@@ -30,7 +30,7 @@ function createTelemetry() {
setBattery: (data: Battery) => { setBattery: (data: Battery) => {
update((telemetry_data) => ({ update((telemetry_data) => ({
...telemetry_data, ...telemetry_data,
battery: { soc: data.soc, charging: data.charging } battery: { voltage: data.voltage, current: data.current }
})); }));
}, },
setDownloadOTA: (data: DownloadOTA) => { setDownloadOTA: (data: DownloadOTA) => {
+2 -2
View File
@@ -70,8 +70,8 @@ export type RSSI = {
}; };
export type Battery = { export type Battery = {
soc: number; voltage: number;
charging: boolean; current: boolean;
}; };
export type DownloadOTA = { export type DownloadOTA = {
+2 -2
View File
@@ -61,8 +61,8 @@
{#if $page.data.features.battery} {#if $page.data.features.battery}
<div class="flex-none"> <div class="flex-none">
<BatteryIndicator <BatteryIndicator
charging={$telemetry.battery.charging} voltage={$telemetry.battery.voltage}
soc={$telemetry.battery.soc} current={$telemetry.battery.current}
class="h-7 w-7" class="h-7 w-7"
/> />
</div> </div>