Skip to content

Commit 44a1f47

Browse files
authored
Improve auto CQ (#489)
* stop auto CQ on callsign grab (relevant for digimode) * handle Ctrl/Alt-PgUp/Dn and PgUp/Dn keys internally without stopping auto CQ
1 parent c3ff1a2 commit 44a1f47

File tree

7 files changed

+121
-58
lines changed

7 files changed

+121
-58
lines changed

src/autocq.c

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#include "clear_display.h"
3131
#include "cw_utils.h"
3232
#include "globalvars.h"
33+
#include "keyer.h"
34+
#include "keystroke_names.h"
3335
#include "printcall.h"
3436
#include "sendbuf.h"
3537
#include "stoptx.h"
@@ -47,19 +49,50 @@ static int get_autocq_time() {
4749
if (trxmode != CWMODE) {
4850
return 0; // unknown
4951
}
50-
const int cw_message_len = cw_message_length(message[11]);
52+
const int cw_message_len = cw_message_length(message[AUTO_CQ_MSG]);
5153
return (int)(1200.0 / speed) * cw_message_len;
5254
}
5355

54-
#define NO_KEY -1
56+
#define NO_KEY (-1)
57+
58+
// non-keypress events:
59+
#define EVENT_CALLSIGN_GRAB (NO_KEY - 1)
60+
61+
static int handle_immediate_key(int key) {
62+
int cury, curx;
63+
switch (key) {
64+
// keyer speed change
65+
case KEY_PPAGE: // <Page-Up>
66+
case KEY_NPAGE: // <Page-Down>
67+
68+
// auto CQ delay change
69+
case TERM_KEY_CTRL_PGUP:
70+
case TERM_KEY_ALT_PGUP:
71+
case TERM_KEY_CTRL_PGDN:
72+
case TERM_KEY_ALT_PGDN:
73+
74+
getyx(stdscr, cury, curx); // save cursor
75+
key = handle_common_key(key);
76+
if (key == 0) { // key has been processed
77+
move(cury, curx); // restore cursor
78+
key = NO_KEY; // pretend there was no key press at all
79+
}
80+
81+
break;
82+
83+
default:
84+
// no action
85+
}
86+
return key;
87+
}
5588

5689
static int wait_50ms_for_key() {
5790

5891
usleep(50 * 1000);
5992

6093
const int inchar = key_poll();
6194
if (inchar > 0 && inchar != KEY_RESIZE) {
62-
return inchar;
95+
return handle_immediate_key(inchar);
6396
}
6497

6598
return NO_KEY;
@@ -105,6 +138,11 @@ static int wait_ms(int ms) {
105138

106139
key = wait_50ms_for_key();
107140

141+
// check if callsign grab happened
142+
if (key == NO_KEY && current_qso.call[0] != 0) {
143+
key = EVENT_CALLSIGN_GRAB;
144+
}
145+
108146
wait_timer -= 50;
109147
update_timer -= 50;
110148

@@ -124,34 +162,35 @@ int auto_cq(void) {
124162
cqmode = AUTO_CQ;
125163
show_header_line();
126164

127-
const long message_time = get_autocq_time();
128-
129165
int key = NO_KEY;
130166

131-
// any key press terminates auto CQ loop
167+
// any unhandled key press terminates auto CQ loop
132168
while (key == NO_KEY) {
133169

134-
send_standard_message(11);
170+
send_standard_message(AUTO_CQ_MSG);
135171

136172
move(12, 29);
137173

138-
attron(modify_attr(COLOR_PAIR(NORMCOLOR)));
139-
140174
// wait till message ends (calculated for CW, playtime for SSB)
141-
// or any key press
175+
// a key pressed or an event happened
142176
if (trxmode == CWMODE || trxmode == DIGIMODE) {
143-
key = wait_ms(message_time);
177+
key = wait_ms(get_autocq_time());
144178
} else {
145179
key = vk_wait_finish();
146180
}
147181

148182
// wait between calls
149183
for (int delayval = cqdelay; delayval > 0 && key == NO_KEY; delayval--) {
150184

185+
attron(modify_attr(COLOR_PAIR(NORMCOLOR)));
151186
mvprintw(12, 29, "Auto CQ %-2d ", delayval);
152187
refreshp();
153188

154189
key = wait_ms(500);
190+
191+
if (delayval > cqdelay) { // in case it was shortened while waiting
192+
delayval = cqdelay;
193+
}
155194
}
156195

157196
mvaddstr(12, 29, spaces(13));
@@ -169,6 +208,10 @@ int auto_cq(void) {
169208
mvaddstr(12, 29, spaces(13));
170209
printcall();
171210

211+
if (key < NO_KEY) { // map events to NO_KEY
212+
key = NO_KEY;
213+
}
214+
172215
return toupper(key);
173216
}
174217

src/callinput.c

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -794,40 +794,6 @@ int callinput(void) {
794794
} /* end switch */
795795

796796

797-
// Ctrl-<Page-Up>, increase cqdelay by 1/2 second.
798-
// Alt-<Page-Up>, same for terminals that consume Ctrl-<Page-Up>.
799-
if ((key_kPRV3 && x == key_kPRV3)
800-
|| (key_kPRV5 && x == key_kPRV5)) {
801-
802-
if (cqdelay <= 60) {
803-
cqdelay++;
804-
805-
attron(COLOR_PAIR(C_HEADER) | A_STANDOUT);
806-
mvaddstr(0, 19, " ");
807-
mvprintw(0, 19, "%i", cqdelay);
808-
}
809-
810-
break;
811-
}
812-
813-
814-
// Ctrl-<Page-Down>, decrease cqdelay by 1/2 Second.
815-
// Alt-<Page-Down>, same for terminals that consume Ctrl-<Page-Down>.
816-
if ((key_kNXT3 && x == key_kNXT3)
817-
|| (key_kNXT5 && x == key_kNXT5)) {
818-
819-
if (cqdelay >= 4) {
820-
cqdelay--;
821-
822-
attron(COLOR_PAIR(C_HEADER) | A_STANDOUT);
823-
mvaddstr(0, 19, " ");
824-
mvprintw(0, 19, "%i", cqdelay);
825-
}
826-
827-
break;
828-
}
829-
830-
831797
/* Add character to call input field. */
832798
if (valid_call_char(x)) {
833799
x = g_ascii_toupper(x);

src/keyer.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,34 @@ int handle_common_key(int key) {
244244
break;
245245
}
246246

247+
// Ctrl-<Page-Up>, increase cqdelay by 1/2 second.
248+
// Alt-<Page-Up>, same for terminals that consume Ctrl-<Page-Up>.
249+
case TERM_KEY_CTRL_PGUP:
250+
case TERM_KEY_ALT_PGUP: {
251+
if (cqdelay <= 60) {
252+
cqdelay++;
253+
254+
attron(COLOR_PAIR(C_HEADER) | A_STANDOUT);
255+
mvprintw(0, 19, "%-2i", cqdelay);
256+
}
257+
258+
break;
259+
}
260+
261+
// Ctrl-<Page-Down>, decrease cqdelay by 1/2 cecond.
262+
// Alt-<Page-Down>, same for terminals that consume Ctrl-<Page-Down>.
263+
case TERM_KEY_CTRL_PGDN:
264+
case TERM_KEY_ALT_PGDN: {
265+
if (cqdelay >= 4) {
266+
cqdelay--;
267+
268+
attron(COLOR_PAIR(C_HEADER) | A_STANDOUT);
269+
mvprintw(0, 19, "%-2i", cqdelay);
270+
}
271+
272+
break;
273+
}
274+
247275
default:
248276
handled = false;
249277
}

src/keystroke_names.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,10 @@
7878
#define RETURN CTRL_M
7979

8080
#define SHIFT_F(n) (KEY_F(n) + 12)
81+
82+
/* Terminal-specific keystrokes, see lookup_keys() */
83+
#define TERM_KEY_ALT_PGUP 10000
84+
#define TERM_KEY_ALT_PGDN 10001
85+
#define TERM_KEY_CTRL_PGUP 10002
86+
#define TERM_KEY_CTRL_PGDN 10003
87+

src/tlf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ enum {
146146

147147
/* special message numbers */
148148
enum {
149+
AUTO_CQ_MSG = 11,
149150
SP_TU_MSG = 12,
150151
CQ_TU_MSG = 13,
151152
SP_CALL_MSG = 24

src/ui_utils.c

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,12 @@
3333
#include "showmsg.h"
3434
#include "splitscreen.h"
3535

36-
3736
extern int ymax, xmax;
3837

39-
int key_kNXT3 = 0;
40-
int key_kPRV3 = 0;
41-
int key_kNXT5 = 0;
42-
int key_kPRV5 = 0;
38+
static int key_kNXT3 = 0;
39+
static int key_kPRV3 = 0;
40+
static int key_kNXT5 = 0;
41+
static int key_kPRV5 = 0;
4342

4443
static pthread_mutex_t panel_mutex = PTHREAD_MUTEX_INITIALIZER;
4544

@@ -77,7 +76,7 @@ int modify_attr(int attr) {
7776
* \param capability - capability name
7877
* \return keycode or 0 if no associated key found
7978
*/
80-
int lookup_key(char *capability) {
79+
static int lookup_key(char *capability) {
8180
char *esc_sequence = NULL;
8281
int keycode = 0;
8382

@@ -169,6 +168,29 @@ static int getkey(bool wait) {
169168
return x;
170169
}
171170

171+
/* Map terminal-specific keys to our internal code
172+
* as Ncurses does not provide predefined values for them
173+
*/
174+
static int map_terminal_key(int key) {
175+
// Alt-<Page-Down>
176+
if (key_kNXT3 && key == key_kNXT3) {
177+
return TERM_KEY_ALT_PGDN;
178+
}
179+
// Alt-<Page-Up>
180+
if (key_kPRV3 && key == key_kPRV3) {
181+
return TERM_KEY_ALT_PGUP;
182+
}
183+
// Ctrl-<Page-Down>
184+
if (key_kNXT5 && key == key_kNXT5) {
185+
return TERM_KEY_CTRL_PGDN;
186+
}
187+
// Ctrl-<Page-Up>
188+
if (key_kPRV5 && key == key_kPRV5) {
189+
return TERM_KEY_CTRL_PGUP;
190+
}
191+
192+
return key;
193+
}
172194

173195
/* New onechar() that takes advantage of Ncurses keypad mode and processes
174196
* certain escaped keys and assigns them to Ncurses values known by
@@ -194,7 +216,7 @@ static int onechar(void) {
194216
if (x == ERR) {
195217
stoptx();
196218

197-
return x = ESCAPE;
219+
return ESCAPE;
198220

199221
} else if (x != 91) {
200222

@@ -339,6 +361,8 @@ static int onechar(void) {
339361
nodelay(stdscr, FALSE);
340362
}
341363

364+
x = map_terminal_key(x);
365+
342366
return x;
343367
}
344368

src/ui_utils.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,8 @@
2121
#ifndef UI_UTILS_H
2222
#define UI_UTILS_H
2323

24-
extern int key_kNXT3;
25-
extern int key_kPRV3;
26-
extern int key_kNXT5;
27-
extern int key_kPRV5;
28-
2924
void refreshp();
3025
int modify_attr(int attr);
31-
int lookup_key(char *capability);
3226
void lookup_keys();
3327

3428
/** convenience macro to name alt-keys */

0 commit comments

Comments
 (0)