From d9ca8cdc521e14b58469f589604aac33ce09b99b Mon Sep 17 00:00:00 2001 From: Alex Swedenburg Date: Tue, 17 Nov 2015 11:19:12 -0700 Subject: [PATCH] Implement TXINH --- atest.c | 4 +++ hdlc_rec.c | 6 ++++- ptt.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ ptt.h | 1 + 4 files changed, 85 insertions(+), 1 deletion(-) diff --git a/atest.c b/atest.c index c869698..aa48de7 100644 --- a/atest.c +++ b/atest.c @@ -679,6 +679,10 @@ void ptt_set (int ot, int chan, int ptt_signal) return; } +int get_input (int it, int chan) +{ + return -1; +} static void usage (void) { diff --git a/hdlc_rec.c b/hdlc_rec.c index 975c26c..98a3f90 100644 --- a/hdlc_rec.c +++ b/hdlc_rec.c @@ -634,9 +634,13 @@ void dcd_change (int chan, int subchan, int state) int hdlc_rec_data_detect_any (int chan) { + int busy = 0; + assert (chan >= 0 && chan < MAX_CHANS); - return (composite_dcd[chan] != 0); + if (composite_dcd[chan] != 0) busy = 1; + + if (get_input(ICTYPE_TXINH, chan) == 1) busy = 1; } /* end hdlc_rec_data_detect_any */ diff --git a/ptt.c b/ptt.c index 78efc6f..414c04b 100644 --- a/ptt.c +++ b/ptt.c @@ -147,6 +147,21 @@ void ptt_set_debug(int debug) ptt_debug_level = debug; } +/*------------------------------------------------------------------- + * + * Name: export_gpio + * + * Purpose: Tell the GPIO subsystem to export a GPIO line for + * us to use, and set the initial state of the GPIO. + * + * Inputs: gpio - GPIO line to export + * invert: - Is the GPIO active low? + * direction: - 0 for input, 1 for output + * + * Outputs: None. + * + *------------------------------------------------------------------*/ + void export_gpio(int gpio, int invert, int direction) { HANDLE fd; @@ -843,7 +858,67 @@ void ptt_set (int ot, int chan, int ptt_signal) } /* end ptt_set */ +/*------------------------------------------------------------------- + * + * Name: get_input + * + * Purpose: Read the value of an input line + * + * Inputs: it - Input type (ICTYPE_TCINH supported so far) + * chan - Audio channel number + * + * Outputs: 0 = inactive, 1 = active, -1 = error + * + * ------------------------------------------------------------------*/ +int get_input (int it, int chan) +{ + assert (it >= 0 && it < NUM_ICTYPES); + assert (chan >= 0 && chan < MAX_CHANS); + + if ( ! save_audio_config_p->achan[chan].valid) { + text_color_set(DW_COLOR_ERROR); + dw_printf ("Internal error, get_input ( %d, %d ), did not expect invalid channel.\n", it, chan); + return -1; + } + +#if __WIN32__ +#else + if (save_audio_config_p->achan[chan].ictrl[it].method == PTT_METHOD_GPIO) { + int fd; + char stemp[80]; + + snprintf (stemp, sizeof(stemp), "/sys/class/gpio/gpio%d/value", save_audio_config_p->achan[chan].ictrl[it].gpio); + + fd = open(stemp, O_RDONLY); + if (fd < 0) { + int e = errno; + text_color_set(DW_COLOR_ERROR); + dw_printf ("Error opening %s to check input.\n", stemp); + dw_printf ("%s\n", strerror(e)); + return -1; + } + + char vtemp[2]; + if (read (fd, vtemp, 1) != 1) { + int e = errno; + text_color_set(DW_COLOR_ERROR); + dw_printf ("Error getting GPIO %d value\n", save_audio_config_p->achan[chan].ictrl[it].gpio); + dw_printf ("%s\n", strerror(e)); + } + close (fd); + + if (atoi(vtemp) != save_audio_config_p->achan[chan].ictrl[it].invert) { + return 1; + } + else { + return 0; + } + } +#endif + + return -1; /* Method was none, or something went wrong */ +} /*------------------------------------------------------------------- * diff --git a/ptt.h b/ptt.h index 7e9f639..6e75253 100644 --- a/ptt.h +++ b/ptt.h @@ -15,6 +15,7 @@ void ptt_set (int octype, int chan, int ptt); void ptt_term (void); +int get_input (int it, int chan); #endif