LCOV - code coverage report
Current view: top level - ledger/signer/src - signer_ux.c (source / functions) Hit Total Coverage
Test: powHSM firmware Lines: 30 32 93.8 %
Date: 2025-07-10 13:49:13 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /**
       2             :  * The MIT License (MIT)
       3             :  *
       4             :  * Copyright (c) 2021 RSK Labs Ltd
       5             :  *
       6             :  * Permission is hereby granted, free of charge, to any person obtaining a copy
       7             :  * of this software and associated documentation files (the "Software"), to
       8             :  * deal in the Software without restriction, including without limitation the
       9             :  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
      10             :  * sell copies of the Software, and to permit persons to whom the Software is
      11             :  * furnished to do so, subject to the following conditions:
      12             :  *
      13             :  * The above copyright notice and this permission notice shall be included in
      14             :  * all copies or substantial portions of the Software.
      15             :  *
      16             :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      17             :  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      18             :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
      19             :  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      20             :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
      21             :  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
      22             :  * IN THE SOFTWARE.
      23             :  */
      24             : 
      25             : #include "signer_ux.h"
      26             : 
      27             : // UI currently displayed
      28             : enum UI_STATE { UI_INFO, UI_SCREENSAVER };
      29             : enum UI_STATE G_ui_state;
      30             : // Time spent since the last button press
      31             : static unsigned int G_idle_time_ms;
      32             : // The time in milliseconds after which the screen saver is displayed if no
      33             : // button is pressed
      34             : static unsigned int G_screensaver_timeout_ms;
      35             : 
      36             : // Local functions
      37         216 : static void signer_ux_update(void) {
      38         216 :     switch (G_ui_state) {
      39         204 :     case UI_INFO:
      40         204 :         if (G_idle_time_ms >= G_screensaver_timeout_ms) {
      41           3 :             G_ui_state = UI_SCREENSAVER;
      42           3 :             signer_ux_screensaver();
      43             :         }
      44         204 :         break;
      45          12 :     case UI_SCREENSAVER:
      46          12 :         if (G_idle_time_ms < G_screensaver_timeout_ms) {
      47           2 :             G_ui_state = UI_INFO;
      48           2 :             signer_ux_info();
      49             :         }
      50          12 :         break;
      51           0 :     default:
      52           0 :         break;
      53             :     }
      54         216 : }
      55             : 
      56             : // Public interface
      57           5 : void signer_ux_init(unsigned int screensaver_timeout_ms) {
      58           5 :     G_idle_time_ms = 0;
      59           5 :     G_ui_state = UI_INFO;
      60           5 :     G_screensaver_timeout_ms = screensaver_timeout_ms;
      61           5 :     signer_ux_info();
      62           5 : }
      63             : 
      64         102 : void signer_ux_handle_button_press(void) {
      65         102 :     G_idle_time_ms = 0;
      66         102 :     signer_ux_update();
      67         102 : }
      68             : 
      69         114 : void signer_ux_handle_ticker_event(unsigned int interval_ms) {
      70         114 :     unsigned int last_idle_time_ms = G_idle_time_ms;
      71         114 :     G_idle_time_ms += interval_ms;
      72             :     // Handle overflow
      73         114 :     if (G_idle_time_ms < last_idle_time_ms) {
      74           9 :         G_idle_time_ms = last_idle_time_ms;
      75             :     }
      76         114 :     signer_ux_update();
      77         114 : }

Generated by: LCOV version 1.16