From: c vw <dl1ycf@darc.de>
Date: Mon, 6 Aug 2018 17:12:23 +0000 (+0200)
Subject: added CW vox
X-Git-Url: https://git.rkrishnan.org/components/specifications/simplejson/htmlfontify-example.html?a=commitdiff_plain;h=75b7b2487bb4dc18ac78063999e83cb0528aaf29;p=pihpsdr.git

added CW vox
---

diff --git a/gpio.c b/gpio.c
index 2e6590b..089f0fa 100644
--- a/gpio.c
+++ b/gpio.c
@@ -974,8 +974,12 @@ fprintf(stderr,"setup_encoder_pin: pin=%d updown=%d\n",pin,up_down);
 
 #ifdef LOCALCW
 
+// Note we cannot use debouncing, as after the first interrupt,
+// we might read the wrong level. So we forward all CW interrupts
+// to the keyer.
+
 static void setup_cw_pin(int pin, void(*pAlert)(void)) {
-fprintf(stderr,"setup_cw_pin: pin=%d \n",pin);
+   fprintf(stderr,"setup_cw_pin: pin=%d \n",pin);
    pinMode(pin,INPUT);
    pullUpDnControl(pin,PUD_UP);
    usleep(10000);
@@ -983,19 +987,19 @@ fprintf(stderr,"setup_cw_pin: pin=%d \n",pin);
 }
 
 static void cwAlert_left() {
-	int level=digitalRead(CWL_BUTTON);
-	//fprintf(stderr,"cwl button : level=%d \n",level);
-   if (cw_keyer_internal == 0 ){
-      keyer_event(CWL_BUTTON, cw_active_level == 0 ? level : (level==0));
-   }
+    int level;
+    if (cw_keyer_internal != 0) return; // as quickly as possible
+    level=digitalRead(CWL_BUTTON);
+    //fprintf(stderr,"cwl button : level=%d \n",level);
+    keyer_event(CWL_BUTTON, cw_active_level == 0 ? level : (level==0));
 }
 
 static void cwAlert_right() {
-	int level=digitalRead(CWR_BUTTON);
-	//fprintf(stderr,"cwr button : level=%d \n",level);
-   if (cw_keyer_internal == 0 ){
-      keyer_event(CWR_BUTTON, cw_active_level == 0 ? level : (level==0));
-   }
+    int level;
+    if (cw_keyer_internal != 0) return; // as quickly as possible
+    level=digitalRead(CWR_BUTTON);
+    //fprintf(stderr,"cwr button : level=%d \n",level);
+     keyer_event(CWR_BUTTON, cw_active_level == 0 ? level : (level==0));
 }
 
 #endif
diff --git a/iambic.c b/iambic.c
index 5cd0307..0f5bf47 100644
--- a/iambic.c
+++ b/iambic.c
@@ -78,6 +78,7 @@
 #include "new_protocol.h"
 #include "iambic.h"
 #include "transmitter.h"
+#include "ext.h"
 
 static void* keyer_thread(void *arg);
 static pthread_t keyer_thread_id;
@@ -122,6 +123,8 @@ static sem_t *cw_event;
 static sem_t cw_event;
 #endif
 
+static int cwvox = 0;
+
 int keyer_out = 0;
 
 // using clock_nanosleep of librt
@@ -158,14 +161,22 @@ void keyer_update() {
 void keyer_event(int gpio, int level) {
     int state = (level == 0);
 
-    // This is for aborting CAT CW messages if the key is hit.
     if (state) {
+        // This is for aborting CAT CW messages if the key is hit.
 	cw_key_hit = 1;
+        // we do PTT as soon as possible ...
+        if (running && !cwvox) {
+	   g_idle_add(ext_mox_update, (gpointer)(long) 1);
+           cwvox=(int) vox_hang;
+	}
     }
-    if (gpio == CWL_BUTTON)
+    if (gpio == CWL_BUTTON) {
         kcwl = state;
-    else  // CWR_BUTTON
+        //fprintf(stderr,"L=%d\n",state);   
+    } else { // CWR_BUTTON
         kcwr = state;
+        //fprintf(stderr,"R=%d\n",state);   
+    }
 
     if (state || cw_keyer_mode == KEYER_STRAIGHT) {
 #ifdef __APPLE__
@@ -189,7 +200,7 @@ void set_keyer_out(int state) {
 	//         MOX before starting local CW.
         keyer_out = state;
         if(protocol==NEW_PROTOCOL) schedule_high_priority(9);
-		fprintf(stderr,"set_keyer_out keyer_out= %d\n", keyer_out);
+		//fprintf(stderr,"set_keyer_out keyer_out= %d\n", keyer_out);
         if (state) {
 	    // DL1YCF: we must call cw_hold_key in *any* case, else no
 	    //         CW signal will be produced. We certainly do not
@@ -222,9 +233,21 @@ fprintf(stderr,"keyer_thread  state running= %d\n", running);
 
         key_state = CHECK;
 
-        while (key_state != EXITLOOP) {
-            switch(key_state) {
+	// If MOX still hanging, continue spinnning/checking and decrement cwvox
+
+        while (key_state != EXITLOOP || cwvox > 0) {
+          if (cwvox > 0 && key_state != EXITLOOP && key_state != CHECK) cwvox=(int) vox_hang;
+	  switch (key_state) {
+	    case EXITLOOP:
+		if (cwvox >0) cwvox--;
+                if (cwvox == 0) {
+		    g_idle_add(ext_mox_update,(gpointer)(long) 0);
+		} else {
+		    key_state=CHECK;
+		}
+	        break;
             case CHECK: // check for key press
+		if (cwvox > 1) cwvox--;
                 if (cw_keyer_mode == KEYER_STRAIGHT) {       // Straight/External key or bug
                     if (*kdash) {                  // send manual dashes
                         set_keyer_out(1);