From 6099a35ad98a40b7efae5429f87349c0ded6d5e3 Mon Sep 17 00:00:00 2001 From: Chris Vig Date: Wed, 10 Sep 2025 20:28:57 -0500 Subject: [PATCH] Add ability to wait for autokey buffer to clear. --- scripts/superkey/interface.py | 22 +++++++++++++++++++++- scripts/superkey/types.py | 1 + src/main/application/intf_port.c | 21 +++++++++++++++++++++ src/main/application/intf_types.h | 1 + src/main/application/keyer.c | 7 +++++++ src/main/application/keyer.h | 6 ++++++ 6 files changed, 57 insertions(+), 1 deletion(-) diff --git a/scripts/superkey/interface.py b/scripts/superkey/interface.py index dfe835b..5895cb4 100644 --- a/scripts/superkey/interface.py +++ b/scripts/superkey/interface.py @@ -11,6 +11,7 @@ import serial import struct +import time from typing import Iterable, Optional, Tuple from .constants import * @@ -111,7 +112,7 @@ def __exit__(self, exc_type, exc_value, traceback): if self.serial is not None and self.serial.is_open: self.serial.close() - def autokey(self, string: str, flags: Iterable[AutokeyFlag] = []): + def autokey(self, string: str, flags: Iterable[AutokeyFlag] = [], block: bool = False): """ Sends the `REQUEST_AUTOKEY_EX` command. Queues the specified string to be automatically keyed. """ @@ -129,6 +130,17 @@ def autokey(self, string: str, flags: Iterable[AutokeyFlag] = []): self.__send_packet(MessageID.REQUEST_AUTOKEY_EX, payload) self.__check_reply_empty() + # If blocking was selected, wait for autokey to complete + if block: + self.autokey_wait() + + def autokey_count(self) -> int: + """ + Sends the `REQUEST_AUTOKEY_COUNT` command. Returns the number of Morse code elements in the autokey buffer. + """ + self.__send_packet(MessageID.REQUEST_AUTOKEY_COUNT) + return self.__check_reply(' bool: """ Sends the `REQUEST_GET_BUZZER_ENABLED` command. Returns whether the buzzer is enabled or not. diff --git a/scripts/superkey/types.py b/scripts/superkey/types.py index b6dc92c..32ea143 100644 --- a/scripts/superkey/types.py +++ b/scripts/superkey/types.py @@ -104,6 +104,7 @@ [ # Requests 'REQUEST_AUTOKEY', + 'REQUEST_AUTOKEY_COUNT', 'REQUEST_AUTOKEY_EX', 'REQUEST_AUTOKEY_QUICK_MSG', 'REQUEST_GET_BUZZER_ENABLED', diff --git a/src/main/application/intf_port.c b/src/main/application/intf_port.c index 6ba2689..c5de6a5 100644 --- a/src/main/application/intf_port.c +++ b/src/main/application/intf_port.c @@ -110,6 +110,12 @@ static void process_message( intf_header_t const * header, void const * payload */ static void process_message_request_autokey( intf_header_t const * header, void const * payload ); +/** + * @fn process_message_request_autokey_count( intf_header_t const *, void const * ) + * @brief Processes the specified interface message with the `INTF_MESSAGE_REQUEST_AUTOKEY_COUNT` message ID. + */ +static void process_message_request_autokey_count( intf_header_t const * header, void const * payload ); + /** * @fn process_message_request_autokey_ex( intf_header_t const *, void const * ) * @brief Processes the specified interface message with the `INTF_MESSAGE_REQUEST_AUTOKEY_EX` message ID. @@ -417,6 +423,10 @@ static void process_message( intf_header_t const * header, void const * payload process_message_request_autokey( header, payload ); break; + case INTF_MESSAGE_REQUEST_AUTOKEY_COUNT: + process_message_request_autokey_count( header, payload ); + break; + case INTF_MESSAGE_REQUEST_AUTOKEY_EX: process_message_request_autokey_ex( header, payload ); break; @@ -570,6 +580,17 @@ static void process_message_request_autokey( intf_header_t const * header, void } /* process_message_request_autokey() */ +static void process_message_request_autokey_count( intf_header_t const * header, void const * payload ) +{ + ( void )payload; + VALIDATE_PAYLOAD_SIZE_OR_BAIL( 0 ); + + size_t count = keyer_autokey_count(); + send_packet( INTF_MESSAGE_REPLY_SUCCESS, & count, sizeof( count ) ); + +} /* process_message_request_autokey_count() */ + + static void process_message_request_autokey_ex( intf_header_t const * header, void const * payload ) { typedef struct diff --git a/src/main/application/intf_types.h b/src/main/application/intf_types.h index c55a04c..c4a4573 100644 --- a/src/main/application/intf_types.h +++ b/src/main/application/intf_types.h @@ -44,6 +44,7 @@ typedef uint16_t intf_message_t; enum { INTF_MESSAGE_REQUEST_AUTOKEY, /**< Queues a string to be autokeyed. */ + INTF_MESSAGE_REQUEST_AUTOKEY_COUNT, /**< Get number of Morse code elements in autokey buffer. */ INTF_MESSAGE_REQUEST_AUTOKEY_EX, /**< Queues a string to be autokeyed with flags. */ INTF_MESSAGE_REQUEST_AUTOKEY_QUICK_MSG, /**< Queues a quick message to be autokeyed.*/ INTF_MESSAGE_REQUEST_GET_BUZZER_ENABLED,/**< Get buzzer enablement. */ diff --git a/src/main/application/keyer.c b/src/main/application/keyer.c index 8c83cac..905022c 100644 --- a/src/main/application/keyer.c +++ b/src/main/application/keyer.c @@ -225,6 +225,13 @@ bool keyer_autokey_char_ex( char c, keyer_autokey_flag_field_t flags ) } /* keyer_autokey_char_ex() */ +size_t keyer_autokey_count( void ) +{ + return( autokey_count() ); + +} /* keyer_autokey_count() */ + + size_t keyer_autokey_str( char const * str ) { return( keyer_autokey_str_ex( str, KEYER_AUTOKEY_FLAG_NONE ) ); diff --git a/src/main/application/keyer.h b/src/main/application/keyer.h index 77b31a3..ef19c2b 100644 --- a/src/main/application/keyer.h +++ b/src/main/application/keyer.h @@ -102,6 +102,12 @@ bool keyer_autokey_char( char c ); */ bool keyer_autokey_char_ex( char c, keyer_autokey_flag_field_t flags ); +/** + * @fn keyer_autokey_count( void ) + * @brief Returns the number of Morse code elements currently in the autokey buffer. + */ +size_t keyer_autokey_count( void ); + /** * @fn keyer_autokey_str( char const * ) * @brief Adds the specified string to the keyer's autokey buffer.