From 9d0dac76689aa84c62e0356b0b2bc05cab9dce6c Mon Sep 17 00:00:00 2001 From: Jason Milldrum Date: Mon, 15 Jan 2018 17:22:20 -0800 Subject: [PATCH] Add support for no output pin toggling --- README.md | 5 +++-- src/Morse.cpp | 28 ++++++++++++++++++++++------ src/Morse.h | 1 - 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index dbc240e..684a2bd 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ If you need to check to see if the Morse library is currently sending the conten The sending speed can be changed on-the-fly by using the _setWPM()_ method. The parameter is typed using a _float_ so that fractional words per minute can be specified. Why would you want to do this? In case you need to send Morse code using a very long integration time such as with the QRSS operating mode. For example, a setting of 0.2 WPM sets a Morse code "dit" length of 6 seconds. -If you don't want to have the library directly control a digital I/O pin, you may have your sketch poll the boolean _tx_ member variable and act on it accordingly within their periodic 1 ms function. +If you don't want to have the library directly control a digital I/O pin, you may have your sketch poll the boolean _tx_ member variable and act on it accordingly within their periodic 1 ms function. Set the output pin parameter in the constructor to 0. Startup Conditions and Constraints ---------------------------------- @@ -61,7 +61,8 @@ Public Methods * * Create an instance of the Morse class. * - * tx_pin - Arduino pin used as the output by this library. + * tx_pin - Arduino pin used as the output by this library. Will not toggle an + * output pin if set to 0. * init_wpm - Sending speed in words per minute. * */ diff --git a/src/Morse.cpp b/src/Morse.cpp index d1b332b..27ab094 100644 --- a/src/Morse.cpp +++ b/src/Morse.cpp @@ -36,7 +36,8 @@ * * Create an instance of the Morse class. * - * tx_pin - Arduino pin used as the output by this library. + * tx_pin - Arduino pin used as the output by this library. Will not toggle an + * output pin if set to 0. * init_wpm - Sending speed in words per minute. * */ @@ -48,7 +49,10 @@ Morse::Morse(uint8_t tx_pin, float init_wpm) : output_pin(tx_pin) setWPM(init_wpm); - pinMode(output_pin, OUTPUT); + if(output_pin) + { + pinMode(output_pin, OUTPUT); + } cur_state = State::IDLE; next_state = State::IDLE; @@ -223,7 +227,10 @@ void Morse::update() case State::PREAMBLE: // Transmitter on tx = true; - digitalWrite(output_pin, HIGH); + if(output_pin) + { + digitalWrite(output_pin, HIGH); + } // When done waiting, go back to IDLE state to start the message if(cur_timer > cur_state_end) @@ -235,12 +242,18 @@ void Morse::update() case State::DIT: case State::DAH: tx = true; - digitalWrite(output_pin, HIGH); + if(output_pin) + { + digitalWrite(output_pin, HIGH); + } if(cur_timer > cur_state_end) { tx = false; - digitalWrite(output_pin, LOW); + if(output_pin) + { + digitalWrite(output_pin, LOW); + } cur_state_end = cur_timer + dit_length; cur_state = State::DITDELAY; @@ -252,7 +265,10 @@ void Morse::update() case State::MSGDELAY: case State::EOMDELAY: tx = false; - digitalWrite(output_pin, LOW); + if(output_pin) + { + digitalWrite(output_pin, LOW); + } if(cur_timer > cur_state_end) { diff --git a/src/Morse.h b/src/Morse.h index 49e9587..aec69a7 100644 --- a/src/Morse.h +++ b/src/Morse.h @@ -28,7 +28,6 @@ #include "Arduino.h" - // Constants constexpr uint8_t DEFAULT_OUTPUT_PIN = LED_BUILTIN; constexpr float DEFAULT_WPM = 25;