import {useRef,useState} from 'react'; import {Button,InspectorSelectField,ResourceList,ResourceRow,SettingsCard} from '@nodedc/ui-react'; import type {SensorBoardSettingsProps} from '../../../../packages/sensor-ui/src/extensions'; import {perform,type Sensor} from '../../../../packages/sensor-ui/src/contracts'; import {drivePositions,vescStatus,type DriveProfile} from './model'; import {VescLimits} from './VescLimits'; export function VescBoardSettings({inventory,transport,enabled,refresh,failure,openDevice}:SensorBoardSettingsProps){ const controllers=inventory?.items.filter(device=>device.kind==='vesc.controller')??[]; const profile=controllers.map(device=>vescStatus(device).drive_profile).filter((value):value is DriveProfile=>!!value).sort((a,b)=>b.revision-a.revision)[0]; const anchor=controllers.find(device=>device.online&&device.verified&&vescStatus(device).board_settings_supported); const [busy,setBusy]=useState(false);const running=useRef(false); const active=inventory?.operations?.some(value=>['queued','running'].includes(value.state)&&controllers.some(device=>device.id===value.device_id)); const blocked=!enabled||!anchor||busy||active||!profile; const positions=drivePositions(profile?.layout??null); async function change(device:Sensor,action:string,parameters:Record){ if(blocked||running.current||!profile)return; running.current=true;setBusy(true);failure(null); try{await perform(transport,device,action,{revision:profile.revision,...parameters});await refresh();} catch(error){failure(error);await refresh();}finally{running.current=false;setBusy(false);} } return
{if(anchor)void change(anchor,'vesc.drive.layout',{layout});}}/> {!profile&&

{inventory?'Подключите VESC, чтобы получить профиль привода с борта.':'Получение профиля привода…'}

} {profile&&!anchor&&

Профиль показан по последним сведениям с борта. Для изменения нужна связь с VESC и актуальное бортовое приложение.

} {profile?.layout&&<>

Стороны — по направлению движения вперёд. Назначения сохраняются автоматически и остаются с контроллером при смене USB-порта.

{Object.entries(positions).map(([slot,label])=>{ const bound=profile.bindings[slot]; const missing=bound&&!controllers.some(device=>device.id===bound.device_id); return ({value:device.id,label:device.name+(!device.online?' · нет связи':''),disabled:!device.online||!device.verified||Object.entries(profile.bindings).some(([other,binding])=>other!==slot&&binding.device_id===device.id)})), ...(missing?[{value:bound.device_id,label:`VESC ${bound.uuid.slice(0,6).toUpperCase()} · нет связи`,disabled:true}]:[]), ]} onChange={id=>{ const target=id?controllers.find(device=>device.id===id):anchor; if(!target)return; void change(target,id?'vesc.drive.assign':'vesc.drive.unassign',id?{layout:profile.layout,slot}:{slot}); }}/>; })} {Object.entries(profile.bindings).map(([slot,binding])=>{ const target=controllers.find(device=>device.id===binding.device_id); return
  • openDevice(binding.device_id)}>Настройка мотора}/>
  • ; })}
    }
    ; }