-
Notifications
You must be signed in to change notification settings - Fork 1
/
cwinkey.h
609 lines (567 loc) · 20.5 KB
/
cwinkey.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
/* -*- mode: c++; tab-width: 8 -*- */
/*
* hasak (ham and swiss army knife) keyer for Teensy 4.X, 3.X
* Copyright (c) 2021 by Roger Critchlow, Charlestown, MA, USA
* ad5dz, [email protected]
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice, development funding notice, and this permission
* notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#if ! defined(KYR_ENABLE_WINKEY)
void cwinkey_setup(void) { }
//void cwinkey_loop(void) { }
#else
////////////////////////////////////////////////////////////////////////////////////////
//
// Teensy keyer with audio (WinKey emulator)
//
// (C) Christoph van Wüllen, DL1YCF, 2020/2021
//
// Designed for the Teensy 4, using the "Serial+MIDI+Audio" programming model
//
//
//
// WinKey state machine: the states
// The numerical (enum) values ADMIN ... BUFNOP must agree with the
// winkey command bytes.
//
#define WKVERSION 21 // This version is returned to the host
enum WKSTAT {
ADMIN =0x00,
SIDETONE =0x01,
WKSPEED =0x02,
WEIGHT =0x03,
PTT =0x04,
POTSET =0x05,
PAUSE =0x06,
GETPOT =0x07,
BACKSPACE =0x08,
PINCONFIG =0x09,
CLEAR =0x0a,
TUNE =0x0b,
HSCW =0x0c,
FARNS =0x0d,
WK2MODE =0x0e,
LOADDEF =0x0f,
EXTENSION =0x10,
KEYCOMP =0x11,
PADSW =0x12,
NULLCMD =0x13,
SOFTPAD =0x14,
WKSTAT =0x15,
POINTER =0x16,
RATIO =0x17,
SETPTT =0x18,
KEYBUF =0x19,
WAIT =0x1a,
PROSIGN =0x1b,
BUFSPD =0x1c,
HSCWSPD =0x1d,
CANCELSPD =0x1e,
BUFNOP =0x1f,
FREE,
SWALLOW,
XECHO,
WRPROM,
RDPROM,
MESSAGE,
POINTER_1,
POINTER_2,
POINTER_3
} cwinkey_state=FREE;
//
// Winkeyer properties all reduced to this enumeration
//
typedef enum {
WK_MODE_REGISTER = 0,
WK_SPEED,
WK_SIDETONE,
WK_WEIGHT,
WK_PTT_LEAD_IN,
WK_PTT_TAIL,
WK_MIN_WPM,
WK_WPM_RANGE,
WK_EXTENSION,
WK_COMPENSATION,
WK_FARNSWORTH,
WK_PADDLE_POINT,
WK_RATIO,
WK_PIN_CONFIG
} cwinkey_property_t;
//
// Winkey variable abstraction, 14 bytes of state translated to/from nrpn equivalents
//
//
// Macros to read the ModeRegister
//
#define PADDLE_SWAP(ModeRegister) ((ModeRegister & 0x08) != 0)
#define PADDLE_ECHO(ModeRegister) ((ModeRegister & 0x40) != 0)
#define SERIAL_ECHO(ModeRegister) ((ModeRegister & 0x04) != 0)
#define PADDLE_MODE(ModeRegister) ((ModeRegister & 0x30)>>4)
#define IAMBIC_A(ModeRegister) ((ModeRegister & 0x30) == 0x10)
#define IAMBIC_B(ModeRegister) ((ModeRegister & 0x30) == 0x00)
#define BUGMODE(ModeRegister) ((ModeRegister & 0x30) == 0x30)
#define ULTIMATIC(ModeRegister) ((ModeRegister & 0x30) == 0x20)
//
// Macros to read PinConfig
//
#define SIDETONE_ENABLED(PinConfig) (PinConfig & 0x02)
#define PTT_ENABLED(PinConfig) (PinConfig & 0x01)
#define HANGBITS(PinConfig) ((PinConfig & 0x30) >> 4)
static void cwinkey_set(cwinkey_property_t p, int v) {
switch (p) {
case WK_MODE_REGISTER:
//static uint8_t ModeRegister=0x10; // no echos, no swap, Iambic-A by default
// mode register: serial echo / paddle echo / swap / paddle mode
// bits used in ModeRegiser:
// b6: echo characters entered by paddle or straight key (to serial line)
// b4/5: Paddle mode (00 = Iambic-B, 01 = Iambic-A, 10 = Ultimatic, 11 = Bugmode)
// b3: swap paddles
// b2: echo characters received from the serial line as they are transmitted
//
if (nrpn_get(NRPN_PAD_SWAP) != PADDLE_SWAP(v))
nrpn_set(NRPN_PAD_SWAP, PADDLE_SWAP(v) != 0);
if (nrpn_get(NRPN_PAD_KEYER) != VAL_KEYER_VK6PH)
nrpn_set(NRPN_PAD_KEYER, VAL_KEYER_VK6PH);
if (ULTIMATIC(v)) {
if (nrpn_get(NRPN_PAD_ADAPT) != VAL_ADAPT_ULTIMATIC)
nrpn_set(NRPN_PAD_ADAPT, VAL_ADAPT_ULTIMATIC);
if (nrpn_get(NRPN_PAD_MODE) != VAL_MODE_A)
nrpn_set(NRPN_PAD_MODE, VAL_MODE_A);
} else {
if (nrpn_get(NRPN_PAD_ADAPT) != VAL_ADAPT_NORMAL)
nrpn_set(NRPN_PAD_ADAPT, VAL_ADAPT_NORMAL);
switch (PADDLE_MODE(v)) {
case 0:
if (nrpn_get(NRPN_PAD_MODE) != VAL_MODE_B)
nrpn_set(NRPN_PAD_MODE, VAL_MODE_B);
break;
case 1:
if (nrpn_get(NRPN_PAD_MODE) != VAL_MODE_A)
nrpn_set(NRPN_PAD_MODE, VAL_MODE_A);
break;
case 3:
if (nrpn_get(NRPN_PAD_MODE) != VAL_MODE_S)
nrpn_set(NRPN_PAD_MODE, VAL_MODE_S);
break;
}
}
if (PADDLE_ECHO(v)) // do something FIX.ME
;
if (SERIAL_ECHO(v)) // do something FIX.ME
;
break;
case WK_SPEED:
//static uint8_t Speed=0; // CW speed (zero means: use speed pot)
// speed: 0 means use speed pot
// Speed=byte;
if (nrpn_get(NRPN_SPEED) != v)
nrpn_set(NRPN_SPEED, v); // FIX.ME, what if no speed pot and v == 0
break;
case WK_SIDETONE:
//static uint8_t Sidetone=5; // 800 Hz
// 4000/(byte&15) hz, default 5 => 800Hz // Sidetone=byte;
// myfreq=4000/(Sidetone & 0x0F);
// sidetonefrequency(myfreq);
v = 4000/(v & 0x0F);
if (nrpn_get(NRPN_TONE) != v)
nrpn_set(NRPN_TONE, v);
break;
case WK_WEIGHT:
//static uint8_t Weight=50; // used to modify dit/dah length
// max(10, min(90, byte)), default 50
// if (byte < 10) byte=10;
// if (byte > 90) byte=90;
// Weight=byte;
v = max(10, min(90, v));
if (nrpn_get(NRPN_WEIGHT) != v)
nrpn_set(NRPN_WEIGHT, v); // FIX.ME, this is a wider range of values than ctrlr implements
break;
case WK_PTT_LEAD_IN:
//static uint8_t LeadIn=15; // PTT Lead-in time (in units of 10 ms)
// unit == 10ms
v = 10*v;
if (nrpn_get(NRPN_HEAD_TIME) != v)
nrpn_set(NRPN_HEAD_TIME, v);
break;
case WK_PTT_TAIL:
//static uint8_t Tail=0; // PTT tail (in 10 ms), zero means "use hang bits"
// unit == 10ms
v = 10*v;
if (nrpn_get(NRPN_TAIL_TIME) != v)
nrpn_set(NRPN_TAIL_TIME, v);
break;
case WK_MIN_WPM:
//static uint8_t MinWPM=5; // CW speed when speed pot maximally CCW
// FIX.ME - how to implement with no speed pot
break;
case WK_WPM_RANGE:
//static uint8_t WPMrange=25; // CW speed range for SpeedPot
// range of speed pot
// range = min(31, range);
// FIX.ME - how to implement with no speed pot
break;
case WK_EXTENSION:
//static uint8_t Extension=0; // ignored
// FIX.ME - stretch the first element of a transmission sequence to compensate
// for lousy transmitter ptt timing
break;
case WK_COMPENSATION:
//static uint8_t Compensation=0; // Used to modify dit/dah lengths
v = 10*v;
if (nrpn_get(NRPN_COMP) != v)
nrpn_set(NRPN_COMP, v);
break;
case WK_FARNSWORTH:
//static uint8_t Farnsworth=10; // Farnsworth speed (10 means: no Farnsworth)
// if (byte < 10) byte=10;
// if (byte > 99) byte=99;
// Farnsworth=byte;
v = max(10, min(99, v));
if (nrpn_get(NRPN_FARNS) != v)
nrpn_set(NRPN_FARNS, v);
break;
case WK_PADDLE_POINT:
//static uint8_t PaddlePoint; // debounce refractory period
v = 10*v; // convert ms to tenth ms
if (nrpn_get(NRPN_DEBOUNCE) != v)
nrpn_set(NRPN_DEBOUNCE, v);
break;
case WK_RATIO:
//static uint8_t Ratio=50; // dah/dit ratio = (3*ratio)/50
// if (byte < 33) byte=33;
// if (byte > 66) byte=66;
v = max(33, min(66, v));
if (nrpn_get(NRPN_RATIO) != v)
nrpn_set(NRPN_RATIO, v);
break;
case WK_PIN_CONFIG:
//static uint8_t PinConfig=0x23; // PTT and side tone enabled, 1.67 word space hang time
// bits used in PinConfig:
// b0: PTT enable/disable bit, if PTT disabled, LeadIn times will have no effect
// b1: Sidetone enable/disable bit
// b4/b5: PTT tail = 2 wordspaces (11), 1.67 wordspaces, 1.33 wordspaces, 1.00 wordspaces dit(00)
default:
break;
}
}
static int cwinkey_get(cwinkey_property_t p) {
switch (p) {
case WK_MODE_REGISTER: {
int v = 0;
if (nrpn_get(NRPN_PAD_SWAP)) v |= 0x08;
if (nrpn_get(NRPN_PAD_ADAPT) == VAL_ADAPT_ULTIMATIC)
v |= 0x20;
else
switch (nrpn_get(NRPN_PAD_MODE)) {
case VAL_MODE_A: v |= 0x10; break;
case VAL_MODE_B: v |= 0x00; break;
case VAL_MODE_S: v |= 0x30; break;
}
// PADDLE_ECHO FIX.ME
// SERIAL_ECHO FIX.ME
return v;
}
case WK_SPEED: return nrpn_get(NRPN_SPEED);
case WK_SIDETONE: return (int)(nrpn_get(NRPN_TONE)/4000.0);
case WK_WEIGHT: return nrpn_get(NRPN_WEIGHT);
case WK_PTT_LEAD_IN: return nrpn_get(NRPN_HEAD_TIME)/10;
case WK_PTT_TAIL: return nrpn_get(NRPN_TAIL_TIME)/10;
case WK_MIN_WPM: return 0; // FIX.ME
case WK_WPM_RANGE: return 0; // FIX.ME
case WK_EXTENSION: return 0;
case WK_COMPENSATION: return nrpn_get(NRPN_COMP)/10;
case WK_FARNSWORTH: return nrpn_get(NRPN_FARNS);
case WK_PADDLE_POINT: return nrpn_get(NRPN_DEBOUNCE)/10;
case WK_RATIO: return nrpn_get(NRPN_RATIO);
case WK_PIN_CONFIG: {
int v = 0;
return v;
}
default:
return 0;
}
}
static uint8_t WKstatus=0xC0; // reported to host when it changes
static int inum; // counter for number of bytes received in a given state
// static uint8_t pausing=0; // "pause" state
static uint8_t breakin=1; // breakin state
//static uint8_t straight=0; // state of the straight key (1 = pressed, 0 = released)
//static uint8_t tuning=0; // "Tune" mode active, deactivate paddle
static uint8_t hostmode = 0; // host mode
static uint8_t SpeedPot = 0; // Speed value from the Potentiometer
//static int myfreq=800; // current side tone frequency
//static uint8_t myspeed; // current CW speed
//static uint8_t prosign=0; // set if we are in the middle of a prosign
///////////////////////////////////////
//
// Winkeyer functions
//
///////////////////////////////////////
// check for available byte from host
static byte cwinkey_available(void) { return Serial2.available(); }
// Read one byte from host
static int cwinkey_from_host() { return Serial2.read(); }
// Write one byte to the host
static void cwinkey_to_host(int c) { Serial2.write(c); }
// remove last queued character
static void cwinkey_backspace(void) { wink.unsend_text(); }
// clear queued characters
static void cwinkey_clearbuf(void) { wink.abort(); }
// queue one, two, or three characters
static void cwinkey_queue(uint8_t c) { wink.send_text(c); }
static void cwinkey_setbufpos(uint8_t byte) {
// not clear what to do
// if (byte > 0) byte--;
}
static void cwinkey_bufzero(uint8_t byte) {
// not clear what to do
}
// restore winkey state from eeprom
static void cwinkey_read_from_eeprom(void) { }
// restore winkey byte from eeprom
static byte cwinkey_read_eeprom(int inum) { return 0; }
// write winkey byte to eeprom
static void cwinkey_update_eeprom(byte inum, byte data) { }
// set the pausing
static void cwinkey_set_pausing(uint8_t byte) { }
// see if the keyer is idle
static int cwinkey_keyer_idle(void) { return nrpn_get(NRPN_ACTIVE_ST) > NOTE_TEXT_ST; }
// tune on/off
static void cwinkey_tune(int byte) {
// hmm, these delays are going to screw everything up
// Do not bother about lead-in and tail times, but DO switch PTT
// if (byte) {
// cwinkey_clearbuf();
// tuning=1;
// if (PTT_ENABLED) {
// ptt_on();
// delay(50);
// }
// keydown();
// } else {
// keyup();
// if (PTT_ENABLED) {
// delay(10);
// ptt_off();
// }
// tuning=0;
// }
}
static void cwinkey_rdprom(void) {
// dump EEPROM command
// only dump bytes 0 through 15,
// report the others being zero
// Nothing must interrupt us, therefore no state machine
// delays are a no no
for (inum=0; inum<16; inum++) {
cwinkey_to_host(cwinkey_read_eeprom(inum));
// delay(20);
}
for (inum=16; inum < 256; inum++) {
cwinkey_to_host(0);
// delay(20);
}
}
static void cwinkey_wrprom(void) {
//
// Load EEPROM command
// nothing must interrupt us, hence no state machine
//
for (int inum = 0; inum < 256; inum += 1) {
while ( ! cwinkey_available());
if (inum < 16)
cwinkey_update_eeprom(inum, cwinkey_from_host());
else
(void)cwinkey_from_host();
}
}
static void cwinkey_dump_default(void) {
// never used so I refrain from making an own "state" for this.
cwinkey_to_host(cwinkey_get(WK_MODE_REGISTER)); // 0
cwinkey_to_host(cwinkey_get(WK_SPEED)); // 1
cwinkey_to_host(cwinkey_get(WK_SIDETONE)); // 2
cwinkey_to_host(cwinkey_get(WK_WEIGHT)); // 3
cwinkey_to_host(cwinkey_get(WK_PTT_LEAD_IN)); // 4
cwinkey_to_host(cwinkey_get(WK_PTT_TAIL)); // 5
cwinkey_to_host(cwinkey_get(WK_MIN_WPM)); // 6
cwinkey_to_host(cwinkey_get(WK_WPM_RANGE)); // 7
cwinkey_to_host(cwinkey_get(WK_EXTENSION)); // 8
cwinkey_to_host(cwinkey_get(WK_COMPENSATION)); // 9
cwinkey_to_host(cwinkey_get(WK_FARNSWORTH)); // 10
cwinkey_to_host(cwinkey_get(WK_PADDLE_POINT)); // 11
cwinkey_to_host(cwinkey_get(WK_RATIO)); // 12
cwinkey_to_host(cwinkey_get(WK_PIN_CONFIG)); // 13
cwinkey_to_host(0); // 14
}
static byte cwinkey_get_speed_pot(void) {
return 0;
}
///////////////////////////////////////
//
// This is the WinKey state machine
//
///////////////////////////////////////
void cwinkey_state_machine(int nrpn) {
uint8_t byte;
static int OldWKstatus=-1; // this is to detect status changes
static int OldSpeedPot=-1; // this is to detect Speed pot changes
//
// Now comes the WinKey state machine
// First, handle commands that need no further bytes
//
switch (cwinkey_state) {
case GETPOT: cwinkey_to_host(128+cwinkey_get_speed_pot()); cwinkey_state=FREE; break; // send immediately
case BACKSPACE: cwinkey_backspace(); cwinkey_state=FREE; break;
case CLEAR: cwinkey_clearbuf(); cwinkey_state=FREE; break;
case WKSTAT: cwinkey_to_host(WKstatus); cwinkey_state=FREE; break;
case NULLCMD: cwinkey_state=FREE; break;
case CANCELSPD: cwinkey_state=FREE; break; // cancel buffered speed, ignored
case BUFNOP: cwinkey_state=FREE; break; // buffered no-op; ignored
case RDPROM: cwinkey_rdprom(); cwinkey_state=FREE; break;
case WRPROM: cwinkey_wrprom(); cwinkey_state=FREE; break;
default: break; // This is a multi-byte command handled below
}
//
// Check serial line, if in hostmode or ADMIN command enter "WinKey" state machine
// NOTE: process *all* ADMIN command even if hostmode is closed. For example,
// fldigi sends "echo" first and then "open".
//
if (cwinkey_available()) {
byte=cwinkey_from_host();
if (hostmode == 0 && cwinkey_state == FREE && byte != ADMIN) return;
//
// This switch statement builds the "WinKey" state machine
//
switch (cwinkey_state) {
case FREE:
//
// In the idle state, the incoming byte is either a letter to
// be transmitted or the start of the WinKey command.
//
if (byte >= 0x20) {
cwinkey_queue(byte); cwinkey_state=FREE;
} else {
cwinkey_state=(enum WKSTAT) byte; inum=0;
}
break;
case SWALLOW: cwinkey_state=FREE; break;
case XECHO: cwinkey_to_host(byte); cwinkey_state=FREE; break;
case MESSAGE: cwinkey_state=FREE; break; // output stored message as CW
case ADMIN:
switch (byte) {
case 0: cwinkey_state=SWALLOW; break; // Admin Calibrate
case 1: cwinkey_state=FREE; cwinkey_read_from_eeprom(); hostmode=0; break; // Admin Reset
case 2: hostmode = 1; cwinkey_to_host(WKVERSION); cwinkey_state=FREE; break; // Admin Open
case 3: hostmode = 0; cwinkey_read_from_eeprom(); cwinkey_state=FREE; break; // Admin Close
case 4: cwinkey_state=XECHO; break; // Admin Echo
case 5: // Admin
case 6:
case 8:
case 9: cwinkey_to_host(0); break; // only for backwards compatibility
case 7: cwinkey_dump_default(); cwinkey_state=FREE; break; // Admin DumpDefault
case 10: cwinkey_state=FREE; break; // Admin set WK1 mode
case 11: cwinkey_state=FREE; break; // Admin set WK2 mode
case 12: cwinkey_state=RDPROM; break;
case 13: cwinkey_state=WRPROM; break;
case 14: cwinkey_state=MESSAGE; break;
}
break;
case WK2MODE: cwinkey_set(WK_MODE_REGISTER, byte); cwinkey_state=FREE; break;
case WKSPEED: cwinkey_set(WK_SPEED, byte); cwinkey_state=FREE; break;
case SIDETONE: cwinkey_set(WK_SIDETONE, byte); cwinkey_state=FREE; break;
case WEIGHT: cwinkey_set(WK_WEIGHT, byte); cwinkey_state=FREE; break;
case PTT:
if (inum==0) { cwinkey_set(WK_PTT_LEAD_IN, byte); inum += 1; break; }
if (inum==1) { cwinkey_set(WK_PTT_TAIL, byte); cwinkey_state=FREE; break; }
cwinkey_state=FREE; break;
case POTSET:
if (inum==0) { cwinkey_set(WK_MIN_WPM, byte); inum += 1; break; }
if (inum==1) { cwinkey_set(WK_WPM_RANGE, byte); cwinkey_state=FREE; break; }
cwinkey_state=FREE; break;
case FARNS: cwinkey_set(WK_FARNSWORTH, byte); cwinkey_state=FREE; break;
case EXTENSION: cwinkey_set(WK_EXTENSION, byte); cwinkey_state=FREE; break;
case KEYCOMP: cwinkey_set(WK_COMPENSATION, byte); cwinkey_state=FREE; break;
case RATIO: cwinkey_set(WK_RATIO, byte); cwinkey_state=FREE; break;
case PINCONFIG: cwinkey_set(WK_PIN_CONFIG, byte); cwinkey_state=FREE; break;
case PAUSE: cwinkey_set_pausing(byte); cwinkey_state=FREE; break;
case TUNE: cwinkey_tune(byte); cwinkey_state=FREE; break;
case HSCW: cwinkey_state=FREE; break; // ignored
case LOADDEF:
if (inum>=WK_MODE_REGISTER &&
inum<=WK_PIN_CONFIG) {
cwinkey_set((cwinkey_property_t)inum, byte); inum += 1; break;
}
cwinkey_state=FREE; break;
case PADSW: cwinkey_state=FREE; break; // paddle switch-point ignored
case SOFTPAD: cwinkey_state=FREE; break; // software paddle ignored
case POINTER_1:
case POINTER_2: cwinkey_setbufpos(byte); cwinkey_state=FREE; break; // unclear
case POINTER_3: cwinkey_bufzero(byte); cwinkey_state=FREE; break; // unclear
case POINTER:
switch (byte) {
case 0: cwinkey_clearbuf(); cwinkey_state=FREE; break;
case 1: cwinkey_state=POINTER_1; break;
case 2: cwinkey_state=POINTER_2; break;
case 3: cwinkey_state=POINTER_3; break;
default: cwinkey_state=FREE; break;
}
break;
case SETPTT: cwinkey_state=FREE; break; // buffered PTT ignored
case KEYBUF: cwinkey_state=FREE; break; //buffered key-down ignored
case WAIT: cwinkey_state=FREE; break; // buffered wait ignored
case PROSIGN:
if (inum==0) { cwinkey_queue(0x1b); cwinkey_queue(byte); inum += 1; break; }
if (inum==1) { cwinkey_queue(byte); cwinkey_state=FREE; break; }
cwinkey_state=FREE; break;
case BUFSPD: cwinkey_state=FREE; break; // buffered speed change ignored
case HSCWSPD: break; // HSCW speed change ignored
default: cwinkey_state=FREE; break;
}
}
//
// loop exit code: update WK status and send if changed
//
if (breakin) {
WKstatus |= 0x02;
breakin=0;
} else {
WKstatus &= 0xFD;
if (cwinkey_keyer_idle()) {
WKstatus &= 0xFB;
} else {
WKstatus |= 0x04;
}
}
if ((WKstatus != OldWKstatus) && hostmode) {
cwinkey_to_host(WKstatus);
OldWKstatus=WKstatus;
}
if ((SpeedPot != OldSpeedPot) && hostmode) {
cwinkey_to_host(128+SpeedPot);
OldSpeedPot=SpeedPot;
}
}
/***************************************************************
** Winkey interface
***************************************************************/
static void cwinkey_setup(void) {
nrpn_listen(NRPN_MILLI, winkey_state_machine);
}
//static void cwinkey_loop(void) {}
#endif