]> git.rkrishnan.org Git - pihpsdr.git/commitdiff
polished MIDI CWKEY message handling
authorc vw <dl1ycf@darc.de>
Fri, 15 Jan 2021 08:42:47 +0000 (09:42 +0100)
committerc vw <dl1ycf@darc.de>
Fri, 15 Jan 2021 08:42:47 +0000 (09:42 +0100)
iambic.c
iambic.h
midi3.c

index f9e27ede2724438a40fb2e6ea8d4e836aa60ba28..6ce933f28bfef46e5f3988144767a84483eb8e7b 100644 (file)
--- a/iambic.c
+++ b/iambic.c
@@ -248,6 +248,22 @@ int gpio_cw_sidetone_enabled() { return 0; }
 void gpio_cw_sidetone_set(int level) {}
 #endif
 
+void keyer_straight_key(state) {
+  //
+  // Interface for simple key-down action e.g. from a MIDI message
+  //
+  if (state != 0) {
+    cw_key_down=960000;  // max. 20 sec to protect hardware
+    cw_key_up=0;
+    cw_key_active=1;
+    gpio_cw_sidetone_set(1);
+  } else {
+    cw_key_down=0;
+    cw_key_up=0;
+    gpio_cw_sidetone_set(0);
+  }
+}
+
 void keyer_update() {
     //
     // This function will take notice of changes in the following variables
@@ -441,9 +457,7 @@ static void* keyer_thread(void *arg) {
                     // If both paddles are pressed (should not happen), then
                     // the dash paddle wins.
                     if (*kdash) {                  // send manual dashes
-                      cw_key_down=960000;            // 20 sec maximum
-                      cw_key_up=0;
-                      gpio_cw_sidetone_set(1);
+                      keyer_straight_key(1);       // do key down
                       key_state=STRAIGHT;
                     }
                 } else {
@@ -461,8 +475,7 @@ static void* keyer_thread(void *arg) {
                // Wait for dash paddle being released in "straight key" mode.
                 //
                 if (! *kdash) {
-                  cw_key_down=0;
-                  gpio_cw_sidetone_set(0);
+                  keyer_straight_key(0);   // key-up
                   key_state=CHECK;
                 }
                 break;
index 91fcd4341749967df328021f905058ab728fa916..f1b381a716441a3d6b4e5be048c979204fb1972b 100644 (file)
--- a/iambic.h
+++ b/iambic.h
@@ -14,6 +14,7 @@ enum {
     EXITLOOP
 };
 
+void keyer_straight_key(state);
 void keyer_event(int left, int state);
 void keyer_update();
 void keyer_close();
diff --git a/midi3.c b/midi3.c
index 0e53ed65acfb411da6b34e2e3e3c63dfcb21857e..751bd20f3c467cd7c5fdc29234aa9f507404c2d2 100644 (file)
--- a/midi3.c
+++ b/midi3.c
@@ -220,23 +220,23 @@ void DoTheMidi(enum MIDIaction action, enum MIDItype type, int val) {
        /////////////////////////////////////////////////////////// "CW"
        case MIDI_ACTION_CWKEY: // only key
          //
-         // This is a CW key-up/down which works outside the keyer.
-         // It is intended for the use of external keyers
-         // and works if not compiled with LOCALCW
-         // and/or using "CW handled in radio". 
-         // NO BREAK-IN! The keyer has to send a MIDI "PTT on" command and
-         // wait a decent amount of time before doing key-down.
+         // This is a CW key-up/down which uses functions from the keyer
+         // that by-pass the interrupt-driven standard action.
+         // It is intended to
+         // be used with external keyers that send key-up/down messages via
+         // MIDI using this command.
+         //
+         // NO BREAK-IN! The keyer has to take care of sending MIDI PTT
+         // on/off messages at appropriate times.
           //
+#ifdef LOCALCW
            if (type == MIDI_TYPE_KEY) {
-              if (val != 0) {
-               cw_key_down=960000;  // max. 20 sec to protect hardware
-               cw_key_up=0;
-               cw_key_hit=1;        // abort any pending CAT CW messages
-             } else {
-               cw_key_down=0;
-               cw_key_up=0;
-             }
+              keyer_straight_key(val);
             }
+#else
+           g_print("%s: CWKEY:%d\n",__FUNCTION__,val);
+
+#endif
            break;
        /////////////////////////////////////////////////////////// "CWL"
        /////////////////////////////////////////////////////////// "CWR"