forked from kruzhok-team/lapki-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Поддержка МС-ТЮК в загрузчике (бета) (kruzhok-team#449)
- Локальный загрузчик распознаёт интерфейс программирования МС-ТЮК - Можно прошивать устройство по заданному адресу, пинговать или узнавать адрес - Прототип менеджера МС-ТЮК Кроме этого, содержит в себе PR: - Фикс распознавания клона Uno (kruzhok-team#451) - Исправление возможных проблем с синхронизацией внутри загрузчика (kruzhok-team#441) - Возможность заменить список устройств для локального загрузчика (kruzhok-team#452)
- Loading branch information
1 parent
ba54386
commit 83ded55
Showing
15 changed files
with
487 additions
and
92 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
Окно менеджера для МС-ТЮК | ||
*/ | ||
import { useEffect, useLayoutEffect, useRef, useState } from 'react'; | ||
|
||
import { useManagerMS } from '@renderer/store/useManagerMS'; | ||
import { useSerialMonitor } from '@renderer/store/useSerialMonitor'; | ||
|
||
import { Flasher } from './Modules/Flasher'; | ||
import { ManagerMS } from './Modules/ManagerMS'; | ||
import { Switch, TextField } from './UI'; | ||
|
||
export const ManagerMSTab: React.FC = () => { | ||
const { device, log, setLog, address, setAddress } = useManagerMS(); | ||
const { device: serialMonitorDevice, connectionStatus: serialConnectionStatus } = | ||
useSerialMonitor(); | ||
const [autoScroll, setAutoScroll] = useState<boolean>(true); | ||
const logContainerRef = useRef<HTMLDivElement>(null); | ||
// При изменении log прокручиваем вниз, если включена автопрокрутка | ||
useLayoutEffect(() => { | ||
if (autoScroll && logContainerRef.current) { | ||
logContainerRef.current.scrollTop = logContainerRef.current.scrollHeight; | ||
} | ||
}, [log, autoScroll]); | ||
useEffect(() => { | ||
setAddress(''); | ||
}, [device]); | ||
const handleGetAddress = () => { | ||
if (!device) return; | ||
ManagerMS.getAddress(device.deviceID); | ||
}; | ||
const handleSendBin = () => { | ||
if (!device) return; | ||
Flasher.setFile().then(() => { | ||
ManagerMS.binStart(device, address, serialMonitorDevice, serialConnectionStatus); | ||
}); | ||
}; | ||
const handlePing = () => { | ||
if (!device) return; | ||
ManagerMS.ping(device.deviceID, address); | ||
ManagerMS.addLog('Отправлен пинг на устройство'); | ||
}; | ||
const handleCurrentDeviceDisplay = () => { | ||
if (device === undefined) { | ||
return 'Устройство отсутствует'; | ||
} | ||
return device.displayName(); | ||
}; | ||
const handleClear = () => { | ||
setLog(() => []); | ||
}; | ||
return ( | ||
<section className="mr-3 flex h-full flex-col bg-bg-secondary"> | ||
<div className="m-2 flex justify-between">{handleCurrentDeviceDisplay()}</div> | ||
<div className="m-2"> | ||
<TextField | ||
label="Адрес:" | ||
className="mr-2 max-w-full" | ||
placeholder="Напишите адрес" | ||
value={address} | ||
onChange={(e) => setAddress(e.target.value)} | ||
/> | ||
</div> | ||
<div className="m-2 flex"> | ||
<button className="btn-primary mr-4" onClick={handleGetAddress}> | ||
Узнать адрес... | ||
</button> | ||
<button className="btn-primary mr-4" onClick={handleSendBin}> | ||
Отправить bin... | ||
</button> | ||
<button className="btn-primary mr-4" onClick={handlePing}> | ||
Пинг | ||
</button> | ||
</div> | ||
<div className="m-2 flex"> | ||
<div className="mr-4 flex w-40 items-center justify-between"> | ||
<Switch | ||
checked={autoScroll} | ||
onCheckedChange={() => { | ||
setAutoScroll(!autoScroll); | ||
}} | ||
/> | ||
Автопрокрутка | ||
</div> | ||
<button className="btn-primary" onClick={handleClear}> | ||
Очистить | ||
</button> | ||
</div> | ||
<div | ||
className="mx-2 h-full overflow-y-auto whitespace-break-spaces bg-bg-primary scrollbar-thin scrollbar-track-scrollbar-track scrollbar-thumb-scrollbar-thumb" | ||
ref={logContainerRef} | ||
> | ||
{log.map((msg, index) => ( | ||
<div key={index}>{msg}</div> | ||
))} | ||
</div> | ||
</section> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
export class Device { | ||
deviceID: string; | ||
name: string; | ||
|
||
constructor(device: Device) { | ||
this.deviceID = device.deviceID; | ||
this.name = device.name; | ||
} | ||
|
||
isMSDevice(): boolean { | ||
return this instanceof MSDevice; | ||
} | ||
|
||
isArduinoDevice(): boolean { | ||
return this instanceof ArduinoDevice; | ||
} | ||
|
||
displayName(): string { | ||
return this.name; | ||
} | ||
|
||
displaySerialName(): string { | ||
return this.displayName(); | ||
} | ||
} | ||
|
||
export class ArduinoDevice extends Device { | ||
controller: string; | ||
programmer: string; | ||
portName: string; | ||
serialID: string; | ||
|
||
constructor(device: ArduinoDevice) { | ||
super(device); | ||
this.controller = device.controller; | ||
this.programmer = device.programmer; | ||
this.portName = device.portName; | ||
this.serialID = device.serialID; | ||
} | ||
|
||
displayName(): string { | ||
return `${this.name} (${this.portName})`; | ||
} | ||
} | ||
|
||
export class MSDevice extends Device { | ||
portNames: string[]; | ||
|
||
constructor(device: MSDevice) { | ||
super(device); | ||
this.portNames = device.portNames; | ||
} | ||
|
||
displayName(): string { | ||
return `${this.name} (${this.portNames[0]})`; | ||
} | ||
displaySerialName(): string { | ||
return `${this.name} (${this.portNames[3]})`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.