Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update NBGL spinner: previous and new strings shall be stored to enab… #236

Merged
merged 2 commits into from
Jan 31, 2025
Merged
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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ledger_device_sdk/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ledger_device_sdk"
version = "1.19.6"
version = "1.20.0"
authors = ["yhql", "yogh333", "agrojean-ledger", "kingofpayne"]
edition = "2021"
license.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion ledger_device_sdk/examples/nbgl_spinner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ extern "C" fn sample_main() {
.glyph(&FERRIS)
.show(&my_field);

NbglSpinner::new().text("Please wait...").show();
NbglSpinner::new().show("Please wait...");

// Simulate an idle state of the app where it just
// waits for some event to happen (such as APDU reception), going through
Expand Down
2 changes: 1 addition & 1 deletion ledger_device_sdk/src/libcall/swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ pub fn sign_tx_params(arg0: u32) -> CreateTxParams {
}

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

create_tx_params
}
Expand Down
26 changes: 16 additions & 10 deletions ledger_device_sdk/src/nbgl/nbgl_spinner.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,34 @@
use super::*;
extern crate alloc;
use alloc::ffi::CString;

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

impl NbglSpinner {
pub fn new() -> NbglSpinner {
NbglSpinner {
text: CString::new("").unwrap(),
text: [CString::default(), CString::default()],
write_idx: 0,
read_idx: 0,
}
}

pub fn text(self, text: &str) -> NbglSpinner {
NbglSpinner {
text: CString::new(text).unwrap(),
}
}

pub fn show(&self) {
/// Shows the spinner with the current text.
/// Every call make the spinner "turn" to the next text.
pub fn show(&mut self, text: &str) {
self.text[self.write_idx] = CString::new(text).unwrap();
self.read_idx = self.write_idx;
self.write_idx = (self.write_idx + 1) % 2;
unsafe {
nbgl_useCaseSpinner(self.text.as_ptr() as *const c_char);
nbgl_useCaseSpinner(self.text[self.read_idx].as_ptr() as *const c_char);
}
}
}
Loading