Skip to content

Commit

Permalink
Add StaticReview
Browse files Browse the repository at this point in the history
  • Loading branch information
agrojean-ledger committed Jan 17, 2024
1 parent 5e67dca commit 9bb8be1
Show file tree
Hide file tree
Showing 3 changed files with 236 additions and 43 deletions.
43 changes: 33 additions & 10 deletions ledger_device_sdk/examples/stax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@ use ledger_device_sdk as _;

use const_zero::const_zero;
use ledger_device_sdk::io::*;
use ledger_device_sdk::nbgl::Home;
use ledger_device_sdk::uxapp::UxEvent;
use ledger_secure_sdk_sys::seph;
use ledger_device_sdk::nbgl::{NbglUI, Field};
use ledger_secure_sdk_sys::*;

use include_gif::include_gif;
use ledger_device_sdk::testing::debug_print;

#[no_mangle]
pub static mut G_ux_params: bolos_ux_params_t = unsafe { const_zero!(bolos_ux_params_t) };
Expand Down Expand Up @@ -91,21 +88,47 @@ extern "C" fn sample_main() {

let mut comm = Comm::new();

let mut myHome = Home::new(Some(&mut comm))
let mut nbgl_ui = NbglUI::new(Some(&mut comm))
.app_name("Stax Sample\0")
.info_contents(env!("CARGO_PKG_VERSION"), env!("CARGO_PKG_AUTHORS"))
.icon(&BTC_BMP);

myHome.show();
// let myStaticReview = StaticReview::new(Some(&comm));

// myStaticReview.show_and_wait_validation();

// myNBGL.show_home();

let fields = [
Field {
name: "Field 1\0",
value: "Value 1\0",
},
Field {
name: "Field 2\0",
value: "Value 2\0",
},
Field {
name: "Field 3\0",
value: "Value 3\0",
},
];


if nbgl_ui.show_review_and_wait_validation(&fields) {
debug_print("Validation result: true\n");
} else {
debug_print("Validation result: false\n");
}

loop {
match myHome.get_events::<Instruction>() {
Event::Command(ins) => (),
match nbgl_ui.get_events::<Instruction>() {
Event::Command(_) => (),
_ => (),
};
}

exit_app(0);
// exit_app(0);
}

const BTC_BMP: [u8; 573] = [
Expand Down
13 changes: 12 additions & 1 deletion ledger_device_sdk/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ pub enum Event<T> {
/// APDU event
Command(T),
/// Button press or release event
#[cfg(not(target_os = "stax"))]
Button(ButtonEvent),
#[cfg(target_os = "stax")]
TouchEvent,
/// Ticker
Ticker,
}
Expand Down Expand Up @@ -271,6 +274,7 @@ impl Comm {
// If this is an APDU, return with the "received command" event
// Any other event (usb, xfer, ticker) is silently handled
match seph::Events::from(tag) {
#[cfg(not(target_os = "stax"))]
seph::Events::ButtonPush => {
let button_info = spi_buffer[3] >> 1;
if let Some(btn_evt) = get_button_event(&mut self.buttons, button_info) {
Expand All @@ -292,11 +296,18 @@ impl Comm {
#[cfg(target_os = "nanox")]
seph::Events::BleReceive => ble::receive(&mut self.apdu_buffer, spi_buffer),

seph::Events::TickerEvent => return Some(Event::Ticker),
seph::Events::TickerEvent => {
#[cfg(target_os = "stax")]
unsafe {
ux_process_ticker_event();
}
return Some(Event::Ticker);
},

#[cfg(target_os = "stax")]
seph::Events::ScreenTouch => unsafe {
ux_process_finger_event(spi_buffer.as_mut_ptr());
return Some(Event::TouchEvent);
},

_ => (),
Expand Down
Loading

0 comments on commit 9bb8be1

Please sign in to comment.