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
5689static 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
0 commit comments