minor morse updates

This commit is contained in:
Morgan Redfield 2019-05-11 15:32:13 -07:00
parent 12fd074aed
commit 7e509ca0fc
2 changed files with 34 additions and 11 deletions

View File

@ -20,13 +20,13 @@
#define SWITCH_PIN 2 #define SWITCH_PIN 2
#define MORSE_FREQ 600 #define MORSE_FREQ 600
#define MORSE_DOT 100 // ms #define MORSE_DOT 150 // ms
// Note that all timing is defined in terms of MORSE_DOT relative durations // Note that all timing is defined in terms of MORSE_DOT relative durations
// You may want to tweak those timings below // You may want to tweak those timings below
#define SYMBOL_END_TIME 5 //millis #define SYMBOL_END_TIME 5 //millis
#define CHAR_END_TIME (MORSE_DOT*2.3) #define CHAR_END_TIME (MORSE_DOT*2.7)
#define MESSAGE_END_TIME (MORSE_DOT*15) #define MESSAGE_END_TIME (MORSE_DOT*8)
#define MIN_DOT_TIME (MORSE_DOT*0.7) #define MIN_DOT_TIME (MORSE_DOT*0.7)
#define MAX_DOT_TIME (MORSE_DOT*1.3) #define MAX_DOT_TIME (MORSE_DOT*1.3)
@ -41,6 +41,7 @@ uint32_t tone_in_progress; // track how long the current tone lasts
uint32_t space_in_progress; // track how long since the last tone uint32_t space_in_progress; // track how long since the last tone
uint8_t rx_morse_char; uint8_t rx_morse_char;
uint8_t rx_morse_bit; uint8_t rx_morse_bit;
bool bits_to_process;
char rx_msg[128]; char rx_msg[128];
uint8_t rx_idx; uint8_t rx_idx;
@ -92,6 +93,9 @@ void setup() {
rx_morse_char = 0; // haven't found any tones yet rx_morse_char = 0; // haven't found any tones yet
rx_idx = 0; rx_idx = 0;
rx_morse_bit = 1; rx_morse_bit = 1;
bits_to_process = false;
radio.bypassPreDeEmph();
} }
void loop() { void loop() {
@ -101,6 +105,7 @@ void loop() {
if (tone_in_progress == 0) { if (tone_in_progress == 0) {
// start a new tone // start a new tone
tone_in_progress = millis(); tone_in_progress = millis();
//Serial.print('t');
} }
} else { } else {
// keep track of how long the silence is // keep track of how long the silence is
@ -119,8 +124,9 @@ void loop() {
} }
// we might be done with a character if the space is long enough // we might be done with a character if the space is long enough
if ((millis() - space_in_progress) > CHAR_END_TIME) { if (((millis() - space_in_progress) > CHAR_END_TIME) && bits_to_process) {
char m = parseMorse(); char m = parseMorse();
bits_to_process = false;
if (m != 0) { if (m != 0) {
rx_msg[rx_idx++] = m; rx_msg[rx_idx++] = m;
} }
@ -162,6 +168,7 @@ void loop() {
// We're done sending the message, set the radio back into recieve mode. // We're done sending the message, set the radio back into recieve mode.
radio.setModeReceive(); radio.setModeReceive();
radio.lookForTone(MORSE_FREQ);
Serial.println("sent"); Serial.println("sent");
} else { } else {
// If we get here, the channel is busy. Let's also print out the RSSI. // If we get here, the channel is busy. Let's also print out the RSSI.
@ -176,10 +183,12 @@ void handleTone(uint16_t tone_time) {
if (tone_time > MIN_DOT_TIME && tone_time < MAX_DOT_TIME) { if (tone_time > MIN_DOT_TIME && tone_time < MAX_DOT_TIME) {
// add a dot // add a dot
//Serial.print("."); //Serial.print(".");
bits_to_process = true;
//nothing to do for this bit position, since . = 0 //nothing to do for this bit position, since . = 0
} else if (tone_time > MIN_DASH_TIME && tone_time < MAX_DASH_TIME) { } else if (tone_time > MIN_DASH_TIME && tone_time < MAX_DASH_TIME) {
// add a dash // add a dash
//Serial.print("-"); //Serial.print("-");
bits_to_process = true;
rx_morse_char += rx_morse_bit; rx_morse_char += rx_morse_bit;
} }
@ -200,4 +209,3 @@ char parseMorse() {
rx_morse_bit = 1; rx_morse_bit = 1;
return c; return c;
} }

View File

@ -18,6 +18,7 @@
/* don't change this regulatory value, use dangerMode() and safeMode() instead */ /* don't change this regulatory value, use dangerMode() and safeMode() instead */
bool restrictions = true; bool restrictions = true;
uint16_t old_dtmf_reg;
/* channel lookup tables */ /* channel lookup tables */
@ -232,6 +233,9 @@ void HamShield::initialize(bool narrowBand) {
setDTMFIdleTime(50); setDTMFIdleTime(50);
setDTMFTxTime(60); setDTMFTxTime(60);
setDTMFDetectTime(24); setDTMFDetectTime(24);
HSreadWord(devAddr, A1846S_DTMF_ENABLE_REG, radio_i2c_buf);
old_dtmf_reg = radio_i2c_buf[0];
} }
@ -1066,18 +1070,24 @@ void HamShield::setDTMFCode(uint16_t code){
void HamShield::HStone(uint8_t pin, unsigned int frequency) { void HamShield::HStone(uint8_t pin, unsigned int frequency) {
HSreadWord(devAddr, A1846S_DTMF_ENABLE_REG, radio_i2c_buf);
old_dtmf_reg = radio_i2c_buf[0];
HSwriteBitsW(devAddr, 0x79, 15, 2, 0x3); // transmit single tone (not dtmf) HSwriteBitsW(devAddr, 0x79, 15, 2, 0x3); // transmit single tone (not dtmf)
HSwriteBitsW(devAddr, A1846S_DTMF_ENABLE_REG, 15, 2, 0x1); // transmit single tone (not dtmf) HSwriteBitsW(devAddr, A1846S_DTMF_ENABLE_REG, A1846S_DTMF_ENABLE_BIT, 2, 0x2); // transmit single tone (not dtmf)
// bypass pre/de-emphasis // bypass pre/de-emphasis
HSwriteBitsW(devAddr, A1846S_FILTER_REG, A1846S_EMPH_FILTER_EN, 1, 1); HSwriteBitsW(devAddr, A1846S_FILTER_REG, A1846S_EMPH_FILTER_EN, 1, 1);
HSwriteWord(devAddr, A1846S_TONE1_FREQ, frequency*10); HSwriteWord(devAddr, A1846S_TONE1_FREQ, frequency*10);
setTxSourceTone1(); setTxSourceTone1();
//tone(pin, frequency);
} }
void HamShield::HSnoTone(uint8_t pin) { void HamShield::HSnoTone(uint8_t pin) {
HSwriteBitsW(devAddr, A1846S_DTMF_ENABLE_REG, 15, 2, 0x0); // disable tone and dtmf HSwriteWord(devAddr, A1846S_DTMF_ENABLE_REG, old_dtmf_reg); // disable tone and dtmf
setTxSourceMic(); setTxSourceMic();
// noTone(pin);
} }
// Tone detection // Tone detection
@ -1611,6 +1621,7 @@ void HamShield::morseOut(char buffer[HAMSHIELD_MORSE_BUFFER_SIZE]) {
int i; int i;
char prev = 0; char prev = 0;
for(i = 0; buffer[i] != '\0' && i < HAMSHIELD_MORSE_BUFFER_SIZE; prev = buffer[i], i++) { for(i = 0; buffer[i] != '\0' && i < HAMSHIELD_MORSE_BUFFER_SIZE; prev = buffer[i], i++) {
// On a space, delay 7 dots // On a space, delay 7 dots
if(buffer[i] == ' ') { if(buffer[i] == ' ') {
// We delay by 4 here, if we previously sent a symbol. Otherwise 7. // We delay by 4 here, if we previously sent a symbol. Otherwise 7.
@ -1619,10 +1630,12 @@ void HamShield::morseOut(char buffer[HAMSHIELD_MORSE_BUFFER_SIZE]) {
//tone(hs_mic_pin, 6000, morse_dot_millis * 7); //tone(hs_mic_pin, 6000, morse_dot_millis * 7);
HSnoTone(hs_mic_pin); HSnoTone(hs_mic_pin);
HSdelay(morse_dot_millis*7); HSdelay(morse_dot_millis*7);
//Serial.print(" ");
} else { } else {
//tone(hs_mic_pin, 6000, morse_dot_millis * 4); //tone(hs_mic_pin, 6000, morse_dot_millis * 4);
HSnoTone(hs_mic_pin); HSnoTone(hs_mic_pin);
HSdelay(morse_dot_millis*4); HSdelay(morse_dot_millis*4);
//Serial.print(" ");
} }
continue; continue;
} }
@ -1634,14 +1647,16 @@ void HamShield::morseOut(char buffer[HAMSHIELD_MORSE_BUFFER_SIZE]) {
HStone(hs_mic_pin, morse_freq);//, morse_dot_millis * 3); HStone(hs_mic_pin, morse_freq);//, morse_dot_millis * 3);
HSdelay(morse_dot_millis*3); HSdelay(morse_dot_millis*3);
HSnoTone(hs_mic_pin); HSnoTone(hs_mic_pin);
//Serial.print('-');
} else { } else {
HStone(hs_mic_pin, morse_freq);//, morse_dot_millis); HStone(hs_mic_pin, morse_freq);//, morse_dot_millis);
HSdelay(morse_dot_millis); HSdelay(morse_dot_millis);
HSnoTone(hs_mic_pin); HSnoTone(hs_mic_pin);
//Serial.print('.');
} }
//tone(hs_mic_pin, 6000, morse_dot_millis); //tone(hs_mic_pin, 6000, morse_dot_millis);
HSnoTone(hs_mic_pin); HSnoTone(hs_mic_pin);
HSdelay(morse_dot_millis); HSdelay(morse_dot_millis); // delay between elements
bits >>= 1; // Shift into the next symbol bits >>= 1; // Shift into the next symbol
} while(bits != 1); // Wait for 1 termination to be all we have left } while(bits != 1); // Wait for 1 termination to be all we have left
} }