From bf3477b914ab39f36d0ce71b62316ccd79672f40 Mon Sep 17 00:00:00 2001 From: Brad Campbell Date: Wed, 19 Jun 2024 14:54:22 -0400 Subject: [PATCH] hotp: add code for displaying keys on screen --- .../hotp/hotp_milestone_one/screen.c | 65 +++++++++++++++++++ .../hotp/hotp_milestone_one/screen.h | 4 ++ 2 files changed, 69 insertions(+) create mode 100644 examples/tutorials/hotp/hotp_milestone_one/screen.c create mode 100644 examples/tutorials/hotp/hotp_milestone_one/screen.h diff --git a/examples/tutorials/hotp/hotp_milestone_one/screen.c b/examples/tutorials/hotp/hotp_milestone_one/screen.c new file mode 100644 index 000000000..a6cffff2a --- /dev/null +++ b/examples/tutorials/hotp/hotp_milestone_one/screen.c @@ -0,0 +1,65 @@ +#include +#include +#include +#include + +#include +#include + +#include "step0.h" +#include "screen.h" + +u8g2_t u8g2; +bool inited = false; + +int display_hotp_keys(hotp_key_t* hotp_key, int num_keys) { + // Only init if not previously init-ed. + if (!inited) { + int ret = u8g2_tock_init(&u8g2); + if (ret != 0) { + return -1; + } + inited = true; + } + + + // int height = u8g2_GetDisplayHeight(&u8g2); + int width = u8g2_GetDisplayWidth(&u8g2); + + u8g2_SetFont(&u8g2, u8g2_font_profont17_tr); + u8g2_SetFontPosTop(&u8g2); + + u8g2_ClearBuffer(&u8g2); + + // Draw title. + u8g2_DrawStr(&u8g2, 0, 0, "HOTP App"); + + // Draw line below title. + int title_height = u8g2_GetMaxCharHeight(&u8g2); + u8g2_DrawHLine(&u8g2, 0, title_height , width); + + // Draw for each key. + u8g2_SetFont(&u8g2, u8g2_font_helvR08_tr); + int lines_start = title_height+1; + int offset = u8g2_GetMaxCharHeight(&u8g2) + 1; + + for (int i=0;i