// 系统设计
项目架构
Eidolon 是一个完全本地的 Arduino 仿真器,使用官方的 Wokwi 仓库以获得最大兼容性。它具有真实的 AVR8 CPU 仿真、48 个以上的交互式电子组件、全面的导线系统以及构建时的组件发现管道。
高级概述
Browser (React + Vite)
├── Monaco Editor ──► useEditorStore (Zustand)
├── SimulatorCanvas ──► useSimulatorStore (Zustand)
│ ├── AVRSimulator (avr8js) 16 MHz AVR8 CPU
│ ├── RP2040Simulator (rp2040js)
│ ├── PinManager pin → component mapping
│ ├── PartSimulationRegistry 16 interactive parts
│ └── 48+ wokwi-elements Lit Web Components
└── HTTP (Axios) ──► eidolon-server (port 8001)
└── eidolon-firmware ──► arduino-cli subprocess数据流
1. 编译
Click "Compile"
→ EditorToolbar reads all workspace files
→ POST /api/compile/ { files, board_fqbn }
→ eidolon-firmware writes the sketch to a build directory
→ arduino-cli compile --fqbn <board> --output-dir build/
→ Returns hex_content (Intel HEX string)
→ useSimulatorStore.setCompiledHex() → loadHex()2. 仿真循环
Click "Run"
→ AVRSimulator.start()
→ requestAnimationFrame loop @ ~60 FPS
→ Each frame: Math.floor(267 000 × speed) cycles
├── avrInstruction(cpu) — decode + execute one AVR instruction
└── cpu.tick() — advance Timer0/1/2, USART, ADC
→ PORTB/C/D write listeners fire
→ PinManager.updatePort() → per-pin callbacks
→ PartSimulationRegistry.onPinStateChange()
→ wokwi-elements update visually3. 输入组件
User presses button on canvas
→ wokwi web component fires 'button-press' event
→ DynamicComponent catches event
→ PartSimulationRegistry.attachEvents() handler
→ AVRSimulator.setPinState(arduinoPin, LOW)
→ AVRIOPort.setPin() injects external pin state
→ CPU reads pin in next instruction关键前端存储 (Zustand)
| 存储 | 关键状态 | 用途 |
|---|---|---|
useEditorStore | files[], activeFileId | 多文件 Monaco 工作区 |
useSimulatorStore | simulator, components, wires, running | 仿真 + 画布状态 |
useProjectStore | projectId, slug | 当前打开的项目 |
后端路由
| 路由 | 描述 |
|---|---|
POST /api/compile/ | 编译草图文件 - Intel HEX / UF2 |
GET /api/compile/boards | 列出可用开发板 |
GET /api/libraries/* | Arduino 库管理器集成 |
GET /health | 健康检查端点 |
导线系统
导线存储为对象,其起点/终点端点连接到组件引脚位置:
1{
2 id: string
3 start: { componentId, pinName, x, y }
4 end: { componentId, pinName, x, y }
5 color: string
6 signalType: 'digital' | 'analog' | 'power-vcc' | 'power-gnd'
7}- 正交布线,无对角线线段
- 线段拖动,垂直于线段方向拖动
- 自动更新,移动组件时重新计算导线位置
- 网格吸附,所有导线端点使用 20 像素网格
完整详情: 请参阅仓库中的 docs/ARCHITECTURE.md。