mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-12-05 08:12:29 -08:00
Runtime (#1678)
This commit is contained in:
7 files changed
+66
-25
No files matched your search
@@ -2,11 +2,14 @@ import { useConfig } from '@/hooks/config';
|
||||
import { useLocaleConfig } from '@/i18n/config';
|
||||
import { BatteryIcon } from '@/components/commons/icon/BatteryIcon';
|
||||
import { Typography } from '@/components/commons/Typography';
|
||||
import { Tooltip } from '@/components/commons/Tooltip';
|
||||
|
||||
export function TrackerBattery({
|
||||
value,
|
||||
voltage,
|
||||
runtime,
|
||||
disabled,
|
||||
moreInfo = false,
|
||||
textColor = 'primary',
|
||||
}: {
|
||||
/**
|
||||
@@ -14,7 +17,9 @@ export function TrackerBattery({
|
||||
*/
|
||||
value: number;
|
||||
voltage?: number | null;
|
||||
runtime?: bigint | null;
|
||||
disabled?: boolean;
|
||||
moreInfo?: boolean;
|
||||
textColor?: string;
|
||||
}) {
|
||||
const { currentLocales } = useLocaleConfig();
|
||||
@@ -28,31 +33,49 @@ export function TrackerBattery({
|
||||
});
|
||||
|
||||
const charging = (voltage || 0) > 4.3;
|
||||
const showVoltage = voltage && config?.debug;
|
||||
const debug = config?.debug || config?.devSettings.moreInfo;
|
||||
const showVoltage = moreInfo && voltage && debug;
|
||||
|
||||
return (
|
||||
<div className="flex gap-2">
|
||||
<div className="flex flex-col justify-around">
|
||||
<BatteryIcon value={value} disabled={disabled} charging={charging} />
|
||||
<Tooltip
|
||||
disabled={!charging && (!runtime || debug)}
|
||||
preferedDirection="left"
|
||||
content=<Typography>{percentFormatter.format(value)}</Typography>
|
||||
>
|
||||
<div className="flex gap-2">
|
||||
<div className="flex flex-col justify-around">
|
||||
<BatteryIcon value={value} disabled={disabled} charging={charging} />
|
||||
</div>
|
||||
{((!charging || showVoltage) && (
|
||||
<div className="w-15">
|
||||
{!charging && runtime != null && runtime > 0 && (
|
||||
<Typography color={textColor}>
|
||||
{(runtime / BigInt(3600000000)).toString() +
|
||||
'h ' +
|
||||
(
|
||||
(runtime % BigInt(3600000000)) /
|
||||
BigInt(60000000)
|
||||
).toString() +
|
||||
'min'}
|
||||
</Typography>
|
||||
)}
|
||||
{!charging && (!runtime || debug) && (
|
||||
<Typography color={textColor}>
|
||||
{percentFormatter.format(value)}
|
||||
</Typography>
|
||||
)}
|
||||
{showVoltage && (
|
||||
<Typography color={textColor}>
|
||||
{voltageFormatter.format(voltage)}V
|
||||
</Typography>
|
||||
)}
|
||||
</div>
|
||||
)) || (
|
||||
<div className="flex flex-col justify-center w-15">
|
||||
<div className="w-5 h-1 bg-background-30 rounded-full" />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{((!charging || showVoltage) && (
|
||||
<div className="w-10">
|
||||
{!charging && (
|
||||
<Typography color={textColor}>
|
||||
{percentFormatter.format(value)}
|
||||
</Typography>
|
||||
)}
|
||||
{showVoltage && (
|
||||
<Typography color={textColor}>
|
||||
{voltageFormatter.format(voltage)}V
|
||||
</Typography>
|
||||
)}
|
||||
</div>
|
||||
)) || (
|
||||
<div className="flex flex-col justify-center w-10">
|
||||
<div className="w-5 h-1 bg-background-30 rounded-full" />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</Tooltip>
|
||||
);
|
||||
}
|
||||
@@ -51,7 +51,9 @@ function TrackerBig({
|
||||
<TrackerBattery
|
||||
voltage={device.hardwareStatus.batteryVoltage}
|
||||
value={device.hardwareStatus.batteryPctEstimate / 100}
|
||||
runtime={device.hardwareStatus.batteryRuntimeEstimate}
|
||||
disabled={tracker.status === TrackerStatusEnum.DISCONNECTED}
|
||||
moreInfo={true}
|
||||
/>
|
||||
)}
|
||||
<div className="flex gap-2">
|
||||
@@ -119,6 +121,7 @@ function TrackerSmol({
|
||||
<TrackerBattery
|
||||
voltage={device.hardwareStatus.batteryVoltage}
|
||||
value={device.hardwareStatus.batteryPctEstimate / 100}
|
||||
runtime={device.hardwareStatus.batteryRuntimeEstimate}
|
||||
disabled={tracker.status === TrackerStatusEnum.DISCONNECTED}
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -229,7 +229,9 @@ function Row({
|
||||
<TrackerBattery
|
||||
value={device.hardwareStatus.batteryPctEstimate / 100}
|
||||
voltage={device.hardwareStatus.batteryVoltage}
|
||||
runtime={device.hardwareStatus.batteryRuntimeEstimate}
|
||||
disabled={tracker.status === TrackerStatusEnum.DISCONNECTED}
|
||||
moreInfo={config?.devSettings.moreInfo}
|
||||
textColor={fontColor}
|
||||
/>
|
||||
)}
|
||||
@@ -329,7 +331,7 @@ export function TrackersTable({
|
||||
const cols = [
|
||||
'minmax(150px, 1.5fr)', // Name
|
||||
'minmax(100px, 1fr)', // Type
|
||||
'minmax(60px, 1fr)', // Battery
|
||||
'minmax(110px, 1fr)', // Battery
|
||||
'6rem', // Ping (w-24)
|
||||
'minmax(60px, 1fr)', // TPS
|
||||
config?.devSettings?.preciseRotation ? '11rem' : '8rem', // Rotation
|
||||
|
||||
@@ -317,6 +317,9 @@ public class DataFeedBuilder {
|
||||
HardwareStatus.addRssi(fbb, (short) tracker.getSignalStrength().floatValue());
|
||||
}
|
||||
|
||||
if (tracker.getBatteryRemainingRuntime() != null) {
|
||||
HardwareStatus.addBatteryRuntimeEstimate(fbb, tracker.getBatteryRemainingRuntime());
|
||||
}
|
||||
|
||||
int hardwareDataOffset = HardwareStatus.endHardwareStatus(fbb);
|
||||
int hardwareInfoOffset = DataFeedBuilder.createHardwareInfo(fbb, device);
|
||||
|
||||
@@ -112,6 +112,7 @@ class Tracker @JvmOverloads constructor(
|
||||
val trackerFlexHandler: TrackerFlexHandler = TrackerFlexHandler(this)
|
||||
var batteryVoltage: Float? = null
|
||||
var batteryLevel: Float? = null
|
||||
var batteryRemainingRuntime: Long? = null
|
||||
var ping: Int? = null
|
||||
var signalStrength: Int? = null
|
||||
var temperature: Float? = null
|
||||
|
||||
@@ -138,6 +138,7 @@ class HIDCommon {
|
||||
}
|
||||
|
||||
// Packet data
|
||||
var runtime: Long? = null
|
||||
var batt: Int? = null
|
||||
var batt_v: Int? = null
|
||||
var temp: Int? = null
|
||||
@@ -221,6 +222,11 @@ class HIDCommon {
|
||||
}
|
||||
}
|
||||
|
||||
5 -> { // runtime
|
||||
// ulong as little endian
|
||||
runtime = (dataReceived[i + 9].toUByte().toLong() shl 56) or (dataReceived[i + 8].toUByte().toLong() shl 48) or (dataReceived[i + 7].toUByte().toLong() shl 40) or (dataReceived[i + 6].toUByte().toLong() shl 32) or (dataReceived[i + 5].toUByte().toLong() shl 24) or (dataReceived[i + 4].toUByte().toLong() shl 16) or (dataReceived[i + 3].toUByte().toLong() shl 8) or dataReceived[i + 2].toUByte().toLong()
|
||||
}
|
||||
|
||||
6 -> { // data
|
||||
button = dataReceived[i + 2].toUByte().toInt()
|
||||
rssi = dataReceived[i + 15].toUByte().toInt()
|
||||
@@ -248,6 +254,9 @@ class HIDCommon {
|
||||
}
|
||||
|
||||
// Assign data
|
||||
if (runtime != null) {
|
||||
tracker.batteryRemainingRuntime = runtime
|
||||
}
|
||||
if (batt != null) {
|
||||
tracker.batteryLevel = if (batt == 128) 1f else (batt and 127).toFloat()
|
||||
}
|
||||
|
||||
+1
-1
Submodule solarxr-protocol updated: b51232989c...3400a6e6dd.
Reference in new issue
Block a user