Alter morseOut to use a for loop and clearer dit/dah timing in the tone.

Back up to 1000Hz tones.
This commit is contained in:
Stephen Olesen 2015-06-30 15:30:06 -06:00
parent 1c7dbfc4b6
commit fc09429133
1 changed files with 7 additions and 5 deletions

View File

@ -1268,12 +1268,13 @@ bool HamShield::waitForChannel(long timeout = 0, long breakwindow = 0, int setRS
/* 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]) {
int i = 0; int i;
char prev = 0; char prev = 0;
while(buffer[i] != '\0' && i < HAMSHIELD_MORSE_BUFFER_SIZE) { 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.
// This could probably just be always 7 and go relatively unnoticed.
if(prev == 0 || prev == ' ') if(prev == 0 || prev == ' ')
delay(HAMSHIELD_MORSE_DOT*7); delay(HAMSHIELD_MORSE_DOT*7);
else else
@ -1284,15 +1285,16 @@ void HamShield::morseOut(char buffer[HAMSHIELD_MORSE_BUFFER_SIZE]) {
uint8_t bits = morseLookup(buffer[i]); uint8_t bits = morseLookup(buffer[i]);
if(bits) { // If it is a valid character... if(bits) { // If it is a valid character...
do { do {
tone(HAMSHIELD_PWM_PIN, 600, HAMSHIELD_MORSE_DOT * (bits & 1 ? 3 : 1)); if(bits & 1)
tone(HAMSHIELD_PWM_PIN, 1000, HAMSHIELD_MORSE_DOT * 3);
else
tone(HAMSHIELD_PWM_PIN, 1000, HAMSHIELD_MORSE_DOT);
delay(HAMSHIELD_MORSE_DOT); delay(HAMSHIELD_MORSE_DOT);
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
delay(HAMSHIELD_MORSE_DOT * 3); delay(HAMSHIELD_MORSE_DOT * 3);
prev = buffer[i];
i++;
} }
return; return;
} }