Skip to content

feat(engineer): simulate the real firmware and check the whole system fits - #41

Merged
alanshen27 merged 1 commit into
mainfrom
devin/1785908519-integration-fit-check
Aug 5, 2026
Merged

feat(engineer): simulate the real firmware and check the whole system fits#41
alanshen27 merged 1 commit into
mainfrom
devin/1785908519-integration-fit-check

Conversation

@devin-ai-integration

Copy link
Copy Markdown
Contributor

Summary

Three gaps closed, all versions of the same problem — the stages produced artifacts that were never checked against each other.

1. The simulator runs the firmware, not a parallel sketch. lib/sim/arduino.ts translates a supported Arduino C++ subset into the existing JS runtime, so src/main.cpp is the simulation source and there is nothing to keep in sync by hand. It is a subset on purpose: unsupported constructs are refused rather than approximated, because a sim that quietly ignores Servo.h is worse than one that says it cannot run.

sketchSourceFor("src/main.cpp", src) // -> { source, warnings, errors }
// delay(500)            -> yield delay(500)      (keeps the virtual clock deterministic)
// helperWithDelay()     -> yield* helperWithDelay()
// Serial.println(x)     -> print(x)
// classes/templates/... -> errors[], nothing runs

2. Schematic parts can carry internals. PartSpec (data, never model-authored code) compiles to the PartModel the engine already consumes — drives, shorts, indicator, analog, interactivity — and is stored on CircuitDoc.models, validated on the way in. A part with neither a built-in model nor a spec is inert and named: "Hall (UNMODELLED)", surfaced in the canvas and the fit check, instead of silently doing nothing. save_circuit/import_wokwi_diagram now return partsWithoutSimulationModel, and a new define_part_models tool fills them in.

3. A fit check that actually runs the thing. evaluateFit(input) compares schematic ↔ PCB ↔ firmware ↔ BOM ↔ CAD and then executes the firmware against the schematic. Pin usage is recorded at the simulator boundary rather than parsed out of the source, so a pin reached through a variable or a helper still counts:

class RecordingSimulator extends Simulator {
  override setMcuDrive(id, pin, drive) { this.touched.add(pin); super.setMcuDrive(id, pin, drive); }
}
// firmware blinks 13, schematic wires the LED to 9 ->
//   error: "Firmware uses U1 pin 13, which nothing is wired to."
// LED wired but never driven ->
//   warning: "LED1 never activated in 3s of simulated run."

Exposed as verify.fitCheck (read-only query), the copilot tool check_integration, and a Verify panel labelled SIMULATED — behavioural, not compiled firmware on hardware.

Prompt. CAD and schematic were serialised behind each other for no reason; a Zoo generation takes ~5 minutes. They now go in the same step, with PCB/firmware after the schematic and check_integration as a mandatory final step that must be re-run after any cross-stage change.

Testing

test/part-spec.test.ts (10) and test/fit-check.test.ts (9) added, alongside the existing test/arduino-translate.test.ts. Full suite 466 passing; prettier, eslint and tsc --noEmit clean. Not exercised in a browser — the Verify panel and canvas changes are untested end-to-end.

Link to Devin session: https://app.devin.ai/sessions/27a2860693d444f8a9a37442a83762d7
Requested by: @alanshen27

…whole system fits

The simulator ran a hand-written sketch.js that had nothing to do with the
generated src/main.cpp, imported schematics had no internals to simulate
against, and nothing ever asked whether the stages agreed with each other.

- translate a supported Arduino C++ subset so firmware is the sim source
- carry declarative part internals on the circuit doc, with UNMODELLED
  parts named rather than silently inert
- add a cross-stage fit check (schematic/PCB/firmware/BOM/CAD + a
  simulated run) as a copilot tool and a Verify panel
- run CAD and schematic generation in parallel in the copilot prompt

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@alanshen27 alanshen27 self-assigned this Aug 5, 2026
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@alanshen27
alanshen27 merged commit a50fb7e into main Aug 5, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant