velxio/frontend/src/components/velxio-components/GpsNeo6mElement.ts

145 lines
5.2 KiB
TypeScript
Raw Normal View History

feat(components): DS3231 RTC module + GPS NEO-6M NMEA talker DS3231 (I2C 0x68): - New velxio-ds3231 Web Component (4-pin module: GND/VCC/SDA/SCL) with pinInfo per CLAUDE.md 6a; registered in elements-register + main.tsx. - Catalog entry in scripts/component-overrides.json (_customComponents) mirrored into components-metadata.json exactly as the generator emits it (verified by cloning wokwi-elements and running generate:metadata: zero drift). - The existing VirtualDS3231 device sim (DS1307-compatible time regs 0x00-0x06 + control 0x0E / status 0x0F / temperature 0x11-0x12 at 0.25 C steps) is now user-reachable from the picker; the AVR/RP2040 attach path gains live temperature updates via the SensorControlPanel (new ds3231 slider in sensorControlConfig). GPS NEO-6M (UART talker, 9600 baud): - New velxio-gps-neo6m Web Component (VCC/RX/TX/GND, pulsing PPS LED). - New part sim GpsParts.ts: emits a valid GPGGA+GPRMC cycle per second (correct XOR checksums, ddmm.mmmmm coords, UTC clock advancing 1 s/cycle) with lat/lng/altitude/speed configurable via property dialog and live via a new SensorControlPanel entry. Defaults: Madrid 40.4168 N 3.7038 W. - Injection routes, chosen by classifying the wired board pin: 1) hardware UART RX -> new uniform sim.feedUart(uart, data) seam (AVR USART0, RP2040 uart0/1 via rp2040js feedByte, ESP32 uart0/2 and STM32 USART1/2 via their bridge shims); byte feed is paced in 8-byte wall-clock chunks so 32-byte RX FIFOs never overflow; 2) any other digital pin on a cycle-accurate sim -> real 8N1 bit-banged waveform via schedulePinChange, so SoftwareSerial decodes it; 3) feedUart rejection (e.g. Mega USART1-3, not modelled by avr8js) degrades permanently to the bit-banged path. - Interconnect already probed sim.feedUart; implementing it also upgrades cross-board UART byte shortcuts for RP2040 uart1. Tests: new gps-neo6m.test.ts (16 tests: NMEA builders, byte injection on Uno RX0 / ESP32 RX2, Mega RX1 fallback, waveform decode back to $GPGGA, live position updates, PPS pulse) + 3 new ds3231 AVR-path tests in protocol-parts.test.ts. Full frontend suite: 2294 passed, 2 pre-existing Galaksija Z80 timeouts that pass in isolation. npx tsc --noEmit clean.
2026-08-01 01:38:06 +07:00
/**
* GpsNeo6mElement.ts — `<velxio-gps-neo6m>` u-blox NEO-6M GPS module.
*
* Visual follows the common GY-GPS6MV2 breakout: blue PCB, u-blox chip,
* stacked beige ceramic patch antenna and a 4-pin header (VCC / RX / TX /
* GND) on the left edge.
*
* The behaviour (a 9600-baud NMEA stream — GPGGA + GPRMC every second —
* pushed out of the TX pin into the wired board UART) lives in
* `simulation/parts/GpsParts.ts`.
*
* Runtime surface used by the part:
* - `lat` / `lng` / `altitude` / `speed` properties (position fed into
* the NMEA sentences; synced from metadata defaults + property dialog
* by DynamicComponent, and live-updated via the SensorControlPanel).
* - `set pps(on)` — pulses the red PPS LED once per emitted NMEA cycle.
*
* Per CLAUDE.md §6a this MUST be a real Web Component — the wire system
* reads `pinInfo` from the DOM node to place wire endpoints on pin tips.
*/
const BODY_W = 150;
const BODY_H = 100;
// Left-edge 0.1" header (GY-GPS6MV2 silkscreen order top→bottom).
const PIN_X = 9;
const PIN_SPACING = 18;
const PIN_Y0 = 23;
const PIN_NAMES = ['VCC', 'RX', 'TX', 'GND'] as const;
const PIN_RING = ['#C08540', '#8F5DBF', '#2E9E5B', '#B4AEAB'];
function signalsFor(name: string) {
if (name === 'GND') return [{ type: 'power', signal: 'GND' }];
if (name === 'VCC') return [{ type: 'power', signal: 'VCC' }];
// The module's TX carries the NMEA stream towards the board's RX.
if (name === 'TX') return [{ type: 'usart', signal: 'TX' }];
if (name === 'RX') return [{ type: 'usart', signal: 'RX' }];
return [];
}
class GpsNeo6mElement extends HTMLElement {
/** Decimal-degree position encoded into the NMEA sentences. */
lat = 40.4168;
lng = -3.7038;
/** Altitude above mean sea level, metres (GPGGA field 9). */
altitude = 667;
/** Speed over ground, knots (GPRMC field 7). */
speed = 0;
private _pps = false;
constructor() {
super();
this.attachShadow({ mode: 'open' });
}
connectedCallback(): void {
this.render();
}
/** Wire system reads this from the DOM — do NOT memoize. */
get pinInfo() {
return PIN_NAMES.map((name, i) => ({
name,
x: PIN_X,
y: PIN_Y0 + i * PIN_SPACING,
number: i + 1,
signals: signalsFor(name),
}));
}
/** PPS indicator — the part pulses this once per emitted NMEA cycle. */
set pps(on: boolean) {
this._pps = Boolean(on);
const led = this.shadowRoot?.querySelector('[data-pps-led]');
if (led) led.setAttribute('fill', this._pps ? '#FF3B30' : '#5A1512');
}
get pps(): boolean {
return this._pps;
}
private render(): void {
if (!this.shadowRoot) return;
this.shadowRoot.innerHTML = `
<style>
:host { display: inline-block; line-height: 0; }
svg { display: block; user-select: none; -webkit-user-select: none; }
</style>
<svg width="${BODY_W}" height="${BODY_H}" xmlns="http://www.w3.org/2000/svg">
<!-- Blue PCB -->
<rect stroke="#BE9B72" fill="#025CAF" x=".5" y=".5"
width="${BODY_W - 1}" height="${BODY_H - 1}" rx="8" />
<!-- Mounting holes -->
<g fill="#59340A" stroke="#BE9B72" stroke-width="0.6">
<circle cx="9" cy="9" r="4" />
<circle cx="${BODY_W - 9}" cy="${BODY_H - 9}" r="4" />
</g>
<!-- Ceramic patch antenna (stacked on the right half) -->
<rect x="${BODY_W - 66}" y="16" width="56" height="56" rx="3"
fill="#D9CDA8" stroke="#B5A87F" />
<rect x="${BODY_W - 52}" y="30" width="28" height="28"
fill="#C7B98F" stroke="#B5A87F" stroke-width="0.6" />
<circle cx="${BODY_W - 60}" cy="44" r="2.2" fill="#8F8468" />
<!-- u-blox NEO-6M chip -->
<rect x="34" y="24" width="40" height="26" rx="2" fill="#20242B" stroke="#3A3F48" />
<text x="54" y="35" text-anchor="middle" font-family="monospace"
font-size="6.5" fill="#DDD">u-blox</text>
<text x="54" y="44" text-anchor="middle" font-family="monospace"
font-size="6" fill="#999">NEO-6M</text>
<!-- PPS fix LED -->
<circle data-pps-led cx="40" cy="66" r="3.5"
fill="${this._pps ? '#FF3B30' : '#5A1512'}" stroke="#2B0B09" stroke-width="0.6" />
<text x="48" y="68.5" font-family="monospace" font-size="5.5" fill="#FFF">PPS</text>
<text x="34" y="90" font-family="monospace" font-size="6" fill="#9BE1FF">GPS NEO-6M</text>
<text x="34" y="97" font-family="monospace" font-size="4.5" fill="#9BE1FF">NMEA 9600 baud</text>
<!-- 4-pin header + labels -->
<g font-family="monospace" font-size="6.5" font-weight="300" fill="#FFF">
${PIN_NAMES.map(
(name, i) =>
`<text x="${PIN_X + 8}" y="${PIN_Y0 + i * PIN_SPACING + 2}">${name}</text>`,
).join('')}
</g>
<g fill="#9D9D9A" stroke-width="0.4">
${PIN_NAMES.map(
(_, i) =>
`<circle stroke="${PIN_RING[i]}" cx="${PIN_X}" cy="${PIN_Y0 + i * PIN_SPACING}" r="3.5" />`,
).join('')}
</g>
</svg>
`;
}
}
if (typeof customElements !== 'undefined' && !customElements.get('velxio-gps-neo6m')) {
customElements.define('velxio-gps-neo6m', GpsNeo6mElement);
}
export type { GpsNeo6mElement };