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
14 changes: 14 additions & 0 deletions scripts/superkey/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,13 @@ def get_paddle_mode(self) -> PaddleMode:
self.__send_packet(MessageID.REQUEST_GET_PADDLE_MODE)
return PaddleMode(self.__check_reply('<B')[0])

def get_trainer_mode(self) -> bool:
"""
Sends the `REQUEST_GET_TRAINER_MODE` command. Returns whether trainer mode is enabled or not.
"""
self.__send_packet(MessageID.REQUEST_GET_TRAINER_MODE)
return self.__check_reply('<?')[0]

def get_wpm(self) -> float:
"""
Sends the `REQUEST_GET_WPM` command. Returns the current WPM setting.
Expand Down Expand Up @@ -260,6 +267,13 @@ def set_paddle_mode(self, mode: PaddleMode):
self.__send_packet(MessageID.REQUEST_SET_PADDLE_MODE, struct.pack('<B', mode))
self.__check_reply_empty()

def set_trainer_mode(self, enabled: bool):
"""
Sends the `SET_TRAINER_MODE` command. Enables or disables trainer mode.
"""
self.__send_packet(MessageID.REQUEST_SET_TRAINER_MODE, struct.pack('<?', enabled))
self.__check_reply_empty()

def set_wpm(self, wpm: float):
"""
Sends the `REQUEST_SET_WPM` command. Sets the keyer's WPM setting.
Expand Down
2 changes: 2 additions & 0 deletions scripts/superkey/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
'REQUEST_GET_IO_TYPE',
'REQUEST_GET_LED_ENABLED',
'REQUEST_GET_PADDLE_MODE',
'REQUEST_GET_TRAINER_MODE',
'REQUEST_GET_WPM',
'REQUEST_GET_WPM_SCALE',
'REQUEST_PANIC',
Expand All @@ -115,6 +116,7 @@
'REQUEST_SET_IO_TYPE',
'REQUEST_SET_LED_ENABLED',
'REQUEST_SET_PADDLE_MODE',
'REQUEST_SET_TRAINER_MODE',
'REQUEST_SET_WPM',
'REQUEST_SET_WPM_SCALE',
'REQUEST_VERSION',
Expand Down
42 changes: 42 additions & 0 deletions src/main/application/intf_port.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ static void process_message_request_get_led_enabled( intf_header_t const * heade
*/
static void process_message_request_get_paddle_mode( intf_header_t const * header, void const * payload );

/**
* @fn process_message_request_get_trainer_mode( intf_header_t const *, void const * )
* @brief Processes the specified interface message with the `INTF_MESSAGE_REQUEST_GET_TRAINER_MODE` message ID.
*/
static void process_message_request_get_trainer_mode( intf_header_t const * header, void const * payload );

/**
* @fn process_message_request_get_wpm( intf_header_t const *, void const * )
* @brief Processes the specified interface message with the `INTF_MESSAGE_REQUEST_GET_WPM` message ID.
Expand Down Expand Up @@ -235,6 +241,12 @@ static void process_message_request_set_led_enabled( intf_header_t const * heade
*/
static void process_message_request_set_paddle_mode( intf_header_t const * header, void const * payload );

/**
* @fn process_message_request_set_trainer_mode( intf_header_t const *, void const * )
* @brief Processes the specified interface message with the `INTF_MESSAGE_REQUEST_SET_TRAINER_MODE` message ID.
*/
static void process_message_request_set_trainer_mode( intf_header_t const * header, void const * payload );

/**
* @fn process_message_request_set_wpm( intf_header_t const *, void const * )
* @brief Processes the specified interface message with the `INTF_MESSAGE_REQUEST_sET_WPM` message ID.
Expand Down Expand Up @@ -410,6 +422,10 @@ static void process_message( intf_header_t const * header, void const * payload
process_message_request_get_paddle_mode( header, payload );
break;

case INTF_MESSAGE_REQUEST_GET_TRAINER_MODE:
process_message_request_get_trainer_mode( header, payload );
break;

case INTF_MESSAGE_REQUEST_GET_WPM:
process_message_request_get_wpm( header, payload );
break;
Expand Down Expand Up @@ -458,6 +474,10 @@ static void process_message( intf_header_t const * header, void const * payload
process_message_request_set_paddle_mode( header, payload );
break;

case INTF_MESSAGE_REQUEST_SET_TRAINER_MODE:
process_message_request_set_trainer_mode( header, payload );
break;

case INTF_MESSAGE_REQUEST_SET_WPM:
process_message_request_set_wpm( header, payload );
break;
Expand Down Expand Up @@ -609,6 +629,17 @@ static void process_message_request_get_led_enabled( intf_header_t const * heade
} /* process_message_request_get_paddle_mode() */


static void process_message_request_get_trainer_mode( intf_header_t const * header, void const * payload )
{
( void )payload;
VALIDATE_PAYLOAD_SIZE_OR_BAIL( 0 );

bool enabled = keyer_get_trainer_mode_enabled();
send_packet( INTF_MESSAGE_REPLY_SUCCESS, & enabled, sizeof( enabled ) );

} /* process_message_request_get_trainer_mode() */


static void process_message_request_get_wpm( intf_header_t const * header, void const * payload )
{
( void )payload;
Expand Down Expand Up @@ -775,6 +806,17 @@ static void process_message_request_set_paddle_mode( intf_header_t const * heade
} /* process_message_request_set_paddle_mode() */


static void process_message_request_set_trainer_mode( intf_header_t const * header, void const * payload )
{
VALIDATE_PAYLOAD_SIZE_OR_BAIL( sizeof( bool ) );

bool enabled = *( ( bool const * )payload );
keyer_set_trainer_mode_enabled( enabled );
send_empty_packet( INTF_MESSAGE_REPLY_SUCCESS );

} /* process_message_request_set_trainer_mode() */


static void process_message_request_set_wpm( intf_header_t const * header, void const * payload )
{
VALIDATE_PAYLOAD_SIZE_OR_BAIL( sizeof( wpm_t ) );
Expand Down
2 changes: 2 additions & 0 deletions src/main/application/intf_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ enum
INTF_MESSAGE_REQUEST_GET_IO_TYPE, /**< Gets I/O pin type. */
INTF_MESSAGE_REQUEST_GET_LED_ENABLED, /**< Gets enablement for LED. */
INTF_MESSAGE_REQUEST_GET_PADDLE_MODE, /**< Gets the paddle mode. */
INTF_MESSAGE_REQUEST_GET_TRAINER_MODE, /**< Gets enablement for trainer mode. */
INTF_MESSAGE_REQUEST_GET_WPM, /**< Get WPM setting. */
INTF_MESSAGE_REQUEST_GET_WPM_SCALE, /**< Get element WPM scale. */
INTF_MESSAGE_REQUEST_PANIC, /**< Immediately stop the keyer. */
Expand All @@ -60,6 +61,7 @@ enum
INTF_MESSAGE_REQUEST_SET_IO_TYPE, /**< Sets I/O pin type. */
INTF_MESSAGE_REQUEST_SET_LED_ENABLED, /**< Sets enablement for LED. */
INTF_MESSAGE_REQUEST_SET_PADDLE_MODE, /**< Sets the paddle mode. */
INTF_MESSAGE_REQUEST_SET_TRAINER_MODE, /**< Set enablement for trainer mode. */
INTF_MESSAGE_REQUEST_SET_WPM, /**< Set WPM. */
INTF_MESSAGE_REQUEST_SET_WPM_SCALE, /**< Set WPM scale. */
INTF_MESSAGE_REQUEST_VERSION, /**< Get application version information. */
Expand Down
20 changes: 19 additions & 1 deletion src/main/application/keyer.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ enum

static bool s_keyed = false; /**< Is the keyer hardware currently keyed? */
static bool s_panicked = false; /**< Was the keyer panic activated? */
static bool s_trainer_mode = false; /**< Is trainer mode on? */

static state_t s_state = STATE_OFF; /**< Currently active keyer state. */

Expand Down Expand Up @@ -655,11 +656,19 @@ keyer_paddle_mode_t keyer_get_paddle_mode( void )
} /* keyer_get_paddle_mode() */


bool keyer_get_trainer_mode_enabled( void )
{
return( s_trainer_mode );

} /* keyer_get_trainer_mode_enabled() */


void keyer_init( void )
{
// Initialize local state
s_keyed = false;
s_panicked = false;
s_trainer_mode = false;
s_state = STATE_OFF;
s_el = WPM_ELEMENT_NONE;
s_lockout_el = WPM_ELEMENT_NONE;
Expand Down Expand Up @@ -709,6 +718,15 @@ void keyer_set_paddle_mode( keyer_paddle_mode_t mode )
} /* keyer_set_paddle_mode() */


void keyer_set_trainer_mode_enabled( bool enabled )
{
s_trainer_mode = enabled;

update_hardware();

} /* keyer_set_trainer_mode_enabled() */


void keyer_tick( tick_t tick )
{
// Update element tick counts if required
Expand Down Expand Up @@ -1053,7 +1071,7 @@ static void set_keyed( bool keyed )

static void update_hardware( void )
{
io_set_output_state_type( IO_TYPE_OUTPUT_KEYER, s_keyed ? IO_STATE_ON : IO_STATE_OFF );
io_set_output_state_type( IO_TYPE_OUTPUT_KEYER, s_keyed && ! s_trainer_mode ? IO_STATE_ON : IO_STATE_OFF );
led_set_on( LED_KEY, s_keyed );
buzzer_set_on( s_keyed );

Expand Down
14 changes: 14 additions & 0 deletions src/main/application/keyer.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ bool keyer_get_paddle_invert( void );
*/
keyer_paddle_mode_t keyer_get_paddle_mode( void );

/**
* @fn keyer_get_trainer_mode_enabled( void )
* @brief Returns `true` if trainer mode is enabled.
* @note In trainer mode, the keyer output to any connected radios will not actually be activated.
*/
bool keyer_get_trainer_mode_enabled( void );

/**
* @fn keyer_init( void )
* @brief Initializes the keyer module.
Expand Down Expand Up @@ -119,6 +126,13 @@ void keyer_set_paddle_invert( bool invert );
*/
void keyer_set_paddle_mode( keyer_paddle_mode_t mode );

/**
* @fn keyer_set_trainer_mode_enabled( bool )
* @brief Enables or disables trainer mode.
* @note In trainer mode, the keyer output to any connected radios will not actually be activated.
*/
void keyer_set_trainer_mode_enabled( bool enabled );

/**
* @fn keyer_tick( tick_t )
* @brief Performs periodic processing at the specified tick count.
Expand Down