From 29813352d4a5e2805368fd87a57209c6e98a1781 Mon Sep 17 00:00:00 2001 From: jgromes Date: Fri, 18 Nov 2022 13:54:12 +0100 Subject: [PATCH] [SSTV] Moved correction factor to its own method --- examples/SSTV/SSTV_Transmit/SSTV_Transmit.ino | 14 ++++++++-- .../SSTV_Transmit_AFSK/SSTV_Transmit_AFSK.ino | 14 ++++++++-- src/protocols/SSTV/SSTV.cpp | 26 ++++++++++++------- src/protocols/SSTV/SSTV.h | 15 +++++++---- 4 files changed, 51 insertions(+), 18 deletions(-) diff --git a/examples/SSTV/SSTV_Transmit/SSTV_Transmit.ino b/examples/SSTV/SSTV_Transmit/SSTV_Transmit.ino index 3a189c98..e532e2d4 100644 --- a/examples/SSTV/SSTV_Transmit/SSTV_Transmit.ino +++ b/examples/SSTV/SSTV_Transmit/SSTV_Transmit.ino @@ -107,7 +107,16 @@ void setup() { Serial.print(F("[SSTV] Initializing ... ")); // 0 Hz tone frequency: 434.0 MHz // SSTV mode: Wrasse (SC2-180) - // correction factor: 0.95 + state = sstv.begin(434.0, Wrasse); + if(state == RADIOLIB_ERR_NONE) { + Serial.println(F("success!")); + } else { + Serial.print(F("failed, code ")); + Serial.println(state); + while(true); + } + + // set correction factor // NOTE: Due to different speeds of various platforms // supported by RadioLib (Arduino Uno, ESP32 etc), // and because SSTV is analog protocol, incorrect @@ -116,7 +125,8 @@ void setup() { // to adjust the length of timing pulses // (lower number = shorter pulses). // The value is usually around 0.95 (95%). - state = sstv.begin(434.0, Wrasse, 0.95); + Serial.print(F("[SSTV] Setting correction ... ")); + state = sstv.setCorrection(0.95); if(state == RADIOLIB_ERR_NONE) { Serial.println(F("success!")); } else { diff --git a/examples/SSTV/SSTV_Transmit_AFSK/SSTV_Transmit_AFSK.ino b/examples/SSTV/SSTV_Transmit_AFSK/SSTV_Transmit_AFSK.ino index 8678fa71..4719adaf 100644 --- a/examples/SSTV/SSTV_Transmit_AFSK/SSTV_Transmit_AFSK.ino +++ b/examples/SSTV/SSTV_Transmit_AFSK/SSTV_Transmit_AFSK.ino @@ -105,7 +105,16 @@ void setup() { // initialize SSTV client Serial.print(F("[SSTV] Initializing ... ")); // SSTV mode: Wrasse (SC2-180) - // correction factor: 0.95 + state = sstv.begin(Wrasse); + if(state == RADIOLIB_ERR_NONE) { + Serial.println(F("success!")); + } else { + Serial.print(F("failed, code ")); + Serial.println(state); + while(true); + } + + // set correction factor // NOTE: Due to different speeds of various platforms // supported by RadioLib (Arduino Uno, ESP32 etc), // and because SSTV is analog protocol, incorrect @@ -114,7 +123,8 @@ void setup() { // to adjust the length of timing pulses // (lower number = shorter pulses). // The value is usually around 0.95 (95%). - state = sstv.begin(Wrasse, 0.95); + Serial.print(F("[SSTV] Setting correction ... ")); + state = sstv.setCorrection(0.95); if(state == RADIOLIB_ERR_NONE) { Serial.println(F("success!")); } else { diff --git a/src/protocols/SSTV/SSTV.cpp b/src/protocols/SSTV/SSTV.cpp index ec5957c5..d8fda186 100644 --- a/src/protocols/SSTV/SSTV.cpp +++ b/src/protocols/SSTV/SSTV.cpp @@ -169,26 +169,20 @@ SSTVClient::SSTVClient(AFSKClient* audio) { #endif #if !defined(RADIOLIB_EXCLUDE_AFSK) -int16_t SSTVClient::begin(const SSTVMode_t& mode, float correction) { +int16_t SSTVClient::begin(const SSTVMode_t& mode) { if(_audio == nullptr) { // this initialization method can only be used in AFSK mode return(RADIOLIB_ERR_WRONG_MODEM); } - return(begin(0, mode, correction)); + return(begin(0, mode)); } #endif -int16_t SSTVClient::begin(float base, const SSTVMode_t& mode, float correction) { +int16_t SSTVClient::begin(float base, const SSTVMode_t& mode) { // save mode _mode = mode; - // apply correction factor to all timings - _mode.scanPixelLen *= correction; - for(uint8_t i = 0; i < _mode.numTones; i++) { - _mode.tones[i].len *= correction; - } - // calculate 24-bit frequency _base = (base * 1000000.0) / _phy->getFreqStep(); @@ -196,6 +190,20 @@ int16_t SSTVClient::begin(float base, const SSTVMode_t& mode, float correction) return(_phy->startDirect()); } +int16_t SSTVClient::setCorrection(float correction) { + // check if mode is initialized + if(_mode.visCode == 0) { + return(RADIOLIB_ERR_WRONG_MODEM); + } + + // apply correction factor to all timings + _mode.scanPixelLen *= correction; + for(uint8_t i = 0; i < _mode.numTones; i++) { + _mode.tones[i].len *= correction; + } + return(RADIOLIB_ERR_NONE); +} + void SSTVClient::idle() { _phy->transmitDirect(); this->tone(RADIOLIB_SSTV_TONE_LEADER); diff --git a/src/protocols/SSTV/SSTV.h b/src/protocols/SSTV/SSTV.h index f24053e4..5a094cd6 100644 --- a/src/protocols/SSTV/SSTV.h +++ b/src/protocols/SSTV/SSTV.h @@ -144,11 +144,9 @@ class SSTVClient { \param mode SSTV mode to be used. Currently supported modes are Scottie1, Scottie2, ScottieDX, Martin1, Martin2, Wrasse, PasokonP3, PasokonP5 and PasokonP7. - \param correction Timing correction factor, used to adjust the length of timing pulses. Less than 1.0 leads to shorter timing pulses, defaults to 1.0 (no correction). - \returns \ref status_codes */ - int16_t begin(float base, const SSTVMode_t& mode, float correction = 1.0); + int16_t begin(float base, const SSTVMode_t& mode); #if !defined(RADIOLIB_EXCLUDE_AFSK) /*! @@ -156,12 +154,19 @@ class SSTVClient { \param mode SSTV mode to be used. Currently supported modes are Scottie1, Scottie2, ScottieDX, Martin1, Martin2, Wrasse, PasokonP3, PasokonP5 and PasokonP7. + \returns \ref status_codes + */ + int16_t begin(const SSTVMode_t& mode); + #endif + + /*! + \brief Set correction coefficient for tone length. + \param correction Timing correction factor, used to adjust the length of timing pulses. Less than 1.0 leads to shorter timing pulses, defaults to 1.0 (no correction). \returns \ref status_codes */ - int16_t begin(const SSTVMode_t& mode, float correction = 1.0); - #endif + int16_t setCorrection(float correction); /*! \brief Sends out tone at 1900 Hz.