Skip to content

Commit c0f098d

Browse files
committed
fix: fix battery status
1 parent 6aabb71 commit c0f098d

10 files changed

Lines changed: 29 additions & 55 deletions

File tree

docs/docs/main/docs/features/event.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ RMK provides built-in event types organized by category:
4040
**Battery Events** (`rmk::event::battery`):
4141
- `BatteryAdcEvent` - Raw battery ADC reading
4242
- `ChargingStateEvent` - Charging state changed
43-
- `BatteryStatusEvent` - Battery state changed (includes level and charging status)
43+
- `BatteryStatusEvent` - Battery status changed (includes level and charging status)
4444

4545
**Connection Events** (`rmk::event::connection`):
4646
- `ConnectionChangeEvent` - Connection type changed (USB/BLE)
@@ -49,7 +49,7 @@ RMK provides built-in event types organized by category:
4949
**Split Keyboard Events** (`rmk::event::split`, when split is enabled):
5050
- `PeripheralConnectedEvent` - Peripheral connection state changed
5151
- `CentralConnectedEvent` - Connected to central state changed
52-
- `PeripheralBatteryEvent` - Peripheral battery state changed
52+
- `PeripheralBatteryEvent` - Peripheral battery status changed
5353
- `ClearPeerEvent` - BLE peer clearing event
5454

5555
## Defining Custom Events

examples/use_rust/nrf52840_ble_split_dongle/Cargo.lock

Lines changed: 0 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rmk-config/src/resolved/build_constants.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl crate::KeyboardTomlConfig {
6868
wpm_update,
6969
led_indicator,
7070
sleep_state,
71-
battery_state,
71+
battery_status,
7272
battery_adc,
7373
charging_state,
7474
pointing,

rmk/src/ble/battery_service.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ impl<P: PacketPool> BleBatteryServer<'_, '_, '_, P> {
6969

7070
// Report the battery level.
7171
loop {
72-
let battery_state = self.wait_until_battery_state_available().await;
72+
let battery_status = self.wait_until_battery_status_available().await;
7373

7474
// Try to receive the latest message
75-
let state = self.sub.try_next_message_pure().unwrap_or(battery_state);
75+
let state = self.sub.try_next_message_pure().unwrap_or(battery_status);
7676
if let BatteryStatus::Available { level: Some(level), .. } = state.0 {
7777
if let Err(e) = self.battery_level.notify(self.conn, &level).await {
7878
error!("Failed to notify battery level: {:?}", e);
@@ -81,13 +81,13 @@ impl<P: PacketPool> BleBatteryServer<'_, '_, '_, P> {
8181
}
8282
}
8383

84-
/// Wait until the battery state is available.
84+
/// Wait until the battery status is available.
8585
/// To avoid unexpected wakeup, before reporting battery level, all conditions should be satistied:
8686
///
87-
/// 1. There's a battery state update
87+
/// 1. There's a battery status update
8888
/// 2. There's a key press in last 1 minute, or timeout(30 minutes)
8989
/// 3. The keyboard is not in the sleep mode
90-
async fn wait_until_battery_state_available(&mut self) -> BatteryStatusEvent {
90+
async fn wait_until_battery_status_available(&mut self) -> BatteryStatusEvent {
9191
loop {
9292
// Calculate timeout when reporting battery level
9393
let timeout = async {
@@ -100,8 +100,8 @@ impl<P: PacketPool> BleBatteryServer<'_, '_, '_, P> {
100100
}
101101
};
102102

103-
// Wait until there are both battery state update and key pressing or timeout
104-
let (battery_state, last_press) =
103+
// Wait until there are both battery status update and key pressing or timeout
104+
let (battery_status, last_press) =
105105
join(self.sub.next_message_pure(), select(timeout, LAST_KEY_TIMESTAMP.wait())).await;
106106

107107
// Then check the value last press time
@@ -110,10 +110,10 @@ impl<P: PacketPool> BleBatteryServer<'_, '_, '_, P> {
110110
Either::Second(last_press) => last_press,
111111
};
112112

113-
// Only report battery state if the last key action is less than 60 seconds ago
113+
// Only report battery status if the last key action is less than 60 seconds ago
114114
let current_time = Instant::now().as_secs() as u32;
115115
if current_time.saturating_sub(last_press) < 60 {
116-
return battery_state;
116+
return battery_status;
117117
}
118118
}
119119
}

rmk/src/event/battery.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! This module contains all battery-related events:
44
//! - Battery ADC reading events
55
//! - Charging state events
6-
//! - Battery state events (computed from ADC and charging state)
6+
//! - Battery status events (computed from ADC and charging state)
77
88
use postcard::experimental::max_size::MaxSize;
99
use rmk_macro::event;
@@ -32,7 +32,7 @@ pub struct ChargingStateEvent {
3232
pub charging: bool,
3333
}
3434

35-
/// Battery state changed event, wraps [`BatteryStatus`].
35+
/// Battery status changed event, wraps [`BatteryStatus`].
3636
#[event(channel_size = crate::BATTERY_STATUS_EVENT_CHANNEL_SIZE, pubs = crate::BATTERY_STATUS_EVENT_PUB_SIZE, subs = crate::BATTERY_STATUS_EVENT_SUB_SIZE)]
3737
#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq, MaxSize)]
3838
#[cfg_attr(feature = "defmt", derive(defmt::Format))]

rmk/src/event/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//!
1212
//! - `input`: Input events (keyboard, modifier, pointing device)
1313
//! - `state`: Keyboard state events (layer, WPM, LED indicator, sleep)
14-
//! - `battery`: Battery events (ADC, charging, battery state)
14+
//! - `battery`: Battery events (ADC, charging, battery status)
1515
//! - `connection`: Connection events (USB/BLE, BLE status)
1616
//! - `split`: Split keyboard events (peripheral/central connection)
1717

rmk/src/event/split.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub struct CentralConnectedEvent {
2121
pub connected: bool,
2222
}
2323

24-
/// Peripheral battery state changed event
24+
/// Peripheral battery status changed event
2525
#[event(channel_size = crate::PERIPHERAL_BATTERY_EVENT_CHANNEL_SIZE, pubs = crate::PERIPHERAL_BATTERY_EVENT_PUB_SIZE, subs = crate::PERIPHERAL_BATTERY_EVENT_SUB_SIZE)]
2626
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
2727
#[cfg_attr(feature = "defmt", derive(defmt::Format))]

rmk/src/input_device/battery.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,21 +75,21 @@ impl<I: InputPin> ChargingStateReader<I> {
7575
}
7676

7777
/// BatteryProcessor processes battery adc value and charging state,
78-
/// emits `BatteryStatusEvent` when battery state changes.
78+
/// emits `BatteryStatusEvent` when battery status changes.
7979
#[processor(subscribe = [BatteryAdcEvent, ChargingStateEvent])]
8080
pub struct BatteryProcessor {
8181
adc_divider_measured: u32,
8282
adc_divider_total: u32,
83-
/// Current battery state
84-
battery_state: BatteryStatus,
83+
/// Current battery status
84+
battery_status: BatteryStatus,
8585
}
8686

8787
impl BatteryProcessor {
8888
pub fn new(adc_divider_measured: u32, adc_divider_total: u32) -> Self {
8989
BatteryProcessor {
9090
adc_divider_measured,
9191
adc_divider_total,
92-
battery_state: BatteryStatus::Unavailable,
92+
battery_status: BatteryStatus::Unavailable,
9393
}
9494
}
9595

@@ -138,19 +138,19 @@ impl BatteryProcessor {
138138
#[cfg(feature = "_ble")]
139139
{
140140
// Only update level when not charging
141-
let (charge_state, current_level) = match self.battery_state {
141+
let (charge_state, current_level) = match self.battery_status {
142142
BatteryStatus::Available { charge_state, level } => (Some(charge_state), level),
143143
BatteryStatus::Unavailable => (None, None),
144144
};
145145
if !matches!(charge_state, Some(ChargeState::Charging)) {
146146
let battery_percent = self.get_battery_percent(val);
147147
if current_level != Some(battery_percent) || charge_state.is_none() {
148-
self.battery_state = BatteryStatus::Available {
148+
self.battery_status = BatteryStatus::Available {
149149
charge_state: charge_state.unwrap_or(ChargeState::Unknown),
150150
level: Some(battery_percent),
151151
};
152152

153-
publish_event(BatteryStatusEvent::from(self.battery_state));
153+
publish_event(BatteryStatusEvent::from(self.battery_status));
154154
}
155155
}
156156
}
@@ -164,20 +164,20 @@ impl BatteryProcessor {
164164
{
165165
if charging {
166166
// Keep current level when charging
167-
let level = match self.battery_state {
167+
let level = match self.battery_status {
168168
BatteryStatus::Available { level, .. } => level,
169169
BatteryStatus::Unavailable => None,
170170
};
171-
self.battery_state = BatteryStatus::Available {
171+
self.battery_status = BatteryStatus::Available {
172172
charge_state: ChargeState::Charging,
173173
level,
174174
};
175175
} else {
176176
// When unplugged, mark unavailable until next ADC reading
177-
self.battery_state = BatteryStatus::Unavailable;
177+
self.battery_status = BatteryStatus::Unavailable;
178178
}
179179

180-
publish_event(BatteryStatusEvent::from(self.battery_state));
180+
publish_event(BatteryStatusEvent::from(self.battery_status));
181181
}
182182
}
183183
}

rmk/src/processor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ pub trait Processor: Runnable {
8181
///
8282
/// // Called every 1000ms (poll_interval)
8383
/// async fn poll(&mut self) {
84-
/// // Toggle LED based on battery state
84+
/// // Toggle LED based on battery status
8585
/// self.led_on = !self.led_on;
8686
/// }
8787
/// }

rmk/src/split/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub(crate) enum SplitMessage {
4141
KeyboardIndicator(u8),
4242
/// Layer number from central to peripheral
4343
Layer(u8),
44-
/// Battery state, from peripheral to central
44+
/// Battery status, from peripheral to central
4545
#[cfg(feature = "_ble")]
4646
BatteryStatus(BatteryStatusEvent),
4747
}

0 commit comments

Comments
 (0)