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 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
// You may want to tweak those timings below
#define SYMBOL_END_TIME 5 //millis
#define CHAR_END_TIME (MORSE_DOT*2.3)
#define MESSAGE_END_TIME (MORSE_DOT*15)
#define CHAR_END_TIME (MORSE_DOT*2.7)
#define MESSAGE_END_TIME (MORSE_DOT*8)
#define MIN_DOT_TIME (MORSE_DOT*0.7)
#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
uint8_t rx_morse_char;
uint8_t rx_morse_bit;
bool bits_to_process;
char rx_msg[128];
uint8_t rx_idx;
@ -92,6 +93,9 @@ void setup() {
rx_morse_char = 0; // haven't found any tones yet
rx_idx = 0;
rx_morse_bit = 1;
bits_to_process = false;
radio.bypassPreDeEmph();
}
void loop() {
@ -101,6 +105,7 @@ void loop() {
if (tone_in_progress == 0) {
// start a new tone
tone_in_progress = millis();
//Serial.print('t');
}
} else {
// 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
if ((millis() - space_in_progress) > CHAR_END_TIME) {
if (((millis() - space_in_progress) > CHAR_END_TIME) && bits_to_process) {
char m = parseMorse();
bits_to_process = false;
if (m != 0) {
rx_msg[rx_idx++] = m;
}
@ -162,6 +168,7 @@ void loop() {
// We're done sending the message, set the radio back into recieve mode.
radio.setModeReceive();
radio.lookForTone(MORSE_FREQ);
Serial.println("sent");
} else {
// 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) {
// add a dot
//Serial.print(".");
bits_to_process = true;
//nothing to do for this bit position, since . = 0
} else if (tone_time > MIN_DASH_TIME && tone_time < MAX_DASH_TIME) {
// add a dash
//Serial.print("-");
bits_to_process = true;
rx_morse_char += rx_morse_bit;
}
@ -200,4 +209,3 @@ char parseMorse() {
rx_morse_bit = 1;
return c;
}

View File

@ -18,6 +18,7 @@
/* don't change this regulatory value, use dangerMode() and safeMode() instead */
bool restrictions = true;
uint16_t old_dtmf_reg;
/* channel lookup tables */
@ -232,6 +233,9 @@ void HamShield::initialize(bool narrowBand) {
setDTMFIdleTime(50);
setDTMFTxTime(60);
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) {
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, 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
HSwriteBitsW(devAddr, A1846S_FILTER_REG, A1846S_EMPH_FILTER_EN, 1, 1);
HSwriteWord(devAddr, A1846S_TONE1_FREQ, frequency*10);
setTxSourceTone1();
//tone(pin, frequency);
}
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();
// noTone(pin);
}
// Tone detection
@ -1611,6 +1621,7 @@ void HamShield::morseOut(char buffer[HAMSHIELD_MORSE_BUFFER_SIZE]) {
int i;
char prev = 0;
for(i = 0; buffer[i] != '\0' && i < HAMSHIELD_MORSE_BUFFER_SIZE; prev = buffer[i], i++) {
// On a space, delay 7 dots
if(buffer[i] == ' ') {
// We delay by 4 here, if we previously sent a symbol. Otherwise 7.
@ -1618,11 +1629,13 @@ void HamShield::morseOut(char buffer[HAMSHIELD_MORSE_BUFFER_SIZE]) {
if(prev == 0 || prev == ' '){
//tone(hs_mic_pin, 6000, morse_dot_millis * 7);
HSnoTone(hs_mic_pin);
HSdelay(morse_dot_millis*7);
HSdelay(morse_dot_millis*7);
//Serial.print(" ");
} else {
//tone(hs_mic_pin, 6000, morse_dot_millis * 4);
HSnoTone(hs_mic_pin);
HSdelay(morse_dot_millis*4);
HSdelay(morse_dot_millis*4);
//Serial.print(" ");
}
continue;
}
@ -1634,14 +1647,16 @@ void HamShield::morseOut(char buffer[HAMSHIELD_MORSE_BUFFER_SIZE]) {
HStone(hs_mic_pin, morse_freq);//, morse_dot_millis * 3);
HSdelay(morse_dot_millis*3);
HSnoTone(hs_mic_pin);
//Serial.print('-');
} else {
HStone(hs_mic_pin, morse_freq);//, morse_dot_millis);
HSdelay(morse_dot_millis);
HSnoTone(hs_mic_pin);
//Serial.print('.');
}
//tone(hs_mic_pin, 6000, morse_dot_millis);
HSnoTone(hs_mic_pin);
HSdelay(morse_dot_millis);
HSdelay(morse_dot_millis); // delay between elements
bits >>= 1; // Shift into the next symbol
} while(bits != 1); // Wait for 1 termination to be all we have left
}