From 5742eff883b4368a78d5335de831fe368a59c58b Mon Sep 17 00:00:00 2001 From: c vw Date: Tue, 10 Jul 2018 09:35:00 +0200 Subject: [PATCH] Fixed CAT "MD" command, fixed LOCALCW option in gpio.c --- ext.c | 8 ++++++++ ext.h | 1 + gpio.c | 20 ++++++++------------ portaudio.c | 36 ++++++++++++++++++++++++++++-------- rigctl.c | 9 +++++++++ 5 files changed, 54 insertions(+), 20 deletions(-) diff --git a/ext.c b/ext.c index c5ba619..a7cbb55 100644 --- a/ext.c +++ b/ext.c @@ -36,6 +36,14 @@ // The following calls functions can be called usig g_idle_add +// DL1YCF: added interface for mode change, to be used by rigctl +// (MD command) +int ext_vfo_mode_changed(void * data) +{ + vfo_mode_changed((int) (long) data); + return 0; +} + int ext_discovery(void *data) { discovery(); return 0; diff --git a/ext.h b/ext.h index 22a001c..1b850db 100644 --- a/ext.h +++ b/ext.h @@ -53,3 +53,4 @@ extern int ext_tx_set_ps(void *data); extern int ext_ps_twotone(void *data); #endif int ext_vfo_step(void *data); +int ext_vfo_mode_changed(void *data); diff --git a/gpio.c b/gpio.c index b11ad53..8f0db75 100644 --- a/gpio.c +++ b/gpio.c @@ -969,7 +969,6 @@ fprintf(stderr,"setup_encoder_pin: pin=%d updown=%d\n",pin,up_down); } #ifdef LOCALCW -#ifdef RADIOBERRY #define BUTTON_STEADY_TIME_US 5000 static void setup_button(int button, gpioAlertFunc_t pAlert) { gpioSetMode(button, PI_INPUT); @@ -981,14 +980,13 @@ static void setup_button(int button, gpioAlertFunc_t pAlert) { } static void cwAlert(int gpio, int level, uint32_t tick) { - //fprintf(stderr,"cw key at pin %d \n", gpio); + //fprintf(stderr,"cw key at pin %d \n", gpio); if (cw_keyer_internal == 0 ){ - //fprintf(stderr,"call keyer_event...\n"); + //fprintf(stderr,"call keyer_event...\n"); keyer_event(gpio, cw_active_level == 0 ? level : (level==0)); - } + } } #endif -#endif int gpio_init() { int i; @@ -1115,13 +1113,11 @@ int gpio_init() { #endif #ifdef LOCALCW - fprintf(stderr,"GPIO: ENABLE_CW_BUTTONS=%d CWL_BUTTON=%d CWR_BUTTON=%d\n",ENABLE_CW_BUTTONS, CWL_BUTTON, CWR_BUTTON); - if(ENABLE_CW_BUTTONS) { - #ifdef RADIOBERRY - setup_button(CWL_BUTTON, cwAlert); - setup_button(CWR_BUTTON, cwAlert); - #endif - } + fprintf(stderr,"GPIO: ENABLE_CW_BUTTONS=%d CWL_BUTTON=%d CWR_BUTTON=%d\n", ENABLE_CW_BUTTONS, CWL_BUTTON, CWR_BUTTON); + if(ENABLE_CW_BUTTONS) { + setup_button(CWL_BUTTON, cwAlert); + setup_button(CWR_BUTTON, cwAlert); + } #endif return 0; diff --git a/portaudio.c b/portaudio.c index dfb1dc0..55786c3 100644 --- a/portaudio.c +++ b/portaudio.c @@ -45,6 +45,12 @@ static unsigned char *mic_buffer=NULL; static int mic_buffer_size; static int audio_buffer_size=256; +// +// compile with DummyTwoTone defined, and you will have an +// additional "microphone" device producing a two-tone signal +// with 700 and 1900 Hz. +// +#ifdef DummyTwoTone // // Dummy Two-tone input device // @@ -52,8 +58,8 @@ static int TwoTone=0; #define lentab 480 static float sintab[lentab]; static int tonept; -#define twopi 6.2831853071795864769252867665590 -#define factab (twopi/480) +#define factab 0.013089969389957471826927680763665 // 2 Pi / 480 +#endif // @@ -69,8 +75,10 @@ void audio_get_cards() PaError err; - // generate sine tab - for (i=0; i< lentab; i++) sintab[i] = 0.35*(sin(7*i*factab)+sin(19*i*factab)); +#ifdef DummyTwoTone + // generate sine tab, 700 and 1900 Hz. + for (i=0; i< lentab; i++) sintab[i] = 0.45*(sin(7*i*factab)+sin(19*i*factab)); +#endif err = Pa_Initialize(); if( err != paNoError ) @@ -94,12 +102,14 @@ void audio_get_cards() inputParameters.suggestedLatency = 0; /* ignored by Pa_IsFormatSupported() */ inputParameters.hostApiSpecificStreamInfo = NULL; if (Pa_IsFormatSupported(&inputParameters, NULL, 48000.0) == paFormatIsSupported) { +#ifdef DummyTwoTone // duplicate the first suitable device, this will become // a dummy two-tone generator if (n_input_devices == 0) { input_devices[n_input_devices]="TwoTone"; in_device_no[n_input_devices++] =i; } +#endif if (n_input_devices < MAXDEVICES) { input_devices[n_input_devices]=deviceInfo->name; in_device_no[n_input_devices++] =i; @@ -182,11 +192,13 @@ int audio_open_input() } mic_buffer=(unsigned char *)malloc(2*framesPerBuffer); mic_buffer_size=framesPerBuffer; +#ifdef DummyTwoTone TwoTone=0; if (transmitter->input_device == 0) { tonept=0; TwoTone=1; } +#endif return 0; } @@ -205,7 +217,9 @@ int pa_mic_cb(const void *inputBuffer, void *outputBuffer, unsigned long framesP // // Convert input buffer in paFloat32 into a sequence of 16-bit -// values in the mic buffer +// values in the mic buffer. If using the dummy Two-Tone +// device, mic input will be discarded and a two-tone +// signal produced instead. // if (mic_buffer == NULL) return paAbort; @@ -215,19 +229,25 @@ int pa_mic_cb(const void *inputBuffer, void *outputBuffer, unsigned long framesP *p++ = 0; *p++ = 0; } +#ifdef DummyTwoTone } else if (TwoTone == 0) { +#else + } else { +#endif for (i=0; i> 8)& 0xFF; + *p++ = (isample & 0xFF); // LittleEndian + *p++ = (isample >> 8)& 0xFF; } +#ifdef DummyTwoTone } else { for (i=0; i> 8)& 0xFF; } +#endif } // // Call routine to send mic buffer diff --git a/rigctl.c b/rigctl.c index ec44ba4..599b686 100644 --- a/rigctl.c +++ b/rigctl.c @@ -2269,6 +2269,7 @@ void parse_cmd ( char * cmd_input,int len,int client_sock) { fprintf(stderr,"MD command Unknown\n"); #endif } +#if 0 // Other stuff to switch modes goes here.. // since new_mode has the interpreted command in // in it now. @@ -2291,6 +2292,14 @@ void parse_cmd ( char * cmd_input,int len,int client_sock) { set_filter(active_receiver,band_filter->low,band_filter->high); /* Need a way to update VFO info here..*/ g_idle_add(ext_vfo_update,NULL); +#endif + // DL1YCF: I do not understand why the above code is so complicated. + // It is also problematic that the mode of the transmitter + // is not updated. I think one should simply behave as if + // a mode change had been selected from the menu. To this + // end, I added an interface for vfo_mode_changed in ext.c, + // to be able to call it using g_idle_add. + g_idle_add(ext_vfo_mode_changed, (void *) (long) new_mode); } else { // Read Mode int curr_mode; switch (vfo[active_receiver->id].mode) { -- 2.45.2