From: c vw <dl1ycf@darc.de>
Date: Wed, 5 Feb 2020 14:31:58 +0000 (+0100)
Subject: added DIVERSITY functions (toggle, change gain/phase) to MIDI functions
X-Git-Url: https://git.rkrishnan.org/pf/components/vdrive/frontends/%22file://%22%22.?a=commitdiff_plain;h=c19e1a09dd3017b7def9067a9902687282ac2844;p=pihpsdr.git

added DIVERSITY functions (toggle, change gain/phase) to MIDI functions
---

diff --git a/diversity_menu.c b/diversity_menu.c
index 6df0296..1b66296 100644
--- a/diversity_menu.c
+++ b/diversity_menu.c
@@ -128,7 +128,7 @@ static void phase_fine_changed_cb(GtkWidget *widget, gpointer data) {
 }
 
 void update_diversity_gain(double increment) {
-  double g=div_gain+(increment/10);
+  double g=div_gain+(0.1*increment);
   if(g<-27.0) g=-27.0;
   if(g>27.0) g=27.0;
   div_gain=g;
diff --git a/ext.c b/ext.c
index 9543b78..34981e0 100644
--- a/ext.c
+++ b/ext.c
@@ -574,6 +574,20 @@ int ext_diversity_update(void *data) {
   return 0;
 }
 
+int ext_diversity_change_gain(void *data) {
+  double *dp = (double *) data;
+  update_diversity_gain(*dp);
+  free(dp);
+  return 0;
+}
+
+int ext_diversity_change_phase(void *data) {
+  double *dp = (double *) data;
+  update_diversity_phase(*dp);
+  free(dp);
+  return 0;
+}
+
 #ifdef PURESIGNAL
 int ext_start_ps(void *data) {
   start_ps();
diff --git a/ext.h b/ext.h
index 6442dc5..810be49 100644
--- a/ext.h
+++ b/ext.h
@@ -104,6 +104,8 @@ int ext_set_compression(void *data);
 int ext_start_rx(void *data);
 int ext_start_tx(void *data);
 int ext_diversity_update(void *data);
+int ext_diversity_change_gain(void *data);
+int ext_diversity_change_phase(void *data);
 int ext_sat_update(void *data);
 int ext_set_rf_gain(void *data);
 int ext_set_duplex(void *data);
diff --git a/midi.h b/midi.h
index 999bc0f..3090b23 100644
--- a/midi.h
+++ b/midi.h
@@ -62,6 +62,9 @@ enum MIDIaction {
   CWL,			// CWL:			Left paddle pressed (use with ONOFF)
   CWR,			// CWR:			Right paddle pressed (use with ONOFF)
   CWSPEED,		// CWSPEED:		Set speed of (iambic) CW keyer
+  DIV_GAIN,		// DIVGAIN:		change DIVERSITY gain
+  DIV_PHASE,		// DIVPHASE:		change DIVERSITY phase
+  DIV_TOGGLE,		// DIVTOGGLE:		DIVERSITY on/off
   MIDI_DUP,		// DUP:			toggle duplex on/off
   FILTER_DOWN,		// FILTERDOWN:		cycle through filters downwards
   FILTER_UP,		// FILTERUP:		cycle through filters upwards
diff --git a/midi2.c b/midi2.c
index 29788e2..6385e5d 100644
--- a/midi2.c
+++ b/midi2.c
@@ -115,6 +115,9 @@ static struct {
 	{ CWL,			"CWL"},
 	{ CWR,			"CWR"},
 	{ CWSPEED,		"CWSPEED"},
+	{ DIV_GAIN,		"DIVGAIN"},
+	{ DIV_PHASE,		"DIVPHASE"},
+	{ DIV_TOGGLE,		"DIVTOGGLE"},
 	{ MIDI_DUP,  		"DUP"},
         { FILTER_DOWN,  	"FILTERDOWN"},
         { FILTER_UP,    	"FILTERUP"},
diff --git a/midi3.c b/midi3.c
index 56a1333..d35b7c9 100644
--- a/midi3.c
+++ b/midi3.c
@@ -232,6 +232,54 @@ void DoTheMidi(enum MIDIaction action, enum MIDItype type, int val) {
 #endif
             g_idle_add(ext_vfo_update, NULL);
 	    break;
+	/////////////////////////////////////////////////////////// "DIVGAIN"
+	case DIV_GAIN:  // knob or wheel supported
+            switch (type) {
+              case MIDI_KNOB:
+		dnew = 10.0*(-25.0 + 0.5*val - div_gain);
+                break;
+              case MIDI_WHEEL:
+                dnew= val;
+                break;
+              default:
+                // do not change
+                // we should not come here anyway
+		dnew = 0.0;
+                break;
+            }
+	    // dnew is the delta times 10
+	    dp=malloc(sizeof(double));
+	    *dp=dnew;
+            g_idle_add(ext_diversity_change_gain, dp);
+            break;
+        /////////////////////////////////////////////////////////// "DIVPHASE"
+        case DIV_PHASE:  // knob or wheel supported
+            switch (type) {
+              case MIDI_KNOB:
+                dnew = (-180.0 + 3.6*val - div_phase);
+                break;
+              case MIDI_WHEEL:
+                dnew= val;
+                break;
+              default:
+                // do not change
+                // we should not come here anyway
+                dnew = 0.0;
+                break;
+            }
+            // dnew is the delta
+            dp=malloc(sizeof(double));
+            *dp=dnew;
+            g_idle_add(ext_diversity_change_phase, dp);
+            break;
+        /////////////////////////////////////////////////////////// "DIVTOGGLE"
+        case DIV_TOGGLE:   // only key supported
+            if (type == MIDI_KEY) {
+                // enable/disable DIVERSITY
+                diversity_enabled = diversity_enabled ? 0 : 1;
+                g_idle_add(ext_vfo_update, NULL);
+            }
+            break;
 	/////////////////////////////////////////////////////////// "DUP"
         case MIDI_DUP:
 	    if (can_transmit && !isTransmitting()) {