WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
This repository was archived by the owner on Oct 28, 2025. It is now read-only.

Commit 441024f

Browse files
Copilotfz6m
andcommitted
Add SHOW_DIRECTION configuration feature
Co-authored-by: fz6m <[email protected]>
1 parent e5a5605 commit 441024f

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

app-rust/src/config.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ pub struct Config {
2020
pub xiaomi_band: Option<bool>,
2121
#[serde(rename = "HEART_RATE_LABEL")]
2222
pub heart_rate_label: HashMap<String, Vec<String>>,
23+
#[serde(rename = "SHOW_DIRECTION")]
24+
pub show_direction: bool,
2325
}
2426

2527
impl Default for Config {
@@ -49,6 +51,7 @@ impl Default for Config {
4951
apple_watch: false,
5052
xiaomi_band: Some(false),
5153
heart_rate_label,
54+
show_direction: false,
5255
}
5356
}
5457
}
@@ -94,7 +97,7 @@ impl Config {
9497
}
9598

9699
/// Get heart rate text based on BPM and configured thresholds
97-
pub fn get_heart_rate_text(&self, bpm: u32) -> Option<String> {
100+
pub fn get_heart_rate_text(&self, bpm: u32, previous_bpm: Option<u32>) -> Option<String> {
98101
// Find the appropriate threshold
99102
let thresholds: Vec<u32> = self.heart_rate_label.keys()
100103
.filter_map(|k| k.parse().ok())
@@ -123,6 +126,20 @@ impl Config {
123126
&labels[index]
124127
};
125128

126-
Some(label.replace("{{bpm}}", &bpm.to_string()))
129+
let mut text = label.replace("{{bpm}}", &bpm.to_string());
130+
131+
// Add direction indicator if enabled and previous BPM is available
132+
if self.show_direction {
133+
if let Some(prev_bpm) = previous_bpm {
134+
if bpm > prev_bpm {
135+
text.push_str("【↑】");
136+
} else if bpm < prev_bpm {
137+
text.push_str("【↓】");
138+
}
139+
// No indicator when values are equal
140+
}
141+
}
142+
143+
Some(text)
127144
}
128145
}

app-rust/src/heart_rate.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pub struct HeartRateMonitor {
2828
start_time: Instant,
2929
heart_rate_count: u32,
3030
heart_rate_sum: u32,
31+
previous_heart_rate: Option<u32>,
3132
}
3233

3334
impl HeartRateMonitor {
@@ -51,6 +52,7 @@ impl HeartRateMonitor {
5152
start_time: Instant::now(),
5253
heart_rate_count: 0,
5354
heart_rate_sum: 0,
55+
previous_heart_rate: None,
5456
}
5557
}
5658

@@ -300,6 +302,9 @@ impl HeartRateMonitor {
300302
// Send OSC message (with rate limiting)
301303
self.send_osc_message(heart_rate).await?;
302304

305+
// Store current heart rate as previous for next iteration
306+
self.previous_heart_rate = Some(heart_rate);
307+
303308
Ok(())
304309
}
305310

@@ -313,7 +318,7 @@ impl HeartRateMonitor {
313318
return Ok(());
314319
}
315320

316-
if let Some(text) = self.config.get_heart_rate_text(heart_rate) {
321+
if let Some(text) = self.config.get_heart_rate_text(heart_rate, self.previous_heart_rate) {
317322
if let Some(osc_client) = &self.osc_client {
318323
match osc_client.send_message(&text).await {
319324
Ok(_) => {

0 commit comments

Comments
 (0)