Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,867 changes: 747 additions & 1,120 deletions Cargo.lock

Large diffs are not rendered by default.

11 changes: 5 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
[workspace]
resolver = "2"
resolver = "3"
members = [
"flasher",
"dso-parser",
"gui",
]

[workspace.package]
version = "0.2.1"
edition = "2021"
description = "Tools for ZeeWeii DSO3D12 oscilloscope and Winner Micro MCUs"
version = "0.3.0"
edition = "2024"
license = "MIT"
repository = "https://github.com/rssdev10/wm-tools"

[workspace.dependencies]
anyhow = "1.0"
thiserror = "2.0"
log = "0.4"
rust-i18n = "3"
png = "0.17"
rust-i18n = "4"
png = "0.18"
tiny-skia = "0.12"
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ To use the snapshot view feature, you must install the modified firmware. For mo

## Requirements

- Rust toolchain (stable, 2021 edition or later)
- Rust toolchain (stable, 1.85 or later for the 2024 edition)
- A USB-to-serial adapter connected to the target device (or integrated one)

## How to build
Expand Down Expand Up @@ -157,6 +157,8 @@ Cargo workspace (`resolver = "2"`). Shared dependencies are in `[workspace.depen
| `main.rs` | Boots `iced::application(App::new, App::update, App::view)` with `.subscription()`. |
| `app.rs` | `App` state, messages, view composition, subscriptions; headless unit tests. |
| `canvas.rs` | `Scope` canvas program: grid, traces, measurement and device cursors. |
| `plot.rs` | Renderer-neutral waveform helpers shared by the canvas and the PNG export (per-column min/max, so no samples are dropped; trace clipping). |
| `scale.rs` | Per-capture display scale: from the capture's metadata, or the manual scale for captures without metadata. |
| `range_slider.rs` | Custom two-knob range slider widget (`canvas::Program`). |
| `serial.rs` | Background serial listener: port list, auto-reconnect, capture detection. |
| `flash.rs` | Background firmware update over XMODEM-1K. |
Expand Down
82 changes: 70 additions & 12 deletions docs/GUI_DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,53 @@ This document describes the GUI layout, interaction model and state of the
Custom `iced::widget::canvas` (`canvas.rs`, `Scope`). 10×8 grid, centred axes,
yellow CH1, cyan CH2. Renders:
* Traces in **Line / Dot / Smooth** mode (smooth = moving average).
Traces are clipped to the grid area, so off-screen samples never run
over the scale labels. The clipping is done on the trace geometry
(`plot::clip_polyline_y`), not with `Frame::with_clip`: in iced 0.14 a
clipped sub-frame is drawn before the parent frame's own shapes, so the
opaque background covered the traces.
The canvas draws three layers: background and grid, traces, then cursors
and labels. The trace layer is cached (`canvas::Cache` in `ScopeState`)
and rebuilt only when the samples, the trace options or the plot size
change, so dragging a cursor does not re-tessellate 60 000 samples.
Dot mode draws each dot as a small square through iced's rectangle fast
path; one path of thousands of overlapping circles was very slow to fill. Line and Dot modes never drop samples: with more
samples than pixel columns, each column draws the min/max of its samples
(Line) or each distinct value once (Dot), so single-sample spikes stay
visible (`plot.rs`, shared with the PNG export). Only Smooth averages.
* Pink interactive cursors (range-shaded) for **measurement cursors**.
Cursors can also be moved by clicking/dragging directly on the graph
(nearest cursor line snaps to click position).
Cursors can also be moved by clicking/dragging directly on the graph.
A press moves the single nearest cursor line (distance measured in
pixels). A press within 12 px of the crossing of the nearest X and Y
lines drags both lines together. The pointer changes to a resize/move
shape over a line or crossing. A drag keeps following the pointer when it
leaves the canvas (the line stops at the plot edge) and ends on release
anywhere.
* **Zoom** on both axes (`plot::View` = one `plot::AxisView` per axis, the
visible `lo..hi` in unit coordinates: fraction of the capture for time,
fraction of the device screen height for voltage). Wheel zooms time around
the pointer (1.25× per notch; trackpad pixel scrolling doubles every
200 px); Option/Alt + wheel, or wheel over the voltage labels, zooms
voltage; horizontal scrolling or Shift + wheel pans time; right/middle-drag
pans both axes; a double-click (iced `mouse::Click`, 300 ms / 6 px)
resets both axes. Because a single click places the nearest cursor line,
the canvas remembers the cursor ranges from before the first click and
`Message::ViewReset` restores them, so a double-click only unzooms.
Limits (`AxisLimits`): time stays inside the capture and
stops at 10 visible samples; voltage may zoom out past the device screen to
the full ADC range (0..=255, `Y_LIMITS`) and stops at 8 ADC levels. Zooming
through the unzoomed span stops exactly at `AxisView::UNIT` (a detent). When
the voltage view extends past the screen, its top and bottom edges are drawn
as orange lines. The canvas publishes `Message::ViewChanged`; the app
stores the view together with the identity of the capture it was made on
(sample-buffer address and timestamp), so any other capture is shown
unzoomed without explicit resets. Only the visible samples are processed
when drawing. Measurement and device cursors stay in unit coordinates: they
are mapped through the view for drawing and hit-testing, and lines outside
the view are neither drawn nor grabbable. Time and voltage labels follow
the visible window, with enough decimals to tell divisions apart; an
`X ×N Y ×M` indicator shows the zoomed axes. PNG export is not affected
by the zoom.
* Green thin lines for **device cursors** (data-supplied, read-only) with
numeric labels (sample numbers for X, voltage for Y).
* Optional **axis scales** toggled via "Show scales" setting. Scale values
Expand All @@ -79,14 +123,22 @@ When capture metadata includes probe-mode information (×1, ×10, ×100), a
**Probe:** row is shown beneath V/div, and probe + coupling info appear in the
Trigger section.

When a capture arrives via the **screenshot protocol** (live), V/div, V/offset
and t/div are **automatically filled** from the packet's embedded settings
metadata. The same auto-population applies when **switching between captures**
in the thumbnail strip — clicking a screenshot capture applies its `scope_state`
settings. For single-capture `.zwcap` or `.bin` files, settings are applied
automatically on load. For multi-capture files, select the desired capture
from the thumbnails to apply its settings. ASCII dumps (without metadata)
retain the last-used settings.
**Each capture keeps its own scale** (`scale.rs`, `CaptureScale`):

* A capture **with metadata** (`record.scope_state`: screenshot packets and
`.zwcap` records saved from them) is drawn, measured and exported with the
V/div, V/off and t/div from its metadata. The inputs show these values
read-only (`text_input` without `on_input`), with the note "Scales from
capture metadata". A value missing from the metadata (a channel that was
off) falls back to the manual value.
* A capture **without metadata** (ASCII debug dump) uses the **manual scale**
stored in `settings.json`. The inputs are editable, with the note "Manual
scales".

Receiving, loading or selecting a capture never writes to the manual scale,
so one capture's scale cannot leak into another. The canvas, the measurement
panel and PNG export (including export of a capture that is not shown, from
the thumbnail context menu) all take the scale of their own capture.

**Signal information** (shown when a capture is loaded):
* Voltage range for CH1/CH2 (computed from V/div × 8 divs, centered at 0).
Expand Down Expand Up @@ -197,6 +249,11 @@ traces, written as a valid PNG file using a minimal built-in encoder (no
external image crate needed). Filename is auto-generated as
`capture_YYYYMMDD_HHMMSS.png` saved to the Downloads directory (no file picker).

The export keeps as much of the input data as possible: Line mode draws the
per-column min/max envelope when there are more samples than columns (and
interpolates linearly when there are fewer), and Dot mode draws every sample
(dots on the same spot are drawn once). Only Smooth mode filters the data.

## Persisted state (`settings.json`)

```jsonc
Expand Down Expand Up @@ -241,5 +298,6 @@ Default level: info; override with `RUST_LOG`.
where `v` = screen-coordinate ADC value (0 = top, 255 = bottom) and
25 = pixels per division. This matches the DSO3D12's own `pixel_to_volts`.
* Time axis = 12 divisions × t/div (ms).
* When receiving screenshot packets or loading `.zwcap` files with metadata,
V/div, V/offset, t/div and probe mode are auto-filled from device metadata.
* Captures with metadata (screenshot packets, `.zwcap` records with
`scope_state`) are shown with their own V/div, V/offset, t/div and probe
mode; captures without metadata use the manual scale (see above).
69 changes: 55 additions & 14 deletions docs/USER_MANUAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ There are two independent capture methods:
4. **Long-press Save** to initiate the debug data transmission.

Transfers ~150–500 kB at 115200 baud. Delivers 60 000 raw ADC samples per
channel. Use `V/div` and `t/div` in the Measurement panel to set the scale.
channel. A debug dump carries no scale metadata: set `V/div`, `V/off` and
`t/div` in the Measurement panel (see [Scale configuration](#scale-configuration)).

#### Method 2 — Screenshot binary packet (display pixels)

Expand All @@ -47,8 +48,8 @@ channel. Use `V/div` and `t/div` in the Measurement panel to set the scale.
binary packet** containing the 300 display pixels plus all instrument settings.

The app detects this packet by its size and decodes the embedded calibration
data to set `V/div`, `V/off`, `t/div` and **probe mode** (×1, ×10, ×100)
automatically. Probe and coupling info are shown in the Measurement panel's
data: the capture is shown with its own `V/div`, `V/off`, `t/div` and **probe
mode** (×1, ×10, ×100). Probe and coupling info are shown in the Measurement panel's
Trigger section, and the probe multiplier is reflected in the displayed V/div
and V/off values.

Expand All @@ -65,20 +66,49 @@ Re-plug and the connection resumes without manual intervention.
Click **Load Capture** and select a `.zwcap`, `.bin`, `.dat` or `.raw` file.
Files can contain one or many consecutive captures.

When loading files that contain embedded instrument metadata (`.zwcap` files
or screenshot `.bin` files), the **V/div**, **V/off** and **t/div** settings
are **automatically populated** from the capture data. You can still adjust
them manually if needed.

When switching between captures in the thumbnail strip, the scale settings
update automatically for each capture that has embedded metadata.
Each capture is shown with its own scale. Captures with embedded instrument
metadata (screenshot packets, and `.zwcap` records saved from them) use the
**V/div**, **V/off** and **t/div** the oscilloscope reported. Captures without
metadata (debug dumps) use the manual scale from the Measurement panel. See
[Scale configuration](#scale-configuration).

## Viewing the graph

* **Grid**: 10 × 8 divisions (oscilloscope style).
* **CH1** (yellow), **CH2** (cyan) — toggle visibility in the controls panel.
* **View mode** dropdown: Line, Dot, or Smooth (moving-average filter).

### Zoom

Zoom works on both axes, with the pointer over the graph:

| Action | Effect |
|--------|--------|
| Mouse wheel up / down (or two-finger scroll on a trackpad) | Zoom **time** in / out around the pointer: the point under the pointer stays in place |
| **Option/Alt** + wheel, or wheel over the **voltage labels** on the left | Zoom **voltage** in / out around the pointer |
| Horizontal scroll (trackpad swipe, tilt wheel) or **Shift** + wheel | Pan time left / right |
| **Right-drag** (or middle-drag) | Pan both axes: the signal follows the pointer |
| **Double-click** | Reset the zoom on both axes (cursors are left where they were) |
| Zoom out on an axis | Stops once at the normal view (whole capture, device screen); keep going to zoom out further |

The zoom factor of each zoomed axis is shown in the top-right corner of the
graph (for example `X ×4.0 Y ×2.0`), and the time and voltage labels show the
zoomed window. Time zoom stops when about 10 samples fill the width, so it is
most useful on debug dumps (60 000 samples); a screenshot has only 300 points.
Voltage zoom stops at 8 ADC steps across the height.

The voltage axis can be zoomed out **past the device screen**, up to the full
ADC range (0–255), to show the parts of the signal the oscilloscope clipped
off its own screen. The device screen's top and bottom edges are then marked
with orange lines.

Each capture keeps its own zoom: selecting another capture shows it unzoomed,
and coming back restores the zoom. Measurement cursors stay on the signal
while zooming; a cursor line outside the zoomed window is not drawn and cannot
be grabbed until it is in view again. Δt, ΔV and the slider positions always
refer to the whole capture and the device screen. PNG export always shows the
whole capture, unzoomed.

## Scale configuration

At the top of the **Measurement** panel you can set the real-world scale.
Expand All @@ -96,9 +126,18 @@ the real scope). The DSO3D12 screen has **8 vertical** and **12 horizontal**
divisions (AC mode). All voltage and time calculations, axis labels, and PNG
scales use the per-channel values.

When a capture arrives via the **screenshot protocol**, V/div and V/offset
are automatically filled for each channel from the packet's embedded settings
metadata (CH1 and CH2 separately).
The scale fields depend on the capture being shown:

* **Capture with metadata** (screenshot protocol, or a `.zwcap` record saved
from one): the fields show that capture's own V/div, V/off and t/div,
read-only. The note under the fields reads "Scales from capture metadata".
* **Capture without metadata** (debug dump): the fields are editable and set
the **manual scale**, used for every capture without metadata. It is saved
between sessions. The note reads "Manual scales".

Receiving or selecting a capture never changes the manual scale, so switching
between a screenshot and a dump always shows each with the right scale. PNG
export uses the scale of the capture being exported.

## Measurement cursors

Expand All @@ -110,7 +149,9 @@ In the right-hand **Measurement** panel:
| ☐ Cursor Y (voltage) | Two knobs on vertical range | ΔV (volts) + absolute voltages per channel (CH1 and CH2) |

**Drag the knob closest to your click** in the slider — or **click/drag
directly on the graph** to move the nearest cursor line. The shaded band
directly on the graph** to move the nearest cursor line. To move an X and a
Y line together, press close to the point where they cross (within about
12 pixels); the pointer changes to a move shape there. The shaded band
between cursors is drawn on the canvas in pink and updates in real time.
Y cursor voltages are computed independently for CH1 and CH2 using each
channel's V/div and V/offset settings.
Expand Down
4 changes: 2 additions & 2 deletions gui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ iced = { version = "0.14", features = ["canvas", "tokio", "advanced", "image"] }
iced_aw = { version = "0.14", features = ["context_menu"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
rfd = "0.15"
dirs = "6.0"
rfd = "0.18"
dirs = "7.0"
csv = "1.3"
chrono = { version = "0.4", default-features = false, features = ["clock"] }
serialport = "4.6"
Expand Down
2 changes: 2 additions & 0 deletions gui/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
"label.voff": "V/off, V:",
"label.tdiv": "t/div, ms:",
"label.ac_mode": "AC mode: 8×V, 12×t div",
"label.scale_from_metadata": "Scales from capture metadata (read-only)",
"label.scale_manual": "Manual scales (capture has no metadata)",
"label.time_range": "Time range: %{ms} ms (%{n} samp)",
"label.ch1_stats": "CH1: n=%{n} min=%{min} max=%{max} avg=%{avg}",
"label.ch2_stats": "CH2: n=%{n} min=%{min} max=%{max} avg=%{avg}",
Expand Down
2 changes: 2 additions & 0 deletions gui/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
"label.voff": "Despl V, V:",
"label.tdiv": "t/div, ms:",
"label.ac_mode": "Modo CA: 8×V, 12×t div",
"label.scale_from_metadata": "Escalas de los metadatos de la captura (solo lectura)",
"label.scale_manual": "Escalas manuales (la captura no tiene metadatos)",
"label.time_range": "Tiempo: %{ms} ms (%{n} muestras)",
"label.ch1_stats": "CH1: n=%{n} mín=%{min} máx=%{max} prom=%{avg}",
"label.ch2_stats": "CH2: n=%{n} mín=%{min} máx=%{max} prom=%{avg}",
Expand Down
2 changes: 2 additions & 0 deletions gui/locales/hi.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
"label.voff": "V ऑफ़सेट, V:",
"label.tdiv": "t/डिव, मि.से.:",
"label.ac_mode": "AC मोड: 8×V, 12×t डिव",
"label.scale_from_metadata": "स्केल कैप्चर मेटाडेटा से (केवल पढ़ने के लिए)",
"label.scale_manual": "मैनुअल स्केल (कैप्चर में मेटाडेटा नहीं है)",
"label.time_range": "समय: %{ms} मि.से. (%{n} नमूने)",
"label.ch1_stats": "CH1: n=%{n} न्यून=%{min} अधि=%{max} औसत=%{avg}",
"label.ch2_stats": "CH2: n=%{n} न्यून=%{min} अधि=%{max} औसत=%{avg}",
Expand Down
2 changes: 2 additions & 0 deletions gui/locales/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
"label.voff": "Смещ, В:",
"label.tdiv": "время/дел, мс:",
"label.ac_mode": "Режим АС: 8×В, 12×t дел",
"label.scale_from_metadata": "Масштабы из метаданных захвата (только чтение)",
"label.scale_manual": "Ручные масштабы (у захвата нет метаданных)",
"label.time_range": "Время: %{ms} мс (%{n} отсчётов)",
"label.ch1_stats": "CH1: n=%{n} мин=%{min} макс=%{max} ср=%{avg}",
"label.ch2_stats": "CH2: n=%{n} мин=%{min} макс=%{max} ср=%{avg}",
Expand Down
2 changes: 2 additions & 0 deletions gui/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
"label.voff": "偏置, V:",
"label.tdiv": "时基, 毫秒:",
"label.ac_mode": "交流模式: 8×V, 12×t 格",
"label.scale_from_metadata": "刻度来自捕获元数据(只读)",
"label.scale_manual": "手动刻度(捕获没有元数据)",
"label.time_range": "时间: %{ms} 毫秒 (%{n} 采样)",
"label.ch1_stats": "CH1: n=%{n} 最小值=%{min} 最大值=%{max} 平均值=%{avg}",
"label.ch2_stats": "CH2: n=%{n} 最小值=%{min} 最大值=%{max} 平均值=%{avg}",
Expand Down
Loading
Loading