-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds "screen saver" mode to signer app (#190)
Adds a "screen saver" mode that turns off the display after 30 seconds of inactivity in the Signer app. The goal is to extend the Ledger screen lifetime by reducing the time the display shows a static screen uninterruptedly. - Added new `ui_screensaver` screen to Signer app - Factored out Signer UX code into testable units - Added unit tests to the Signer app - Added signer ux code to coverage report
- Loading branch information
1 parent
85c304d
commit 6bbebfa
Showing
14 changed files
with
567 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/** | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2021 RSK Labs Ltd | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to | ||
* deal in the Software without restriction, including without limitation the | ||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | ||
* sell copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
* IN THE SOFTWARE. | ||
*/ | ||
|
||
#include "signer_ux.h" | ||
|
||
// UI currently displayed | ||
enum UI_STATE { UI_INFO, UI_SCREENSAVER }; | ||
enum UI_STATE G_ui_state; | ||
// Time spent since the last button press | ||
static unsigned int G_idle_time_ms; | ||
// The time in milliseconds after which the screen saver is displayed if no | ||
// button is pressed | ||
static unsigned int G_screensaver_timeout_ms; | ||
|
||
// Local functions | ||
static void signer_ux_update(void) { | ||
switch (G_ui_state) { | ||
case UI_INFO: | ||
if (G_idle_time_ms >= G_screensaver_timeout_ms) { | ||
G_ui_state = UI_SCREENSAVER; | ||
signer_ux_screensaver(); | ||
} | ||
break; | ||
case UI_SCREENSAVER: | ||
if (G_idle_time_ms < G_screensaver_timeout_ms) { | ||
G_ui_state = UI_INFO; | ||
signer_ux_info(); | ||
} | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
// Public interface | ||
void signer_ux_init(unsigned int screensaver_timeout_ms) { | ||
G_idle_time_ms = 0; | ||
G_ui_state = UI_INFO; | ||
G_screensaver_timeout_ms = screensaver_timeout_ms; | ||
signer_ux_info(); | ||
} | ||
|
||
void signer_ux_handle_button_press(void) { | ||
G_idle_time_ms = 0; | ||
signer_ux_update(); | ||
} | ||
|
||
void signer_ux_handle_ticker_event(unsigned int interval_ms) { | ||
unsigned int last_idle_time_ms = G_idle_time_ms; | ||
G_idle_time_ms += interval_ms; | ||
// Handle overflow | ||
if (G_idle_time_ms < last_idle_time_ms) { | ||
G_idle_time_ms = last_idle_time_ms; | ||
} | ||
signer_ux_update(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2021 RSK Labs Ltd | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to | ||
* deal in the Software without restriction, including without limitation the | ||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | ||
* sell copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
* IN THE SOFTWARE. | ||
*/ | ||
|
||
#ifndef __SIGNER_UX_H | ||
#define __SIGNER_UX_H | ||
|
||
/* | ||
* Initialize the UX state. | ||
* | ||
* @arg[in] screensaver_timeout_ms The time after which the screen saver is | ||
* displayed if no button is pressed | ||
*/ | ||
void signer_ux_init(unsigned int screensaver_timeout_ms); | ||
|
||
/* | ||
* Handle a button press event. | ||
* | ||
* This function should be called whenever a button is pressed. | ||
*/ | ||
void signer_ux_handle_button_press(void); | ||
/* | ||
* Handles a ticker event. | ||
* | ||
* Increments the internal timer and updates the UI state if necessary. | ||
* | ||
* @arg[in] interval_ms Time spent since last ticker event | ||
*/ | ||
void signer_ux_handle_ticker_event(unsigned int interval_ms); | ||
|
||
// all screens | ||
void signer_ux_info(void); | ||
void signer_ux_screensaver(void); | ||
|
||
#endif // __SIGNER_UX_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/** | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2021 RSK Labs Ltd | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to | ||
* deal in the Software without restriction, including without limitation the | ||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | ||
* sell copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
* IN THE SOFTWARE. | ||
*/ | ||
|
||
#include <stddef.h> | ||
#include "os_io_seproxyhal.h" | ||
#include "signer_ux.h" | ||
|
||
// clang-format off | ||
static const bagl_element_t bagl_ui_info_nanos[] = { | ||
{ | ||
{BAGL_RECTANGLE, 0x00, 0, 0, 128, 32, 0, 0, BAGL_FILL, 0x000000, | ||
0xFFFFFF, 0, 0}, | ||
NULL, | ||
0, | ||
0, | ||
0, | ||
NULL, | ||
NULL, | ||
NULL, | ||
}, | ||
{ | ||
{BAGL_LABELINE, 0x02, 0, 12, 128, 11, 0, 0, 0, 0xFFFFFF, 0x000000, | ||
BAGL_FONT_OPEN_SANS_REGULAR_11px | BAGL_FONT_ALIGNMENT_CENTER, 0}, | ||
"Signer running...", | ||
0, | ||
0, | ||
0, | ||
NULL, | ||
NULL, | ||
NULL, | ||
} | ||
}; | ||
// clang-format on | ||
|
||
static unsigned int bagl_ui_info_nanos_button( | ||
unsigned int button_mask, unsigned int button_mask_counter) { | ||
// no-op - button presses are handled directly in the event loop | ||
return 0; | ||
} | ||
|
||
void signer_ux_info(void) { | ||
UX_DISPLAY(bagl_ui_info_nanos, NULL); | ||
} |
Oops, something went wrong.