# -*- coding: utf-8 -*- u"""P4B-HUB 的元件最终位置(分块摆放)。 页面分块(1170×825,标题栏占 x>455 且 y<192): y=800 ┌ 【去耦 bank】x 40~320, y 700~760 ─────────────────────────┐ │ 【B1 晶振】x 900~1140, y 620~760 │ 左侧端口列 x=170 【B2 RBIAS/VDD18PLL/VDD18】y 520~600 │ (标签朝左) ┌ U32 ┐ 【B3 口6/7禁用】y 430~510 │ 【B5 分压】 │65 脚│ 【B4 跳线下拉+RESET】y 340~420 │ x 40~80 └─────┘ 右侧端口列 x=760(标签朝右) y=340 ├───────────────────────────────────────────────────────────┤ │ 【B8 LDO】x 100~340 【B7 12V→5V】x 480~900 【去耦续】 │ y=192 ├──────────────── 标题栏从这里往下、往右 ────────────────────┤ │ 【B6 上游 USB-C】x 120~440, y 40~190(全在标题栏左边) │ y= 20 └───────────────────────────────────────────────────────────┘ 用法: python .claude/p4b_pos.py # 把元件挪到位并重新读回引脚 """ import io, json, os, sys HERE = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, HERE) PAGE = '7a469c6f43d6d0c8' POS = { 'U32': (500, 500, 0), # 【B1】晶振 'Y1': (1000, 700, 0), 'C740': (920, 660, 270), 'C741': (1090, 660, 270), # 【B2】RBIAS / VDD18PLL / VDD18 'R708': (960, 560, 270), 'C743': (1060, 560, 270), 'C742': (1130, 560, 270), # 【B3】端口 6/7 禁用上拉 'R714': (955, 450, 0), 'R715': (955, 490, 0), # 【B4】跳线下拉 + RESET 上拉 'R711': (920, 380, 270), 'R712': (970, 380, 270), 'R719': (1020, 380, 270), 'R720': (1070, 380, 270), 'R716': (1130, 380, 270), # 【B5】VBUS_DET 分压 'R709': (60, 400, 270), 'R710': (60, 320, 270), # 【B6】上游 USB-C 'J23': (260, 110, 0), 'R717': (400, 140, 0), 'R718': (400, 100, 0), # 【B7】12V → 5V 'C731': (500, 280, 270), 'C732': (535, 280, 270), 'U30': (600, 270, 0), 'C733': (660, 330, 270), 'L3': (730, 280, 0), 'C734': (790, 280, 270), 'C735': (825, 280, 270), 'R706': (880, 300, 270), 'R707': (880, 230, 270), # 【B8】5V → 3V3(Hub 专用) 'C736': (120, 260, 270), 'U31': (200, 260, 0), 'C737': (320, 260, 270), # 3V3 去耦 bank(PCB 上要贴到各电源脚,§10) 'C744': (60, 720, 270), 'C745': (95, 720, 270), 'C746': (130, 720, 270), 'C747': (165, 720, 270), 'C748': (200, 720, 270), 'C749': (235, 720, 270), 'C750': (270, 720, 270), 'C751': (305, 720, 270), } if __name__ == '__main__': from eda import run js = """ await eda.dmt_EditorControl.openDocument('%s'); await new Promise(r=>setTimeout(r,1500)); if ((await eda.dmt_Schematic.getCurrentSchematicPageInfo()).name !== 'P4B-HUB') return {err:'页面不对'}; const POS = %s; let n = 0; const miss = []; for (const c of await eda.sch_PrimitiveComponent.getAll()){ if (c.getState_ComponentType() !== 'part') continue; const d = c.getState_Designator(); if (!POS[d]) { miss.push(d); continue; } const [x, y, r] = POS[d]; await c.toAsync().setState_X(x).setState_Y(y).setState_Rotation(r).done(); n++; } const out = {}; for (const c of await eda.sch_PrimitiveComponent.getAll()){ if (c.getState_ComponentType() !== 'part') continue; const o = {}; for (const p of await c.getAllPins()) o[p.getState_PinNumber ? p.getState_PinNumber() : p.getState_PinName()] = [Math.round(p.getState_X()), Math.round(p.getState_Y()), p.getState_PinName()]; out[c.getState_Designator()] = o; } return {moved: n, missing: miss, pins: out}; """ % (PAGE, json.dumps(POS)) r = run(js, timeout=600) if not r.get('success'): print(json.dumps(r, ensure_ascii=False)[:400]); sys.exit(1) res = r['result'] print(u'挪了 %d 个,未在表里: %s' % (res['moved'], res['missing'])) io.open(os.path.join(HERE, 'p4b-pins.json'), 'w', encoding='utf-8').write( json.dumps(res['pins'], ensure_ascii=False, indent=1)) print(u'引脚已写入 .claude/p4b-pins.json')