-
Notifications
You must be signed in to change notification settings - Fork 1
/
cwdecode.h
114 lines (105 loc) · 3.94 KB
/
cwdecode.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
/* -*- 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.
*/
/*
** listen to the elements from cwdetime, decode the sequences into ascii
** transcoded into C from the javascript of https://keyer.elf.org
*/
static void cwdecode_sample(void) {}
static void cwdecode_setup(void) {}
//static void cwdecode_loop(void) {}
/* the decode part still in javascript, using a different table */
#if 0
// Local Variables:
// mode: JavaScript
// js-indent-level: 2
// End:
//
// keyer.js - a progressive web app for morse code
// Copyright (c) 2020 Roger E Critchlow Jr, Charlestown, MA, USA
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//
import { KeyerDetime } from './KeyerDetime.js';
// translate dit dah strings to text
export class KeyerDecode extends KeyerDetime {
constructor(context) {
super(context);
this.table = null;
this.elements = [];
this.elementTimeout = null;
this.on('element', (elt, timeEnded) => this.onelement(elt, timeEnded));
}
elementTimeoutFun() {
this.elementTimeout = null;
if (this.elements.length > 0) {
const code = this.elements.join('');
const ltr = this.table.decode(code) || '\u25a1';
// console.log('decode.emit.letter timeout', ltr, code);
this.emit('letter', ltr, code);
this.elements = [];
}
}
onelement(elt, timeEnded) {
// console.log('decode.onelement("'+elt+'", '+timeEnded+')');
if (this.elementTimeout) {
clearTimeout(this.elementTimeout);
this.elementTimeout = null;
}
if (elt === '') {
return;
}
if (elt === '.' || elt === '-') {
this.elements.push(elt);
this.elementTimeout = setTimeout((...args) => this.elementTimeoutFun(...args), 1000 * (timeEnded - this.context.currentTime) + 250 );
return;
}
if (this.elements.length > 0) {
const code = this.elements.join('');
const ltr = this.table.decode(code) || '\u25a1';
// console.log('decode.emit.letter space', ltr, code);
this.emit('letter', ltr, code);
this.elements = [];
}
if (elt === '\t') {
this.emit('letter', ' ', elt);
}
}
}
// Local Variables:
// mode: JavaScript
// js-indent-level: 2
// End:
#endif