From 8acfc7b73e724162a46d6e647041a28a15c78f56 Mon Sep 17 00:00:00 2001 From: Keir Fraser Date: Thu, 10 Oct 2019 08:06:44 +0100 Subject: [PATCH] Allow multi-row hotkey text. Include example for Piotr AmiGotek. --- inc/config.h | 2 +- src/default_config.c | 15 +++++++++++++++ src/main.c | 15 +++++++++++---- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/inc/config.h b/inc/config.h index 4dbf89c..146ddf5 100644 --- a/inc/config.h +++ b/inc/config.h @@ -37,7 +37,7 @@ extern struct __packed config { /* Mask of user pins driven HIGH by this hotkey. * Pins in @pin_mod but not in @pin_high are driven LOW. */ uint8_t pin_high; - char str[22]; + char str[30]; } hotkey[10]; uint16_t crc16_ccitt; diff --git a/src/default_config.c b/src/default_config.c index a15e822..c550e5c 100644 --- a/src/default_config.c +++ b/src/default_config.c @@ -58,6 +58,21 @@ const static struct config dfl_config = { } #endif +#if 0 + /* An example configuration for DF0/DF1 switching, for Piotr. + * Also an example of multi-row hotkey description text. */ + .user_pin_opendrain = 0, + .user_pin_pushpull = U(0), + .user_pin_high = U(0), /* Default = DF0: AmiGotek */ + .hotkey = { + [F(9)] = { .str = "DF0: AmiGotek\0DF1: Floppy", + .pin_mod = U(0), + .pin_high = U(0), }, + [F(10)] = { .str = "DF0: Floppy\0DF1: AmiGotek", + .pin_mod = U(0), }, + } +#endif + #undef F #undef U diff --git a/src/main.c b/src/main.c index 6b6a792..698e110 100644 --- a/src/main.c +++ b/src/main.c @@ -469,6 +469,7 @@ static void update_amiga_keys(void) static uint16_t hk_latch; bool_t hk_pressed; uint32_t s, r; + char *p; /* Unused hotkey? */ if (hk->pin_mod == 0) continue; @@ -484,10 +485,16 @@ static void update_amiga_keys(void) s = (uint16_t)hk->pin_high << pin_u0; r = (uint16_t)(hk->pin_mod & ~hk->pin_high) << pin_u0; gpio_user->bsrr = ((uint32_t)r << 16) | s; - if (hk->str[0]) { - strcpy((char *)notify.text[0], hk->str); - notify.cols = strlen(hk->str); - notify.rows = 1; + if (*(p = hk->str)) { + notify.cols = notify.rows = 0; + memset(notify.text, 0, sizeof(notify.text)); + while (*p) { + int len = strlen(p); + strcpy((char *)notify.text[notify.rows], p); + notify.cols = max(notify.cols, len); + notify.rows++; + p += len + 1; + } notify.on = TRUE; notify_time = time_now(); }