Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion scripts/superkey/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import serial
import struct
import time
from typing import Iterable, Optional, Tuple

from .constants import *
Expand Down Expand Up @@ -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.
"""
Expand All @@ -129,13 +130,32 @@ 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('<H')[0]

def autokey_quick_msg(self, index: int):
"""
Sends the `REQUEST_AUTOKEY_QUICK_MSG` command. Keys a quick message.
"""
self.__send_packet(MessageID.REQUEST_AUTOKEY_QUICK_MSG, struct.pack('<B', index))
self.__check_reply_empty()

def autokey_wait(self, delay: float = 0.25):
"""
Waits until the autokey buffer is empty.
NOTE: This is not an interface call - it periodically polls `autokey_count()`.
"""
while self.autokey_count() != 0:
time.sleep(delay)

def get_buzzer_enabled(self) -> bool:
"""
Sends the `REQUEST_GET_BUZZER_ENABLED` command. Returns whether the buzzer is enabled or not.
Expand Down
1 change: 1 addition & 0 deletions scripts/superkey/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
[
# Requests
'REQUEST_AUTOKEY',
'REQUEST_AUTOKEY_COUNT',
'REQUEST_AUTOKEY_EX',
'REQUEST_AUTOKEY_QUICK_MSG',
'REQUEST_GET_BUZZER_ENABLED',
Expand Down
21 changes: 21 additions & 0 deletions src/main/application/intf_port.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/main/application/intf_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
7 changes: 7 additions & 0 deletions src/main/application/keyer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );
Expand Down
6 changes: 6 additions & 0 deletions src/main/application/keyer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down