# EEG SNN Dashboard

Local browser dashboard for the XIAO ESP32S3 EEG firmware: plot raw EEG, view band features, record labelled data, train, deploy, and edit the OLED Display Studio.

## Run it

```bash
npm start          # then open http://localhost:5176
```

## Connecting to the board

- **Server USB** (most reliable): the Node server opens `/dev/cu.usbmodem*`, streams board rows into the page, and sends commands back.
- **Connect USB**: browser Web Serial at 115200 baud.
- **Wi-Fi**: opens `ws://<board-ip>:81/` with the same line protocol.
- **Simulate**: synthetic rows for testing the UI; never saved for training.

The Raw EEG panel shows live RMS and peak-to-peak with a readiness hint, so you can catch noisy contact before recording.

## Record + train

1. Connect `Server USB`, pick `Rest` / `Blink` / `Eyes Closed`, set a length, click `Record + Save`.
2. Repeat for at least two labels.
3. Click `Train + Deploy`, then reconnect USB.

Predictions stay hidden while the active `model_weights.py` is the heuristic starter; they appear only after trained weights are deployed. The board and model both carry the feature-pipeline name (`detrend_hann_clip_v3`); a mismatch disables predictions until you retrain.

## Display Studio

Edits up to seven OLED pages from board-native widgets (time, date, weather, custom text, animation, blink counter, blink Pong, Button Jump). `Save Page` / `Save All` push them to the XIAO. The square viewport control aligns the visible area with the optics. Time and weather sync on the board over its own Wi-Fi; the dashboard's geolocation weather is only a preview.

## Gmail (optional)

The inbox widget needs OAuth (an API key can't read a private inbox). Start the server with credentials and use the Gmail panel's OAuth button:

```bash
GMAIL_CLIENT_ID="..." GMAIL_CLIENT_SECRET="..." npm start
```

Redirect URI: `http://localhost:5176/api/gmail/oauth/callback`. Without OAuth it honestly shows "OAuth needed" instead of a fake count.

---

*Documentation generated with AI assistance.*
