Commit Graph

554 Commits

Author SHA1 Message Date
David Montero Crespo 175b248108 feat(epaper): Add SVG layouts and emulation plan for ePaper panels
- Introduced SVG layout dimensions for Phase 1 (B/W mono) and Phase 2 (colour) ePaper panels, detailing active areas, bezels, and pin layouts.
- Developed a phased emulation plan outlining the architecture and deliverables for different panel types, including SSD168x and UC81xx.
- Created a canonical "Hello, World!" sketch for the 1.54" ePaper panel, ensuring compatibility across ESP32, Raspberry Pi Pico, and Arduino Uno.
- Implemented a pure Python SSD168x decoder to validate SPI command sets and framebuffers against specifications.
- Added tests for compiling the hello-world sketch across supported boards and for the SSD168x protocol to ensure correct framebuffer behavior.
2026-04-29 02:33:59 -03:00
David Montero Crespo 641ac8c1de Add comprehensive tests for Cyw43Emulator functionality and lifecycle
- Implemented handshake tests to validate initial bus state and register responses.
- Created end-to-end tests for Pico W LED blinking using MicroPython firmware.
- Added SDPCM framing tests to ensure proper encoding and decoding of control frames.
- Developed IOCTL tests to verify command responses and state changes in the emulator.
- Established a full lifecycle test for WiFi operations, including scanning, connecting, and packet handling.
- Introduced TypeScript configuration for test files to ensure compatibility and strict type checking.
2026-04-29 00:21:26 -03:00
David Montero Crespo b39041ca4c feat(editor): enhance toolbar layout with center slot for file tabs and improve responsiveness 2026-04-28 23:23:20 -03:00
David Montero Crespo 7a26d01965 feat(attiny85): add Web Component for ATtiny85 with pinInfo support 2026-04-28 22:57:50 -03:00
David Montero Crespo 0a66c70512 feat(examples): update dual Pico example to demonstrate bidirectional digital handshake 2026-04-28 22:38:54 -03:00
David Montero Crespo 2ac94aed24 fix(loadExample): update filename logic for Arduino-style boards to ensure correct file extension 2026-04-28 20:40:48 -03:00
David Montero Crespo 7f2014bef7 Add ESP32 chip demos and comprehensive tests for I2C, SPI, and UART interactions
- Implemented `esp32_spi_chip_demo.ino` to demonstrate SPI communication with a 74HC595 shift register.
- Created `esp32_uart_chip_demo.ino` for UART loopback testing with ROT13 transformation.
- Added Python tests for compiling chips and sketches, ensuring valid WASM output and successful compilation for various board families.
- Developed end-to-end tests for ESP32 with custom chips using I2C and SPI, validating synchronous communication through the backend.
- Introduced GPIO bridge tests to verify serial communication and GPIO state changes.
- Ensured all tests validate the expected behavior of the custom chips and their interaction with the ESP32 firmware.
2026-04-28 19:24:39 -03:00
David Montero Crespo fa170a082a Add shared validators and test configurations for Velxio projects
https://github.com/kritishmohapatra/100_Days_100_IoT_Projects
- Introduced `_lib.py` containing shared validators for board support and static source analysis for MicroPython projects.
- Added `conftest.py` to configure pytest for the test suite, simplifying import paths.
- Created `NOT_SUPPORTED.md` files for two projects indicating they cannot be emulated in Velxio due to lack of source code.
- Implemented unit tests for the unsupported projects to verify the presence of the NOT_SUPPORTED marker and source preservation.
2026-04-28 00:36:05 -03:00
David Montero Crespo 63896e2049 feat(activity): add user daily activity metrics and modal for detailed project interaction 2026-04-26 19:39:45 -03:00
David Montero Crespo ba63aba4dc feat(env): add example environment configuration file for backend 2026-04-26 18:03:04 -03:00
David Montero Crespo 8e769f8a4e feat(multi-board): add wire-aware cross-board interconnect router
Fixes the user-reported bug where two RPi Pico W boards wired GP0↔GP1
running SerialPassthrough don't communicate. Replaces the broken
broadcast-style cross-board logic in addBoard (only routed AVR↔Pi3B,
ignored wires entirely, no RP2040↔anything path) with a wire-aware
Interconnect singleton.

Architecture: digital pin transitions are the lowest-common-denominator
abstraction. Each simulator's hardware peripherals (UART/I2C/SPI) and
bit-banging libraries (SoftwareSerial, software I2C) decode the
transitions naturally — propagate the pin and the protocols come for
free. For cross-process boards (ESP32 backend QEMU, Pi3B QEMU) a
byte-level shortcut is additionally enabled on hardware-UART pin
pairs to handle high-baud links over WebSocket latency.

Implementation:
- New simulation/Interconnect.ts singleton subscribes to wire/board
  changes via the Zustand store. Handlers per tier: browser-sim →
  pinManager.onPinChange, ESP32 → Esp32Bridge.sendPinEvent, Pi3B →
  bridge.sendPinEvent. Re-entrancy guard via per-(board,pin) Set.
- New utils/boardProtocols.ts classifies pins (uart-tx, i2c-sda, etc.)
  per board kind, used as optimization hint for the byte shortcut.
- types/wire.ts: added signalType field, exports WireSignalType /
  WireColorMap (fixes a pre-existing TS import error in wireColors).
- Deleted the bridgeMap/simulatorMap broadcast forEach blocks in
  addBoard. Initial board + future boards register with Interconnect
  via setInterconnectRuntime + store subscription.
- PinManager.resetPinStates() helper for test isolation.

Tests (16 new files, 96 tests, all passing):
- Per-pair × per-protocol matrix: dual-arduino-digital,
  dual-pico-digital, arduino-pico-digital, triple-pico-digital-chain,
  dual-arduino-hw-uart, dual-arduino-software-serial,
  arduino-pico-mixed-uart, arduino-esp32-uart, dual-esp32-uart,
  pi3-pico-uart, arduino-pico-i2c, arduino-arduino-spi,
  interconnect-routing, dual-arduino-multi-protocol (UART+I2C+SPI+
  digital + concurrent), dual-pico-multi-protocol (UART0+UART1 alt+
  I2C0+I2C1+SPI0+digital + 3-Pico star topology)
- Updated dual-pico-serial-passthrough to assert correct behaviour
- Backend test/multi_board_esp32/test_dual_esp32_serial.py for two
  real QEMU instances (skip-graceful when lcgamboa lib absent)

Verified: 1107/1107 tests pass, zero regressions, vite build OK.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-25 19:47:40 -03:00
David Montero Crespo 5bf3a3d5ed feat(metrics): add usage analytics dashboard with country tracking
Track per-user, per-project, and per-board usage to inform pricing tier
decisions. Adds an admin dashboard with KPIs (DAU/WAU/MAU, totals,
success rate), time-series charts for compiles/runs, board family +
FQBN breakdowns, "board diversity" pie chart (key freemium signal),
top users/projects, and per-country breakdown via Cloudflare's
CF-IPCountry header. Admin can now also view private projects.

Backend:
- New UsageEvent table (append-only event log with user_id, project_id,
  event_type, board_fqbn/family, country, error_kind, duration_ms)
- Aggregate counters on User (total_compiles/runs/errors, last_active,
  signup_country, last_country) and Project (compile/run/update counts,
  last_compiled/run timestamps) kept in sync by MetricsService for O(1)
  dashboard reads
- 10 admin endpoints under /api/admin/metrics/{overview, timeseries,
  boards, board-diversity, top-users, top-projects, countries,
  users/{id}, projects/{id}}
- POST /api/metrics/run for client-side run telemetry
- Country detection via cf-ipcountry header (no DB / no API calls)
- Auto-migrations in lifespan for legacy DBs

Frontend:
- recharts-powered Dashboard tab with KPI cards and 4 charts
- New Boards tab with per-family + per-FQBN breakdown
- Country column with flag emoji on Users tab
- Top countries card on Dashboard
- compileCode now forwards project_id; Run button reports via WS

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-25 19:47:40 -03:00
davidmonterocrespo24 fd1cd03a26 docs(readme): add missing wokwi-boards clone to manual setup
A user (st_stefanov on Discord) reported the manual setup steps clone
avr8js, wokwi-elements, and rp2040js but skip wokwi-boards. The frontend
imports board.svg assets from wokwi-libs/wokwi-boards/boards/* (ESP32
DevKit V1, ESP32-S3, ESP32-C3, Pi Pico W, etc.), so without that repo
the Vite build fails on missing imports.

Dockerfile.standalone:77 already clones it; the README's Option C
(manual setup) was the only path missing the line. wokwi-boards is
asset-only — no npm install or build step needed.
2026-04-25 05:03:47 +02:00
davidmonterocrespo24 979df2608b ci(backend-e2e): run photodiode SPICE co-simulation test
Registers test_esp32_spice_photodiode.mjs (added in the previous commit)
in the ESP32 + ngspice section of the backend e2e workflow, with a 150s
timeout to accommodate ESP32 firmware compile + QEMU boot.
2026-04-24 19:20:09 +02:00
davidmonterocrespo24 2bc492c16f test(e2e): add ESP32 + SPICE photodiode co-simulation test
Follows the same pattern as test_esp32_spice_analog.mjs and
test_esp32_spice_ntc_bridge.mjs: compile an ESP32 sketch on-the-fly via
/api/compile/, boot QEMU through the backend WebSocket, and sweep lux
levels while verifying analogRead() returns what ngspice solved.

The netlist uses the exact photodiode cards emitted by
frontend/.../componentToSpice.ts (D_<id> + I_<id>_ph + DPHOTO model), so
any drift in the frontend SPICE mapper surfaces here.

Validated against the live Docker container — lux=0/1000/2500 produce
raw=4095/2854/992, matching the expected 4095/2854/993 within ±1 LSB
and monotonically decreasing with brightness as expected.

The package-lock.json churn is a pre-existing drift: eecircuit-engine
was in package.json but missing from the lock — npm install re-added it.

Companion workflow change (registering the test in backend-e2e-tests.yml)
lives in a separate commit that requires a PAT with workflow scope to push.
2026-04-24 19:20:02 +02:00
davidmonterocrespo24 4d17dfd832 feat: add /v2-5 release landing page for Velxio 2.5 (SPICE)
Mirrors the /v2 page structure but targets the 2.5 launch: ngspice-WASM
analog simulation, hybrid digital + analog co-simulation with Arduino /
ESP32 / RP2040, expanded component catalog, live instruments, 40 new
analog/hybrid examples.

- Reuses Velxio2Page.css + SEOPage.css — no new stylesheet to maintain
- Adds SoftwareApplication, BreadcrumbList, and FAQPage JSON-LD for
  rich-results eligibility
- Registers the route in App, entry-server (SSR prerender), and
  seoRoutes (sitemap, priority 0.95 / changefreq weekly)
2026-04-24 16:42:47 +02:00
davidmonterocrespo24 7e026179aa feat(photodiode): add lux control in sensor panel and property dialog
The SPICE emitter already reads properties.lux (default 500, 100 nA/lux)
but the UI had no way to set it — the static dialog rejected the "range"
control type and there was no entry in SENSOR_CONTROLS for the live panel.

- Add photodiode entry in SENSOR_CONTROLS (slider 0-1000 lux)
- Register a minimal PartSimulationRegistry handler that forwards slider
  values via emitPropertyChange so the netlist memo invalidates
- Switch the photodiode lux control from "range" to "number" so the
  static ComponentPropertyDialog renders an editable input
2026-04-24 16:42:36 +02:00
davidmonterocrespo24 4708d54195 fix(examples): re-create board when loading an Arduino example after an analog one
Loading an analog-only example removes every board. The single-board
branch of loadExample then called setBoardType, which only maps over
existing entries in boards[] and silently did nothing when the array
was empty — components rendered but no board. Fall back to addBoard +
setActiveBoardId when there are no boards.
2026-04-23 05:22:35 +02:00
David Montero Crespo a1161b3a79
Merge pull request #118 from davidmonterocrespo24/feature/electrical-simulation-ngspice
Feature/electrical simulation ngspice
2026-04-21 18:04:11 -03:00
David Montero Crespo 6ca0f91074 refactor: make 'generatedAt' optional in component metadata and remove timestamp generation to prevent CI drift 2026-04-21 17:35:13 -03:00
David Montero Crespo 07c9718bc3 test: update BMP280 chip ID assertions and clarify tagName uniqueness in metadata drift test 2026-04-21 17:31:51 -03:00
David Montero Crespo ff918375d7 test: increase timeout for blink sketch compilation test 2026-04-21 17:23:36 -03:00
David Montero Crespo 692af00258 style: update ESLint rules and clean up code formatting across multiple files 2026-04-21 17:14:27 -03:00
David Montero Crespo 53efc226a3 Merge branch 'master' into feature/electrical-simulation-ngspice
# Conflicts:
#	deploy/entrypoint.sh
#	frontend/src/components/examples/ExamplesGallery.tsx
2026-04-21 17:11:26 -03:00
David Montero Crespo 212ecd1bcb refactor: rename components and update prefixes to 'velxio-' for consistency
- Modified the index file to reflect the new naming convention for Velxio components.
- Changed JSX declarations to use 'velxio-' prefix for various components.
- Updated component overrides to replace 'wokwi-' with 'velxio-' for logic gates and other components.
- Adjusted SVG generation script to use 'velxio-' prefix for BMP280 and Raspberry Pi components.
- Marked submodules as dirty in QEMU and RP2040 libraries.
- Added .prettierignore and .prettierrc.json for consistent code formatting.
- Introduced InstrumentComponent with support for Voltmeter and Ammeter, including pin information handling.
2026-04-21 16:45:45 -03:00
David Montero Crespo 0623a7dd55 feat: add custom web components for electronic elements
- Introduced RelayElements for SPDT relay representation.
- Added Resistor component for adjustable resistance in ohms.
- Created RiscVBoard component for visualizing a RISC-V chip.
- Implemented TransistorElements for BJT and MOSFET packages.
- Added Capacitor and CapacitorElectrolytic elements for capacitors.
- Introduced Inductor element for inductor representation.
- Updated index file to export new custom elements.
2026-04-21 16:44:39 -03:00
David Montero Crespo 993a25390c feat: add passive component presets and custom elements
- Implemented a script to inject passive-component preset variants into `scripts/component-overrides.json`, including resistors, capacitors, and inductors with custom names and thumbnails.
- Added a new custom element `<wokwi-capacitor-electrolytic>` representing a polarized aluminum-can capacitor with appropriate SVG representation.
- Updated metadata generation to accommodate new component names and thumbnails for better user experience in the component picker.
- Marked submodules `qemu-lcgamboa` and `rp2040js` as dirty to reflect local changes.
2026-04-21 15:21:03 -03:00
David Montero Crespo 7bdbac9f83 feat: add local custom elements for capacitor and inductor, enhancing SPICE simulation support 2026-04-21 13:50:45 -03:00
David Montero Crespo a1d3179e1c Add SPICE behavior tests for analog examples and update example circuit definitions 2026-04-21 13:20:48 -03:00
David Montero Crespo eaf3fffd36 Refactor code structure for improved readability and maintainability 2026-04-21 12:59:59 -03:00
David Montero Crespo 9ce4ad0147 refactor: remove PinSelector component and associated styles 2026-04-21 11:16:11 -03:00
David Montero Crespo b152cb1919 Refactor property synchronization in simulation parts; introduce emitPropertyChange event
- Replaced syncStoreProperty function with emitPropertyChange to decouple parts from Zustand store.
- Updated relay component mapping to ensure proper handling of coil and contact states.
- Added new test cases for half-wave rectifier and relay-controlled LED to ensure correct functionality.
- Introduced InlineComponentSVGs for schematic-style icons of various components.
- Updated submodule references for qemu-lcgamboa, rp2040js, and wokwi-elements to indicate dirty state.
2026-04-21 10:56:20 -03:00
David Montero Crespo 9cc9cfebd6 Add end-to-end tests for ammeter, voltmeter, and capacitor charging behavior
- Implement `ammeter-waveform.test.ts` to validate AC readings from a sine wave source.
- Create `capacitor-charge-transient.test.ts` to test the charging response of an RC circuit driven by a microcontroller pin.
- Introduce `esp32-rectifier-integration.test.ts` for testing rectifier behavior using QEMU and ESP32.
- Add helper functions in `esp32RectifierE2E.ts` for the rectifier test harness.
- Develop `voltmeter-waveform.test.ts` to ensure correct AC and DC readings from a sine wave source.
- Implement unit tests for waveform statistics in `waveform-stats.test.ts` to validate RMS, mean, peak, and interpolation functions.
- Create `waveformStats.ts` to provide statistical functions for time-domain waveform analysis.
2026-04-21 02:17:30 -03:00
David Montero Crespo 137f9ab0a0 Add tests for serial batching and spice rectifier functionality
- Implement `serial-batching.test.ts` to verify the behavior of `createSerialBatcher`, ensuring it coalesces multiple appends into a single flush, preserves byte order, and groups by board.
- Create `spice-rectifier-integration.test.ts` to test the end-to-end functionality of the Half-Wave Rectifier example, covering the entire simulation pipeline from input building to circuit solving.
- Add `spice-rectifier-live-repro.test.ts` to reproduce a live-app failure scenario, tracing through each layer of the simulation to identify potential failure points.
- Introduce `spice-signal-generator-tran.test.ts` to validate the behavior of the signal generator and ensure correct analysis type switching based on circuit components.
- Establish `serialBatcher.ts` to implement a batching mechanism for USART output, reducing the frequency of store updates and preventing React's maximum update depth error.
2026-04-20 23:56:42 -03:00
David Montero Crespo dcb8a92b79 feat: enhance electrical simulation and testing framework
- Decoupled electrical simulation from the simulator store, ensuring SPICE is always active for accurate circuit analysis.
- Removed feature flag for electrical simulation, simplifying the state management.
- Preloaded SPICE engine at app start to eliminate latency during the first solve.
- Added comprehensive tests for MOSFET PWM LED behavior and NPN transistor switch functionality, ensuring correct current flow and response to pin states.
- Implemented diagnostics for floating input nodes in RC low-pass filter circuits, addressing singular matrix issues in SPICE simulations.
- Introduced active semiconductor metadata registry for better component management and simulation fidelity.
- Updated Vite configuration to force re-bundling of local wokwi-elements after component additions.
2026-04-20 16:38:31 -03:00
David Montero b86273870e docs: add Docker production error report (2026-04-19)
Documents 5 issues found in production logs: RPi3 missing QEMU boot
files (51 hits), ESP32-S3 unsupported machine type, WebSocket race
condition, Google OAuth unhandled 400, and the uvicorn keepalive crash
that was mitigated in 8e3c00e.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-19 00:37:07 +02:00
David Montero Crespo 61c1ddfc22 feat: add capacitor and inductor components, update netlist builder to return pinNetMap 2026-04-17 19:27:18 -03:00
David Montero Crespo 64f6f76160 fix: update proxy target to use 127.0.0.1 and mark subproject commits as dirty 2026-04-16 23:13:16 -03:00
David Montero Crespo 00a15c6f76 feat: add 'circuits' category to ExampleProject interface
fix: increase timeout for compilation requests to 180 seconds

refactor: call recalculateAllWirePositions after loading examples

chore: update subproject commit for rp2040js to dirty state

chore: update subproject commit for wokwi-elements to dirty state
2026-04-16 08:39:47 -03:00
David Montero Crespo b422f2b4c1 fix(seo): include circuitExamples in sitemap generator
generate-sitemap.mjs was only scanning examples.ts for example IDs using a
textual regex. With the 40 new circuit examples living in a separate file
(examples-circuits.ts), they were missing from the generated sitemap.xml
and therefore invisible to search engines / SSR prerender URL list.

Now the generator reads both source files and merges their example IDs.

Also includes auto-applied formatting changes to generate-component-metadata.ts.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 01:06:26 -03:00
David Montero Crespo 3b240a9168 Merge branch 'feature/electrical-simulation-ngspice' of https://github.com/davidmonterocrespo24/velxio into feature/electrical-simulation-ngspice 2026-04-16 01:02:37 -03:00
David Montero Crespo 635bc2a952 fix(examples): merge circuitExamples via array spread, not side-effect push
Previously examples.ts pushed to exampleProjects[] after declaration, which
some bundlers can treat as dead code under aggressive tree-shaking. This
also made HMR unreliable when examples-circuits.ts changed.

Now:
  const legacyExamples = [...]
  export const exampleProjects = [...legacyExamples, ...circuitExamples]

Single immutable export. Guaranteed to include all 150 examples at import
time. The gallery (ExamplesGallery.tsx) and SSR prerender (entry-server.tsx)
both pick up the new circuit examples automatically.

Also adds frontend/src/__tests__/examples-circuits.test.ts with 5 assertions
to catch future regressions (all circuit ids present, no duplicates, valid
required fields, expected categories covered).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 01:02:27 -03:00
David Montero Crespo f5ef107eaa feat: implement asyncio exception handler and update entrypoint script for process management 2026-04-16 00:57:30 -03:00
David Montero 8e3c00ee7e fix: exit container when backend or nginx dies so Docker can restart it
Previously uvicorn was launched with `&` while nginx ran with `exec`, so if
the backend crashed (e.g. the `AssertionError` in websockets' keepalive_ping
that took prod down for ~31h), nginx kept the container "up" and every
/api/* request returned 502. Now both processes are monitored with
`wait -n`; whichever dies first triggers the entrypoint to exit, letting
`restart: unless-stopped` recover the container cleanly.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 05:53:06 +02:00
David Montero Crespo df37fdf6a4 feat: add 40 circuit examples + matching SPICE tests
Adds frontend/src/data/examples-circuits.ts with 40 new examples organized
into 6 categories, each demonstrating a specific analog/digital/electromech
concept that the SPICE engine can simulate end-to-end:

PASSIVE / ANALOG (10):
  voltage-divider, rc-low-pass-filter, wheatstone-bridge,
  ntc-temperature, led-current-limiting, parallel-resistors,
  pot-adc-reader, photoresistor-light, multi-led-bar,
  capacitor-charge-curve

TRANSISTOR / SEMICONDUCTOR (8):
  npn-led-switch, pnp-high-side-switch, mosfet-pwm-led,
  diode-rectifier, zener-regulator, schottky-reverse-protection,
  bjt-common-emitter, darlington-high-current

OP-AMP (5):
  opamp-inverting, opamp-voltage-follower, opamp-comparator,
  opamp-difference, opamp-schmitt-trigger

LOGIC GATES (6):
  and-gate-alarm, xor-toggle-detector, nand-sr-latch,
  full-adder, binary-counter-leds, logic-probe

ELECTROMECHANICAL (4):
  relay-led-switch, optocoupler-signal,
  l293d-motor-control, l293d-speed-pwm

POWER / REGULATOR (3):
  power-supply-7805, lm317-adjustable-psu, battery-voltage-monitor

BOARD-SPECIFIC (4):
  esp32-dual-adc, mega-multi-led, nano-sensor-station,
  esp32-pwm-led-rgb (uses ESP32 LEDC peripheral)

The new examples are appended to exampleProjects[] in examples.ts so the
existing gallery and category filters pick them up automatically.

test/test_circuit/test/spice_examples.test.js validates each example's
analog topology in ngspice — 45 individual assertions covering all 40
examples (plus extra cases for NTC/Zener sweeps and L293D direction).

Sandbox tally: 164 -> 209 tests, 7.9s runtime, all green.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 00:52:51 -03:00
David Montero Crespo 79b0b94ed3 ci: add ESP32 + ngspice co-simulation tests to backend E2E pipeline
Adds three new test steps to backend-e2e-tests.yml:
- ngspice smoke test (standalone, no backend needed)
- ESP32 voltage divider co-simulation (compile + QEMU + ngspice ADC injection)
- ESP32 Wheatstone bridge co-simulation (NTC temperature sweep)

These run alongside the existing DHT22/HC-SR04/MPU6050/MicroPython tests
using the same QEMU .so libraries and ESP32 Arduino core 2.0.17.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 00:33:59 -03:00
David Montero Crespo 3197935461 feat: add ESP32 + ngspice co-simulation E2E tests
Three new end-to-end tests that combine ESP32 QEMU emulation (via backend
WebSocket) with ngspice-WASM analog circuit solving:

1. test_esp32_spice_analog.mjs — voltage divider sweep
   - Compiles a sketch that reads analogRead(34)
   - Solves two voltage dividers with ngspice (R1/R2=10k/10k then 10k/30k)
   - Injects solved V(mid) into ESP32's ADC via esp32_adc_set
   - Verifies Serial output matches within +-50 counts (12-bit ADC)
   - Confirms circuit change is detected (different ADC values)

2. test_esp32_spice_ntc_bridge.mjs — Wheatstone bridge temperature sweep
   - NTC thermistor in a bridge (0C / 25C / 50C)
   - ngspice solves the bridge for each temperature
   - ESP32 reads both legs (ADC34+ADC35), computes R_ntc and T via beta model
   - Verifies temperature within +-5C tolerance across sweep

3. test_esp32_spice_smoke.mjs — ngspice-only smoke test (no backend needed)

Also adds eecircuit-engine to test/backend/e2e/package.json.

Prerequisites: backend on localhost:8001 with esp32 core installed.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 23:28:47 -03:00
David Montero Crespo 04d14a74b2 feat: always-on SPICE mode, full board ADC integration, LED brightness from current
Electrical simulation is now active by default (mode='spice' instead of
'off') — users no longer need to toggle the mode on manually. The engine
lazy-loads on first solve, so there is no startup cost penalty.

Changes:
- useElectricalStore: default mode = 'spice' when ELECTRICAL_SIM_ENABLED
- subscribeToStore: ADC_PIN_MAP expanded to all 18 board types (Uno, Nano,
  Mega with 16 ADC channels, ATtiny85, RP2040 GP26-29, ESP32/S3/C3 GPIO
  ADCs). Voltages from SPICE solutions now inject into MCU ADC peripherals
  for all boards.
- BasicParts LED: reads branchCurrents from useElectricalStore when SPICE
  is active. Brightness = clamp(|I_led| / 20mA, 0, 1) instead of boolean.
  Subscribes to store changes to update in real time.
- ElectricalOverlay: shows per-wire voltage labels (gold monospace on dark
  pill) using buildWireNetMap() which replicates the NetlistBuilder's
  Union-Find to map wireId -> netName -> nodeVoltage. Summary pill shows
  net count + solve time.
- NetlistBuilder: new export buildWireNetMap() for lightweight wire-to-net
  resolution without running ngspice.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 22:59:22 -03:00
David Montero Crespo 36543e2479 feat: expand SPICE component catalog (fases 9 + 10)
Adds 44 SPICE mappers, 58 custom metadata entries, and 12 visual
Web Components covering logic gates, transistors, op-amps, regulators,
sources, electromechanical parts and integrated-circuit packaging.

Fase 9 — component catalog expansion
------------------------------------
- 7 logic gates (AND/OR/NAND/NOR/XOR/XNOR + NOT) as SPICE B-sources
- 8 multi-input gates (AND/OR/NAND/NOR with 3 and 4 inputs)
- 9 transistors: 5 BJTs (incl. PNP 2N3906/BC557) + 4 MOSFETs (incl.
  P-channel IRF9540/FQP27P06). NMOS refactored from Level=3 W=0.1
  (hangs ngspice) to Level=1 with sane W/L
- 5 op-amps: LM358, LM741, TL072, LM324 with per-chip saturation
  rails + opamp-ideal
- 4 linear regulators (7805, 7812, 7905, LM317) with dropout
- 3 batteries (9V, AA, coin-cell) with realistic ESR
- Signal generator (sine / square / DC)
- 2 Schottky diodes (1N5817, 1N5819) + photodiode (lux-driven
  current source)

Fase 10 — electromechanical + ICs
---------------------------------
- Relay (SPDT): coil + L + S-switch with native hysteresis +
  flyback diode, inverted-control trick for the NC contact
- Optocouplers 4N25 and PC817 (LED + CCCS with CTR=0.5 / 1.0)
- 7 74HC ICs as DIP-14 packages emitting 4 or 6 B-sources per
  component (first mapper pattern emitting multiple device cards)
- 3 flip-flops (D, T, JK) — digital-sim only (edge detection is
  not representable in ngspice .op)
- L293D dual H-bridge motor driver

Infrastructure
--------------
- scripts/component-overrides.json gains a _customComponents[] array
  that lets new Velxio-only parts survive metadata regeneration
  (previously applyOverrides() could only patch wokwi-elements
  components that had already been scanned)
- scripts/generate-component-metadata.ts injects custom entries
  before the patch loop
- New ComponentCategory values: 'logic', 'analog', 'electromech'
- frontend/src/components/DynamicComponent.tsx PASSIVE tracing
  extended from just ['resistor','resistor-us'] to 9 two-terminal
  passives with per-part pin name maps
- New CI workflow test-circuit.yml runs the sandbox on push/PR
- frontend-tests.yml regenerates metadata and fails if committed
  JSON is stale
- Documented 2 new ngspice gotchas in circuit-emulation-gotchas.md:
  unicode in netlist titles silently hangs the parser, and
  MOSFET Level=3 + W=0.1m causes .op to hang
- 164/164 sandbox tests passing in ~9 s (was 88 pre-fase-9)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 22:41:26 -03:00
davidmonterocrespo24 ed9911dcc3 feat: electrical simulation via ngspice-WASM (eecircuit-engine)
Adds full SPICE-accurate electrical simulation to Velxio, behind a lazy-
loaded  toolbar toggle. Arduino / ESP32 / RP2040 sketches now co-simulate
with real analog behaviour: correct voltages on wires, real I–V curves on
LEDs, working potentiometers, NTC thermistors read by analogRead(), PWM
driving RC filters, transistors, op-amps, diodes, MOSFETs, etc.

Engine: eecircuit-engine (ngspice compiled to WebAssembly). Main bundle
stays at 2.4 MB; the 20 MB SPICE chunk only loads when the user activates
electrical mode. Disabled at build time via VITE_ELECTRICAL_SIM=false.

Frontend additions:
- simulation/spice/: SpiceEngine wrapper + lazy entry, NetlistBuilder with
  UnionFind over wires, componentToSpice mapping (24 metadataIds incl.
  real part numbers: 2N2222, 2N3055, BC547, IRF540, 2N7000, 1N4148,
  1N4007, 1N4733, LEDs, NTC, op-amp ideal), CircuitScheduler with
  debounced coalescing, AVRSpiceBridge for quasi-static co-simulation.
- store/useElectricalStore: Zustand slice, feature-flag aware.
- components/analog-ui/:  toolbar toggle + SVG voltage overlay.
- components/components-instruments/: Voltmeter, Ammeter probes.
- 62 tests (spice-*, netlist-builder, component-to-spice, instruments).

Sandbox (test/test_circuit/): 47-test validation sandbox that proved
the approach (hand-rolled MNA baseline + ngspice pipeline) before
porting to the app. Kept as reference.

Docs: docs/wiki/circuit-emulation-*.md (13 engineering pages covering
architecture, solvers, components, AVR bridge, gotchas, performance,
integration plan, API reference, appendix) + electrical-simulation-
user-guide.md (end-user facing).

Reference plan: test/test_circuit/plan/phase_8_velxio_implementation.md

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 12:11:54 +00:00