From 292a774a79e54244dbc176ec2a8f11582c9f740e Mon Sep 17 00:00:00 2001 From: morgan Date: Mon, 19 Dec 2016 11:53:36 -0800 Subject: [PATCH] make morse dot duration user settable --- examples/FMBeacon/FMBeacon.ino | 1 + src/HamShield.cpp | 37 +++++++++++++++++++++++----------- src/HamShield.h | 3 ++- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/examples/FMBeacon/FMBeacon.ino b/examples/FMBeacon/FMBeacon.ino index 98042fd..8252781 100644 --- a/examples/FMBeacon/FMBeacon.ino +++ b/examples/FMBeacon/FMBeacon.ino @@ -54,6 +54,7 @@ void setup() { radio.setRfPower(0); radio.setMorseFreq(400); + radio.setMorseDotMillis(200); // Configure the HamShield to transmit and recieve on 446.000MHz radio.frequency(438000); diff --git a/src/HamShield.cpp b/src/HamShield.cpp index 9edd28c..2d7df0b 100644 --- a/src/HamShield.cpp +++ b/src/HamShield.cpp @@ -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_dot_millis = 100; /* morse code lookup table */ // 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; } +// 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 */ 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. // This could probably just be always 7 and go relatively unnoticed. if(prev == 0 || prev == ' '){ - tone(HAMSHIELD_PWM_PIN, 6000, HAMSHIELD_MORSE_DOT * 7); - delay(HAMSHIELD_MORSE_DOT*7); + tone(HAMSHIELD_PWM_PIN, 6000, morse_dot_millis * 7); + delay(morse_dot_millis*7); } else { - tone(HAMSHIELD_PWM_PIN, 6000, HAMSHIELD_MORSE_DOT * 4); - delay(HAMSHIELD_MORSE_DOT*4); + tone(HAMSHIELD_PWM_PIN, 6000, morse_dot_millis * 4); + delay(morse_dot_millis*4); } continue; } @@ -1322,20 +1335,20 @@ void HamShield::morseOut(char buffer[HAMSHIELD_MORSE_BUFFER_SIZE]) { if(bits) { // If it is a valid character... do { if(bits & 1) { - tone(HAMSHIELD_PWM_PIN, morse_freq, HAMSHIELD_MORSE_DOT * 3); - delay(HAMSHIELD_MORSE_DOT*3); + tone(HAMSHIELD_PWM_PIN, morse_freq, morse_dot_millis * 3); + delay(morse_dot_millis*3); } else { - tone(HAMSHIELD_PWM_PIN, morse_freq, HAMSHIELD_MORSE_DOT); - delay(HAMSHIELD_MORSE_DOT); + tone(HAMSHIELD_PWM_PIN, morse_freq, morse_dot_millis); + delay(morse_dot_millis); } - tone(HAMSHIELD_PWM_PIN, 6000, HAMSHIELD_MORSE_DOT); - delay(HAMSHIELD_MORSE_DOT); + tone(HAMSHIELD_PWM_PIN, 6000, morse_dot_millis); + delay(morse_dot_millis); bits >>= 1; // Shift into the next symbol } while(bits != 1); // Wait for 1 termination to be all we have left } // End of character - tone(HAMSHIELD_PWM_PIN, 6000, HAMSHIELD_MORSE_DOT * 3); - delay(HAMSHIELD_MORSE_DOT * 3); + tone(HAMSHIELD_PWM_PIN, 6000, morse_dot_millis * 3); + delay(morse_dot_millis * 3); } return; } diff --git a/src/HamShield.h b/src/HamShield.h index 9093526..a0093bf 100644 --- a/src/HamShield.h +++ b/src/HamShield.h @@ -16,7 +16,6 @@ // 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_AUX_BUTTON 2 // Pin assignment for AUX button #define HAMSHIELD_PWM_PIN 3 // Pin assignment for PWM output @@ -483,6 +482,8 @@ class HamShield { static void isr_reset(); unsigned int getMorseFreq(); 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]); uint8_t morseLookup(char letter); bool waitForChannel(long timeout, long breakwindow, int setRSSI);