feat: remove unnecessary logging and streamline potentiometer and servo simulations

pull/47/head
David Montero Crespo 2026-03-21 17:20:48 -03:00
parent aac3465d49
commit ee7281383c
2 changed files with 3 additions and 81 deletions

View File

@ -272,7 +272,6 @@ export class RP2040Simulator {
this.running = true; this.running = true;
console.log('[RP2040] Starting simulation at 125 MHz...'); console.log('[RP2040] Starting simulation at 125 MHz...');
let frameCount = 0;
const execute = () => { const execute = () => {
if (!this.running || !this.rp2040) return; if (!this.running || !this.rp2040) return;
@ -333,37 +332,6 @@ export class RP2040Simulator {
} }
} }
frameCount++;
if (frameCount % 60 === 0) {
console.log(`[RP2040] Frame ${frameCount}, PC: 0x${core.PC.toString(16)}`);
// PIO diagnostic: check GPIO 15 state and PIO1 status (servo uses PIO1)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const rp = this.rp2040 as any;
if (rp && frameCount <= 300) {
const gpio15 = rp.gpio[15];
const pio1 = rp.pio[1];
const funcSel = gpio15 ? (gpio15.ctrl & 0x1f) : -1;
const pio1Stopped = pio1 ? pio1.stopped : true;
const pio1PinVal = pio1 ? ((pio1.pinValues >> 15) & 1) : -1;
const pio1PinDir = pio1 ? ((pio1.pinDirections >> 15) & 1) : -1;
// Find clockDivInt for first enabled machine in PIO1
let pio1ClkDiv = 'N/A';
if (pio1?.machines) {
for (const m of pio1.machines) {
if (m.enabled) {
pio1ClkDiv = `${m.clockDivInt}.${m.clockDivFrac || 0}`;
break;
}
}
}
console.log(
`[RP2040 PIO diag] pioDiv=${pioDiv}` +
` gpio15.funcSel=${funcSel} (7=PIO1)` +
` pio1.stopped=${pio1Stopped} pinVal[15]=${pio1PinVal} pinDir[15]=${pio1PinDir}` +
` pio1.clkDiv=${pio1ClkDiv}`
);
}
}
} catch (error) { } catch (error) {
console.error('[RP2040] Simulation error:', error); console.error('[RP2040] Simulation error:', error);
this.stop(); this.stop();

View File

@ -64,24 +64,16 @@ PartSimulationRegistry.register('rgb-led', {
PartSimulationRegistry.register('potentiometer', { PartSimulationRegistry.register('potentiometer', {
attachEvents: (element, simulator, getArduinoPinHelper) => { attachEvents: (element, simulator, getArduinoPinHelper) => {
const pin = getArduinoPinHelper('SIG'); const pin = getArduinoPinHelper('SIG');
console.log(`[Potentiometer] attachEvents called, SIG pin resolved to: ${pin}`); if (pin === null) return () => { };
if (pin === null) {
console.warn('[Potentiometer] No SIG pin found — skipping ADC attachment');
return () => { };
}
// Determine reference voltage based on board type // Determine reference voltage based on board type
const isRP2040 = simulator instanceof RP2040Simulator; const isRP2040 = simulator instanceof RP2040Simulator;
const refVoltage = isRP2040 ? 3.3 : 5.0; const refVoltage = isRP2040 ? 3.3 : 5.0;
console.log(`[Potentiometer] Board type: ${isRP2040 ? 'RP2040' : 'AVR'}, refV: ${refVoltage}`);
const onInput = () => { const onInput = () => {
const raw = parseInt((element as any).value || '0', 10); const raw = parseInt((element as any).value || '0', 10);
const volts = (raw / 1023.0) * refVoltage; const volts = (raw / 1023.0) * refVoltage;
console.log(`[Potentiometer] pin=${pin}, raw=${raw}, volts=${volts.toFixed(3)}`); setAdcVoltage(simulator, pin, volts);
if (!setAdcVoltage(simulator, pin, volts)) {
console.warn(`[Potentiometer] ADC not available for pin ${pin}`);
}
}; };
// Fire once on attach to set initial value // Fire once on attach to set initial value
@ -279,9 +271,7 @@ PartSimulationRegistry.register('servo', {
// directly, which fires gpio.addListener → onPinChangeWithTime with the // directly, which fires gpio.addListener → onPinChangeWithTime with the
// accurate simulation time from SimulationClock.nanosCounter. // accurate simulation time from SimulationClock.nanosCounter.
if (avrSimulator instanceof RP2040Simulator && pinSIG !== null) { if (avrSimulator instanceof RP2040Simulator && pinSIG !== null) {
console.log(`[Servo RP2040] attached, pinSIG=${pinSIG}`);
let riseTimeMs = -1; let riseTimeMs = -1;
let logCount = 0;
// Self-calibrating pulse range: the PIO clock divider may not match // Self-calibrating pulse range: the PIO clock divider may not match
// exactly, producing pulses offset from the standard 544-2400µs range. // exactly, producing pulses offset from the standard 544-2400µs range.
@ -292,10 +282,6 @@ PartSimulationRegistry.register('servo', {
avrSimulator.onPinChangeWithTime = (pin, state, timeMs) => { avrSimulator.onPinChangeWithTime = (pin, state, timeMs) => {
if (pin !== pinSIG) return; if (pin !== pinSIG) return;
if (logCount < 10) {
logCount++;
console.log(`[Servo RP2040] pin=${pin} state=${state} timeMs=${timeMs.toFixed(3)}`);
}
if (state) { if (state) {
riseTimeMs = timeMs; riseTimeMs = timeMs;
} else if (riseTimeMs >= 0) { } else if (riseTimeMs >= 0) {
@ -305,10 +291,6 @@ PartSimulationRegistry.register('servo', {
// Reject noise: only consider pulses in a reasonable servo range // Reject noise: only consider pulses in a reasonable servo range
if (pulseUs < 100 || pulseUs > 25000) return; if (pulseUs < 100 || pulseUs > 25000) return;
if (logCount <= 12) {
console.log(`[Servo RP2040] pulseUs=${pulseUs.toFixed(1)} observedMin=${observedMin.toFixed(1)}`);
}
// Update calibration baseline // Update calibration baseline
if (pulseUs < observedMin) observedMin = pulseUs; if (pulseUs < observedMin) observedMin = pulseUs;
@ -672,7 +654,6 @@ function createLcdSimulation(cols: number, rows: number) {
} }
refreshDisplay(); refreshDisplay();
console.log(`[LCD] ${cols}x${rows} simulation initialized`);
return () => { return () => {
unsubscribers.forEach(u => u()); unsubscribers.forEach(u => u());
@ -705,12 +686,7 @@ const ili9341Simulation = {
const pinManager = (avrSimulator as any).pinManager; const pinManager = (avrSimulator as any).pinManager;
const spi = (avrSimulator as any).spi; const spi = (avrSimulator as any).spi;
console.log('[ILI9341] attachEvents called. spi=', !!spi, 'pinManager=', !!pinManager, 'cpu=', !!(avrSimulator as any).cpu); if (!pinManager || !spi) return () => {};
if (!pinManager || !spi) {
console.warn('[ILI9341] pinManager or SPI peripheral not available');
return () => {};
}
// ── Canvas setup ────────────────────────────────────────────────── // ── Canvas setup ──────────────────────────────────────────────────
const SCREEN_W = 240; const SCREEN_W = 240;
@ -743,7 +719,6 @@ const ili9341Simulation = {
let pendingFlush = false; let pendingFlush = false;
let rafId: number | null = null; let rafId: number | null = null;
let flushCount = 0;
const scheduleFlush = () => { const scheduleFlush = () => {
if (rafId !== null) return; if (rafId !== null) return;
rafId = requestAnimationFrame(() => { rafId = requestAnimationFrame(() => {
@ -751,10 +726,6 @@ const ili9341Simulation = {
if (pendingFlush && ctx && imageData) { if (pendingFlush && ctx && imageData) {
ctx.putImageData(imageData, 0, 0); ctx.putImageData(imageData, 0, 0);
pendingFlush = false; pendingFlush = false;
flushCount++;
if (flushCount === 1) console.log('[ILI9341] First canvas flush complete');
} else if (pendingFlush) {
console.warn('[ILI9341] Flush skipped: ctx=', !!ctx, 'imageData=', !!imageData);
} }
}); });
}; };
@ -807,7 +778,6 @@ const ili9341Simulation = {
}; };
// ── Command / data processing ───────────────────────────────────── // ── Command / data processing ─────────────────────────────────────
let ramwrPixelCount = 0;
const processCommand = (cmd: number) => { const processCommand = (cmd: number) => {
currentCmd = cmd; currentCmd = cmd;
dataBytes = []; dataBytes = [];
@ -815,15 +785,11 @@ const ili9341Simulation = {
pixelByteCount = 0; pixelByteCount = 0;
if (cmd === 0x01) { // SWRESET clear framebuffer if (cmd === 0x01) { // SWRESET clear framebuffer
console.log('[ILI9341] SWRESET received, ctx=', !!ctx);
colStart = 0; colEnd = SCREEN_W - 1; colStart = 0; colEnd = SCREEN_W - 1;
rowStart = 0; rowEnd = SCREEN_H - 1; rowStart = 0; rowEnd = SCREEN_H - 1;
curX = 0; curY = 0; curX = 0; curY = 0;
imageData = null; imageData = null;
if (ctx) ctx.clearRect(0, 0, SCREEN_W, SCREEN_H); if (ctx) ctx.clearRect(0, 0, SCREEN_W, SCREEN_H);
} else if (cmd === 0x2C) { // RAMWR
ramwrPixelCount = 0;
console.log('[ILI9341] RAMWR received, ctx=', !!ctx, 'col=', colStart, '-', colEnd, 'row=', rowStart, '-', rowEnd);
} }
}; };
@ -837,10 +803,6 @@ const ili9341Simulation = {
writePixel(pixelHiByte, value); writePixel(pixelHiByte, value);
scheduleFlush(); scheduleFlush();
pixelByteCount = 0; pixelByteCount = 0;
ramwrPixelCount++;
if (ramwrPixelCount === 1) {
console.log('[ILI9341] First pixel written: rgb565=', ((pixelHiByte << 8) | value).toString(16));
}
} }
return; return;
} }
@ -862,12 +824,7 @@ const ili9341Simulation = {
// ── Intercept SPI ───────────────────────────────────────────────── // ── Intercept SPI ─────────────────────────────────────────────────
const prevOnByte = spi.onByte.bind(spi); const prevOnByte = spi.onByte.bind(spi);
let spiByteCount = 0;
spi.onByte = (value: number) => { spi.onByte = (value: number) => {
spiByteCount++;
if (spiByteCount === 1) {
console.log('[ILI9341] First SPI byte! value=0x' + value.toString(16) + ' dcState=' + dcState);
}
if (!dcState) { if (!dcState) {
processCommand(value); processCommand(value);
} else { } else {
@ -876,9 +833,6 @@ const ili9341Simulation = {
spi.completeTransfer(0xFF); // Unblock CPU immediately spi.completeTransfer(0xFF); // Unblock CPU immediately
}; };
// Verify the override was applied (same object ref check)
console.log(`[ILI9341] SPI simulation ready. DC→pin${pinDC}. spi.onByte overridden=${spi.onByte !== prevOnByte}`);
// ── Cleanup ─────────────────────────────────────────────────────── // ── Cleanup ───────────────────────────────────────────────────────
return () => { return () => {
spi.onByte = prevOnByte; spi.onByte = prevOnByte;