Skip to content

Commit

Permalink
orb-ui: operator qr scan (#261)
Browse files Browse the repository at this point in the history
* orb-ui: operator qr scan

differentiate between operator-based (legacy) and self-serve mode.

in operator-based mode, scanning the operator QR code shouldn't look
like an error.

* orb-ui: update simulation for operator-based or self-serve

* orb-ui: tweak color
  • Loading branch information
fouge authored Oct 14, 2024
1 parent a639b03 commit 161f488
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 38 deletions.
2 changes: 2 additions & 0 deletions orb-ui/rgb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ impl Argb {
/// Outer-ring color during operator QR scans
pub const DIAMOND_RING_OPERATOR_QR_SCAN: Argb = Argb(Some(5), 77, 14, 0);
pub const DIAMOND_RING_OPERATOR_QR_SCAN_SPINNER: Argb = Argb(Some(10), 80, 50, 30);
pub const DIAMOND_RING_OPERATOR_QR_SCAN_SPINNER_OPERATOR_BASED: Argb =
Argb(Some(10), 100, 88, 20);
/// Outer-ring color during user QR scans
pub const DIAMOND_RING_USER_QR_SCAN: Argb = Argb(Some(5), 120, 100, 4); // same as DIAMOND_RING_USER_CAPTURE, lower brightness
pub const DIAMOND_RING_USER_QR_SCAN_SPINNER: Argb = Argb(Some(10), 80, 60, 40);
Expand Down
41 changes: 22 additions & 19 deletions orb-ui/src/engine/diamond.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ impl EventHandler for Runner<DIAMOND_RING_LED_COUNT, DIAMOND_CENTER_LED_COUNT> {
Event::QrScanStart { schema } => {
self.stop_center(LEVEL_FOREGROUND, Transition::ForceStop);
match schema {
QrScanSchema::Operator => {
QrScanSchema::OperatorSelfServe => {
self.operator_signup_phase.signup_phase_started();
self.set_ring(
LEVEL_FOREGROUND,
Expand All @@ -331,6 +331,18 @@ impl EventHandler for Runner<DIAMOND_RING_LED_COUNT, DIAMOND_CENTER_LED_COUNT> {
);
self.operator_signup_phase.operator_qr_code_ok();
}
QrScanSchema::Operator => {
self.operator_signup_phase.signup_phase_started();
self.set_ring(
LEVEL_FOREGROUND,
animations::SimpleSpinner::new(
Argb::DIAMOND_RING_OPERATOR_QR_SCAN_SPINNER_OPERATOR_BASED,
Some(Argb::OFF),
)
.fade_in(1.5),
);
self.operator_signup_phase.operator_qr_code_ok();
}
QrScanSchema::Wifi => {
self.operator_idle.no_wlan();
self.sound.queue(
Expand All @@ -357,18 +369,13 @@ impl EventHandler for Runner<DIAMOND_RING_LED_COUNT, DIAMOND_CENTER_LED_COUNT> {
Duration::ZERO,
)?;
}
Event::QrScanCompleted { schema } => {
Event::QrScanCompleted { schema: _ } => {
self.stop_center(LEVEL_FOREGROUND, Transition::ForceStop);
// reset ring background to black/off so that it's turned off in next animations
self.set_ring(
LEVEL_BACKGROUND,
animations::Static::<DIAMOND_RING_LED_COUNT>::new(Argb::OFF, None),
);
match schema {
QrScanSchema::Operator => {}
QrScanSchema::User => {}
QrScanSchema::Wifi => {}
}
}
Event::QrScanUnexpected { schema, reason } => {
self.set_ring(
Expand Down Expand Up @@ -398,7 +405,7 @@ impl EventHandler for Runner<DIAMOND_RING_LED_COUNT, DIAMOND_CENTER_LED_COUNT> {
QrScanSchema::User => {
self.operator_signup_phase.user_qr_code_issue();
}
QrScanSchema::Operator => {
QrScanSchema::Operator | QrScanSchema::OperatorSelfServe => {
self.operator_signup_phase.operator_qr_code_issue();
}
QrScanSchema::Wifi => {}
Expand All @@ -410,7 +417,9 @@ impl EventHandler for Runner<DIAMOND_RING_LED_COUNT, DIAMOND_CENTER_LED_COUNT> {
Duration::ZERO,
)?;
match schema {
QrScanSchema::User | QrScanSchema::Operator => {
QrScanSchema::User
| QrScanSchema::Operator
| QrScanSchema::OperatorSelfServe => {
self.operator_signup_phase.failure();
self.set_ring(
LEVEL_NOTICE,
Expand All @@ -426,7 +435,7 @@ impl EventHandler for Runner<DIAMOND_RING_LED_COUNT, DIAMOND_CENTER_LED_COUNT> {
}
}
Event::QrScanSuccess { schema } => match schema {
QrScanSchema::Operator => {
QrScanSchema::Operator | QrScanSchema::OperatorSelfServe => {
self.sound.queue(
sound::Type::Melody(sound::Melody::QrLoadSuccess),
Duration::ZERO,
Expand Down Expand Up @@ -459,15 +468,9 @@ impl EventHandler for Runner<DIAMOND_RING_LED_COUNT, DIAMOND_CENTER_LED_COUNT> {
self.sound
.queue(sound::Type::Voice(sound::Voice::Timeout), Duration::ZERO)?;
match schema {
QrScanSchema::User | QrScanSchema::Operator => {
self.stop_center(LEVEL_FOREGROUND, Transition::FadeOut(1.0));
self.set_center(
LEVEL_FOREGROUND,
animations::Static::<DIAMOND_CENTER_LED_COUNT>::new(
Argb::OFF,
None,
),
);
QrScanSchema::User
| QrScanSchema::Operator
| QrScanSchema::OperatorSelfServe => {
self.operator_signup_phase.failure();

// show error animation
Expand Down
2 changes: 2 additions & 0 deletions orb-ui/src/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ macro_rules! event_enum {
pub enum QrScanSchema {
/// Operator QR-code scanning.
Operator,
/// Operator QR-code scanning, self-serve mode.
OperatorSelfServe,
/// User QR-code scanning.
User,
/// WiFi QR-code scanning.
Expand Down
22 changes: 10 additions & 12 deletions orb-ui/src/engine/pearl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ impl EventHandler for Runner<PEARL_RING_LED_COUNT, PEARL_CENTER_LED_COUNT> {
);

match schema {
QrScanSchema::Operator => {
QrScanSchema::Operator | QrScanSchema::OperatorSelfServe => {
self.operator_signup_phase.operator_qr_code_ok();
}
QrScanSchema::Wifi => {
Expand Down Expand Up @@ -317,7 +317,7 @@ impl EventHandler for Runner<PEARL_RING_LED_COUNT, PEARL_CENTER_LED_COUNT> {
Duration::ZERO,
)?;
}
Event::QrScanCompleted { schema } => {
Event::QrScanCompleted { schema: _ } => {
// stop wave (foreground) & show alert/blinks (notice)
self.stop_center(LEVEL_FOREGROUND, Transition::ForceStop);
self.set_center(
Expand All @@ -329,12 +329,6 @@ impl EventHandler for Runner<PEARL_RING_LED_COUNT, PEARL_CENTER_LED_COUNT> {
false,
),
);

match schema {
QrScanSchema::Operator => {}
QrScanSchema::User => {}
QrScanSchema::Wifi => {}
}
}
Event::QrScanUnexpected { schema, reason } => {
match reason {
Expand All @@ -357,7 +351,7 @@ impl EventHandler for Runner<PEARL_RING_LED_COUNT, PEARL_CENTER_LED_COUNT> {
self.stop_ring(LEVEL_FOREGROUND, Transition::ForceStop);
self.operator_signup_phase.user_qr_code_issue();
}
QrScanSchema::Operator => {
QrScanSchema::Operator | QrScanSchema::OperatorSelfServe => {
self.operator_signup_phase.operator_qr_code_issue();
}
QrScanSchema::Wifi => {}
Expand All @@ -371,7 +365,9 @@ impl EventHandler for Runner<PEARL_RING_LED_COUNT, PEARL_CENTER_LED_COUNT> {
Duration::ZERO,
)?;
match schema {
QrScanSchema::User | QrScanSchema::Operator => {
QrScanSchema::User
| QrScanSchema::Operator
| QrScanSchema::OperatorSelfServe => {
// in case schema is user qr
self.stop_ring(LEVEL_FOREGROUND, Transition::ForceStop);
self.operator_signup_phase.failure();
Expand All @@ -383,7 +379,7 @@ impl EventHandler for Runner<PEARL_RING_LED_COUNT, PEARL_CENTER_LED_COUNT> {
}
Event::QrScanSuccess { schema } => {
match schema {
QrScanSchema::Operator => {
QrScanSchema::Operator | QrScanSchema::OperatorSelfServe => {
self.sound.queue(
sound::Type::Melody(sound::Melody::QrLoadSuccess),
Duration::ZERO,
Expand All @@ -406,7 +402,9 @@ impl EventHandler for Runner<PEARL_RING_LED_COUNT, PEARL_CENTER_LED_COUNT> {
self.sound
.queue(sound::Type::Voice(sound::Voice::Timeout), Duration::ZERO)?;
match schema {
QrScanSchema::User | QrScanSchema::Operator => {
QrScanSchema::User
| QrScanSchema::Operator
| QrScanSchema::OperatorSelfServe => {
// in case schema is user qr
self.stop_ring(LEVEL_FOREGROUND, Transition::ForceStop);
self.operator_signup_phase.failure();
Expand Down
24 changes: 17 additions & 7 deletions orb-ui/src/simulation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,23 @@ pub async fn signup_simulation(

loop {
if !showcar {
// scanning operator QR code
ui.qr_scan_start(QrScanSchema::Operator);
time::sleep(Duration::from_secs(10)).await;
ui.qr_scan_capture();
time::sleep(Duration::from_secs(2)).await;
ui.qr_scan_completed(QrScanSchema::Operator);
ui.qr_scan_success(QrScanSchema::Operator);
if self_serve {
// scanning operator QR code
ui.qr_scan_start(QrScanSchema::OperatorSelfServe);
time::sleep(Duration::from_secs(10)).await;
ui.qr_scan_capture();
time::sleep(Duration::from_secs(2)).await;
ui.qr_scan_completed(QrScanSchema::OperatorSelfServe);
ui.qr_scan_success(QrScanSchema::OperatorSelfServe);
} else {
// scanning operator QR code
ui.qr_scan_start(QrScanSchema::Operator);
time::sleep(Duration::from_secs(10)).await;
ui.qr_scan_capture();
time::sleep(Duration::from_secs(2)).await;
ui.qr_scan_completed(QrScanSchema::Operator);
ui.qr_scan_success(QrScanSchema::Operator);
}

// scanning user QR code
time::sleep(Duration::from_secs(1)).await;
Expand Down

0 comments on commit 161f488

Please sign in to comment.