@@ -147,6 +147,21 @@ void ptt_set_debug(int debug)
147147 ptt_debug_level = debug ;
148148}
149149
150+ /*-------------------------------------------------------------------
151+ *
152+ * Name: export_gpio
153+ *
154+ * Purpose: Tell the GPIO subsystem to export a GPIO line for
155+ * us to use, and set the initial state of the GPIO.
156+ *
157+ * Inputs: gpio - GPIO line to export
158+ * invert: - Is the GPIO active low?
159+ * direction: - 0 for input, 1 for output
160+ *
161+ * Outputs: None.
162+ *
163+ *------------------------------------------------------------------*/
164+
150165void export_gpio (int gpio , int invert , int direction )
151166{
152167 HANDLE fd ;
@@ -843,7 +858,67 @@ void ptt_set (int ot, int chan, int ptt_signal)
843858
844859} /* end ptt_set */
845860
861+ /*-------------------------------------------------------------------
862+ *
863+ * Name: get_input
864+ *
865+ * Purpose: Read the value of an input line
866+ *
867+ * Inputs: it - Input type (ICTYPE_TCINH supported so far)
868+ * chan - Audio channel number
869+ *
870+ * Outputs: 0 = inactive, 1 = active, -1 = error
871+ *
872+ * ------------------------------------------------------------------*/
873+
874+ int get_input (int it , int chan )
875+ {
876+ assert (it >= 0 && it < NUM_ICTYPES );
877+ assert (chan >= 0 && chan < MAX_CHANS );
846878
879+ if ( ! save_audio_config_p -> achan [chan ].valid ) {
880+ text_color_set (DW_COLOR_ERROR );
881+ dw_printf ("Internal error, get_input ( %d, %d ), did not expect invalid channel.\n" , it , chan );
882+ return -1 ;
883+ }
884+
885+ #if __WIN32__
886+ #else
887+ if (save_audio_config_p -> achan [chan ].ictrl [it ].method == PTT_METHOD_GPIO ) {
888+ int fd ;
889+ char stemp [80 ];
890+
891+ snprintf (stemp , sizeof (stemp ), "/sys/class/gpio/gpio%d/value" , save_audio_config_p -> achan [chan ].ictrl [it ].gpio );
892+
893+ fd = open (stemp , O_RDONLY );
894+ if (fd < 0 ) {
895+ int e = errno ;
896+ text_color_set (DW_COLOR_ERROR );
897+ dw_printf ("Error opening %s to check input.\n" , stemp );
898+ dw_printf ("%s\n" , strerror (e ));
899+ return -1 ;
900+ }
901+
902+ char vtemp [2 ];
903+ if (read (fd , vtemp , 1 ) != 1 ) {
904+ int e = errno ;
905+ text_color_set (DW_COLOR_ERROR );
906+ dw_printf ("Error getting GPIO %d value\n" , save_audio_config_p -> achan [chan ].ictrl [it ].gpio );
907+ dw_printf ("%s\n" , strerror (e ));
908+ }
909+ close (fd );
910+
911+ if (atoi (vtemp ) != save_audio_config_p -> achan [chan ].ictrl [it ].invert ) {
912+ return 1 ;
913+ }
914+ else {
915+ return 0 ;
916+ }
917+ }
918+ #endif
919+
920+ return -1 ; /* Method was none, or something went wrong */
921+ }
847922
848923/*-------------------------------------------------------------------
849924 *
0 commit comments