update DTMF example
This commit is contained in:
parent
c813bac7b8
commit
a9f3380f85
|
@ -75,7 +75,7 @@ void setup() {
|
||||||
radio.frequency(freq);
|
radio.frequency(freq);
|
||||||
|
|
||||||
// set RX volume to minimum to reduce false positives on DTMF rx
|
// set RX volume to minimum to reduce false positives on DTMF rx
|
||||||
radio.setVolume1(4);
|
radio.setVolume1(6);
|
||||||
radio.setVolume2(0);
|
radio.setVolume2(0);
|
||||||
|
|
||||||
// set to receive
|
// set to receive
|
||||||
|
@ -91,22 +91,17 @@ void setup() {
|
||||||
Serial.println("ready");
|
Serial.println("ready");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char rx_dtmf_buf[255];
|
||||||
|
int rx_dtmf_idx = 0;
|
||||||
void loop() {
|
void loop() {
|
||||||
|
|
||||||
// look for tone
|
// look for tone
|
||||||
if (radio.getDTMFSample() != 0) {
|
if (radio.getDTMFSample() != 0) {
|
||||||
uint16_t code = radio.getDTMFCode();
|
uint16_t code = radio.getDTMFCode();
|
||||||
if (code < 10) {
|
|
||||||
Serial.println(code);
|
rx_dtmf_buf[rx_dtmf_idx++] = code2char(code);
|
||||||
} else if (code < 0xE) {
|
|
||||||
Serial.println(code, HEX);
|
// reset after this tone
|
||||||
} else if (code == 0xE) {
|
|
||||||
Serial.println('*');
|
|
||||||
} else if (code == 0xF) {
|
|
||||||
Serial.println('#');
|
|
||||||
} else {
|
|
||||||
Serial.println('?'); // invalid code
|
|
||||||
}
|
|
||||||
int j = 0;
|
int j = 0;
|
||||||
while (j < 4) {
|
while (j < 4) {
|
||||||
if (radio.getDTMFSample() == 0) {
|
if (radio.getDTMFSample() == 0) {
|
||||||
|
@ -114,11 +109,48 @@ void loop() {
|
||||||
}
|
}
|
||||||
delay(10);
|
delay(10);
|
||||||
}
|
}
|
||||||
|
} else if (rx_dtmf_idx > 0) {
|
||||||
|
rx_dtmf_buf[rx_dtmf_idx] = '\0'; // NULL terminate the string
|
||||||
|
Serial.println(rx_dtmf_buf);
|
||||||
|
rx_dtmf_idx = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is it time to send tone?
|
// Is it time to send tone?
|
||||||
if (Serial.available()) {
|
if (Serial.available()) {
|
||||||
char c = Serial.read();
|
uint8_t code = char2code(Serial.read());
|
||||||
|
|
||||||
|
// start transmitting
|
||||||
|
radio.setDTMFCode(code); // set first
|
||||||
|
radio.setTxSourceTones();
|
||||||
|
radio.setModeTransmit();
|
||||||
|
delay(300); // wait for TX to come to full power
|
||||||
|
|
||||||
|
bool dtmf_to_tx = true;
|
||||||
|
while (dtmf_to_tx) {
|
||||||
|
// wait until ready
|
||||||
|
while (radio.getDTMFTxActive() != 1) {
|
||||||
|
// wait until we're ready for a new code
|
||||||
|
delay(10);
|
||||||
|
}
|
||||||
|
while (radio.getDTMFTxActive() != 0) {
|
||||||
|
// wait until this code is done
|
||||||
|
delay(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Serial.available()) {
|
||||||
|
code = char2code(Serial.read());
|
||||||
|
radio.setDTMFCode(code); // set first
|
||||||
|
} else {
|
||||||
|
dtmf_to_tx = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// done with tone
|
||||||
|
radio.setModeReceive();
|
||||||
|
radio.setTxSourceMic();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t char2code(char c) {
|
||||||
uint8_t code;
|
uint8_t code;
|
||||||
if (c == '#') {
|
if (c == '#') {
|
||||||
code = 0xF;
|
code = 0xF;
|
||||||
|
@ -130,29 +162,25 @@ void loop() {
|
||||||
code = c - '0';
|
code = c - '0';
|
||||||
} else {
|
} else {
|
||||||
// invalid code, skip it
|
// invalid code, skip it
|
||||||
Serial.println('?');
|
code = 255;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// start transmitting
|
return code;
|
||||||
radio.setDTMFCode(code); // set first
|
}
|
||||||
radio.setTxSourceTones();
|
|
||||||
radio.setModeTransmit();
|
char code2char(uint16_t code) {
|
||||||
delay(300); // wait for TX to come to full power
|
char c;
|
||||||
|
if (code < 10) {
|
||||||
// wait until ready
|
c = '0' + code;
|
||||||
while (radio.getDTMFTxActive() != 1) {
|
} else if (code < 0xE) {
|
||||||
// wait until we're ready for a new code
|
c = 'A' + code - 10;
|
||||||
delay(10);
|
} else if (code == 0xE) {
|
||||||
}
|
c = '*';
|
||||||
radio.setDTMFCode(code);
|
} else if (code == 0xF) {
|
||||||
while (radio.getDTMFTxActive() != 0) {
|
c = '#';
|
||||||
// wait until this code is done
|
} else {
|
||||||
delay(10);
|
c = '?'; // invalid code
|
||||||
}
|
}
|
||||||
|
|
||||||
// done with tone
|
return c;
|
||||||
radio.setModeReceive();
|
|
||||||
radio.setTxSourceMic();
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -995,7 +995,7 @@ void HamShield::enableDTMFReceive(){
|
||||||
|
|
||||||
//HSwriteBitsW(devAddr, 0x57, 0, 1, 1); // send dtmf to speaker out
|
//HSwriteBitsW(devAddr, 0x57, 0, 1, 1); // send dtmf to speaker out
|
||||||
|
|
||||||
// turn on pre/de-emphasis
|
// bypass pre/de-emphasis
|
||||||
HSwriteBitsW(devAddr, A1846S_EMPH_FILTER_REG, A1846S_EMPH_FILTER_EN, 1, 1);
|
HSwriteBitsW(devAddr, A1846S_EMPH_FILTER_REG, A1846S_EMPH_FILTER_EN, 1, 1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue