]> git.rkrishnan.org Git - pihpsdr.git/commitdiff
Fixed CAT "MD" command, fixed LOCALCW option in gpio.c
authorc vw <dl1ycf@darc.de>
Tue, 10 Jul 2018 07:35:00 +0000 (09:35 +0200)
committerc vw <dl1ycf@darc.de>
Tue, 10 Jul 2018 07:35:00 +0000 (09:35 +0200)
ext.c
ext.h
gpio.c
portaudio.c
rigctl.c

diff --git a/ext.c b/ext.c
index c5ba6191fa33a0ee96783489fcbf9661960c305e..a7cbb55bd6147f0f776bb9e227dceec1cc0bb573 100644 (file)
--- a/ext.c
+++ b/ext.c
 
 // 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 22a001c53009ba55e6400842a9bc110cf27f5e24..1b850db404191362157e0cfab432eaefeb578ac9 100644 (file)
--- 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 b11ad53542369b3c09dbdd7569a6ea07285d5a6d..8f0db753aa2b27c623571e3f1b1a75a1813803e8 100644 (file)
--- 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;
index dfb1dc0224d15f6c90030c4743663502a327d1d4..55786c38f513bf9cc3335d65096761894a209ff5 100644 (file)
@@ -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<framesPerBuffer; i++) {
       isample=(short) (in[i]*32768.0);
-      *p++   = (isample & 0xFF);      // LittleEndian
-      *p++ = (isample >> 8)& 0xFF;
+      *p++   = (isample & 0xFF);         // LittleEndian
+      *p++   = (isample >> 8)& 0xFF;
     }
+#ifdef DummyTwoTone
   } else {
     for (i=0; i<framesPerBuffer; i++) {
-      isample=(short) (sintab[tonept++]*32768.0);
+      isample=(short) (sintab[tonept++]*32767.0);
       if (tonept == lentab) tonept=0;
       *p++   = (isample & 0xFF);      // LittleEndian
       *p++ = (isample >> 8)& 0xFF;
     }
+#endif
   }
 //
 // Call routine to send mic buffer
index ec44ba43eb3d687a1b1608afac2414ad7f00fe1a..599b686f1dc1df61b2a723bf42f41e06dad9440d 100644 (file)
--- 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) {