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
1 change: 1 addition & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"_DEBUG=1",
"_BUILD_TYPE=\"Debug\"",
"_CONFIG_DFLT_WPM=200",
"_CONFIG_DFLT_WPM_ELEMENT_SCALE=1.0f",
"_CONFIG_DFLT_BUZZER_ENABLED=true",
"_CONFIG_DFLT_BUZZER_FREQUENCY=700",
"_CONFIG_DFLT_LED_STATUS_ENABLED=true",
Expand Down
7 changes: 5 additions & 2 deletions configuration.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
# -- Configuration Defaults --

# Define values
set(CONFIG_DFLT_WPM 200
CACHE STRING "Default words per minute, in tenths of a WPM. (10 - 1000)")
set(CONFIG_DFLT_WPM 20.0f
CACHE STRING "Default words per minute. (1.0f - 100.0f)")
set(CONFIG_DFLT_WPM_ELEMENT_SCALE 1.0f
CACHE STRING "Default Morse code element scale. (0.1f - 10.f)")
set(CONFIG_DFLT_BUZZER_ENABLED true
CACHE STRING "Should the buzzer be enabled by default? (true / false)")
set(CONFIG_DFLT_BUZZER_FREQUENCY 700
Expand Down Expand Up @@ -54,6 +56,7 @@ set(CONFIG_DFLT_KEYER_OUTPUT_ACTIVE_LOW true
# Set compile definitions
add_compile_definitions(
_CONFIG_DFLT_WPM=${CONFIG_DFLT_WPM}
_CONFIG_DFLT_WPM_ELEMENT_SCALE=${CONFIG_DFLT_WPM_ELEMENT_SCALE}
_CONFIG_DFLT_BUZZER_ENABLED=${CONFIG_DFLT_BUZZER_ENABLED}
_CONFIG_DFLT_BUZZER_FREQUENCY=${CONFIG_DFLT_BUZZER_FREQUENCY}
_CONFIG_DFLT_LED_STATUS_ENABLED=${CONFIG_DFLT_LED_STATUS_ENABLED}
Expand Down
4 changes: 4 additions & 0 deletions src/executable.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,16 @@ target_link_options(
PRIVATE
${EXECUTABLE_LINK_OPTIONS}
-Wl,-Map=${PROJECT_BUILD_DIR}/${EXECUTABLE_MAP_FILE}
-Wl,-u,vfprintf # Floating point support for printf
-Wl,-u,vfscanf # Floating point support for scanf
)

# Add libraries
target_link_libraries(
${EXECUTABLE_NAME}
${EXECUTABLE_LIBS}
printf_flt # Floating point support for printf
scanf_flt # Floating point support for scanf
)

# Set custom filename for executable
Expand Down
16 changes: 11 additions & 5 deletions src/main/application/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@

/* ----------------------------------------------------- MACROS ----------------------------------------------------- */

_Static_assert( _CONFIG_DFLT_WPM >= WPM_MINIMUM &&
_CONFIG_DFLT_WPM <= WPM_MAXIMUM,
"Invalid default WPM!" );
_Static_assert( _CONFIG_DFLT_BUZZER_FREQUENCY >= BUZZER_MINIMUM_FREQUENCY &&
_CONFIG_DFLT_BUZZER_FREQUENCY <= BUZZER_MAXIMUM_FREQUENCY,
"Invalid default buzzer frequency!" );
Expand Down Expand Up @@ -75,6 +72,8 @@ void config_default( config_t * config )

// Global settings
config->wpm = _CONFIG_DFLT_WPM;
for( wpm_element_t el = 0; el < WPM_ELEMENT_COUNT; el++ )
config->wpm_element_scale[ el ] = _CONFIG_DFLT_WPM_ELEMENT_SCALE;

// Buzzer configuration
config->buzzer_enabled = _CONFIG_DFLT_BUZZER_ENABLED;
Expand Down Expand Up @@ -178,8 +177,15 @@ static void flush( tick_t tick )
static bool validate_config( config_t const * config )
{
if( config->wpm < WPM_MINIMUM ||
config->wpm > WPM_MAXIMUM ||
config->buzzer_frequency < BUZZER_MINIMUM_FREQUENCY ||
config->wpm > WPM_MAXIMUM )
return false;

for( wpm_element_t el = 0; el < WPM_ELEMENT_COUNT; el++ )
if( config->wpm_element_scale[ el ] < WPM_ELEMENT_SCALE_MINIMUM ||
config->wpm_element_scale[ el ] > WPM_ELEMENT_SCALE_MAXIMUM )
return( false );

if( config->buzzer_frequency < BUZZER_MINIMUM_FREQUENCY ||
config->buzzer_frequency > BUZZER_MAXIMUM_FREQUENCY )
return( false );

Expand Down
3 changes: 3 additions & 0 deletions src/main/application/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ typedef struct
/** Global words per minute setting. */
wpm_t wpm;

/** Scale factor for each Morse code element. */
wpm_element_scale_t wpm_element_scale[ WPM_ELEMENT_COUNT ];

/** If set to `false`, the buzzer will be disabled and will not sound. */
bool buzzer_enabled;

Expand Down
59 changes: 46 additions & 13 deletions src/main/application/debug_port.c
Original file line number Diff line number Diff line change
Expand Up @@ -799,44 +799,77 @@ static void exec_command_version( char const * const command )
static void exec_command_wpm( char const * const command )
{
// Scanned variables
unsigned int wpm;
float wpm;
char element_str[ TOKEN_MAX_LEN ];
wpm_element_t element;
float scale;
int sscanf_count;

// Parse subcommand
if( string_equals( command, CMD_STR_WPM ) )
{
// No subcommand - interpret as a status request. No action required.
}
else if( sscanf( command + 4, "%u %n", & wpm, & sscanf_count ) == 1 &&
else if( sscanf( command + 4, "%f %n", & wpm, & sscanf_count ) == 1 &&
( command + 4 )[ sscanf_count ] == NULL_CHAR )
{
// Set WPM
if( wpm < WPM_MINIMUM || wpm > WPM_MAXIMUM )
{
debug_port_printf( "Invalid WPM: \"%u\". Must be between "
stringize_value( WPM_MINIMUM ) " and "
stringize_value( WPM_MAXIMUM ) "." NEWLINE_STR,
wpm );
debug_port_printf( "Invalid WPM: \"%.1f\". Must be between %.1f and %.1f." NEWLINE_STR,
wpm, WPM_MINIMUM, WPM_MAXIMUM );
return;
}
wpm_set( ( wpm_t )wpm );
}
else if( string_equals( command, CMD_STR_WPM " scale default" ) )
{
// Reset element scales to defaults
wpm_element_scale_default();
}
else if( string_begins_with( command, CMD_STR_WPM " scale " ) &&
sscanf( command + 10, TOKEN_FMT_STR " %n", element_str, & sscanf_count ) == 1 &&
( command + 10 )[ sscanf_count ] == NULL_CHAR &&
string_to_element( element_str, & element ) )
{
// Report scale
debug_port_printf( CMD_STR_WPM " scale (%s): %.3f" NEWLINE_STR,
string_from_element( element ),
wpm_get_element_scale( element ) );
return;
}
else if( string_begins_with( command, CMD_STR_WPM " scale " ) &&
sscanf( command + 10, TOKEN_FMT_STR " %f %n", element_str, & scale, & sscanf_count ) == 2 &&
( command + 10 )[ sscanf_count ] == NULL_CHAR &&
string_to_element( element_str, & element ) )
{
// Set scale
if( scale < WPM_ELEMENT_SCALE_MINIMUM || scale > WPM_ELEMENT_SCALE_MAXIMUM )
{
debug_port_printf( "Invalid scale: \"%.1f\". Must be between %.1f and %.1f." NEWLINE_STR,
scale, WPM_ELEMENT_SCALE_MINIMUM, WPM_ELEMENT_SCALE_MAXIMUM );
return;
}
wpm_set_element_scale( element, scale );
}
else
{
// Unrecognized command?
print_invalid_command( command );
return;
}


// Print status info
tick_t dot, dash;
wpm_ticks( wpm_get(), & dot, & dash, NULL, NULL, NULL );
debug_port_printf( CMD_STR_WPM ": %u (%u.%u wpm - dot %lu ms, dash %lu ms)" NEWLINE_STR,
wpm_ticks_t ticks;
wpm_ticks( wpm_get(), ticks );
debug_port_printf( CMD_STR_WPM ": %.1f (dot %lu ms, dash %lu ms, space %lu / %lu / %lu ms)" NEWLINE_STR,
wpm_get(),
wpm_get() / 10,
wpm_get() % 10,
dot / TICKS_PER_MSEC,
dash / TICKS_PER_MSEC );
ticks[ WPM_ELEMENT_DOT ] / TICKS_PER_MSEC,
ticks[ WPM_ELEMENT_DASH ] / TICKS_PER_MSEC,
ticks[ WPM_ELEMENT_ELEMENT_SPACE ] / TICKS_PER_MSEC,
ticks[ WPM_ELEMENT_LETTER_SPACE ] / TICKS_PER_MSEC,
ticks[ WPM_ELEMENT_WORD_SPACE ] / TICKS_PER_MSEC );

} /* exec_command_wpm() */

Expand Down
Loading