Skip to content

Commit

Permalink
Allow setting CW speed liberally in range 6..60 wpm (#437)
Browse files Browse the repository at this point in the history
The old coding had a fixed list of allowed CW speeds that were stepped
through using PgDn/PgUp. While this might make sense for different step
sizes (for example 2 wpm between 12 and 30, and 5 wpm above 30), it was
not used as such. All steps were 2 wpm, and jumps from 12 to 6 and 50 to
60 at the very ends of the scale.

For slow speed contest training, it does make sense to allow speeds
between 6 and 12 wpm. Also, since Hamlib keying was implemented, it's
now very easy to set the speed directly in the rig, and tlf's forcing of
the speed to match the old raster just got in the way.

Drop the whole idea of a list of permitted CW speeds in tlf, and allow
any integer between 6 and 60 wpm. PgDn/PgUp will tune up/down in 2wpm
steps. If Hamlib keying is used, and the rig exposes the range of
supported wpm values, additionally honor that. (The IC-7610 does, but
rigctld does not.)

Since "speed" is now the plain wpm value as an integer, clean up the
code and remove all occurrences of GetCWSpeed() and SetCWSpeed() to
directly reference the variable. (Especially the latter was easy to mix
up with setspeed() which actually *sets* the rig speed, while SetCWSpeed
was just a fat setter function for the internal variable.)

Drop the test code around the speed list handling since there's nothing
to test anymore.
  • Loading branch information
df7cb authored Sep 10, 2024
1 parent 6fe0a15 commit 6304d7d
Show file tree
Hide file tree
Showing 22 changed files with 63 additions and 233 deletions.
2 changes: 1 addition & 1 deletion src/autocq.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ static int get_autocq_time() {
return 0; // unknown
}
const int cw_message_len = cw_message_length(message[11]);
return (int)(1200.0 / GetCWSpeed()) * cw_message_len;
return (int)(1200.0 / speed) * cw_message_len;
}

#define NO_KEY -1
Expand Down
14 changes: 7 additions & 7 deletions src/callinput.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ int callinput(void) {
while (x != ESCAPE) {
nicebox(1, 1, 2, 12, "Cw");
attron(COLOR_PAIR(C_LOG) | A_STANDOUT);
mvprintw(2, 2, "Speed: %2u ", GetCWSpeed());
mvprintw(2, 2, "Speed: %2u ", speed);
mvprintw(3, 2, "Weight: %3d ", weight);
printcall();
refreshp();
Expand All @@ -349,12 +349,12 @@ int callinput(void) {
speedup();
attron(COLOR_PAIR(C_HEADER) | A_STANDOUT);

mvprintw(0, 14, "%2u", GetCWSpeed());
mvprintw(0, 14, "%2u", speed);

} else if (x == KEY_DOWN) {
speeddown();
attron(COLOR_PAIR(C_HEADER) | A_STANDOUT);
mvprintw(0, 14, "%2u", GetCWSpeed());
mvprintw(0, 14, "%2u", speed);

} else
x = ESCAPE;
Expand Down Expand Up @@ -931,10 +931,10 @@ int autosend() {
strcpy(hiscall_sent, current_qso.call);

char_sent = 0; /* no char sent so far */
timeout_sent = (1.2 / GetCWSpeed()) * getCWdots(current_qso.call[char_sent]);
timeout_sent = (1.2 / speed) * getCWdots(current_qso.call[char_sent]);

timer = g_timer_new();
timeout = (1.2 / GetCWSpeed()) * cw_message_length(current_qso.call);
timeout = (1.2 / speed) * cw_message_length(current_qso.call);

x = -1;
while ((x != ESCAPE) && (x != '\n' && x != KEY_ENTER)) {
Expand All @@ -949,7 +949,7 @@ int autosend() {
/* one char sent - display and set new timeout */
char_sent ++;
timeout_sent +=
(1.2 / GetCWSpeed()) * getCWdots(current_qso.call[char_sent]);
(1.2 / speed) * getCWdots(current_qso.call[char_sent]);

}

Expand Down Expand Up @@ -994,7 +994,7 @@ int autosend() {
sendmessage(append);

/* add char length to timeout */
timeout += (1.2 / GetCWSpeed()) * getCWdots((char) x);
timeout += (1.2 / speed) * getCWdots((char) x);

len = strlen(hiscall_sent);
hiscall_sent[len] = x;
Expand Down
2 changes: 1 addition & 1 deletion src/clear_display.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ void show_header_line() {

attron(COLOR_PAIR(C_HEADER) | A_STANDOUT);
mvaddstr(0, 0, spaces(29));
mvprintw(0, 0, " %-8s S=%2i D=%i ", mode, GetCWSpeed(), cqdelay);
mvprintw(0, 0, " %-8s S=%2i D=%i ", mode, speed, cqdelay);
mvaddstr(0, 21, fkey_header);
}

Expand Down
132 changes: 1 addition & 131 deletions src/cw_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,137 +23,7 @@

#include <glib.h>

// *INDENT-OFF*

#define CW_SPEEDS "06121416182022242628303234363840424446485060"
/*< speed string with 2 chars each (in WPM) */

// *INDENT-ON*

char speedstr[50] = CW_SPEEDS;
int speed = 10;


/* converts cw speed in wpm to an numbered index into speedstr table */
int speed_conversion(int cwspeed) {

int x;

switch (cwspeed) {

case 0 ... 6: {
x = 0;
break;
}
case 7 ... 12: {
x = 1;
break;
}
case 13 ... 14: {
x = 2;
break;
}
case 15 ... 16: {
x = 3;
break;
}
case 17 ... 18: {
x = 4;
break;
}
case 19 ... 20: {
x = 5;
break;
}
case 21 ... 22: {
x = 6;
break;
}
case 23 ... 24: {
x = 7;
break;
}
case 25 ... 26: {
x = 8;
break;
}
case 27 ... 28: {
x = 9;
break;
}
case 29 ... 30: {
x = 10;
break;
}
case 31 ... 32: {
x = 11;
break;
}
case 33 ... 34: {
x = 12;
break;
}
case 35 ... 36: {
x = 13;
break;
}
case 37 ... 38: {
x = 14;
break;
}
case 39 ... 40: {
x = 15;
break;
}
case 41 ... 42: {
x = 16;
break;
}
case 43 ... 44: {
x = 17;
break;
}
case 45 ... 46: {
x = 18;
break;
}
case 47 ... 48: {
x = 19;
break;
}
default: {
x = 20;
break;
}
}

return (x);
}


/** Set CW speed
*
* Set CW speed to the nearest supported value. Converts it into an index into
* the speed table and stores that.
* \param wpm The CW speed in WPM
*/
void SetCWSpeed(unsigned int wpm) {
speed = speed_conversion(wpm);
}


/* Get CW speed
*
* Return the actual CW speed in WPM as integer
* \return The CW speed in WPM
*/
unsigned int GetCWSpeed() {
char buff[3];

g_strlcpy(buff, speedstr + (2 * speed), 3);
return (atoi(buff));
}

int speed = 20;

/** get length of CW characters
*
Expand Down
5 changes: 0 additions & 5 deletions src/cw_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@
#ifndef CW_UTILS_H
#define CW_UTILS_H

extern int speed;

void SetCWSpeed(unsigned int wpm);
unsigned int GetCWSpeed();

unsigned int getCWdots(char ch);
unsigned int cw_message_length(char *message);

Expand Down
7 changes: 3 additions & 4 deletions src/gettxinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,11 @@ void gettxinfo(void) {
retval = hamlib_keyer_get_speed(&rig_cwspeed);

if (retval == RIG_OK) {
if (GetCWSpeed() !=
rig_cwspeed) { // FIXME: doesn't work if rig speed is between the values from CW_SPEEDS
SetCWSpeed(rig_cwspeed);
if (speed != rig_cwspeed) {
speed = rig_cwspeed;

attron(COLOR_PAIR(C_HEADER) | A_STANDOUT);
mvprintw(0, 14, "%2u", GetCWSpeed());
mvprintw(0, 14, "%2u", speed);
}
} else {
TLF_LOG_WARN("Problem with rig link: %s", rigerror(retval));
Expand Down
1 change: 1 addition & 0 deletions src/globalvars.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ extern int minitest; // minitest period length in seconds, 0 if not used
extern int portnum;
extern int lan_port;
extern int txdelay;
extern int speed; /* CW speed in wpm */
extern int weight;
extern int cw_bandwidth;
extern int cwpoints;
Expand Down
12 changes: 10 additions & 2 deletions src/hamlib_keyer.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,17 @@
#include "sendqrg.h"
#include "hamlib_keyer.h"

int hamlib_keyer_set_speed(int cwspeed) {
int hamlib_keyer_set_speed(int *cwspeed) {
gran_t keyspd_gran = my_rig->caps->level_gran[rig_setting2idx(
RIG_LEVEL_KEYSPD)];
value_t spd;
spd.i = cwspeed;

/* if rig declared min/max speed, honor it. */
if (keyspd_gran.min.i > 0 && *cwspeed < keyspd_gran.min.i)
*cwspeed = keyspd_gran.min.i;
if (keyspd_gran.max.i > 0 && *cwspeed > keyspd_gran.max.i)
*cwspeed = keyspd_gran.max.i;
spd.i = *cwspeed;

pthread_mutex_lock(&tlf_rig_mutex);
int ret = rig_set_level(my_rig, RIG_VFO_CURR, RIG_LEVEL_KEYSPD, spd);
Expand Down
2 changes: 1 addition & 1 deletion src/hamlib_keyer.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

int hamlib_keyer_set_speed(int cwspeed);
int hamlib_keyer_set_speed(int *cwspeed);
int hamlib_keyer_get_speed(int *cwspeed);
int hamlib_keyer_send(char *cwmessage);
int hamlib_keyer_stop();
6 changes: 3 additions & 3 deletions src/keyer.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ int handle_common_key(int key) {
speedup();

attron(COLOR_PAIR(C_HEADER) | A_STANDOUT);
mvprintw(0, 14, "%2u", GetCWSpeed());
mvprintw(0, 14, "%2u", speed);
}

break;
Expand Down Expand Up @@ -190,7 +190,7 @@ int handle_common_key(int key) {
speeddown();

attron(COLOR_PAIR(C_HEADER) | A_STANDOUT);
mvprintw(0, 14, "%2u", GetCWSpeed());
mvprintw(0, 14, "%2u", speed);
}
break;
}
Expand All @@ -204,7 +204,7 @@ int handle_common_key(int key) {

nicebox(1, 1, 2, 12, "CW");
attron(COLOR_PAIR(C_LOG) | A_STANDOUT);
mvprintw(2, 2, "Speed: %2u ", GetCWSpeed());
mvprintw(2, 2, "Speed: %2u ", speed);
mvprintw(3, 2, "Weight: %3d ", weight);
move(3, 10);
refreshp();
Expand Down
2 changes: 1 addition & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ static void keyer_init() {

write_tone();

snprintf(keyerbuff, 3, "%2u", GetCWSpeed());
snprintf(keyerbuff, 3, "%2u", speed);
netkeyer(K_SPEED, keyerbuff); // set speed

netkeyer(K_WEIGHT, weightbuf); // set weight
Expand Down
5 changes: 3 additions & 2 deletions src/parse_logcfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include "qtcvars.h" // Includes globalvars.h
#include "setcontest.h"
#include "set_tone.h"
#include "speedupndown.h"
#include "startmsg.h"
#include "tlf_curses.h"
#include "searchlog.h"
Expand Down Expand Up @@ -543,11 +544,11 @@ static int cfg_bandmap(const cfg_arg_t arg) {

static int cfg_cwspeed(const cfg_arg_t arg) {
int value = 0; /* avoid warning about uninitialized variables */
int rc = cfg_integer((cfg_arg_t) {.int_p = &value, .min = 6, .max = 60});
int rc = cfg_integer((cfg_arg_t) {.int_p = &value, .min = CW_SPEED_MIN, .max = CW_SPEED_MAX});
if (rc != PARSE_OK) {
return rc;
}
SetCWSpeed(value);
speed = value;
return PARSE_OK;
}

Expand Down
4 changes: 2 additions & 2 deletions src/qtcwin.c
Original file line number Diff line number Diff line change
Expand Up @@ -1083,14 +1083,14 @@ void qtc_main_panel(int direction) {
case KEY_PPAGE:
speedup();
attron(COLOR_PAIR(C_HEADER) | A_STANDOUT);
mvprintw(0, 14, "%2u", GetCWSpeed());
mvprintw(0, 14, "%2u", speed);
break;

// <Page-Down>
case KEY_NPAGE:
speeddown();
attron(COLOR_PAIR(C_HEADER) | A_STANDOUT);
mvprintw(0, 14, "%2u", GetCWSpeed());
mvprintw(0, 14, "%2u", speed);
break;

// Comma or Ctrl-K (^K), keyboard window
Expand Down
3 changes: 2 additions & 1 deletion src/sendqrg.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,12 @@ int init_tlf_rig(void) {
shownr("Freq =", (int) rigfreq);

if (cwkeyer == HAMLIB_KEYER) {

retcode = hamlib_keyer_get_speed(&rig_cwspeed); /* read cw speed from rig */

if (retcode == RIG_OK) {
shownr("CW speed = ", rig_cwspeed);
SetCWSpeed(rig_cwspeed);
speed = rig_cwspeed;
} else {
TLF_LOG_WARN("Could not read CW speed from rig: %s", rigerror(retcode));
if (!debugflag)
Expand Down
Loading

0 comments on commit 6304d7d

Please sign in to comment.