1111
1212import serial
1313import struct
14+ import time
1415from typing import Iterable , Optional , Tuple
1516
1617from .constants import *
@@ -111,7 +112,7 @@ def __exit__(self, exc_type, exc_value, traceback):
111112 if self .serial is not None and self .serial .is_open :
112113 self .serial .close ()
113114
114- def autokey (self , string : str , flags : Iterable [AutokeyFlag ] = []):
115+ def autokey (self , string : str , flags : Iterable [AutokeyFlag ] = [], block : bool = False ):
115116 """
116117 Sends the `REQUEST_AUTOKEY_EX` command. Queues the specified string to be automatically keyed.
117118 """
@@ -129,13 +130,32 @@ def autokey(self, string: str, flags: Iterable[AutokeyFlag] = []):
129130 self .__send_packet (MessageID .REQUEST_AUTOKEY_EX , payload )
130131 self .__check_reply_empty ()
131132
133+ # If blocking was selected, wait for autokey to complete
134+ if block :
135+ self .autokey_wait ()
136+
137+ def autokey_count (self ) -> int :
138+ """
139+ Sends the `REQUEST_AUTOKEY_COUNT` command. Returns the number of Morse code elements in the autokey buffer.
140+ """
141+ self .__send_packet (MessageID .REQUEST_AUTOKEY_COUNT )
142+ return self .__check_reply ('<H' )[0 ]
143+
132144 def autokey_quick_msg (self , index : int ):
133145 """
134146 Sends the `REQUEST_AUTOKEY_QUICK_MSG` command. Keys a quick message.
135147 """
136148 self .__send_packet (MessageID .REQUEST_AUTOKEY_QUICK_MSG , struct .pack ('<B' , index ))
137149 self .__check_reply_empty ()
138150
151+ def autokey_wait (self , delay : float = 0.25 ):
152+ """
153+ Waits until the autokey buffer is empty.
154+ NOTE: This is not an interface call - it periodically polls `autokey_count()`.
155+ """
156+ while self .autokey_count () != 0 :
157+ time .sleep (delay )
158+
139159 def get_buzzer_enabled (self ) -> bool :
140160 """
141161 Sends the `REQUEST_GET_BUZZER_ENABLED` command. Returns whether the buzzer is enabled or not.
0 commit comments