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
65 changes: 54 additions & 11 deletions src/autocq.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#include "clear_display.h"
#include "cw_utils.h"
#include "globalvars.h"
#include "keyer.h"
#include "keystroke_names.h"
#include "printcall.h"
#include "sendbuf.h"
#include "stoptx.h"
Expand All @@ -47,19 +49,50 @@ static int get_autocq_time() {
if (trxmode != CWMODE) {
return 0; // unknown
}
const int cw_message_len = cw_message_length(message[11]);
const int cw_message_len = cw_message_length(message[AUTO_CQ_MSG]);
return (int)(1200.0 / speed) * cw_message_len;
}

#define NO_KEY -1
#define NO_KEY (-1)

// non-keypress events:
#define EVENT_CALLSIGN_GRAB (NO_KEY - 1)

static int handle_immediate_key(int key) {
int cury, curx;
switch (key) {
// keyer speed change
case KEY_PPAGE: // <Page-Up>
case KEY_NPAGE: // <Page-Down>

// auto CQ delay change
case TERM_KEY_CTRL_PGUP:
case TERM_KEY_ALT_PGUP:
case TERM_KEY_CTRL_PGDN:
case TERM_KEY_ALT_PGDN:

getyx(stdscr, cury, curx); // save cursor
key = handle_common_key(key);
if (key == 0) { // key has been processed
move(cury, curx); // restore cursor
key = NO_KEY; // pretend there was no key press at all
}

break;

default:
// no action
}
return key;
}

static int wait_50ms_for_key() {

usleep(50 * 1000);

const int inchar = key_poll();
if (inchar > 0 && inchar != KEY_RESIZE) {
return inchar;
return handle_immediate_key(inchar);
}

return NO_KEY;
Expand Down Expand Up @@ -105,6 +138,11 @@ static int wait_ms(int ms) {

key = wait_50ms_for_key();

// check if callsign grab happened
if (key == NO_KEY && current_qso.call[0] != 0) {
key = EVENT_CALLSIGN_GRAB;
}

wait_timer -= 50;
update_timer -= 50;

Expand All @@ -124,34 +162,35 @@ int auto_cq(void) {
cqmode = AUTO_CQ;
show_header_line();

const long message_time = get_autocq_time();

int key = NO_KEY;

// any key press terminates auto CQ loop
// any unhandled key press terminates auto CQ loop
while (key == NO_KEY) {

send_standard_message(11);
send_standard_message(AUTO_CQ_MSG);

move(12, 29);

attron(modify_attr(COLOR_PAIR(NORMCOLOR)));

// wait till message ends (calculated for CW, playtime for SSB)
// or any key press
// a key pressed or an event happened
if (trxmode == CWMODE || trxmode == DIGIMODE) {
key = wait_ms(message_time);
key = wait_ms(get_autocq_time());
} else {
key = vk_wait_finish();
}

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

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

key = wait_ms(500);

if (delayval > cqdelay) { // in case it was shortened while waiting
delayval = cqdelay;
}
}

mvaddstr(12, 29, spaces(13));
Expand All @@ -169,6 +208,10 @@ int auto_cq(void) {
mvaddstr(12, 29, spaces(13));
printcall();

if (key < NO_KEY) { // map events to NO_KEY
key = NO_KEY;
}

return toupper(key);
}

Expand Down
34 changes: 0 additions & 34 deletions src/callinput.c
Original file line number Diff line number Diff line change
Expand Up @@ -794,40 +794,6 @@ int callinput(void) {
} /* end switch */


// Ctrl-<Page-Up>, increase cqdelay by 1/2 second.
// Alt-<Page-Up>, same for terminals that consume Ctrl-<Page-Up>.
if ((key_kPRV3 && x == key_kPRV3)
|| (key_kPRV5 && x == key_kPRV5)) {

if (cqdelay <= 60) {
cqdelay++;

attron(COLOR_PAIR(C_HEADER) | A_STANDOUT);
mvaddstr(0, 19, " ");
mvprintw(0, 19, "%i", cqdelay);
}

break;
}


// Ctrl-<Page-Down>, decrease cqdelay by 1/2 Second.
// Alt-<Page-Down>, same for terminals that consume Ctrl-<Page-Down>.
if ((key_kNXT3 && x == key_kNXT3)
|| (key_kNXT5 && x == key_kNXT5)) {

if (cqdelay >= 4) {
cqdelay--;

attron(COLOR_PAIR(C_HEADER) | A_STANDOUT);
mvaddstr(0, 19, " ");
mvprintw(0, 19, "%i", cqdelay);
}

break;
}


/* Add character to call input field. */
if (valid_call_char(x)) {
x = g_ascii_toupper(x);
Expand Down
28 changes: 28 additions & 0 deletions src/keyer.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,34 @@ int handle_common_key(int key) {
break;
}

// Ctrl-<Page-Up>, increase cqdelay by 1/2 second.
// Alt-<Page-Up>, same for terminals that consume Ctrl-<Page-Up>.
case TERM_KEY_CTRL_PGUP:
case TERM_KEY_ALT_PGUP: {
if (cqdelay <= 60) {
cqdelay++;

attron(COLOR_PAIR(C_HEADER) | A_STANDOUT);
mvprintw(0, 19, "%-2i", cqdelay);
}

break;
}

// Ctrl-<Page-Down>, decrease cqdelay by 1/2 cecond.
// Alt-<Page-Down>, same for terminals that consume Ctrl-<Page-Down>.
case TERM_KEY_CTRL_PGDN:
case TERM_KEY_ALT_PGDN: {
if (cqdelay >= 4) {
cqdelay--;

attron(COLOR_PAIR(C_HEADER) | A_STANDOUT);
mvprintw(0, 19, "%-2i", cqdelay);
}

break;
}

default:
handled = false;
}
Expand Down
7 changes: 7 additions & 0 deletions src/keystroke_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,10 @@
#define RETURN CTRL_M

#define SHIFT_F(n) (KEY_F(n) + 12)

/* Terminal-specific keystrokes, see lookup_keys() */
#define TERM_KEY_ALT_PGUP 10000
#define TERM_KEY_ALT_PGDN 10001
#define TERM_KEY_CTRL_PGUP 10002
#define TERM_KEY_CTRL_PGDN 10003

1 change: 1 addition & 0 deletions src/tlf.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ enum {

/* special message numbers */
enum {
AUTO_CQ_MSG = 11,
SP_TU_MSG = 12,
CQ_TU_MSG = 13,
SP_CALL_MSG = 24
Expand Down
38 changes: 31 additions & 7 deletions src/ui_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,12 @@
#include "showmsg.h"
#include "splitscreen.h"


extern int ymax, xmax;

int key_kNXT3 = 0;
int key_kPRV3 = 0;
int key_kNXT5 = 0;
int key_kPRV5 = 0;
static int key_kNXT3 = 0;
static int key_kPRV3 = 0;
static int key_kNXT5 = 0;
static int key_kPRV5 = 0;

static pthread_mutex_t panel_mutex = PTHREAD_MUTEX_INITIALIZER;

Expand Down Expand Up @@ -77,7 +76,7 @@ int modify_attr(int attr) {
* \param capability - capability name
* \return keycode or 0 if no associated key found
*/
int lookup_key(char *capability) {
static int lookup_key(char *capability) {
char *esc_sequence = NULL;
int keycode = 0;

Expand Down Expand Up @@ -169,6 +168,29 @@ static int getkey(bool wait) {
return x;
}

/* Map terminal-specific keys to our internal code
* as Ncurses does not provide predefined values for them
*/
static int map_terminal_key(int key) {
// Alt-<Page-Down>
if (key_kNXT3 && key == key_kNXT3) {
return TERM_KEY_ALT_PGDN;
}
// Alt-<Page-Up>
if (key_kPRV3 && key == key_kPRV3) {
return TERM_KEY_ALT_PGUP;
}
// Ctrl-<Page-Down>
if (key_kNXT5 && key == key_kNXT5) {
return TERM_KEY_CTRL_PGDN;
}
// Ctrl-<Page-Up>
if (key_kPRV5 && key == key_kPRV5) {
return TERM_KEY_CTRL_PGUP;
}

return key;
}

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

return x = ESCAPE;
return ESCAPE;

} else if (x != 91) {

Expand Down Expand Up @@ -339,6 +361,8 @@ static int onechar(void) {
nodelay(stdscr, FALSE);
}

x = map_terminal_key(x);

return x;
}

Expand Down
6 changes: 0 additions & 6 deletions src/ui_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,8 @@
#ifndef UI_UTILS_H
#define UI_UTILS_H

extern int key_kNXT3;
extern int key_kPRV3;
extern int key_kNXT5;
extern int key_kPRV5;

void refreshp();
int modify_attr(int attr);
int lookup_key(char *capability);
void lookup_keys();

/** convenience macro to name alt-keys */
Expand Down