make morse dot duration user settable

This commit is contained in:
morgan 2016-12-19 11:53:36 -08:00
parent 5874e6b8e5
commit 292a774a79
3 changed files with 28 additions and 13 deletions

View File

@ -54,6 +54,7 @@ void setup() {
radio.setRfPower(0); radio.setRfPower(0);
radio.setMorseFreq(400); radio.setMorseFreq(400);
radio.setMorseDotMillis(200);
// Configure the HamShield to transmit and recieve on 446.000MHz // Configure the HamShield to transmit and recieve on 446.000MHz
radio.frequency(438000); radio.frequency(438000);

View File

@ -26,6 +26,7 @@ const uint32_t WX[] PROGMEM = {0,162550,162400,162475,162425,162450,162500,16252
unsigned int morse_freq = 600; unsigned int morse_freq = 600;
unsigned int morse_dot_millis = 100;
/* morse code lookup table */ /* morse code lookup table */
// This is the Morse table in reverse binary format. // This is the Morse table in reverse binary format.
@ -1298,6 +1299,18 @@ void HamShield::setMorseFreq(unsigned int morse_freq_hz) {
morse_freq = morse_freq_hz; morse_freq = morse_freq_hz;
} }
// Get current duration of a morse dot (shorter is more WPM)
unsigned int HamShield::getMorseDotMillis() {
return morse_dot_millis;
}
// Set current duration of a morse dot (shorter is more WPM)
void HamShield::setMorseDotMillis(unsigned int morse_dot_dur_millis) {
morse_dot_millis = morse_dot_dur_millis;
}
/* Morse code out, blocking */ /* Morse code out, blocking */
void HamShield::morseOut(char buffer[HAMSHIELD_MORSE_BUFFER_SIZE]) { void HamShield::morseOut(char buffer[HAMSHIELD_MORSE_BUFFER_SIZE]) {
@ -1309,11 +1322,11 @@ void HamShield::morseOut(char buffer[HAMSHIELD_MORSE_BUFFER_SIZE]) {
// 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.
// This could probably just be always 7 and go relatively unnoticed. // This could probably just be always 7 and go relatively unnoticed.
if(prev == 0 || prev == ' '){ if(prev == 0 || prev == ' '){
tone(HAMSHIELD_PWM_PIN, 6000, HAMSHIELD_MORSE_DOT * 7); tone(HAMSHIELD_PWM_PIN, 6000, morse_dot_millis * 7);
delay(HAMSHIELD_MORSE_DOT*7); delay(morse_dot_millis*7);
} else { } else {
tone(HAMSHIELD_PWM_PIN, 6000, HAMSHIELD_MORSE_DOT * 4); tone(HAMSHIELD_PWM_PIN, 6000, morse_dot_millis * 4);
delay(HAMSHIELD_MORSE_DOT*4); delay(morse_dot_millis*4);
} }
continue; continue;
} }
@ -1322,20 +1335,20 @@ void HamShield::morseOut(char buffer[HAMSHIELD_MORSE_BUFFER_SIZE]) {
if(bits) { // If it is a valid character... if(bits) { // If it is a valid character...
do { do {
if(bits & 1) { if(bits & 1) {
tone(HAMSHIELD_PWM_PIN, morse_freq, HAMSHIELD_MORSE_DOT * 3); tone(HAMSHIELD_PWM_PIN, morse_freq, morse_dot_millis * 3);
delay(HAMSHIELD_MORSE_DOT*3); delay(morse_dot_millis*3);
} else { } else {
tone(HAMSHIELD_PWM_PIN, morse_freq, HAMSHIELD_MORSE_DOT); tone(HAMSHIELD_PWM_PIN, morse_freq, morse_dot_millis);
delay(HAMSHIELD_MORSE_DOT); delay(morse_dot_millis);
} }
tone(HAMSHIELD_PWM_PIN, 6000, HAMSHIELD_MORSE_DOT); tone(HAMSHIELD_PWM_PIN, 6000, morse_dot_millis);
delay(HAMSHIELD_MORSE_DOT); delay(morse_dot_millis);
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
} }
// End of character // End of character
tone(HAMSHIELD_PWM_PIN, 6000, HAMSHIELD_MORSE_DOT * 3); tone(HAMSHIELD_PWM_PIN, 6000, morse_dot_millis * 3);
delay(HAMSHIELD_MORSE_DOT * 3); delay(morse_dot_millis * 3);
} }
return; return;
} }

View File

@ -16,7 +16,6 @@
// HamShield constants // HamShield constants
#define HAMSHIELD_MORSE_DOT 100 // Morse code dot length (smaller is faster WPM)
#define HAMSHIELD_MORSE_BUFFER_SIZE 80 // Char buffer size for morse code text #define HAMSHIELD_MORSE_BUFFER_SIZE 80 // Char buffer size for morse code text
#define HAMSHIELD_AUX_BUTTON 2 // Pin assignment for AUX button #define HAMSHIELD_AUX_BUTTON 2 // Pin assignment for AUX button
#define HAMSHIELD_PWM_PIN 3 // Pin assignment for PWM output #define HAMSHIELD_PWM_PIN 3 // Pin assignment for PWM output
@ -483,6 +482,8 @@ class HamShield {
static void isr_reset(); static void isr_reset();
unsigned int getMorseFreq(); unsigned int getMorseFreq();
void setMorseFreq(unsigned int morse_freq_hz); void setMorseFreq(unsigned int morse_freq_hz);
unsigned int getMorseDotMillis();
void setMorseDotMillis(unsigned int morse_dot_dur_millis);
void morseOut(char buffer[HAMSHIELD_MORSE_BUFFER_SIZE]); void morseOut(char buffer[HAMSHIELD_MORSE_BUFFER_SIZE]);
uint8_t morseLookup(char letter); uint8_t morseLookup(char letter);
bool waitForChannel(long timeout, long breakwindow, int setRSSI); bool waitForChannel(long timeout, long breakwindow, int setRSSI);