Skip to content

Commit 61583d7

Browse files
committed
Fix problems when HAMLIB_KEYER is set, but rig control is disabled
When HAMLIB_KEYER is set, but rig control and keying is disabled via `tlf -r`, hitting ESC will trip the assert(init_called) in rig_has_stop_morse. Since init_tlf_rig is called early in main(), it seems unlikely that this assert would ever find an actual bug, so just remove it (along with the init_called variable). Similarly, the hamlib_keyer_* functions were missing protection against being called in that mode. In passing, decrease the timeout after showing the "keying disabled" message to 1s.
1 parent e3b7cb8 commit 61583d7

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

src/hamlib_keyer.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,14 @@
2525
#include "hamlib_keyer.h"
2626

2727
int hamlib_keyer_set_speed(int *cwspeed) {
28-
gran_t keyspd_gran = my_rig->caps->level_gran[rig_setting2idx(
29-
RIG_LEVEL_KEYSPD)];
28+
gran_t keyspd_gran;
3029
value_t spd;
3130

31+
if (! trx_control)
32+
return RIG_OK;
33+
34+
keyspd_gran = my_rig->caps->level_gran[rig_setting2idx(RIG_LEVEL_KEYSPD)];
35+
3236
/* if rig declared min/max speed, honor it. */
3337
if (keyspd_gran.min.i > 0 && *cwspeed < keyspd_gran.min.i)
3438
*cwspeed = keyspd_gran.min.i;
@@ -46,6 +50,9 @@ int hamlib_keyer_set_speed(int *cwspeed) {
4650
int hamlib_keyer_get_speed(int *cwspeed) {
4751
value_t value;
4852

53+
if (! trx_control)
54+
return RIG_OK;
55+
4956
assert(cwspeed != NULL);
5057

5158
pthread_mutex_lock(&tlf_rig_mutex);
@@ -58,6 +65,9 @@ int hamlib_keyer_get_speed(int *cwspeed) {
5865
}
5966

6067
int hamlib_keyer_send(char *cwmessage) {
68+
if (! trx_control)
69+
return RIG_OK;
70+
6171
pthread_mutex_lock(&tlf_rig_mutex);
6272
int ret = rig_send_morse(my_rig, RIG_VFO_CURR, cwmessage);
6373
pthread_mutex_unlock(&tlf_rig_mutex);
@@ -66,6 +76,9 @@ int hamlib_keyer_send(char *cwmessage) {
6676
}
6777

6878
int hamlib_keyer_stop() {
79+
if (! trx_control)
80+
return RIG_OK;
81+
6982
#if HAMLIB_VERSION >= 400
7083
if (rig_has_stop_morse()) {
7184
pthread_mutex_lock(&tlf_rig_mutex);

src/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ static void keyer_init() {
951951
showmsg("CW-Keyer is Hamlib");
952952
if (trx_control_disabled) {
953953
showmsg("Radio control disabled - no keying!");
954-
sleep(2);
954+
sleep(1);
955955
return;
956956
}
957957
if (!trx_control) {

src/sendqrg.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,14 @@
3636
#include "globalvars.h"
3737
#include "qrb.h"
3838

39-
static bool init_called = false;
4039
static bool can_send_morse = false;
4140
static bool can_stop_morse = false;
4241

4342
bool rig_has_send_morse() {
44-
assert(init_called);
4543
return can_send_morse;
4644
}
4745

4846
bool rig_has_stop_morse() {
49-
assert(init_called);
5047
return can_stop_morse;
5148
}
5249

@@ -207,8 +204,6 @@ int init_tlf_rig(void) {
207204
break;
208205
}
209206

210-
init_called = true;
211-
212207
return 0;
213208
}
214209

0 commit comments

Comments
 (0)