56 lines
3.5 KiB
TypeScript
56 lines
3.5 KiB
TypeScript
import type {Sensor} from '../../../../packages/sensor-ui/src/contracts';
|
||
import type {SensorRowAction} from '../../../../packages/sensor-ui/src/extensions';
|
||
|
||
export interface RecoveryStatus {
|
||
supported:boolean; enabled:boolean; preview_wanted:boolean; phase:string;
|
||
wake_available?:boolean;
|
||
}
|
||
|
||
export function cameraRowActions(device:Sensor):readonly SensorRowAction[] {
|
||
if(device.online||!cameraStatus(device).recovery?.supported)return [];
|
||
return [{actionId:'power.wake',label:'Включить',
|
||
description:'На X4 должно быть включено «Пробуждение по Bluetooth». USB оставьте подключённым.',
|
||
disabled:!device.prepared||!(device.configured??device.snapshot.enrollment==='enrolled')||cameraStatus(device).recovery?.wake_available!==true}];
|
||
}
|
||
|
||
export interface CameraStatus {
|
||
connected:boolean; preview:number|null; recording:number|null; function_mode:number|null;
|
||
firmware?:string; battery?:{level:number}; storage?:{free_bytes:number};
|
||
alerts?:{battery_low?:boolean;storage_full?:boolean;temperature_high?:boolean};
|
||
recovery?:RecoveryStatus;
|
||
}
|
||
export interface CameraSettings {
|
||
mode:number; photo_modes:number[]; video_modes:number[]; photo_sizes:number[];
|
||
video_resolutions:{id:number;name:string}[];
|
||
values:Record<string,number>;
|
||
attributes:Record<string,{values:string[];depends_on:string[]}>;
|
||
}
|
||
export interface CameraFiles {items:string[];offset:number;total:number}
|
||
const state=(value:unknown)=>value===0||value===1||value===-1?value:null;
|
||
export function cameraStatus(device:Sensor):CameraStatus {
|
||
const value=device.camera_status??{};
|
||
return {...value,connected:value.connected===true,preview:state(value.preview),recording:state(value.recording),
|
||
function_mode:typeof value.function_mode==='number'&&Number.isInteger(value.function_mode)?value.function_mode:null} as CameraStatus;
|
||
}
|
||
export function cameraLabel(device:Sensor,fresh:boolean):{label:string;tone:'neutral'|'success'|'warning'|'danger'} {
|
||
if(!fresh||!device.online)return {label:fresh?'Камера отключена':'Нет свежих сведений',tone:'neutral'};
|
||
if(device.initializable===false)return {label:'Не удалось определить камеру',tone:'warning'};
|
||
if(!(device.configured??device.snapshot.enrollment==='enrolled'))return {label:'Требуется подготовка',tone:'neutral'};
|
||
if(!device.prepared)return {label:'Драйвер недоступен',tone:'warning'};
|
||
const value=cameraStatus(device);
|
||
if(!value.connected||value.recording===null||value.preview===null)return {label:'Состояние камеры не подтверждено',tone:'warning'};
|
||
if(value.recording===1)return {label:'Запись на карту камеры',tone:'success'};
|
||
if(value.recording===-1)return {label:'Состояние записи не подтверждено',tone:'warning'};
|
||
if(value.preview===-1)return {label:'Состояние просмотра не подтверждено',tone:'warning'};
|
||
if(value.preview===1)return {label:'Идёт просмотр',tone:'success'};
|
||
return {label:'Подключена',tone:'success'};
|
||
}
|
||
export function resolutionLabel(value:string):string {
|
||
const match=/^(\d+)_(\d+)_(\d+)(.*)$/.exec(value);
|
||
return match?`${match[1]} × ${match[2]} · ${match[3]} кадр/с${match[4]==='_plus'?' · повышенное качество':''}`:value;
|
||
}
|
||
export function fileName(value:string):string {
|
||
const path=value.split('?')[0].split('/').at(-1)??value;
|
||
try{return decodeURIComponent(path);}catch{return path;}
|
||
}
|