]> git.rkrishnan.org Git - dttsp.git/blob - jDttSP/keyer.h
Bug fixes to jsdr, keyer
[dttsp.git] / jDttSP / keyer.h
1 /* keyer.h */
2 /*
3 This file is part of a program that implements a Software-Defined Radio.
4
5 The code in this file is derived from routines originally written by
6 Pierre-Philippe Coupard for his CWirc X-chat program. That program
7 is issued under the GPL and is
8 Copyright (C) Pierre-Philippe Coupard - 18/06/2003
9
10 This derived version is
11 Copyright (C) 2004 by Frank Brickle, AB2KT and Bob McGwier, N4HY
12
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26
27 The authors can be reached by email at
28
29 ab2kt@arrl.net
30 or
31 rwmcgwier@comcast.net
32
33 or by paper mail at
34
35 The DTTS Microwave Society
36 6 Kathleen Place
37 Bridgewater, NJ 08807
38 */  
39
40 #ifndef _keyer_h
41 #define _keyer_h
42
43 #include <fromsys.h>
44 #include <banal.h>
45 #include <splitfields.h>
46 #include <datatypes.h>
47
48 //========================================================================
49
50 #define DSR_LINE_CLOSED_KEY      (1)
51 #define CTS_LINE_CLOSED_KEY      (1)
52 #define DTR_LINE_SET             (0)
53 #define RTS_LINE_SET             (0)
54
55 #define NO_TIMEOUTS_SCHED       (-2)
56 #define NO_ELEMENT              (-1)
57 #define DIT                      (0)
58 #define DAH                      (1)
59 #define MODE_A                   (0)
60 #define MODE_B                   (1)
61 #define NO_PADDLE_SQUEEZE        (0)
62 #define PADDLES_SQUEEZED         (1)
63 #define PADDLES_RELEASED         (2)
64 #define NO_DELAY                 (0)
65 #define CHAR_SPACING_DELAY       (1)
66 #define WORD_SPACING_DELAY       (2)
67 #define DEBOUNCE_BUF_MAX_SIZE   (30)
68
69 //========================================================================
70
71 typedef
72 struct _keyer_state {
73
74   struct {
75
76     BOOLEAN iambic,     // iambic or straight
77             mdlmdB,
78             revpdl;     // paddles reversed
79
80     struct {
81       BOOLEAN dit, dah;
82     } memory;
83
84     struct {
85       BOOLEAN khar, word;
86     } autospace;
87
88   } flag;
89
90   int debounce, // # seconds to read paddles
91       mode,     // 0 = mode A, 1 = mode B
92       weight;   // 15 -> 85%
93
94   double wpm;   // for iambic keyer
95
96 } KeyerStateInfo, *KeyerState;
97
98 extern KeyerState newKeyerState(void);
99 extern void delKeyerState(KeyerState ks);
100
101 //------------------------------------------------------------------------
102
103 typedef
104 struct _keyer_logic {
105
106   struct {
107     BOOLEAN init;
108
109     struct {
110       BOOLEAN dit, dah;
111     } prev;
112
113   } flag;
114
115   struct {
116     BOOLEAN invtd, // insert inverted element
117             psqam; // paddles squeezed after mid-element
118     int curr, // -1 = nothing, 0 = dit, 1 = dah
119         iamb, //  0 = none, 1 = squeezed, 2 = released
120         last; // -1 = nothing, 0 = dit, 1 = dah
121   } element;
122
123   struct {
124     double beep, dlay, elem, midl;
125   } timeout;
126
127   int dlay_type; // 0 = none, 1 = interchar, 2 = interword
128
129 } KeyerLogicInfo, *KeyerLogic;
130
131 extern KeyerLogic newKeyerLogic(void);
132 extern void delKeyerLogic(KeyerLogic kl);
133
134 //========================================================================
135
136 extern BOOLEAN klogic(KeyerLogic kl,
137                       BOOLEAN dit,
138                       BOOLEAN dah,
139                       double wpm,
140                       int iambicmode,
141                       BOOLEAN midelementmodeB,
142                       BOOLEAN ditmemory,
143                       BOOLEAN dahmemory,
144                       BOOLEAN autocharspacing,
145                       BOOLEAN autowordspacing,
146                       int weight,
147                       double ticklen);
148
149 extern BOOLEAN read_straight_key_serial(KeyerState ks, int fd);
150 extern BOOLEAN read_iambic_key_serial(KeyerState ks, int fd, KeyerLogic kl, double ticklen);
151
152 //========================================================================
153
154 #endif