Skip to content

Commit 23c892e

Browse files
authored
Implement automatic keyer mode. (#10)
* Implement automatic keyer mode. * Shorten debug command.
1 parent ba15f3b commit 23c892e

6 files changed

Lines changed: 778 additions & 60 deletions

File tree

src/main/application/debug_port.c

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
* @def RX_BUF_SIZE
3939
* @brief Size of the command receive buffer, in bytes.
4040
*/
41-
#define RX_BUF_SIZE 64
41+
#define RX_BUF_SIZE 256
4242

4343
/**
4444
* @def CMD_STR_BUZZER
@@ -147,6 +147,8 @@
147147
static char s_rx_buf[ RX_BUF_SIZE ];
148148
static size_t s_rx_count = 0;
149149

150+
bool s_immediate_autokey = false;
151+
150152
/* ----------------------------------------------------- MACROS ----------------------------------------------------- */
151153

152154
/**
@@ -236,6 +238,12 @@ static void exec_command_version( char const * const command );
236238
*/
237239
static void exec_command_wpm( char const * const command );
238240

241+
/**
242+
* @fn exec_immediate_autokey_mode( void )
243+
* @brief Executes the special "immediate autokey" mode.
244+
*/
245+
static void exec_immediate_autokey_mode( void );
246+
239247
/**
240248
* @fn print_invalid_command( char const * const )
241249
* @brief Sends an "Invalid command" message for the specified command.
@@ -330,6 +338,13 @@ void debug_port_usart_rx( void )
330338

331339
static void evaluate_rx_buf( void )
332340
{
341+
// Are we in immediate autokey mode?
342+
if( s_immediate_autokey )
343+
{
344+
exec_immediate_autokey_mode();
345+
return;
346+
}
347+
333348
// If we receive the terminating character...
334349
if( s_rx_buf[ s_rx_count - 1 ] == TERMINATOR_CHAR )
335350
{
@@ -694,6 +709,20 @@ static void exec_command_keyer( char const * const command )
694709
{
695710
// No subcommand - interpret as a status request. no action required
696711
}
712+
else if( string_equals( command, CMD_STR_KEYER " immediate" ) )
713+
{
714+
// Enter immediate autokey mode
715+
s_immediate_autokey = true;
716+
debug_port_print( CMD_STR_KEYER ": Now in immediate autokey mode. Send null character to exit." NEWLINE_STR );
717+
return;
718+
}
719+
else if( string_begins_with( command, CMD_STR_KEYER " key " ) )
720+
{
721+
// Add remaining string to autokey buffer
722+
size_t count = keyer_autokey_str( command + 10 );
723+
debug_port_printf( CMD_STR_KEYER ": \"%s\" (%u chars queued)" NEWLINE_STR, command + 10, count );
724+
return;
725+
}
697726
else if( string_equals( command, CMD_STR_KEYER " output_active_low " ENABLE_STR ) )
698727
{
699728
// Set output to active low
@@ -898,6 +927,30 @@ static void exec_command_wpm( char const * const command )
898927
} /* exec_command_wpm() */
899928

900929

930+
static void exec_immediate_autokey_mode( void )
931+
{
932+
// Loop through each available character
933+
for( size_t idx = 0; idx < s_rx_count; idx++ )
934+
{
935+
// If we receive the null character, exit autokey mode
936+
if( s_rx_buf[ idx ] == 0 )
937+
{
938+
debug_port_print( NEWLINE_STR CMD_STR_KEYER ": Exited immediate autokey mode." NEWLINE_STR );
939+
s_immediate_autokey = false;
940+
keyer_panic();
941+
break;
942+
}
943+
944+
// Otherwise, queue the character
945+
keyer_autokey_char( ( char )s_rx_buf[ idx ] );
946+
}
947+
948+
// All characters were consumed
949+
s_rx_count = 0;
950+
951+
} /* exec_immediate_autokey_mode() */
952+
953+
901954
static void print_invalid_command( char const * const command )
902955
{
903956
debug_port_print( INVALID_COMMAND_STR "\"" );

0 commit comments

Comments
 (0)