-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdtmf.h
86 lines (66 loc) · 2.15 KB
/
dtmf.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
/**
dtmf.h - DTMF generator
Copyright (C) 2018 Costin STROIE <[email protected]>
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 <http://www.gnu.org/licenses/>.
*/
#ifndef DTMF_H
#define DTMF_H
#define ROWSCOLS 4
#include <Arduino.h>
#include "config.h"
#include "wave.h"
// DTMF frequencies
//
// 1209 1336 1477 1633
// 697 1 2 3 A
// 770 4 5 6 B
// 852 7 8 9 C
// 941 * 0 # D
static const uint16_t frqRows[ROWSCOLS] = { 697, 770, 852, 941};
static const uint16_t frqCols[ROWSCOLS] = {1209, 1336, 1477, 1633};
static const char dtmfRowsCols[ROWSCOLS][ROWSCOLS] = {
{ '1', '2', '3', 'A'},
{ '4', '5', '6', 'B'},
{ '7', '8', '9', 'C'},
{ '*', '0', '#', 'D'}
};
// States in DTMF finite states machines
enum DTMF_STATE {DTMF_DISB, DTMF_WAVE, DTMF_SLNC};
class DTMF {
public:
DTMF(uint8_t pulse = 40, uint8_t pause = 40);
~DTMF();
// The resulting sample
uint8_t sample;
bool getSample();
char send(char chr);
uint8_t send(char *chrs, size_t len);
void setDuration(uint8_t pulse, uint8_t pause = 0);
private:
// The DTMF wave generator
WAVE wave;
// Wave steps (Q8.8)
uint16_t stpRows[ROWSCOLS];
uint16_t stpCols[ROWSCOLS];
// Wave indices for row and col frequencies (Q8.8)
uint16_t rowIdx, colIdx;
// Identified row and col
uint8_t row, col;
// Wave generator status
uint8_t state = DTMF_DISB;
// Pulse and pause length (in samples) and counter
uint16_t lenPulse;
uint16_t lenPause;
uint16_t counter;
bool getRowCol(char chr);
};
#endif /* DTMF_H */