From 7e026179aad948c4a1e3562d132a69155065d1d4 Mon Sep 17 00:00:00 2001 From: davidmonterocrespo24 Date: Fri, 24 Apr 2026 16:42:36 +0200 Subject: [PATCH] feat(photodiode): add lux control in sensor panel and property dialog MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- frontend/public/components-metadata.json | 2 +- frontend/src/simulation/parts/SensorParts.ts | 23 +++++++++++++++++++ .../src/simulation/sensorControlConfig.ts | 18 +++++++++++++++ scripts/component-overrides.json | 2 +- 4 files changed, 43 insertions(+), 2 deletions(-) diff --git a/frontend/public/components-metadata.json b/frontend/public/components-metadata.json index e683dd14..5f8a90a4 100644 --- a/frontend/public/components-metadata.json +++ b/frontend/public/components-metadata.json @@ -3762,7 +3762,7 @@ "name": "lux", "type": "number", "defaultValue": 500, - "control": "range", + "control": "number", "min": 0, "max": 100000, "description": "Illumination in lux" diff --git a/frontend/src/simulation/parts/SensorParts.ts b/frontend/src/simulation/parts/SensorParts.ts index b88cbafc..dc1dc392 100644 --- a/frontend/src/simulation/parts/SensorParts.ts +++ b/frontend/src/simulation/parts/SensorParts.ts @@ -4,6 +4,7 @@ * Implements: * - tilt-switch * - ntc-temperature-sensor + * - photodiode * - gas-sensor (MQ-series) * - flame-sensor * - heart-beat-sensor @@ -99,6 +100,28 @@ PartSimulationRegistry.register('ntc-temperature-sensor', { }, }); +// ─── Photodiode ────────────────────────────────────────────────────────────── + +/** + * Photodiode — 2-terminal passive, reverse-biased light sensor. The SPICE + * emitter (componentToSpice.ts) reads `properties.lux` and drives a current + * source (100 nA/lux). This handler wires the SensorControlPanel slider so + * moving it updates the store → netlist rebuild → re-solve. + */ +PartSimulationRegistry.register('photodiode', { + attachEvents: (_element, _simulator, _getArduinoPinHelper, componentId) => { + registerSensorUpdate(componentId, (values) => { + if ('lux' in values) { + emitPropertyChange(componentId, 'lux', values.lux); + } + }); + + return () => { + unregisterSensorUpdate(componentId); + }; + }, +}); + // ─── Gas Sensor (MQ-series) ────────────────────────────────────────────────── /** diff --git a/frontend/src/simulation/sensorControlConfig.ts b/frontend/src/simulation/sensorControlConfig.ts index e4020d76..096d511d 100644 --- a/frontend/src/simulation/sensorControlConfig.ts +++ b/frontend/src/simulation/sensorControlConfig.ts @@ -226,6 +226,24 @@ export const SENSOR_CONTROLS: Record = { defaultValues: { lux: 500 }, }, + // ── Photodiode ──────────────────────────────────────────────────────────── + photodiode: { + title: 'Photodiode', + controls: [ + { + type: 'slider', + key: 'lux', + label: 'Illumination', + min: 0, + max: 1000, + step: 1, + unit: 'lux', + defaultValue: 500, + }, + ], + defaultValues: { lux: 500 }, + }, + // ── PIR Motion Sensor ───────────────────────────────────────────────────── 'pir-motion-sensor': { title: 'PIR Motion Sensor', diff --git a/scripts/component-overrides.json b/scripts/component-overrides.json index df94f77d..1da9bb50 100644 --- a/scripts/component-overrides.json +++ b/scripts/component-overrides.json @@ -1026,7 +1026,7 @@ "name": "lux", "type": "number", "defaultValue": 500, - "control": "range", + "control": "number", "min": 0, "max": 100000, "description": "Illumination in lux"