Skip to content

Commit c85ed6a

Browse files
committed
Update examples
1 parent 9eb8523 commit c85ed6a

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

README.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,29 @@ A set of tools to plot values from the target to graph in rerun with minimal per
1010
#![no_main]
1111

1212
use cortex_m_rt::entry;
13-
use panic_halt as _;
13+
use probe_plotter::{make_metric, make_setting};
1414

1515
#[entry]
1616
fn main() -> ! {
17-
use probe_plotter::make_metric;
18-
let mut sawtooth = make_metric!(SAWTOOTH: i32 = 42, "(x / 10) % 100").unwrap();
19-
let mut sine = make_metric!(SINE: i32 = 42, "100 * sin(2 * pi * x / 4000)").unwrap();
17+
let mut sawtooth = make_metric!(SAWTOOTH: i32 = 42, "(SAWTOOTH / 10) % 100").unwrap();
18+
let mut sine = make_metric!(SINE: i32 = 42, "100 * sin(2 * pi * SINE / 4000)").unwrap();
19+
20+
let mut setting_roundtrip =
21+
make_metric!(SETTING_ROUNDTRIP: i8 = 0, "SETTING_ROUNDTRIP").unwrap();
22+
23+
// Allow values -1..=7, step by 2, so {-1, 1, 3, 5, 7}
24+
let mut setting = make_setting!(SETTING: i8 = 42, -1..=7, 2).unwrap();
25+
2026
loop {
2127
for i in 0..i32::MAX {
2228
sawtooth.set(i);
2329
sine.set(i);
24-
cortex_m::asm::delay(100_000);
30+
31+
setting_roundtrip.set(setting.get());
2532
}
2633
}
2734
}
35+
2836
```
2937

3038
The formulas seen in the `make_metric` macro invocation are computed by the host and will thus have zero impact on the targets performance. The `set` method on the metrics object is simply a volatile store which is quite cheap. The host will then read that value using the debug probe at regular intervals and update the graph on any changes.
@@ -50,4 +58,4 @@ cargo run ../examples/simple/target/thumbv7em-none-eabihf/debug/simple stm32g474
5058
# Rerun will open with a graph showing all created metrics objects
5159
```
5260

53-
<img width="2880" height="1920" alt="Screenshot" src="https://github.com/user-attachments/assets/5f7f20c9-009d-42c7-9613-789ae26afe54" />
61+
<img width="2050" height="1166" alt="image" src="https://github.com/user-attachments/assets/dcdced90-9130-449f-ae0e-22a92a3dd409" />

examples/simple/src/main.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,28 @@ use cortex_m_rt::entry;
55

66
use defmt_rtt as _;
77
use panic_halt as _;
8+
use probe_plotter::{make_metric, make_setting};
89

910
#[entry]
1011
fn main() -> ! {
11-
use probe_plotter::make_metric;
1212
defmt::println!("Running...");
13-
let mut sawtooth = make_metric!(SAWTOOTH: i32 = 42, "(x / 10) % 100").unwrap();
13+
let mut sawtooth = make_metric!(SAWTOOTH: i32 = 42, "(SAWTOOTH / 10) % 100").unwrap();
1414
defmt::println!("foo initialized to: {}", sawtooth.get());
15-
let mut sine = make_metric!(SINE: i32 = 42, "100 * sin(2 * pi * x / 4000)").unwrap();
15+
let mut sine = make_metric!(SINE: i32 = 42, "100 * sin(2 * pi * SINE / 4000)").unwrap();
16+
17+
let mut setting_roundtrip =
18+
make_metric!(SETTING_ROUNDTRIP: i8 = 0, "SETTING_ROUNDTRIP").unwrap();
19+
20+
// Allow values -1..=7, step by 2, so {-1, 1, 3, 5, 7}
21+
let mut setting = make_setting!(SETTING: i8 = 42, -1..=7, 2).unwrap();
22+
1623
loop {
1724
for i in 0..i32::MAX {
1825
sawtooth.set(i);
1926
sine.set(i);
27+
28+
setting_roundtrip.set(setting.get());
29+
2030
cortex_m::asm::delay(100_000);
2131
}
2232
}

0 commit comments

Comments
 (0)