From 1749cc2629caa86a0d688ea9f172015d392427a6 Mon Sep 17 00:00:00 2001 From: Tobias Schramm Date: Mon, 8 Feb 2021 22:07:32 +0100 Subject: [PATCH] Show last seen identifiers on pinetime display --- src/contacts.c | 22 ++++++++++++++++++++++ src/display.h | 3 +++ src/display_pinetime.c | 2 +- src/main.c | 1 + 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/contacts.c b/src/contacts.c index f0c7942..93d4925 100644 --- a/src/contacts.c +++ b/src/contacts.c @@ -23,6 +23,7 @@ #include "contacts.h" #include "exposure-notification.h" #include "covid.h" +#include "display.h" typedef struct contact { uint32_t most_recent_contact_time; //TODO: what is the correct type here? @@ -105,6 +106,8 @@ contact_t* find_contact(rolling_proximity_identifier_t* rpi, associated_encrypte return NULL; } +#define NIBBLE_TO_HEX(x) (((x & 0xf) < 10) ? '0' + (x) : 'A' + (x) - 10) + int check_add_contact(uint32_t contact_time, rolling_proximity_identifier_t* rpi, associated_encrypted_metadata_t* aem, int8_t rssi){ contact_t* contact = find_contact(rpi, aem); if( contact == NULL ){ @@ -139,6 +142,25 @@ int check_add_contact(uint32_t contact_time, rolling_proximity_identifier_t* rpi // print_aem(aem); // printk(" rssi %i, cnt %i \n", rssi, contacts->cnt); } + + for (int i = 0; i < 10; i++) { + char identifier_hex[COVID_ROLLING_PROXIMITY_IDENTIFIER_LEN * 2 + 1] = { 0 }; + rolling_proximity_identifier_t *ident; + + if (i >= contact_count) { + break; + } + + ident = &contacts[contact_count - i - 1].rolling_proximity_identifier; + + for (int j = 0; j < COVID_ROLLING_PROXIMITY_IDENTIFIER_LEN; j++) { + identifier_hex[j * 2] = NIBBLE_TO_HEX(ident->data[j] & 0x0f); + identifier_hex[j * 2 + 1] = NIBBLE_TO_HEX(ident->data[j] >> 4); + } + + platform_display_draw_string(0, DISPLAY_LINE_LAST_CONTACTS_START + i + 1, identifier_hex); + } + return 0; } diff --git a/src/display.h b/src/display.h index 5f2a0f4..a48f19b 100644 --- a/src/display.h +++ b/src/display.h @@ -3,6 +3,9 @@ #include #include +#define DISPLAY_LINE_CURRENT_IDENTIFIER 0 +#define DISPLAY_LINE_LAST_CONTACTS_START 2 + #ifdef PLATFORM_PINETIME #include "display_pinetime.h" #define platform_display_init pinetime_display_init diff --git a/src/display_pinetime.c b/src/display_pinetime.c index 34e99aa..2723ae2 100644 --- a/src/display_pinetime.c +++ b/src/display_pinetime.c @@ -7,7 +7,7 @@ #include -#include "display.h" +#include "display_pinetime.h" #define BACKLIGHT_LOW_OF_NODE DT_ALIAS(led0) #define BACKLIGHT_MID_OF_NODE DT_ALIAS(led1) diff --git a/src/main.c b/src/main.c index 5da5f7f..02ac9d6 100644 --- a/src/main.c +++ b/src/main.c @@ -33,6 +33,7 @@ void main(void) platform_display_set_powersave(false); platform_display_set_brightness(0xff); platform_display_draw_string(0, 0, "Hello World!"); + platform_display_draw_string(0, DISPLAY_LINE_LAST_CONTACTS_START, "Seen identifiers:"); // first init everything // Use custom randomization as the mbdet_tls context initialization messes with the Zeyhr BLE stack.