Skip to content

Commit 1d93d8e

Browse files
authored
Merge pull request #236 from LedgerHQ/y333/nbgl_spinner_integration
Update NBGL spinner: previous and new strings shall be stored to enab…
2 parents 9277831 + d8b1037 commit 1d93d8e

File tree

5 files changed

+20
-14
lines changed

5 files changed

+20
-14
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ledger_device_sdk/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ledger_device_sdk"
3-
version = "1.19.6"
3+
version = "1.20.0"
44
authors = ["yhql", "yogh333", "agrojean-ledger", "kingofpayne"]
55
edition = "2021"
66
license.workspace = true

ledger_device_sdk/examples/nbgl_spinner.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ extern "C" fn sample_main() {
4949
.glyph(&FERRIS)
5050
.show(&my_field);
5151

52-
NbglSpinner::new().text("Please wait...").show();
52+
NbglSpinner::new().show("Please wait...");
5353

5454
// Simulate an idle state of the app where it just
5555
// waits for some event to happen (such as APDU reception), going through

ledger_device_sdk/src/libcall/swap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ pub fn sign_tx_params(arg0: u32) -> CreateTxParams {
217217
}
218218

219219
#[cfg(any(target_os = "stax", target_os = "flex"))]
220-
NbglSpinner::new().text("Signing").show();
220+
NbglSpinner::new().show("Signing");
221221

222222
create_tx_params
223223
}
Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,34 @@
11
use super::*;
2+
extern crate alloc;
3+
use alloc::ffi::CString;
24

35
/// A wrapper around the asynchronous NBGL nbgl_useCaseSpinner C API binding.
46
/// Draws a spinner page with the given parameters. The spinner will "turn" automatically every
57
/// 800 ms, provided the IO event loop is running to process TickerEvents.
8+
#[derive(Debug, Default)]
69
pub struct NbglSpinner {
7-
text: CString,
10+
text: [CString; 2],
11+
write_idx: usize,
12+
read_idx: usize,
813
}
914

1015
impl NbglSpinner {
1116
pub fn new() -> NbglSpinner {
1217
NbglSpinner {
13-
text: CString::new("").unwrap(),
18+
text: [CString::default(), CString::default()],
19+
write_idx: 0,
20+
read_idx: 0,
1421
}
1522
}
1623

17-
pub fn text(self, text: &str) -> NbglSpinner {
18-
NbglSpinner {
19-
text: CString::new(text).unwrap(),
20-
}
21-
}
22-
23-
pub fn show(&self) {
24+
/// Shows the spinner with the current text.
25+
/// Every call make the spinner "turn" to the next text.
26+
pub fn show(&mut self, text: &str) {
27+
self.text[self.write_idx] = CString::new(text).unwrap();
28+
self.read_idx = self.write_idx;
29+
self.write_idx = (self.write_idx + 1) % 2;
2430
unsafe {
25-
nbgl_useCaseSpinner(self.text.as_ptr() as *const c_char);
31+
nbgl_useCaseSpinner(self.text[self.read_idx].as_ptr() as *const c_char);
2632
}
2733
}
2834
}

0 commit comments

Comments
 (0)