feat: v1.0.0 收尾 — 五芯片 DTR/RTS、类型声明、示例、CI
test / test (push) Canceled after 0s

- CP210x / FTDI / PL2303 补齐 setSignals()(编码与各自初始化序列一致)
- 新增 index.d.ts(TypeScript 类型声明)、examples/minimal.html(最小接入示例)
- 新增 .gitea/workflows/ci.yml(push 时跑离线单测)、.gitattributes(强制 LF)、CHANGELOG.md
- package.json 补 repository / homepage / bugs / types / engines
- 单测 16 项全部通过:node test/driver.test.mjs
This commit is contained in:
2026-09-23 00:41:29 +08:00
parent f02c0b06b8
commit 6c5e647c8a
9 changed files with 271 additions and 10 deletions
+32
View File
@@ -255,6 +255,38 @@ await t('DTR/RTS 控制(CH340 走 0xA4 取反写入)', async () => {
await port.close();
});
await t('CP210x / FTDI / PL2303 的 DTR/RTS 编码', async () => {
// CP210x: vendor/interface req 0x07, value = 0x0300 | (DTR|RTS)
const cp = new MockDevice({ vendorId: 0x10c4, productId: 0xea60 });
const cport = api.fromDevice(cp, {});
await cport.open({ baudRate: 115200 });
cp.control.length = 0;
await cport.setSignals({ dataTerminalReady: true, requestToSend: true });
eq(cp.control, [['out', 'vendor', 'interface', 0x07, 0x0303, 0, null]]);
cp.control.length = 0;
await cport.setSignals({ dataTerminalReady: false, requestToSend: false });
eq(cp.control, [['out', 'vendor', 'interface', 0x07, 0x0300, 0, null]]);
await cport.close();
// FTDI: vendor/device req 0x01, index = controlInterface+1, value = 0x0300 | (DTR|RTS)
const ft = new MockDevice({ vendorId: 0x0403, productId: 0x6001 });
const fport = api.fromDevice(ft, {});
await fport.open({ baudRate: 115200 });
ft.control.length = 0;
await fport.setSignals({ dataTerminalReady: true, requestToSend: false });
eq(ft.control, [['out', 'vendor', 'device', 0x01, 0x0301, 1, null]]);
await fport.close();
// PL2303: class/interface req 0x22, value = bit0 DTR | bit1 RTS
const pl = new MockDevice({ vendorId: 0x067b, productId: 0x2303, deviceClass: 0x02 });
const pport = api.fromDevice(pl, {});
await pport.open({ baudRate: 115200 });
pl.control.length = 0;
await pport.setSignals({ requestToSend: true, dataTerminalReady: false });
eq(pl.control, [['out', 'class', 'interface', 0x22, 0x0002, 0, null]]);
await pport.close();
});
await t('关闭:释放接口 + 关闭设备(CDC 会先 shutdown)', async () => {
const dev = new MockDevice();
const port = api.fromDevice(dev, {});