[SSTV] Moved correction factor to its own method

This commit is contained in:
jgromes 2022-11-18 13:54:12 +01:00
parent f942ccaec7
commit 29813352d4
4 changed files with 51 additions and 18 deletions

View file

@ -107,7 +107,16 @@ void setup() {
Serial.print(F("[SSTV] Initializing ... ")); Serial.print(F("[SSTV] Initializing ... "));
// 0 Hz tone frequency: 434.0 MHz // 0 Hz tone frequency: 434.0 MHz
// SSTV mode: Wrasse (SC2-180) // 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 // NOTE: Due to different speeds of various platforms
// supported by RadioLib (Arduino Uno, ESP32 etc), // supported by RadioLib (Arduino Uno, ESP32 etc),
// and because SSTV is analog protocol, incorrect // and because SSTV is analog protocol, incorrect
@ -116,7 +125,8 @@ void setup() {
// to adjust the length of timing pulses // to adjust the length of timing pulses
// (lower number = shorter pulses). // (lower number = shorter pulses).
// The value is usually around 0.95 (95%). // 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) { if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!")); Serial.println(F("success!"));
} else { } else {

View file

@ -105,7 +105,16 @@ void setup() {
// initialize SSTV client // initialize SSTV client
Serial.print(F("[SSTV] Initializing ... ")); Serial.print(F("[SSTV] Initializing ... "));
// SSTV mode: Wrasse (SC2-180) // 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 // NOTE: Due to different speeds of various platforms
// supported by RadioLib (Arduino Uno, ESP32 etc), // supported by RadioLib (Arduino Uno, ESP32 etc),
// and because SSTV is analog protocol, incorrect // and because SSTV is analog protocol, incorrect
@ -114,7 +123,8 @@ void setup() {
// to adjust the length of timing pulses // to adjust the length of timing pulses
// (lower number = shorter pulses). // (lower number = shorter pulses).
// The value is usually around 0.95 (95%). // 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) { if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!")); Serial.println(F("success!"));
} else { } else {

View file

@ -169,26 +169,20 @@ SSTVClient::SSTVClient(AFSKClient* audio) {
#endif #endif
#if !defined(RADIOLIB_EXCLUDE_AFSK) #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) { if(_audio == nullptr) {
// this initialization method can only be used in AFSK mode // this initialization method can only be used in AFSK mode
return(RADIOLIB_ERR_WRONG_MODEM); return(RADIOLIB_ERR_WRONG_MODEM);
} }
return(begin(0, mode, correction)); return(begin(0, mode));
} }
#endif #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 // save mode
_mode = 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 // calculate 24-bit frequency
_base = (base * 1000000.0) / _phy->getFreqStep(); _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()); 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() { void SSTVClient::idle() {
_phy->transmitDirect(); _phy->transmitDirect();
this->tone(RADIOLIB_SSTV_TONE_LEADER); this->tone(RADIOLIB_SSTV_TONE_LEADER);

View file

@ -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 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 \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) #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. \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). \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 \returns \ref status_codes
*/ */
int16_t begin(const SSTVMode_t& mode, float correction = 1.0); int16_t setCorrection(float correction);
#endif
/*! /*!
\brief Sends out tone at 1900 Hz. \brief Sends out tone at 1900 Hz.