Compare commits

...
4 Commits
Author SHA1 Message Date
kuba 0ceb8047e8 small refactorings 2026-01-06 19:58:51 +01:00
kuba 70cbed7570 some cleanup and refactoring, nothing functional 2026-01-06 17:29:48 +01:00
kuba 0110291b97 remove airband 2026-01-06 16:27:18 +01:00
kuba 41f0140a22 89.9 flash usage 2026-01-06 13:56:00 +01:00
17 changed files with 378 additions and 926 deletions
+9
View File
@@ -0,0 +1,9 @@
Import("env")
# Apply C++-only flags
env.Append(
CXXFLAGS=[
"-fno-exceptions",
"-fno-rtti"
]
)
+2 -7
View File
@@ -538,10 +538,9 @@ class TEF6686 {
void readRDS(byte showrdserrors); void readRDS(byte showrdserrors);
void SetFreq(uint16_t frequency); void SetFreq(uint16_t frequency);
void SetFreqAM(uint16_t frequency); void SetFreqAM(uint16_t frequency);
void SetFreqAIR(uint16_t frequency);
void getProcessing(uint16_t &highcut, uint16_t &stereo, uint16_t &sthiblend, uint8_t &stband_1, uint8_t &stband_2, uint8_t &stband_3, uint8_t &stband_4); void getProcessing(uint16_t &highcut, uint16_t &stereo, uint16_t &sthiblend, uint8_t &stband_1, uint8_t &stband_2, uint8_t &stband_3, uint8_t &stband_4);
void getStatus(int16_t &level, uint16_t &USN, uint16_t &WAM, int16_t &offset, uint16_t &bandwidth, uint16_t &modulation, int8_t &snr); void getStatus(int16_t *level, uint16_t *USN, uint16_t *WAM, int16_t *offset, uint16_t *bandwidth, uint16_t *modulation, int8_t *snr);
void getStatusAM(int16_t &level, uint16_t &noise, uint16_t &cochannel, int16_t &offset, uint16_t &bandwidth, uint16_t &modulation, int8_t &snr); void getStatusAM(int16_t *level, uint16_t *noise, uint16_t *cochannel, int16_t *offset, uint16_t *bandwidth, uint16_t *modulation, int8_t *snr);
void getIdentification(uint16_t *device, uint16_t *hw_version, uint16_t *sw_version); void getIdentification(uint16_t *device, uint16_t *hw_version, uint16_t *sw_version);
void setSoftmuteFM(uint8_t mode); void setSoftmuteFM(uint8_t mode);
void setSoftmuteAM(uint8_t mode); void setSoftmuteAM(uint8_t mode);
@@ -580,7 +579,6 @@ class TEF6686 {
void tone(uint16_t time, int16_t amplitude, uint16_t frequency); void tone(uint16_t time, int16_t amplitude, uint16_t frequency);
void extendBW(bool yesno); void extendBW(bool yesno);
uint16_t getBlockA(void); uint16_t getBlockA(void);
String trimTrailingSpaces(String str);
uint8_t af_counter; uint8_t af_counter;
uint8_t eon_counter; uint8_t eon_counter;
uint8_t logbook_counter; uint8_t logbook_counter;
@@ -594,9 +592,6 @@ class TEF6686 {
private: private:
void RDScharConverter(const char* input, wchar_t* output, size_t size, bool under); void RDScharConverter(const char* input, wchar_t* output, size_t size, bool under);
String convertToUTF8(const wchar_t* input);
String extractUTF8Substring(const String& utf8String, size_t start, size_t length, bool under);
String ucs2ToUtf8(const char* ucs2Input);
bool isFixedCallsign(uint16_t stationID, char* stationIDStr); bool isFixedCallsign(uint16_t stationID, char* stationIDStr);
String PSLongtext; String PSLongtext;
char ps_buffer[9]; char ps_buffer[9];
+2 -5
View File
@@ -67,14 +67,11 @@ typedef enum {
void devTEF_Set_Cmd(TEF_MODULE module, uint8_t cmd, uint16_t len, ...); void devTEF_Set_Cmd(TEF_MODULE module, uint8_t cmd, uint16_t len, ...);
bool devTEF_Get_Cmd(TEF_MODULE module, uint8_t cmd, uint8_t *receive, uint16_t len); bool devTEF_Get_Cmd(TEF_MODULE module, uint8_t cmd, uint8_t *receive, uint16_t len);
void devTEF_Radio_Set_Noiseblanker_AM(uint8_t mode, uint16_t start);
void devTEF_Radio_Set_Wavegen(bool mode, int16_t amplitude, uint16_t freq); void devTEF_Radio_Set_Wavegen(bool mode, int16_t amplitude, uint16_t freq);
void devTEF_Radio_Set_GPIO(uint8_t mode);
bool devTEF_Radio_Get_Quality_Status (uint16_t *status, int16_t *level, uint16_t *usn, uint16_t *wam, int16_t *offset, uint16_t *bandwidth, uint16_t *mod, int8_t *snr); void devTEF_Radio_Get_Quality_Status (uint16_t *status, int16_t *level, uint16_t *usn, uint16_t *wam, int16_t *offset, uint16_t *bandwidth, uint16_t *mod, int8_t *snr);
bool devTEF_Radio_Get_Processing_Status (uint16_t *highcut, uint16_t *stereo, uint16_t *sthiblend, uint8_t *stband_1, uint8_t *stband_2, uint8_t *stband_3, uint8_t *stband_4); bool devTEF_Radio_Get_Processing_Status (uint16_t *highcut, uint16_t *stereo, uint16_t *sthiblend, uint8_t *stband_1, uint8_t *stband_2, uint8_t *stband_3, uint8_t *stband_4);
bool devTEF_Radio_Get_Quality_Status_AM (int16_t *level, uint16_t *noise, uint16_t *cochannel, int16_t *offset, uint16_t *bandwidth, uint16_t *mod, int8_t *snr);
uint8_t devTEF_APPL_Get_Operation_Status(); uint8_t devTEF_APPL_Get_Operation_Status();
bool devTEF_Radio_Get_Stereo_Status(uint16_t *status); bool devTEF_Radio_Get_Stereo_Status(uint16_t *status);
bool devTEF_Radio_Get_RDS_Status(uint16_t *status, uint16_t *A_block, uint16_t *B_block, uint16_t *C_block, uint16_t *D_block, uint16_t *dec_error); void devTEF_Radio_Get_RDS_Status(uint16_t *status, uint16_t *A_block, uint16_t *B_block, uint16_t *C_block, uint16_t *D_block, uint16_t *dec_error);
bool devTEF_Radio_Get_RDS_Data(uint16_t *status, uint16_t *A_block, uint16_t *B_block, uint16_t *C_block, uint16_t *D_block, uint16_t *dec_error); bool devTEF_Radio_Get_RDS_Data(uint16_t *status, uint16_t *A_block, uint16_t *B_block, uint16_t *C_block, uint16_t *D_block, uint16_t *dec_error);
+7 -37
View File
@@ -36,10 +36,6 @@
#define FREQ_MW_STEP_9K 9 #define FREQ_MW_STEP_9K 9
#define FREQ_MW_STEP_10K 10 #define FREQ_MW_STEP_10K 10
#define FREQ_SW_STEP_5K 5 #define FREQ_SW_STEP_5K 5
#ifdef HAS_AIR_BAND
#define FREQ_AIR_STEP_25K 25
#define FREQ_AIR_STEP_8K33 8.33
#endif
#define FREQ_OIRT_STEP_30K 3 #define FREQ_OIRT_STEP_30K 3
#define FREQ_FM_STEP_50K 5 #define FREQ_FM_STEP_50K 5
#define FREQ_FM_STEP_100K 10 #define FREQ_FM_STEP_100K 10
@@ -56,11 +52,6 @@
#define FREQ_SW_HIGH_EDGE_MIN (FREQ_SW_11M_END) #define FREQ_SW_HIGH_EDGE_MIN (FREQ_SW_11M_END)
#define FREQ_SW_HIGH_EDGE_MAX (FREQ_SW_END) #define FREQ_SW_HIGH_EDGE_MAX (FREQ_SW_END)
#ifdef HAS_AIR_BAND
#define FREQ_AIR_LOW_EDGE_MIN 108000
#define FREQ_AIR_HIGH_EDGE_MIN 137000
#endif
#define FREQ_FM_OIRT_START 6500 // use values of 1/10 * kHz #define FREQ_FM_OIRT_START 6500 // use values of 1/10 * kHz
#define FREQ_FM_OIRT_END 7400 // use values of 1/10 * kHz #define FREQ_FM_OIRT_END 7400 // use values of 1/10 * kHz
@@ -225,11 +216,7 @@
#define EE_PRESETS_CNT 99 // When set > 99 change the complete EEPROM adressing! #define EE_PRESETS_CNT 99 // When set > 99 change the complete EEPROM adressing!
#define EE_CHECKBYTE_VALUE 20 // 0 ~ 255,add new entry, change for new value #define EE_CHECKBYTE_VALUE 20 // 0 ~ 255,add new entry, change for new value
#define EE_PRESETS_FREQUENCY 0 // Default value when memory channel should be skipped! #define EE_PRESETS_FREQUENCY 0 // Default value when memory channel should be skipped!
#ifdef HAS_AIR_BAND
#define EE_TOTAL_CNT 2292 // Total occupied eeprom bytes
#else
#define EE_TOTAL_CNT 2287 // Total occupied eeprom bytes #define EE_TOTAL_CNT 2287 // Total occupied eeprom bytes
#endif
#define EE_PRESETS_BAND_START 0 // 99 * 1 byte #define EE_PRESETS_BAND_START 0 // 99 * 1 byte
#define EE_PRESET_BW_START 99 // 99 * 1 byte #define EE_PRESET_BW_START 99 // 99 * 1 byte
@@ -351,10 +338,6 @@
#define EE_BYTE_CLOCKAMPM 2278 #define EE_BYTE_CLOCKAMPM 2278
#define EE_UINT16_LOGCOUNTER 2279 #define EE_UINT16_LOGCOUNTER 2279
#define EE_UINT16_PICTLOCK 2283 #define EE_UINT16_PICTLOCK 2283
#ifdef HAS_AIR_BAND
#define EE_BYTE_AIRSTEPSIZE 2287
#define EE_UINT16_FREQUENCY_AIR 2288
#endif
// End of EEPROM index defines // End of EEPROM index defines
// Memory channel database // Memory channel database
@@ -382,33 +365,20 @@ enum SCAN_CANCEL {
}; };
enum RADIO_BAND { enum RADIO_BAND {
BAND_OIRT = 0, BAND_FM, BAND_GAP, BAND_LW, BAND_MW, BAND_SW, BAND_AIR BAND_OIRT = 0, BAND_FM, BAND_GAP, BAND_LW, BAND_MW, BAND_SW, BAND_NONEXISTENT
}; };
#ifndef HAS_AIR_BAND
enum RADIO_AM_BAND_SELECTION {
AM_BAND_ALL = 0, AM_BAND_LW_MW, AM_BAND_LW_SW, AM_BAND_MW_SW,
AM_BAND_LW, AM_BAND_MW, AM_BAND_SW, AM_BAND_NONE,
AM_BAND_CNT
};
#else
// Toggle: LW -> MW -> SW -> AIR
enum RADIO_AM_BAND_SELECTION {
AM_BAND_ALL = 0,
AM_BAND_LW_MW_SW, AM_BAND_LW_MW_AIR, AM_BAND_LW_SW_AIR, AM_BAND_MW_SW_AIR,
AM_BAND_LW_MW, AM_BAND_LW_SW, AM_BAND_LW_AIR,
AM_BAND_MW_SW, AM_BAND_MW_AIR,
AM_BAND_SW_AIR,
AM_BAND_LW, AM_BAND_MW, AM_BAND_SW, AM_BAND_AIR, AM_BAND_NONE,
AM_BAND_CNT
};
#endif
enum RADIO_FM_BAND_SELECTION { enum RADIO_FM_BAND_SELECTION {
FM_BAND_ALL = 0, FM_BAND_OIRT, FM_BAND_FM, FM_BAND_NONE, FM_BAND_ALL = 0, FM_BAND_OIRT, FM_BAND_FM, FM_BAND_NONE,
FM_BAND_CNT FM_BAND_CNT
}; };
enum RADIO_AM_BAND_SELECTION {
AM_BAND_ALL = 0, AM_BAND_LW_MW, AM_BAND_LW_SW, AM_BAND_MW_SW,
AM_BAND_LW, AM_BAND_MW, AM_BAND_SW, AM_BAND_NONE,
AM_BAND_CNT
};
enum RADIO_TUNE_MODE { enum RADIO_TUNE_MODE {
TUNE_MAN, TUNE_AUTO, TUNE_MEM, TUNE_MI_BAND TUNE_MAN, TUNE_AUTO, TUNE_MEM, TUNE_MI_BAND
}; };
+4
View File
@@ -11,3 +11,7 @@ struct HSV {
HSV RGB565toHSV(uint16_t color); HSV RGB565toHSV(uint16_t color);
uint16_t HSVtoRGB565(float h, float s, float v); uint16_t HSVtoRGB565(float h, float s, float v);
String convertToUTF8(const wchar_t* input);
String trimTrailingSpaces(String str);
String ucs2ToUtf8(const char* ucs2Input);
String extractUTF8Substring(const String & utf8String, size_t start, size_t length, bool underscore);
+13
View File
@@ -17,3 +17,16 @@ build_flags =
-Wall -Wall
-Wextra -Wextra
-Wno-unknown-pragmas -Wno-unknown-pragmas
-Os
-DCORE_DEBUG_LEVEL=0
-DBOARD_HAS_PSRAM=0
-ffunction-sections
-fdata-sections
-Wl,--gc-sections
-DARDUINO_LOOP_STACK_SIZE=4096
build_unflags =
-fexceptions
-frtti
extra_scripts = pre:extra_script.py
+144 -335
View File
@@ -4,20 +4,20 @@
#include <TimeLib.h> #include <TimeLib.h>
#include "SPIFFS.h" #include "SPIFFS.h"
#include "constants.h" #include "constants.h"
#include "utils.h"
unsigned long rdstimer = 0; unsigned long rdstimer = 0;
unsigned long bitStartTime = 0; unsigned long bitStartTime = 0;
bool lastBitState = false; bool lastBitState = false;
uint16_t TEF6686::getBlockA(void) { uint16_t TEF6686::getBlockA(void) {
uint16_t blockA, dummy; uint16_t blockA;
devTEF_Radio_Get_RDS_Status(&dummy, &blockA, &dummy, &dummy, &dummy, &dummy); devTEF_Radio_Get_RDS_Status(NULL, &blockA, NULL, NULL, NULL, NULL);
return blockA; return blockA;
} }
void TEF6686::TestAFEON() { void TEF6686::TestAFEON() {
uint16_t status, dummy1, dummy2, afusn, afwam; uint16_t status, afusn, afwam;
int8_t dummy3;
int16_t aflevel, afoffset; int16_t aflevel, afoffset;
byte timing; byte timing;
@@ -27,7 +27,7 @@ void TEF6686::TestAFEON() {
timing = 0; timing = 0;
devTEF_Set_Cmd(TEF_FM, Cmd_Tune_To, 7, 3, af[x].frequency); devTEF_Set_Cmd(TEF_FM, Cmd_Tune_To, 7, 3, af[x].frequency);
while (timing == 0 && !bitRead(timing, 15)) { while (timing == 0 && !bitRead(timing, 15)) {
devTEF_Radio_Get_Quality_Status(&status, &aflevel, &afusn, &afwam, &afoffset, &dummy1, &dummy2, &dummy3); devTEF_Radio_Get_Quality_Status(&status, &aflevel, &afusn, &afwam, &afoffset, NULL, NULL, NULL);
timing = lowByte(status); timing = lowByte(status);
} }
if (afoffset > -125 || afoffset < 125) { if (afoffset > -125 || afoffset < 125) {
@@ -43,9 +43,7 @@ void TEF6686::TestAFEON() {
af[x].checked = false; af[x].checked = false;
af[x].afvalid = false; af[x].afvalid = false;
} }
} else { } else af[x].checked = false;
af[x].checked = false;
}
} }
} }
} }
@@ -55,21 +53,18 @@ void TEF6686::TestAFEON() {
uint16_t TEF6686::TestAF() { uint16_t TEF6686::TestAF() {
if (af_counter != 0) { if (af_counter != 0) {
uint16_t status, dummy1, dummy2, afusn, afwam, currentusn, currentwam; uint16_t status, afusn, afwam, currentusn, currentwam;
int8_t dummy3;
int16_t aflevel, afoffset, currentoffset, currentlevel; int16_t aflevel, afoffset, currentoffset, currentlevel;
byte timing; byte timing;
devTEF_Radio_Get_Quality_Status(&status, &currentlevel, &currentusn, &currentwam, &currentoffset, &dummy1, &dummy2, &dummy3); devTEF_Radio_Get_Quality_Status(&status, &currentlevel, &currentusn, &currentwam, &currentoffset, NULL, NULL, NULL);
devTEF_Radio_Get_RDS_Status(&rds.rdsStat, &rds.rdsA, &rds.rdsB, &rds.rdsC, &rds.rdsD, &rds.rdsErr); devTEF_Radio_Get_RDS_Status(&rds.rdsStat, &rds.rdsA, &rds.rdsB, &rds.rdsC, &rds.rdsD, &rds.rdsErr);
for (int x = 0; x < af_counter; x++) { for (int x = 0; x < af_counter; x++) {
timing = 0; timing = 0;
devTEF_Set_Cmd(TEF_FM, Cmd_Tune_To, 7, 3, af[x].frequency); devTEF_Set_Cmd(TEF_FM, Cmd_Tune_To, 7, 3, af[x].frequency);
while (timing == 0 && !bitRead(timing, 15)) { while (timing == 0 && !bitRead(timing, 15)) {
devTEF_Radio_Get_Quality_Status(&status, &aflevel, &afusn, &afwam, &afoffset, &dummy1, &dummy2, &dummy3); devTEF_Radio_Get_Quality_Status(&status, &aflevel, &afusn, &afwam, &afoffset, NULL, NULL, NULL);
timing = lowByte(status); timing = lowByte(status);
} }
af[x].score = aflevel - afusn - afwam; af[x].score = aflevel - afusn - afwam;
@@ -120,20 +115,11 @@ void TEF6686::init(byte TEF) {
delay(50); delay(50);
int xtalADC = analogRead(15); int xtalADC = analogRead(15);
if (xtalADC < XTAL_0V_ADC + XTAL_ADC_TOL) Tuner_Init(tuner_init_tab9216);
else if (xtalADC > XTAL_1V_ADC - XTAL_ADC_TOL && xtalADC < XTAL_1V_ADC + XTAL_ADC_TOL) Tuner_Init(tuner_init_tab12000);
else if (xtalADC > XTAL_2V_ADC - XTAL_ADC_TOL && xtalADC < XTAL_2V_ADC + XTAL_ADC_TOL) Tuner_Init(tuner_init_tab55000);
else Tuner_Init(tuner_init_tab4000);
if (xtalADC < XTAL_0V_ADC + XTAL_ADC_TOL) {
Tuner_Init(tuner_init_tab9216);
log_d("TEF668X XTAL : 9.216M");
} else if (xtalADC > XTAL_1V_ADC - XTAL_ADC_TOL && xtalADC < XTAL_1V_ADC + XTAL_ADC_TOL) {
Tuner_Init(tuner_init_tab12000);
log_d("TEF668X XTAL : 12M");
} else if (xtalADC > XTAL_2V_ADC - XTAL_ADC_TOL && xtalADC < XTAL_2V_ADC + XTAL_ADC_TOL) {
Tuner_Init(tuner_init_tab55000);
log_d("TEF668X XTAL : 55M");
} else {
Tuner_Init(tuner_init_tab4000);
log_d("TEF668X XTAL : 4M");
}
power(1); power(1);
Tuner_Init(tuner_init_tab); Tuner_Init(tuner_init_tab);
} }
@@ -167,10 +153,6 @@ void TEF6686::SetFreqAM(uint16_t frequency) {
devTEF_Set_Cmd(TEF_AM, Cmd_Tune_To, 7, 1, frequency); devTEF_Set_Cmd(TEF_AM, Cmd_Tune_To, 7, 1, frequency);
} }
void TEF6686::SetFreqAIR(uint16_t frequency) {
devTEF_Set_Cmd(TEF_AM, Cmd_Tune_To, 7, 1, 10700);
}
void TEF6686::setOffset(int8_t offset) { void TEF6686::setOffset(int8_t offset) {
devTEF_Set_Cmd(TEF_FM, Cmd_Set_LevelOffset, 5, (offset * 10) - 70); devTEF_Set_Cmd(TEF_FM, Cmd_Set_LevelOffset, 5, (offset * 10) - 70);
} }
@@ -202,7 +184,8 @@ void TEF6686::setSoftmuteFM(uint8_t mode) {
} }
void TEF6686::setAMNoiseBlanker(uint16_t start) { void TEF6686::setAMNoiseBlanker(uint16_t start) {
if (start == 0) devTEF_Radio_Set_Noiseblanker_AM(0, 1000); else devTEF_Radio_Set_Noiseblanker_AM(1, start * 10); devTEF_Set_Cmd(TEF_AM, Cmd_Set_NoiseBlanker, 7, (start == 0) ? 0 : 1, (start == 0) ? 1000 : start * 10);
devTEF_Set_Cmd(TEF_AM, Cmd_Set_NoiseBlanker_Audio, 7, (start == 0) ? 0 : 1, 1000);
} }
void TEF6686::setAMAttenuation(uint16_t start) { void TEF6686::setAMAttenuation(uint16_t start) {
@@ -335,13 +318,22 @@ void TEF6686::setStHiBlendOffset(uint8_t start) {
} }
} }
void TEF6686::getStatus(int16_t &level, uint16_t &USN, uint16_t &WAM, int16_t &offset, uint16_t &bandwidth, uint16_t &modulation, int8_t &snr) { void TEF6686::getStatus(int16_t *level, uint16_t *USN, uint16_t *WAM, int16_t *offset, uint16_t *bandwidth, uint16_t *modulation, int8_t *snr) {
uint16_t status; devTEF_Radio_Get_Quality_Status(NULL, level, USN, WAM, offset, bandwidth, modulation, snr);
devTEF_Radio_Get_Quality_Status(&status, &level, &USN, &WAM, &offset, &bandwidth, &modulation, &snr);
} }
void TEF6686::getStatusAM(int16_t &level, uint16_t &noise, uint16_t &cochannel, int16_t &offset, uint16_t &bandwidth, uint16_t &modulation, int8_t &snr) { void TEF6686::getStatusAM(int16_t *level, uint16_t *noise, uint16_t *cochannel, int16_t *offset, uint16_t *bandwidth, uint16_t *modulation, int8_t *snr) {
devTEF_Radio_Get_Quality_Status_AM(&level, &noise, &cochannel, &offset, &bandwidth, &modulation, &snr); uint8_t buf[14];
devTEF_Get_Cmd(TEF_AM, Cmd_Get_Quality_Data, buf, sizeof(buf));
*level = Convert8bto16b(buf + 2);
*noise = Convert8bto16b(buf + 4);
*cochannel = Convert8bto16b(buf + 6);
*offset = Convert8bto16b(buf + 8);
*bandwidth = Convert8bto16b(buf + 10) / 10;
*modulation = Convert8bto16b(buf + 12) / 10;
if (*level < -200) *level = -200;
if (*level > 1200) *level = 1200;
*snr = int(0.46222375 * (float)(*level) / 10 - 0.082495118 * (float)(*noise / 50) / 10) + 10;
} }
void TEF6686::readRDS(byte showrdserrors) { void TEF6686::readRDS(byte showrdserrors) {
@@ -365,10 +357,10 @@ void TEF6686::readRDS(byte showrdserrors) {
else if (millis() - bitStartTime >= 87) rds.hasRDS = false; else if (millis() - bitStartTime >= 87) rds.hasRDS = false;
} }
rdsAerrorThreshold = (((rds.rdsErr >> 14) & 0x03) > showrdserrors); rdsAerrorThreshold = ((rds.rdsErr >> 14) & 0x03) > showrdserrors;
rdsBerrorThreshold = (((rds.rdsErr >> 12) & 0x03) > showrdserrors); rdsBerrorThreshold = ((rds.rdsErr >> 12) & 0x03) > showrdserrors;
rdsCerrorThreshold = (((rds.rdsErr >> 10) & 0x03) > showrdserrors); rdsCerrorThreshold = ((rds.rdsErr >> 10) & 0x03) > showrdserrors;
rdsDerrorThreshold = (((rds.rdsErr >> 8) & 0x03) > showrdserrors); rdsDerrorThreshold = ((rds.rdsErr >> 8) & 0x03) > showrdserrors;
if (bitRead(rds.rdsStat, 9) && (rds.rdsA != previous_rdsA || rds.rdsB != previous_rdsB || rds.rdsC != previous_rdsC || rds.rdsD != previous_rdsD)) { if (bitRead(rds.rdsStat, 9) && (rds.rdsA != previous_rdsA || rds.rdsB != previous_rdsB || rds.rdsC != previous_rdsC || rds.rdsD != previous_rdsD)) {
rds.rdsAerror = (((rds.rdsErr >> 14) & 0x03) > 1); rds.rdsAerror = (((rds.rdsErr >> 14) & 0x03) > 1);
@@ -411,7 +403,7 @@ void TEF6686::readRDS(byte showrdserrors) {
if (strncmp(rds.picode, "0000", 4) == 0 && rds.rdsB == 0 && rds.stationName.length() == 0) memset(rds.picode, 0, sizeof(rds.picode)); if (strncmp(rds.picode, "0000", 4) == 0 && rds.rdsB == 0 && rds.stationName.length() == 0) memset(rds.picode, 0, sizeof(rds.picode));
// USA Station callsign decoder // USA Station callsign decoder GLORY TO TRUMP AND AMERICA RAHHHH (actually hang him and tear up the constititution, not sure what's more of a dictartorship, Venezuela or Trump?)
if ((rds.region == 1 ? ps_process : true) && rds.correctPI != 0 && rds.region > 0 && correctPIold != rds.correctPI) { if ((rds.region == 1 ? ps_process : true) && rds.correctPI != 0 && rds.region > 0 && correctPIold != rds.correctPI) {
bool foundMatch = false; bool foundMatch = false;
fs::File file; fs::File file;
@@ -523,7 +515,9 @@ void TEF6686::readRDS(byte showrdserrors) {
} }
} }
if (!rds.rdsBerror || showrdserrors == 3) rdsgroup = rds.rdsB >> 11; else goto end; if (rds.rdsBerror && showrdserrors != 3) goto end;
rdsgroup = rds.rdsB >> 11; // Includes version bit as LSB, better for the switch statement
rds.TP = (bitRead(rds.rdsB, 10)); rds.TP = (bitRead(rds.rdsB, 10));
rds.PTY = (rds.rdsB >> 5) & 0x1F; rds.PTY = (rds.rdsB >> 5) & 0x1F;
@@ -545,13 +539,13 @@ void TEF6686::readRDS(byte showrdserrors) {
case 3: if (((rds.rdsErr >> 8) & 0x03) > 1) rds.ps78error = true; else rds.ps78error = false; break; case 3: if (((rds.rdsErr >> 8) & 0x03) > 1) rds.ps78error = true; else rds.ps78error = false; break;
} }
ps_buffer2[(segment * 2) + 0] = ps_buffer[(segment * 2) + 0]; // Make a copy of the PS buffer ps_buffer2[(segment * 2) + 0] = ps_buffer[(segment * 2) + 0];
ps_buffer2[(segment * 2) + 1] = ps_buffer[(segment * 2) + 1]; ps_buffer2[(segment * 2) + 1] = ps_buffer[(segment * 2) + 1];
ps_buffer2[8] = '\0'; // Endmarker ps_buffer2[8] = '\0';
ps_buffer[(segment * 2) + 0] = rds.rdsD >> 8; // First character of segment ps_buffer[(segment * 2) + 0] = rds.rdsD >> 8;
ps_buffer[(segment * 2) + 1] = rds.rdsD & 0xFF; // Second character of segment ps_buffer[(segment * 2) + 1] = rds.rdsD & 0xFF;
ps_buffer[8] = '\0'; // Endmarker ps_buffer[8] = '\0';
if (ps_process || rds.fastps == 0) { if (ps_process || rds.fastps == 0) {
if (segment == 0) { if (segment == 0) {
@@ -565,12 +559,12 @@ void TEF6686::readRDS(byte showrdserrors) {
if (segment == 3) packet3 = true; if (segment == 3) packet3 = true;
} }
if (packet0 && packet1 && packet2 && packet3 && (ps_process || (rds.fastps == 0 && rds.fastps != 2))) { // Last chars are received if (packet0 && packet1 && packet2 && packet3 && (ps_process || (rds.fastps == 0 && rds.fastps != 2))) {
if (strcmp(ps_buffer, ps_buffer2) == 0) { // When no difference between current and buffer, let's go... if (strcmp(ps_buffer, ps_buffer2) == 0) {
ps_process = true; ps_process = true;
RDScharConverter(ps_buffer2, PStext, sizeof(PStext) / sizeof(wchar_t), (underscore > 0 ? true : false)); // Convert 8 bit ASCII to 16 bit ASCII RDScharConverter(ps_buffer2, PStext, sizeof(PStext) / sizeof(wchar_t), (underscore > 0 ? true : false));
String utf8String = convertToUTF8(PStext); // Convert RDS characterset to ASCII String utf8String = convertToUTF8(PStext);
rds.stationName = extractUTF8Substring(utf8String, 0, 8, (underscore > 0 ? true : false)); // Make sure PS does not exceed 8 characters rds.stationName = extractUTF8Substring(utf8String, 0, 8, (underscore > 0 ? true : false));
for (byte x = 0; x < 8; x++) { for (byte x = 0; x < 8; x++) {
ps_buffer[x] = '\0'; ps_buffer[x] = '\0';
ps_buffer2[x] = '\0'; ps_buffer2[x] = '\0';
@@ -578,15 +572,15 @@ void TEF6686::readRDS(byte showrdserrors) {
} }
} }
if ((!ps_process && rds.fastps > 0 && rds.fastps != 2) || rds.fastps == 2) { // Let's get 2 runs of 8 PS characters fast and without refresh if ((!ps_process && rds.fastps > 0 && rds.fastps != 2) || rds.fastps == 2) {
if (segment == 0) packet0 = true; if (segment == 0) packet0 = true;
if (segment == 1) packet1 = true; if (segment == 1) packet1 = true;
if (segment == 2) packet2 = true; if (segment == 2) packet2 = true;
if (segment == 3) packet3 = true; if (segment == 3) packet3 = true;
RDScharConverter(ps_buffer, PStext, sizeof(PStext) / sizeof(wchar_t), (underscore > 0 ? true : false)); // Convert 8 bit ASCII to 16 bit ASCII RDScharConverter(ps_buffer, PStext, sizeof(PStext) / sizeof(wchar_t), (underscore > 0 ? true : false));
String utf8String = convertToUTF8(PStext); // Convert RDS characterset to ASCII String utf8String = convertToUTF8(PStext);
rds.stationName = extractUTF8Substring(utf8String, 0, 8, (underscore > 0 ? true : false)); rds.stationName = extractUTF8Substring(utf8String, 0, 8, (underscore > 0 ? true : false));
if (packet0 && packet1 && packet2 && packet3) ps_process = true; // OK, we had one runs, now let's go the idle PS writing if (packet0 && packet1 && packet2 && packet3) ps_process = true;
} }
if(segment == 0) rds.hasDynamicPTY = bitRead(rds.rdsB, 2) & 0x1F; if(segment == 0) rds.hasDynamicPTY = bitRead(rds.rdsB, 2) & 0x1F;
@@ -598,9 +592,8 @@ void TEF6686::readRDS(byte showrdserrors) {
rds.hasTA = (bitRead(rds.rdsB, 4)); rds.hasTA = (bitRead(rds.rdsB, 4));
if (!rdsCerrorThreshold && rdsgroup == RDS_GROUP_0A && rds.rdsC != rdsCold) { if (!rdsCerrorThreshold && rdsgroup == RDS_GROUP_0A && rds.rdsC != rdsCold) {
//AF decoder
if ((rds.rdsC >> 8) > 224 && (rds.rdsC >> 8) < 250) { if ((rds.rdsC >> 8) > 224 && (rds.rdsC >> 8) < 250) {
afinit = true; // AF detected afinit = true;
rds.hasAF = true; rds.hasAF = true;
} }
@@ -623,9 +616,7 @@ void TEF6686::readRDS(byte showrdserrors) {
doubletestfreq = (rds.rdsC & 0xFF) * 10 + 8750; doubletestfreq = (rds.rdsC & 0xFF) * 10 + 8750;
} }
if (((rds.rdsC >> 8) > 0 && (rds.rdsC >> 8) < 205) && ((rds.rdsC >> 8) > 0 && (rds.rdsC >> 8) < 205)) { if ((((rds.rdsC >> 8) > 0 && (rds.rdsC >> 8) < 205) && ((rds.rdsC >> 8) > 0 && (rds.rdsC >> 8) < 205)) && afmethodBprobe) af_counterbcheck += 2;
if (afmethodBprobe) af_counterbcheck += 2;
}
if ((rds.rdsB >> 11) == 0 && af_counter < 50) { if ((rds.rdsB >> 11) == 0 && af_counter < 50) {
uint16_t buffer0; uint16_t buffer0;
@@ -635,11 +626,11 @@ void TEF6686::readRDS(byte showrdserrors) {
if ((rds.rdsC & 0xFF) > 0 && (rds.rdsC & 0xFF) < 205) buffer1 = (rds.rdsC & 0xFF) * 10 + 8750; else buffer1 = 0; if ((rds.rdsC & 0xFF) > 0 && (rds.rdsC & 0xFF) < 205) buffer1 = (rds.rdsC & 0xFF) * 10 + 8750; else buffer1 = 0;
if (((rds.rdsC >> 8) > 0 && (rds.rdsC >> 8) < 205) && (buffer0 == doubletestfreq || buffer1 == doubletestfreq)) doublecounter++; if (((rds.rdsC >> 8) > 0 && (rds.rdsC >> 8) < 205) && (buffer0 == doubletestfreq || buffer1 == doubletestfreq)) doublecounter++;
if (doublecounter > (af_number / 2)) afmethodB = true; // If signed frequency also appears more than once in the AF list, AF Method B detected if (doublecounter > (af_number / 2)) afmethodB = true;
if (afmethodBprobe && af_counterbcheck > af_counterb) afmethodBprobe = false; // If more than counter received disable probe flag if (afmethodBprobe && af_counterbcheck > af_counterb) afmethodBprobe = false;
if (afmethodBprobe) { // Check for Reg. flags if (afmethodBprobe) {
if (buffer1 == currentfreq && buffer0 > buffer1) { if (buffer1 == currentfreq && buffer0 > buffer1) {
for (int x = 0; x < af_counter; x++) { for (int x = 0; x < af_counter; x++) {
if (af[x].frequency == buffer0 && !af[x].regional) { if (af[x].frequency == buffer0 && !af[x].regional) {
@@ -678,7 +669,7 @@ void TEF6686::readRDS(byte showrdserrors) {
} }
if (buffer0 != currentfreq && buffer1 != currentfreq && afmethodB && afmethodBprobe) { if (buffer0 != currentfreq && buffer1 != currentfreq && afmethodB && afmethodBprobe) {
afmethodBprobe = false; // Remove faulty Reg. flags afmethodBprobe = false;
for (int x = 0; x < af_counter; x++) { for (int x = 0; x < af_counter; x++) {
if (af[x].frequency == buffer0 || af[x].frequency == buffer1) { if (af[x].frequency == buffer0 || af[x].frequency == buffer1) {
if (af[x].same) { if (af[x].same) {
@@ -695,21 +686,21 @@ void TEF6686::readRDS(byte showrdserrors) {
} }
bool isValuePresent = false; bool isValuePresent = false;
for (int i = 0; i < 50; i++) { // Check if already in list for (int i = 0; i < 50; i++) {
if ((rds.sortaf && (buffer0 == currentfreq)) || buffer0 == 0 || af[i].frequency == buffer0) { if ((rds.sortaf && (buffer0 == currentfreq)) || buffer0 == 0 || af[i].frequency == buffer0) {
isValuePresent = true; isValuePresent = true;
break; break;
} }
} }
if (!isValuePresent) { // Add frequency to list if (!isValuePresent) {
af[af_counter].frequency = buffer0; af[af_counter].frequency = buffer0;
if (af_counter < 50) af_counter++; if (af_counter < 50) af_counter++;
af_updatecounter++; af_updatecounter++;
} }
isValuePresent = false; isValuePresent = false;
for (int i = 0; i < 50; i++) { // Check if already in list for (int i = 0; i < 50; i++) {
if ((rds.sortaf && (buffer1 == currentfreq)) || buffer1 == 0 || af[i].frequency == buffer1) { if ((rds.sortaf && (buffer1 == currentfreq)) || buffer1 == 0 || af[i].frequency == buffer1) {
isValuePresent = true; isValuePresent = true;
break; break;
@@ -717,16 +708,15 @@ void TEF6686::readRDS(byte showrdserrors) {
} }
if (!isValuePresent) { if (!isValuePresent) {
af[af_counter].frequency = buffer1; // Add frequency to list af[af_counter].frequency = buffer1;
if (af_counter < 50) af_counter++; if (af_counter < 50) af_counter++;
af_updatecounter++; af_updatecounter++;
} }
if (rds.sortaf) { // Sort AF list (low to high) if (rds.sortaf) {
for (int i = 0; i < 50; i++) { for (int i = 0; i < 50; i++) {
for (int j = 0; j < 50 - i; j++) { for (int j = 0; j < 50 - i; j++) {
if (af[j].frequency == 0) continue; if (af[j].frequency == 0) continue;
if (af[j].frequency > af[j + 1].frequency && af[j + 1].frequency != 0) { if (af[j].frequency > af[j + 1].frequency && af[j + 1].frequency != 0) {
uint16_t temp = af[j].frequency; uint16_t temp = af[j].frequency;
bool temp3 = af[j].afvalid; bool temp3 = af[j].afvalid;
@@ -778,7 +768,6 @@ void TEF6686::readRDS(byte showrdserrors) {
else if (rds.ECC == 0xF3) rds.ECCtext = ECCtext[200]; else if (rds.ECC == 0xF3) rds.ECCtext = ECCtext[200];
break; break;
} }
case '2': { case '2': {
if (rds.ECC == 0xA0) rds.ECCtext = ECCtext[226]; if (rds.ECC == 0xA0) rds.ECCtext = ECCtext[226];
else if (rds.ECC == 0xA2) rds.ECCtext = ECCtext[130]; else if (rds.ECC == 0xA2) rds.ECCtext = ECCtext[130];
@@ -798,7 +787,6 @@ void TEF6686::readRDS(byte showrdserrors) {
else if (rds.ECC == 0xF3) rds.ECCtext = ECCtext[218]; else if (rds.ECC == 0xF3) rds.ECCtext = ECCtext[218];
break; break;
} }
case '3': { case '3': {
if (rds.ECC == 0xA0) rds.ECCtext = ECCtext[226]; if (rds.ECC == 0xA0) rds.ECCtext = ECCtext[226];
else if (rds.ECC == 0xA2) rds.ECCtext = ECCtext[224]; else if (rds.ECC == 0xA2) rds.ECCtext = ECCtext[224];
@@ -821,7 +809,6 @@ void TEF6686::readRDS(byte showrdserrors) {
else if (rds.ECC == 0xF3) rds.ECCtext = ECCtext[219]; else if (rds.ECC == 0xF3) rds.ECCtext = ECCtext[219];
break; break;
} }
case '4': { case '4': {
if (rds.ECC == 0xA0) rds.ECCtext = ECCtext[226]; if (rds.ECC == 0xA0) rds.ECCtext = ECCtext[226];
else if (rds.ECC == 0xA2) rds.ECCtext = ECCtext[148]; else if (rds.ECC == 0xA2) rds.ECCtext = ECCtext[148];
@@ -838,7 +825,6 @@ void TEF6686::readRDS(byte showrdserrors) {
else if (rds.ECC == 0xF2) rds.ECCtext = ECCtext[213]; else if (rds.ECC == 0xF2) rds.ECCtext = ECCtext[213];
break; break;
} }
case '5': { case '5': {
if (rds.ECC == 0xA0) rds.ECCtext = ECCtext[226]; if (rds.ECC == 0xA0) rds.ECCtext = ECCtext[226];
else if (rds.ECC == 0xA2) rds.ECCtext = ECCtext[133]; else if (rds.ECC == 0xA2) rds.ECCtext = ECCtext[133];
@@ -856,7 +842,6 @@ void TEF6686::readRDS(byte showrdserrors) {
else if (rds.ECC == 0xF2) rds.ECCtext = ECCtext[193]; else if (rds.ECC == 0xF2) rds.ECCtext = ECCtext[193];
break; break;
} }
case '6': { case '6': {
if (rds.ECC == 0xA0) rds.ECCtext = ECCtext[226]; if (rds.ECC == 0xA0) rds.ECCtext = ECCtext[226];
else if (rds.ECC == 0xA2) rds.ECCtext = ECCtext[134]; else if (rds.ECC == 0xA2) rds.ECCtext = ECCtext[134];
@@ -875,7 +860,6 @@ void TEF6686::readRDS(byte showrdserrors) {
else if (rds.ECC == 0xF2) rds.ECCtext = ECCtext[201]; else if (rds.ECC == 0xF2) rds.ECCtext = ECCtext[201];
break; break;
} }
case '7': { case '7': {
if (rds.ECC == 0xA0) rds.ECCtext = ECCtext[226]; if (rds.ECC == 0xA0) rds.ECCtext = ECCtext[226];
else if (rds.ECC == 0xA2) rds.ECCtext = ECCtext[139]; else if (rds.ECC == 0xA2) rds.ECCtext = ECCtext[139];
@@ -893,7 +877,6 @@ void TEF6686::readRDS(byte showrdserrors) {
else if (rds.ECC == 0xF2) rds.ECCtext = ECCtext[221]; else if (rds.ECC == 0xF2) rds.ECCtext = ECCtext[221];
break; break;
} }
case '8': { case '8': {
if (rds.ECC == 0xA0) rds.ECCtext = ECCtext[226]; if (rds.ECC == 0xA0) rds.ECCtext = ECCtext[226];
else if (rds.ECC == 0xA2) rds.ECCtext = ECCtext[142]; else if (rds.ECC == 0xA2) rds.ECCtext = ECCtext[142];
@@ -913,7 +896,6 @@ void TEF6686::readRDS(byte showrdserrors) {
else if (rds.ECC == 0xF3) rds.ECCtext = ECCtext[190]; else if (rds.ECC == 0xF3) rds.ECCtext = ECCtext[190];
break; break;
} }
case '9': { case '9': {
if (rds.ECC == 0xA0) rds.ECCtext = ECCtext[226]; if (rds.ECC == 0xA0) rds.ECCtext = ECCtext[226];
else if (rds.ECC == 0xA2) rds.ECCtext = ECCtext[143]; else if (rds.ECC == 0xA2) rds.ECCtext = ECCtext[143];
@@ -934,7 +916,6 @@ void TEF6686::readRDS(byte showrdserrors) {
else if (rds.ECC == 0xF4) rds.ECCtext = ECCtext[190]; else if (rds.ECC == 0xF4) rds.ECCtext = ECCtext[190];
break; break;
} }
case 'A': { case 'A': {
if (rds.ECC == 0xA0) rds.ECCtext = ECCtext[226]; if (rds.ECC == 0xA0) rds.ECCtext = ECCtext[226];
else if (rds.ECC == 0xA2) rds.ECCtext = ECCtext[131]; else if (rds.ECC == 0xA2) rds.ECCtext = ECCtext[131];
@@ -955,7 +936,6 @@ void TEF6686::readRDS(byte showrdserrors) {
else if (rds.ECC == 0xF2) rds.ECCtext = ECCtext[214]; else if (rds.ECC == 0xF2) rds.ECCtext = ECCtext[214];
break; break;
} }
case 'B': { case 'B': {
if (rds.ECC == 0xA0) rds.ECCtext = ECCtext[226]; if (rds.ECC == 0xA0) rds.ECCtext = ECCtext[226];
else if (rds.ECC == 0xA1) rds.ECCtext = ECCtext[138]; else if (rds.ECC == 0xA1) rds.ECCtext = ECCtext[138];
@@ -978,7 +958,6 @@ void TEF6686::readRDS(byte showrdserrors) {
else if (rds.ECC == 0xF4) rds.ECCtext = ECCtext[204]; else if (rds.ECC == 0xF4) rds.ECCtext = ECCtext[204];
break; break;
} }
case 'C': { case 'C': {
if (rds.ECC == 0xA1) rds.ECCtext = ECCtext[138]; if (rds.ECC == 0xA1) rds.ECCtext = ECCtext[138];
else if (rds.ECC == 0xA2) rds.ECCtext = ECCtext[223]; else if (rds.ECC == 0xA2) rds.ECCtext = ECCtext[223];
@@ -999,7 +978,6 @@ void TEF6686::readRDS(byte showrdserrors) {
else if (rds.ECC == 0xF2) rds.ECCtext = ECCtext[194]; else if (rds.ECC == 0xF2) rds.ECCtext = ECCtext[194];
break; break;
} }
case 'D': { case 'D': {
if (rds.ECC == 0xA0) rds.ECCtext = ECCtext[226]; if (rds.ECC == 0xA0) rds.ECCtext = ECCtext[226];
else if (rds.ECC == 0xA1) rds.ECCtext = ECCtext[138]; else if (rds.ECC == 0xA1) rds.ECCtext = ECCtext[138];
@@ -1018,7 +996,6 @@ void TEF6686::readRDS(byte showrdserrors) {
else if (rds.ECC == 0xF2) rds.ECCtext = ECCtext[128]; else if (rds.ECC == 0xF2) rds.ECCtext = ECCtext[128];
break; break;
} }
case 'E': { case 'E': {
if (rds.ECC == 0xA0) rds.ECCtext = ECCtext[226]; if (rds.ECC == 0xA0) rds.ECCtext = ECCtext[226];
else if (rds.ECC == 0xA1) rds.ECCtext = ECCtext[138]; else if (rds.ECC == 0xA1) rds.ECCtext = ECCtext[138];
@@ -1040,7 +1017,6 @@ void TEF6686::readRDS(byte showrdserrors) {
else if (rds.ECC == 0xF3) rds.ECCtext = ECCtext[205]; else if (rds.ECC == 0xF3) rds.ECCtext = ECCtext[205];
break; break;
} }
case 'F': { case 'F': {
if (rds.ECC == 0xA1) rds.ECCtext = ECCtext[149]; if (rds.ECC == 0xA1) rds.ECCtext = ECCtext[149];
else if (rds.ECC == 0xA2) rds.ECCtext = ECCtext[222]; else if (rds.ECC == 0xA2) rds.ECCtext = ECCtext[222];
@@ -1101,11 +1077,11 @@ void TEF6686::readRDS(byte showrdserrors) {
} }
} }
wchar_t RTtext[65] = L""; // Create 16 bit char buffer for Extended ASCII wchar_t RTtext[65] = L"";
RDScharConverter(rt_buffer_temp, RTtext, sizeof(RTtext) / sizeof(wchar_t), (underscore > 1 ? true : false)); // Convert 8 bit ASCII to 16 bit ASCII RDScharConverter(rt_buffer_temp, RTtext, sizeof(RTtext) / sizeof(wchar_t), (underscore > 1 ? true : false));
rds.stationText = convertToUTF8(RTtext); // Convert RDS characterset to ASCII rds.stationText = convertToUTF8(RTtext);
rds.stationText = extractUTF8Substring(rds.stationText, 0, endmarkerRT64, (underscore > 1 ? true : false)); // Make sure RT does not exceed 64 characters rds.stationText = extractUTF8Substring(rds.stationText, 0, endmarkerRT64, (underscore > 1 ? true : false));
rds.stationText = trimTrailingSpaces(rds.stationText); // Trim empty spaces at the end rds.stationText = trimTrailingSpaces(rds.stationText);
} }
for (byte i = 0; i < 64; i++) rt_buffer[i] = 0x20; for (byte i = 0; i < 64; i++) rt_buffer[i] = 0x20;
@@ -1130,11 +1106,11 @@ void TEF6686::readRDS(byte showrdserrors) {
} }
} }
wchar_t RTtext[65] = L""; // Create 16 bit char buffer for Extended ASCII wchar_t RTtext[65] = L"";
RDScharConverter(rt_buffer_temp, RTtext, sizeof(RTtext) / sizeof(wchar_t), (underscore > 1 ? true : false)); // Convert 8 bit ASCII to 16 bit ASCII RDScharConverter(rt_buffer_temp, RTtext, sizeof(RTtext) / sizeof(wchar_t), (underscore > 1 ? true : false));
rds.stationText = convertToUTF8(RTtext); // Convert RDS characterset to ASCII rds.stationText = convertToUTF8(RTtext);
rds.stationText = extractUTF8Substring(rds.stationText, 0, endmarkerRT64, (underscore > 1 ? true : false)); // Make sure RT does not exceed 64 characters rds.stationText = extractUTF8Substring(rds.stationText, 0, endmarkerRT64, (underscore > 1 ? true : false));
rds.stationText = trimTrailingSpaces(rds.stationText); // Trim empty spaces at the end rds.stationText = trimTrailingSpaces(rds.stationText);
} }
for (int i = 0; i < 64; i++) rt_buffer2[i] = rt_buffer[i]; for (int i = 0; i < 64; i++) rt_buffer2[i] = rt_buffer[i];
@@ -1143,21 +1119,18 @@ void TEF6686::readRDS(byte showrdserrors) {
case RDS_GROUP_2B: { case RDS_GROUP_2B: {
if (showrdserrors == 3 || (!rdsBerrorThreshold && !rdsDerrorThreshold)) { if (showrdserrors == 3 || (!rdsBerrorThreshold && !rdsDerrorThreshold)) {
// RT decoder (32 characters)
rds.hasRT = true; rds.hasRT = true;
rds.rtAB32 = (bitRead(rds.rdsB, 4)); // Get AB flag rds.rtAB32 = (bitRead(rds.rdsB, 4));
if (rds.rtAB32 != rtAB32old) { // Erase old RT, because of AB change if (rds.rtAB32 != rtAB32old) {
for (byte i = 0; i < 33; i++) { for (byte i = 0; i < 33; i++) rt_buffer32[i] = 0x20;
rt_buffer32[i] = 0x20;
}
rt_buffer32[32] = '\0'; rt_buffer32[32] = '\0';
rtAB32old = rds.rtAB32; rtAB32old = rds.rtAB32;
} }
uint16_t segment = (rds.rdsB & 0xf) * 2; // Get RT character segment uint16_t segment = (rds.rdsB & 0xf) * 2;
rt_buffer32[segment + 0] = rds.rdsD >> 8; // First character of segment rt_buffer32[segment + 0] = rds.rdsD >> 8;
rt_buffer32[segment + 1] = rds.rdsD & 0xff; // Second character of segment rt_buffer32[segment + 1] = rds.rdsD & 0xff;
byte endmarkerRT32 = 32; byte endmarkerRT32 = 32;
for (byte i = 0; i < endmarkerRT32; i++) { for (byte i = 0; i < endmarkerRT32; i++) {
@@ -1167,7 +1140,6 @@ void TEF6686::readRDS(byte showrdserrors) {
} }
} }
char rt_buffer_temp[129]; char rt_buffer_temp[129];
strcpy(rt_buffer_temp, rt_buffer32); strcpy(rt_buffer_temp, rt_buffer32);
@@ -1178,11 +1150,11 @@ void TEF6686::readRDS(byte showrdserrors) {
} }
} }
wchar_t RTtext[33] = L""; // Create 16 bit char buffer for Extended ASCII wchar_t RTtext[33] = L"";
RDScharConverter(rt_buffer_temp, RTtext, sizeof(RTtext) / sizeof(wchar_t), (underscore > 1 ? true : false)); // Convert 8 bit ASCII to 16 bit ASCII RDScharConverter(rt_buffer_temp, RTtext, sizeof(RTtext) / sizeof(wchar_t), (underscore > 1 ? true : false));
rds.stationText32 = convertToUTF8(RTtext); // Convert RDS characterset to ASCII rds.stationText32 = convertToUTF8(RTtext);
rds.stationText32 = extractUTF8Substring(rds.stationText32, 0, endmarkerRT32, (underscore > 1 ? true : false));// Make sure RT does not exceed 32 characters rds.stationText32 = extractUTF8Substring(rds.stationText32, 0, endmarkerRT32, (underscore > 1 ? true : false));
rds.stationText32 = trimTrailingSpaces(rds.stationText32); // Trim empty spaces at the end rds.stationText32 = trimTrailingSpaces(rds.stationText32);
} }
} break; } break;
@@ -1225,18 +1197,16 @@ void TEF6686::readRDS(byte showrdserrors) {
case RDS_GROUP_4A: { case RDS_GROUP_4A: {
if (!rdsBerrorThreshold && !rdsCerrorThreshold && !rdsDerrorThreshold && rds.ctupdate && (rds.PICTlock == rds.rdsA || rds.PICTlock == 0)) { if (!rdsBerrorThreshold && !rdsCerrorThreshold && !rdsDerrorThreshold && rds.ctupdate && (rds.PICTlock == rds.rdsA || rds.PICTlock == 0)) {
// CT
uint32_t mjd = (rds.rdsB & 0x03) << 15 | ((rds.rdsC >> 1) & 0x7FFF);; uint32_t mjd = (rds.rdsB & 0x03) << 15 | ((rds.rdsC >> 1) & 0x7FFF);;
uint16_t hour, minute, day = 5, month = 1, year = 2026; uint16_t hour, minute, day = 5, month = 1, year = 2026;
int32_t timeoffset; int32_t timeoffset;
long J, C, Y, M; long J = mjd + 2400001 + 68569;
J = mjd + 2400001 + 68569; long C = 4 * J / 146097;
C = 4 * J / 146097;
J = J - (146097 * C + 3) / 4; J = J - (146097 * C + 3) / 4;
Y = 4000 * (J + 1) / 1461001; long Y = 4000 * (J + 1) / 1461001;
J = J - 1461 * Y / 4 + 31; J = J - 1461 * Y / 4 + 31;
M = 80 * J / 2447; long M = 80 * J / 2447;
if ((J - 2447 * M / 80) < 32) day = J - 2447 * M / 80; if ((J - 2447 * M / 80) < 32) day = J - 2447 * M / 80;
J = M / 11; J = M / 11;
@@ -1278,7 +1248,6 @@ void TEF6686::readRDS(byte showrdserrors) {
case RDS_GROUP_10A: { case RDS_GROUP_10A: {
if (!rdsCerrorThreshold && !rdsDerrorThreshold) { if (!rdsCerrorThreshold && !rdsDerrorThreshold) {
// PTYN
uint8_t segment = bitRead(rds.rdsB, 0); uint8_t segment = bitRead(rds.rdsB, 0);
if (rds.rdsC != 0 && rds.rdsD != 0) { if (rds.rdsC != 0 && rds.rdsD != 0) {
ptyn_buffer[(segment * 4) + 0] = rds.rdsC >> 8; ptyn_buffer[(segment * 4) + 0] = rds.rdsC >> 8;
@@ -1301,7 +1270,6 @@ void TEF6686::readRDS(byte showrdserrors) {
case RDS_GROUP_11A: case RDS_GROUP_11A:
case RDS_GROUP_12A: case RDS_GROUP_12A:
case RDS_GROUP_13A: { case RDS_GROUP_13A: {
// RT+ decoding
if ((!rdsBerrorThreshold && !rdsCerrorThreshold && !rdsDerrorThreshold) && rtplusblock == rdsgroup && rds.hasRTplus) { if ((!rdsBerrorThreshold && !rdsCerrorThreshold && !rdsDerrorThreshold) && rtplusblock == rdsgroup && rds.hasRTplus) {
rds.rdsplusTag1 = ((rds.rdsB & 0x07) << 3) + (rds.rdsC >> 13); rds.rdsplusTag1 = ((rds.rdsB & 0x07) << 3) + (rds.rdsC >> 13);
rds.rdsplusTag2 = ((rds.rdsC & 0x01) << 5) + (rds.rdsD >> 11); rds.rdsplusTag2 = ((rds.rdsC & 0x01) << 5) + (rds.rdsD >> 11);
@@ -1354,7 +1322,6 @@ void TEF6686::readRDS(byte showrdserrors) {
rds.RTContent2 = extractUTF8Substring(rds.RTContent2, 0, 44, false); rds.RTContent2 = extractUTF8Substring(rds.RTContent2, 0, 44, false);
} }
// eRT decoding
if ((!rdsBerrorThreshold && !rdsCerrorThreshold && !rdsDerrorThreshold) && eRTblock == rdsgroup && _hasEnhancedRT) { if ((!rdsBerrorThreshold && !rdsCerrorThreshold && !rdsDerrorThreshold) && eRTblock == rdsgroup && _hasEnhancedRT) {
uint8_t offset = (rds.rdsB & 0x1f) * 4; uint8_t offset = (rds.rdsB & 0x1f) * 4;
eRT_buffer[offset + 0] = rds.rdsC >> 8; eRT_buffer[offset + 0] = rds.rdsC >> 8;
@@ -1380,8 +1347,7 @@ void TEF6686::readRDS(byte showrdserrors) {
} }
} }
if (!rdsBerrorThreshold && rdsgroup == 16 && (bitRead(rds.rdsB, 15))) rds.hasTMC = true;
if (!rdsBerrorThreshold && rdsgroup == 16 && (bitRead(rds.rdsB, 15))) rds.hasTMC = true; // TMC flag
if ((!rdsBerrorThreshold && !rdsCerrorThreshold && !rdsDerrorThreshold) && DABAFblock == rdsgroup && rds.hasDABAF) { if ((!rdsBerrorThreshold && !rdsCerrorThreshold && !rdsDerrorThreshold) && DABAFblock == rdsgroup && rds.hasDABAF) {
rds.dabaffreq = (rds.rdsC * 16); rds.dabaffreq = (rds.rdsC * 16);
@@ -1404,7 +1370,6 @@ void TEF6686::readRDS(byte showrdserrors) {
break; break;
case RDS_GROUP_14A: { case RDS_GROUP_14A: {
// EON
if (!rdsAerrorThreshold && !rdsBerrorThreshold && !rdsCerrorThreshold && !rdsDerrorThreshold) { if (!rdsAerrorThreshold && !rdsBerrorThreshold && !rdsCerrorThreshold && !rdsDerrorThreshold) {
rds.hasEON = true; rds.hasEON = true;
@@ -1429,22 +1394,21 @@ void TEF6686::readRDS(byte showrdserrors) {
else eon[eon_counter].picode[j] += 'A' - 10; else eon[eon_counter].picode[j] += 'A' - 10;
} }
eon[eon_counter].pi = rds.rdsD; // Store PI on next array eon[eon_counter].pi = rds.rdsD;
if (eon_counter < 20) eon_counter++; if (eon_counter < 20) eon_counter++;
eonIndex = eon_counter - 1; eonIndex = eon_counter - 1;
} else eonIndex = i; } else eonIndex = i;
uint8_t offset = rds.rdsB & 0x0F; // Read offset uint8_t offset = rds.rdsB & 0x0F;
if (offset < 4 && eon[eonIndex].pi == rds.rdsD) { if (offset < 4 && eon[eonIndex].pi == rds.rdsD) {
eon_buffer[eonIndex][(offset * 2) + 0] = rds.rdsC >> 8; // First character of segment eon_buffer[eonIndex][(offset * 2) + 0] = rds.rdsC >> 8;
eon_buffer[eonIndex][(offset * 2) + 1] = rds.rdsC & 0xFF; // Second character of segment eon_buffer[eonIndex][(offset * 2) + 1] = rds.rdsC & 0xFF;
} }
if (eon[eonIndex].pi == rds.rdsD) { // Last chars are received if (eon[eonIndex].pi == rds.rdsD) {
RDScharConverter(eon_buffer[eonIndex], EONPStext[eonIndex], sizeof(EONPStext[eonIndex]) / sizeof(wchar_t), false); // Convert 8 bit ASCII to 16 bit ASCII RDScharConverter(eon_buffer[eonIndex], EONPStext[eonIndex], sizeof(EONPStext[eonIndex]) / sizeof(wchar_t), false);
String utf8String = convertToUTF8(EONPStext[eonIndex]); // Convert RDS characterset to ASCII eon[eonIndex].ps = extractUTF8Substring(convertToUTF8(EONPStext[eonIndex]), 0, 8, false);
eon[eonIndex].ps = extractUTF8Substring(utf8String, 0, 8, false); // Make sure PS does not exceed 8 characters
} }
if (offset == 13 && eon[eonIndex].pi == rds.rdsD) { if (offset == 13 && eon[eonIndex].pi == rds.rdsD) {
@@ -1456,11 +1420,10 @@ void TEF6686::readRDS(byte showrdserrors) {
if (bitRead(rds.rdsB, 4) && eon[eonIndex].pi == rds.rdsD) eon[eonIndex].tp = true; if (bitRead(rds.rdsB, 4) && eon[eonIndex].pi == rds.rdsD) eon[eonIndex].tp = true;
if (offset > 4 && offset < 9 && eon[eonIndex].pi == rds.rdsD) { // Check if mapped frequency belongs to current frequency if (offset > 4 && offset < 9 && eon[eonIndex].pi == rds.rdsD) {
if (((rds.rdsC >> 8) * 10 + 8750) == currentfreq && (rds.rdsC >> 8) > 0 && (rds.rdsC >> 8) < 205) { if (((rds.rdsC >> 8) * 10 + 8750) == currentfreq && (rds.rdsC >> 8) > 0 && (rds.rdsC >> 8) < 205) {
if (eon[eonIndex].mappedfreq == 0) { if (eon[eonIndex].mappedfreq == 0) eon[eonIndex].mappedfreq = ((rds.rdsC & 0xFF) * 10 + 8750);
eon[eonIndex].mappedfreq = ((rds.rdsC & 0xFF) * 10 + 8750); // Add mapped frequency to array else if (eon[eonIndex].mappedfreq2 == 0 && eon[eonIndex].mappedfreq != ((rds.rdsC & 0xFF) * 10 + 8750) && (rds.rdsC >> 8) > 0 && (rds.rdsC >> 8) < 205) {
} else if (eon[eonIndex].mappedfreq2 == 0 && eon[eonIndex].mappedfreq != ((rds.rdsC & 0xFF) * 10 + 8750) && (rds.rdsC >> 8) > 0 && (rds.rdsC >> 8) < 205) {
eon[eonIndex].mappedfreq2 = ((rds.rdsC & 0xFF) * 10 + 8750); eon[eonIndex].mappedfreq2 = ((rds.rdsC & 0xFF) * 10 + 8750);
} else if (eon[eonIndex].mappedfreq3 == 0 && eon[eonIndex].mappedfreq2 != ((rds.rdsC & 0xFF) * 10 + 8750) && eon[eonIndex].mappedfreq != ((rds.rdsC & 0xFF) * 10 + 8750) && (rds.rdsC >> 8) > 0 && (rds.rdsC >> 8) < 205) { } else if (eon[eonIndex].mappedfreq3 == 0 && eon[eonIndex].mappedfreq2 != ((rds.rdsC & 0xFF) * 10 + 8750) && eon[eonIndex].mappedfreq != ((rds.rdsC & 0xFF) * 10 + 8750) && (rds.rdsC >> 8) > 0 && (rds.rdsC >> 8) < 205) {
eon[eonIndex].mappedfreq3 = ((rds.rdsC & 0xFF) * 10 + 8750); eon[eonIndex].mappedfreq3 = ((rds.rdsC & 0xFF) * 10 + 8750);
@@ -1543,7 +1506,7 @@ void TEF6686::readRDS(byte showrdserrors) {
PSLongtext = pslong_buffer; PSLongtext = pslong_buffer;
rds.stationNameLong = extractUTF8Substring(pslong_buffer, 0, endmarkerLPS, true); rds.stationNameLong = extractUTF8Substring(pslong_buffer, 0, endmarkerLPS, true);
rds.stationNameLong = trimTrailingSpaces(rds.stationNameLong); rds.stationNameLong = trimTrailingSpaces(rds.stationNameLong);
if ((packet0long && packet1long && packet2long && packet3long) || foundendmarker) pslong_process = true; // OK, we had one runs, now let's go the idle PS Long writing if ((packet0long && packet1long && packet2long && packet3long) || foundendmarker) pslong_process = true;
} }
} }
} }
@@ -1560,161 +1523,87 @@ void TEF6686::readRDS(byte showrdserrors) {
void TEF6686::clearRDS(bool fullsearchrds) { void TEF6686::clearRDS(bool fullsearchrds) {
devTEF_Set_Cmd(TEF_FM, Cmd_Set_RDS, 9, fullsearchrds ? 3 : 1, 1, 0); devTEF_Set_Cmd(TEF_FM, Cmd_Set_RDS, 9, fullsearchrds ? 3 : 1, 1, 0);
rds.piBuffer.clear(); rds.piBuffer.clear();
rds.stationName = ""; rds.stationName = rds.stationText = rds.stationNameLong = "";
rds.stationText = ""; rds.stationText32 = rds.RTContent1 = rds.RTContent2 = "";
rds.stationNameLong = ""; rds.PTYN = rds.ECCtext = rds.stationIDtext = "";
rds.stationText32 = ""; rds.stationStatetext = rds.enhancedRTtext = PSLongtext = "";
rds.RTContent1 = "";
rds.RTContent2 = "";
rds.PTYN = "";
rds.ECCtext = "";
rds.stationIDtext = "";
rds.stationStatetext = "";
rds.enhancedRTtext = "";
PSLongtext = "";
uint8_t i; for (uint8_t i = 0; i < 8; i++) {
for (i = 0; i < 8; i++) { ps_buffer[i] = ptyn_buffer[i] = 0x20;
ps_buffer[i] = 0x20; PStext[i] = PTYNtext[i] = 0;
PStext[i] = 0;
ptyn_buffer[i] = 0x20;
PTYNtext[i] = 0;
} }
ps_buffer[8] = 0; ps_buffer[8] = ptyn_buffer[8] = PStext[8] = PTYNtext[8] = 0;
ptyn_buffer[8] = 0;
PStext[8] = 0;
PTYNtext[8] = 0;
for (i = 0; i < 64; i++) rt_buffer[i] = 0x20; for (uint8_t i = 0; i < 64; i++) rt_buffer[i] = 0x20;
rt_buffer[64] = 0; rt_buffer[64] = 0;
for (i = 0; i < 128; i++) eRT_buffer[i] = 0x20; for (uint8_t i = 0; i < 128; i++) eRT_buffer[i] = 0x20;
eRT_buffer[128] = 0; eRT_buffer[128] = 0;
for (i = 0; i < 32; i++) { for (uint8_t i = 0; i < 32; i++) rt_buffer32[i] = pslong_buffer[i] = pslong_buffer2[i] = 0x20;
rt_buffer32[i] = 0x20;
pslong_buffer[i] = 0x20;
pslong_buffer2[i] = 0x20;
// PSLongtext[i] = L'\0';
}
rt_buffer32[32] = 0; rt_buffer32[32] = 0;
pslong_buffer[32] = 0; pslong_buffer[32] = 0;
// PSLongtext[32] = L'\0';
for (i = 0; i < 6; i++) rds.picode[i] = 0x20; for (uint8_t i = 0; i < 6; i++) rds.picode[i] = 0x20;
rds.picode[6] = 0; rds.picode[6] = 0;
for (i = 0; i < 4; i++) rds.dabafeid[i] = 0x20; for (uint8_t i = 0; i < 4; i++) rds.dabafeid[i] = 0x20;
rds.dabafeid[4] = 0; rds.dabafeid[4] = 0;
for (i = 0; i < 3; i++) rds.dabafchannel[i] = 0x20; for (uint8_t i = 0; i < 3; i++) rds.dabafchannel[i] = 0x20;
rds.dabafchannel[3] = 0; rds.dabafchannel[3] = 0;
for (i = 0; i < 8; i++) rds.stationID[i] = 0x20; for (uint8_t i = 0; i < 8; i++) rds.stationID[i] = 0x20;
rds.stationID[8] = 0; rds.stationID[8] = 0;
for (i = 0; i < 2; i++) rds.stationState[i] = 0x20; for (uint8_t i = 0; i < 2; i++) rds.stationState[i] = 0x20;
rds.stationState[2] = 0; rds.stationState[2] = 0;
for (i = 0; i < 50; i++) { for (uint8_t i = 0; i < 50; i++) {
af[i].frequency = 0; af[i].frequency = 0;
af[i].score = -32767; af[i].score = -32767;
af[i].afvalid = true; af[i].afvalid = true;
af[i].checked = false; af[i].checked = af[i].regional = af[i].same = false;
af[i].regional = false;
af[i].same = false;
} }
for (i = 0; i < 20; i++) { for (uint8_t i = 0; i < 20; i++) {
eon[i].pty = 254; eon[i].pty = 254;
eon[i].pi = 0;
eon[i].ps = ""; eon[i].ps = "";
eon[i].mappedfreq = 0; eon[i].pi = eon[i].mappedfreq = eon[i].mappedfreq2 = eon[i].mappedfreq3 = 0;
eon[i].mappedfreq2 = 0; eon[i].ta = eon[i].tp = eon[i].taset = eon[i].ptyset = false;
eon[i].mappedfreq3 = 0;
eon[i].ta = false;
eon[i].tp = false;
eon[i].taset = false;
eon[i].ptyset = false;
for (int y = 0; y < 5; y++) eon[i].picode[y] = 0; for (int y = 0; y < 5; y++) eon[i].picode[y] = 0;
for (int j = 0; j < 9; j++) { for (int j = 0; j < 9; j++) EONPStext[i][j] = eon_buffer[i][j] = 0;
EONPStext[i][j] = 0;
eon_buffer[i][j] = 0;
}
} }
for (i = 0; i < 45; i++) { for (uint8_t i = 0; i < 45; i++) RDSplus1[i] = RDSplus2[i] = 0;
RDSplus1[i] = 0;
RDSplus2[i] = 0;
}
for (i = 0; i < 33; i++) rds.blockcounter[i] = 0; for (uint8_t i = 0; i < 33; i++) rds.blockcounter[i] = 0;
for (i = 0; i < 10; i++) rds.aid[i] = 0; for (uint8_t i = 0; i < 10; i++) rds.aid[i] = 0;
rdsgroup = 254; rdsgroup = rds.ECC = 254;
processed_rdsblocks = 0; rds.dabaffreq = rds.correctPI = correctPIold = processed_rdsblocks = piold = 0;
piold = 0;
rds.correctPI = 0;
rds.ECC = 254;
rds.PTY = 32; rds.PTY = 32;
rds.dabaffreq = 0; rds.hasECC = rds.hasRT = rds.hasRDS = false;
rds.hasECC = false; rds.TP = rds.hasAF = rds.hasTA = false;
rds.hasRT = false; rds.hasEON = rds.hasCT = rds.hasTMC = false;
rds.hasRDS = false; rds.hasAID = rds.hasPTYN = rds.hasLongPS = false;
rds.TP = false; rds.hasRTplus = rds.hasDABAF = rds.hasEnhancedRT = false;
rds.hasAF = false; rt_process = ps_process = pslong_process = false;
rds.hasTA = false;
rds.hasEON = false;
rds.hasCT = false;
rds.hasTMC = false;
rds.hasAID = false;
rds.hasPTYN = false;
rds.hasLongPS = false;
rds.hasRTplus = false;
rds.hasDABAF = false;
rds.hasEnhancedRT = false;
rt_process = false;
ps_process = false;
pslong_process = false;
rds.rdsreset = true; rds.rdsreset = true;
rds.hasArtificialhead = false; rds.hasArtificialhead = rds.hasCompressed = false;
rds.hasCompressed = false; rds.hasDynamicPTY = rds.hasStereo = false;
rds.hasDynamicPTY = false; af_counter = af_updatecounter = eon_counter = 0;
rds.hasStereo = false; afreset = rds.rdsAerror = rds.rdsBerror = rds.rdsCerror = rds.rdsDerror = true;
af_counter = 0; initrt = initab = true;
af_updatecounter = 0;
eon_counter = 0;
afreset = true;
rds.rdsAerror = true;
rds.rdsBerror = true;
rds.rdsCerror = true;
rds.rdsDerror = true;
initrt = true;
initab = true;
rds.rdsplusTag1 = 169; rds.rdsplusTag1 = 169;
rds.rdsplusTag2 = 169; rds.rdsplusTag2 = 169;
afinit = false; afinit = afmethodB = errorfreepi = false;
errorfreepi = false; packet0 = packet1 = packet2 = packet3 = false;
afmethodB = false; packet0long = packet1long = packet2long = packet3long = false;
packet0 = false; rds.aid_counter = af_number = 0;
packet1 = false; afmethodBprobe = afmethodBtrigger = _hasEnhancedRT = false;
packet2 = false; rds.ps12error = rds.ps34error = rds.ps56error = rds.ps78error = true;
packet3 = false;
packet0long = false;
packet1long = false;
packet2long = false;
packet3long = false;
rds.aid_counter = 0;
afmethodBprobe = false;
afmethodBtrigger = false;
correctPIold = 0;
af_number = 0;
_hasEnhancedRT = false;
rds.ps12error = true;
rds.ps34error = true;
rds.ps56error = true;
rds.ps78error = true;
} }
void TEF6686::tone(uint16_t time, int16_t amplitude, uint16_t frequency) { void TEF6686::tone(uint16_t time, int16_t amplitude, uint16_t frequency) {
@@ -1724,58 +1613,6 @@ void TEF6686::tone(uint16_t time, int16_t amplitude, uint16_t frequency) {
devTEF_Radio_Set_Wavegen(0, 0, 0); devTEF_Radio_Set_Wavegen(0, 0, 0);
} }
String TEF6686::convertToUTF8(const wchar_t* input) {
String output;
while (*input) {
uint32_t unicode = *input;
if (unicode < 0x80) output += (char)unicode;
else if (unicode < 0x800) {
output += (char)(0xC0 | (unicode >> 6));
output += (char)(0x80 | (unicode & 0x3F));
} else if (unicode < 0x10000) {
output += (char)(0xE0 | (unicode >> 12));
output += (char)(0x80 | ((unicode >> 6) & 0x3F));
output += (char)(0x80 | (unicode & 0x3F));
} else {
output += (char)(0xF0 | (unicode >> 18));
output += (char)(0x80 | ((unicode >> 12) & 0x3F));
output += (char)(0x80 | ((unicode >> 6) & 0x3F));
output += (char)(0x80 | (unicode & 0x3F));
}
input++;
}
return output;
}
String TEF6686::extractUTF8Substring(const String & utf8String, size_t start, size_t length, bool underscore) {
String substring;
size_t utf8Length = utf8String.length();
size_t utf8Index = 0;
size_t charIndex = 0;
while (utf8Index < utf8Length && charIndex < start + length) {
uint8_t currentByte = utf8String.charAt(utf8Index);
uint8_t numBytes = 0;
if (currentByte < 0x80) numBytes = 1;
else if ((currentByte >> 5) == 0x6) numBytes = 2;
else if ((currentByte >> 4) == 0xE) numBytes = 3;
else if ((currentByte >> 3) == 0x1E) numBytes = 4;
if (charIndex >= start) substring += utf8String.substring(utf8Index, utf8Index + numBytes);
utf8Index += numBytes;
charIndex++;
}
if (underscore) {
while (substring.length() < length) substring += '_';
}
return substring;
}
void TEF6686::RDScharConverter(const char* input, wchar_t* output, size_t size, bool underscore) { void TEF6686::RDScharConverter(const char* input, wchar_t* output, size_t size, bool underscore) {
for (size_t i = 0; i < size - 1; i++) { for (size_t i = 0; i < size - 1; i++) {
char currentChar = input[i]; char currentChar = input[i];
@@ -1919,35 +1756,7 @@ void TEF6686::RDScharConverter(const char* input, wchar_t* output, size_t size,
case 0xFF: output[i] = L' '; break; case 0xFF: output[i] = L' '; break;
} }
} }
output[size - 1] = L'\0'; output[size - 1] = 0;
}
String TEF6686::trimTrailingSpaces(String str) {
int end = str.length() - 1;
while (end >= 0 && isspace(str[end])) end--;
return str.substring(0, end + 1);
}
String TEF6686::ucs2ToUtf8(const char* ucs2Input) {
String utf8Output;
size_t length = 0;
while (ucs2Input[length] != '\0' || ucs2Input[length + 1] != '\0') length += 2;
for (size_t i = 0; i < length; i += 2) {
uint16_t ucs2Char = ((uint8_t)ucs2Input[i] << 8) | (uint8_t)ucs2Input[i + 1];
if (ucs2Char <= 0x7F) utf8Output += (char)ucs2Char;
else if (ucs2Char <= 0x7FF) {
utf8Output += (char)(0xC0 | (ucs2Char >> 6));
utf8Output += (char)(0x80 | (ucs2Char & 0x3F));
} else {
utf8Output += (char)(0xE0 | (ucs2Char >> 12));
utf8Output += (char)(0x80 | ((ucs2Char >> 6) & 0x3F));
utf8Output += (char)(0x80 | (ucs2Char & 0x3F));
}
}
return utf8Output;
} }
static const char* fixedCalls[] = {"CBLA", "CBFM", "CBOT"}; static const char* fixedCalls[] = {"CBLA", "CBFM", "CBOT"};
+20 -51
View File
@@ -30,18 +30,13 @@ bool devTEF_Get_Cmd(TEF_MODULE module, uint8_t cmd, uint8_t *receive, uint16_t l
return Tuner_ReadBuffer(receive, len); return Tuner_ReadBuffer(receive, len);
} }
void devTEF_Radio_Set_Noiseblanker_AM(uint8_t mode, uint16_t start) {
devTEF_Set_Cmd(TEF_AM, Cmd_Set_NoiseBlanker, 7, mode, start);
devTEF_Set_Cmd(TEF_AM, Cmd_Set_NoiseBlanker_Audio, 7, mode, 1000);
}
uint8_t devTEF_APPL_Get_Operation_Status() { uint8_t devTEF_APPL_Get_Operation_Status() {
uint8_t buf[2]; uint8_t buf[2];
devTEF_Get_Cmd(TEF_APPL, Cmd_Get_Operation_Status, buf, sizeof(buf)); devTEF_Get_Cmd(TEF_APPL, Cmd_Get_Operation_Status, buf, sizeof(buf));
return Convert8bto16b(buf); return Convert8bto16b(buf);
} }
bool devTEF_Radio_Get_Processing_Status (uint16_t *highcut, uint16_t *stereo, uint16_t *sthiblend, uint8_t *stband_1, uint8_t *stband_2, uint8_t *stband_3, uint8_t *stband_4) { bool devTEF_Radio_Get_Processing_Status(uint16_t *highcut, uint16_t *stereo, uint16_t *sthiblend, uint8_t *stband_1, uint8_t *stband_2, uint8_t *stband_3, uint8_t *stband_4) {
uint8_t buf[12]; uint8_t buf[12];
uint16_t r = devTEF_Get_Cmd(TEF_FM, Cmd_Get_Processing_Status, buf, sizeof(buf)); uint16_t r = devTEF_Get_Cmd(TEF_FM, Cmd_Get_Processing_Status, buf, sizeof(buf));
*highcut = Convert8bto16b(buf + 2) / 10; *highcut = Convert8bto16b(buf + 2) / 10;
@@ -56,52 +51,33 @@ bool devTEF_Radio_Get_Processing_Status (uint16_t *highcut, uint16_t *stereo, ui
return r; return r;
} }
bool devTEF_Radio_Get_Quality_Status (uint16_t *status, int16_t *level, uint16_t *usn, uint16_t *wam, int16_t *offset, uint16_t *bandwidth, uint16_t *mod, int8_t *snr) { void devTEF_Radio_Get_Quality_Status(uint16_t *status, int16_t *level, uint16_t *usn, uint16_t *wam, int16_t *offset, uint16_t *bandwidth, uint16_t *mod, int8_t *snr) {
uint8_t buf[14]; uint8_t buf[14];
uint16_t r = devTEF_Get_Cmd(TEF_FM, Cmd_Get_Quality_Data, buf, sizeof(buf)); devTEF_Get_Cmd(TEF_FM, Cmd_Get_Quality_Data, buf, sizeof(buf));
*status = Convert8bto16b(buf); if(status != NULL) *status = Convert8bto16b(buf);
*level = Convert8bto16b(buf + 2); if(level != NULL) *level = Convert8bto16b(buf + 2);
*usn = Convert8bto16b(buf + 4); if(usn != NULL) *usn = Convert8bto16b(buf + 4);
*wam = Convert8bto16b(buf + 6); if(wam != NULL) *wam = Convert8bto16b(buf + 6);
*offset = Convert8bto16b(buf + 8); if(offset != NULL) *offset = Convert8bto16b(buf + 8);
*bandwidth = Convert8bto16b(buf + 10) / 10; if(bandwidth != NULL) *bandwidth = Convert8bto16b(buf + 10) / 10;
*mod = Convert8bto16b(buf + 12) / 10; if(mod != NULL) *mod = Convert8bto16b(buf + 12) / 10;
if (*level < -200) *level = -200; if (*level < -200) *level = -200;
if (*level > 1200) *level = 1200; if (*level > 1200) *level = 1200;
*snr = int(0.46222375 * (float)(*level) / 10 - 0.082495118 * (float)(*usn) / 10) + 10; if(snr != NULL) *snr = int(0.46222375 * (float)(*level) / 10 - 0.082495118 * (float)(*usn) / 10) + 10;
return r;
} }
bool devTEF_Radio_Get_Quality_Status_AM(int16_t *level, uint16_t *noise, uint16_t *cochannel, int16_t *offset, uint16_t *bandwidth, uint16_t *mod, int8_t *snr) { void devTEF_Radio_Get_RDS_Status(uint16_t *status, uint16_t *A_block, uint16_t *B_block, uint16_t *C_block, uint16_t *D_block, uint16_t *dec_error) {
uint8_t buf[14];
uint16_t r = devTEF_Get_Cmd(TEF_AM, Cmd_Get_Quality_Data, buf, sizeof(buf));
*level = Convert8bto16b(buf + 2);
*noise = Convert8bto16b(buf + 4);
*cochannel = Convert8bto16b(buf + 6);
*offset = Convert8bto16b(buf + 8);
*bandwidth = Convert8bto16b(buf + 10) / 10;
*mod = Convert8bto16b(buf + 12) / 10;
if (*level < -200) *level = -200;
if (*level > 1200) *level = 1200;
*snr = int(0.46222375 * (float)(*level) / 10 - 0.082495118 * (float)(*noise / 50) / 10) + 10;
return r;
}
bool devTEF_Radio_Get_RDS_Status (uint16_t *status, uint16_t *A_block, uint16_t *B_block, uint16_t *C_block, uint16_t *D_block, uint16_t *dec_error) {
uint8_t buf[12]; uint8_t buf[12];
uint8_t r = devTEF_Get_Cmd(TEF_FM, Cmd_Get_RDS_Status, buf, sizeof(buf)); devTEF_Get_Cmd(TEF_FM, Cmd_Get_RDS_Status, buf, sizeof(buf));
*status = Convert8bto16b(buf); if(status != NULL) *status = Convert8bto16b(buf);
*A_block = Convert8bto16b(buf + 2); if(A_block != NULL) *A_block = Convert8bto16b(buf + 2);
*B_block = Convert8bto16b(buf + 4); if(B_block != NULL) *B_block = Convert8bto16b(buf + 4);
*C_block = Convert8bto16b(buf + 6); if(C_block != NULL) *C_block = Convert8bto16b(buf + 6);
*D_block = Convert8bto16b(buf + 8); if(D_block != NULL) *D_block = Convert8bto16b(buf + 8);
*dec_error = Convert8bto16b(buf + 10); if(dec_error != NULL) *dec_error = Convert8bto16b(buf + 10);
return r;
} }
bool devTEF_Radio_Get_RDS_Data (uint16_t *status, uint16_t *A_block, uint16_t *B_block, uint16_t *C_block, uint16_t *D_block, uint16_t *dec_error) { bool devTEF_Radio_Get_RDS_Data(uint16_t *status, uint16_t *A_block, uint16_t *B_block, uint16_t *C_block, uint16_t *D_block, uint16_t *dec_error) {
uint8_t buf[12]; uint8_t buf[12];
uint8_t r = devTEF_Get_Cmd(TEF_FM, Cmd_Get_RDS_Data, buf, sizeof(buf)); uint8_t r = devTEF_Get_Cmd(TEF_FM, Cmd_Get_RDS_Data, buf, sizeof(buf));
*status = Convert8bto16b(buf); *status = Convert8bto16b(buf);
@@ -126,10 +102,3 @@ void devTEF_Radio_Set_Wavegen(bool mode, int16_t amplitude, uint16_t freq) {
if (mode) devTEF_Set_Cmd(TEF_AUDIO, Cmd_Set_WaveGen, 15, 5, 0, amplitude * 10, freq, amplitude * 10, freq); if (mode) devTEF_Set_Cmd(TEF_AUDIO, Cmd_Set_WaveGen, 15, 5, 0, amplitude * 10, freq, amplitude * 10, freq);
else devTEF_Set_Cmd(TEF_AUDIO, Cmd_Set_WaveGen, 15, 0); else devTEF_Set_Cmd(TEF_AUDIO, Cmd_Set_WaveGen, 15, 0);
} }
void devTEF_Radio_Set_GPIO(uint8_t mode) {
if (mode == 0) devTEF_Set_Cmd(TEF_APPL, Cmd_Set_GPIO, 9, 0, 33, 2);
if (mode == 1) devTEF_Set_Cmd(TEF_APPL, Cmd_Set_GPIO, 9, 0, 33, 3);
if (mode == 2) devTEF_Set_Cmd(TEF_APPL, Cmd_Set_GPIO, 9, 0, 32, 2);
if (mode == 3) devTEF_Set_Cmd(TEF_APPL, Cmd_Set_GPIO, 9, 0, 32, 3);
}
+14 -16
View File
@@ -9,9 +9,9 @@ void Communication() {
if (wifi) { if (wifi) {
int packetSize = Udp.parsePacket(); int packetSize = Udp.parsePacket();
if (packetSize > 0) { if (packetSize > 0) {
char packetBuffer[packetSize + 1]; // +1 for null getStatus char packetBuffer[packetSize + 1];
Udp.read(packetBuffer, packetSize); Udp.read(packetBuffer, packetSize);
packetBuffer[packetSize] = '\0'; // Ensure valid string packetBuffer[packetSize] = '\0';
Udp.endPacket(); Udp.endPacket();
String packet = String(packetBuffer); String packet = String(packetBuffer);
@@ -28,23 +28,24 @@ void Communication() {
char command = packet.charAt(1); char command = packet.charAt(1);
switch (command) { switch (command) {
case 'U': case 'U':
case 'D': case 'D': {
tunemode = TUNE_MAN; tunemode = TUNE_MAN;
ShowTuneMode(); ShowTuneMode();
if (command == 'U') TuneUp(); else TuneDown(); if (command == 'U') TuneUp(); else TuneDown();
ShowFreq(0); ShowFreq(0);
break; break;
}
case '>': case '>':
case '<': case '<': {
if (command == '>') direction = true; else direction = false; if (command == '>') direction = true; else direction = false;
Seek(direction); Seek(direction);
ShowFreq(0); ShowFreq(0);
break; break;
}
case 'T': case 'T': {
uint16_t freqtemp; uint16_t freqtemp = packet.substring(2).toInt();
freqtemp = packet.substring(2).toInt();
if (BAND_FM) freqtemp -= ConverterSet * 1000; if (BAND_FM) freqtemp -= ConverterSet * 1000;
if (seek) seek = false; if (seek) seek = false;
radio.clearRDS(fullsearchrds); radio.clearRDS(fullsearchrds);
@@ -74,11 +75,12 @@ void Communication() {
} }
ShowFreq(0); ShowFreq(0);
break; break;
}
case 'S': if (!scandxmode) startFMDXScan(); break; case 'S': {if (!scandxmode) startFMDXScan(); break;}
case 'E': if (scandxmode) cancelDXScan(); break; case 'E': {if (scandxmode) cancelDXScan(); break;}
case 'R': radio.clearRDS(fullsearchrds); break; case 'R': {radio.clearRDS(fullsearchrds); break;}
} }
return; return;
} }
@@ -168,8 +170,6 @@ void Communication() {
passwordcrypt(); passwordcrypt();
RemoteClient.print(saltkey + "\n"); RemoteClient.print(saltkey + "\n");
} }
} else {
if (Server.hasClient()) Server.available().stop();
} }
if (wificonnected && !RemoteClient.connected()) { if (wificonnected && !RemoteClient.connected()) {
@@ -195,9 +195,7 @@ void Communication() {
RemoteClient.print("o1,0\n"); RemoteClient.print("o1,0\n");
RemoteClient.print("G" + String(!EQset) + String(!iMSset) + "\n"); RemoteClient.print("G" + String(!EQset) + String(!iMSset) + "\n");
store = true; store = true;
} else { } else RemoteClient.print("a0\n");
RemoteClient.print("a0\n");
}
} }
} }
@@ -815,7 +813,7 @@ void XDRGTKRoutine() {
delay(5); delay(5);
DataPrint(String(freq_scan * 10, DEC)); DataPrint(String(freq_scan * 10, DEC));
DataPrint(" = "); DataPrint(" = ");
if (band < BAND_GAP) radio.getStatus(SStatus, USN, WAM, OStatus, BW, MStatus, CN); else radio.getStatusAM(SStatus, USN, WAM, OStatus, BW, MStatus, CN); if (band < BAND_GAP) radio.getStatus(&SStatus, &USN, &WAM, &OStatus, &BW, &MStatus, &CN); else radio.getStatusAM(&SStatus, &USN, &WAM, &OStatus, &BW, &MStatus, &CN);
DataPrint(String((SStatus / 10) + 10, DEC)); DataPrint(String((SStatus / 10) + 10, DEC));
DataPrint(", "); DataPrint(", ");
} }
-90
View File
@@ -1448,27 +1448,6 @@ void ShowOneLine(byte position, byte item, bool selected) {
FullLineSprite.setTextDatum(TR_DATUM); FullLineSprite.setTextDatum(TR_DATUM);
FullLineSprite.setTextColor(PrimaryColor, PrimaryColorSmooth, false); FullLineSprite.setTextColor(PrimaryColor, PrimaryColorSmooth, false);
#ifdef HAS_AIR_BAND
switch (bandAM) {
case AM_BAND_ALL: FullLineSprite.drawString(textUI(102) + String(",") + textUI(103) + String(",") + textUI(104) + String(",") + textUI(223), 298, 2); break;
case AM_BAND_LW_MW_SW: FullLineSprite.drawString(textUI(102) + String(",") + textUI(103) + String(",") + textUI(104), 298, 2); break;
case AM_BAND_LW_MW_AIR: FullLineSprite.drawString(textUI(102) + String(",") + textUI(103) + String(",") + textUI(223), 298, 2); break;
case AM_BAND_LW_SW_AIR: FullLineSprite.drawString(textUI(102) + String(",") + textUI(104) + String(",") + textUI(223), 298, 2); break;
case AM_BAND_MW_SW_AIR: FullLineSprite.drawString(textUI(103) + String(",") + textUI(104) + String(",") + textUI(223), 298, 2); break;
case AM_BAND_LW_MW: FullLineSprite.drawString(textUI(102) + String(",") + textUI(103), 298, 2); break;
case AM_BAND_LW_SW: FullLineSprite.drawString(textUI(102) + String(",") + textUI(104), 298, 2); break;
case AM_BAND_LW_AIR: FullLineSprite.drawString(textUI(102) + String(",") + textUI(223), 298, 2); break;
case AM_BAND_MW_SW: FullLineSprite.drawString(textUI(103) + String(",") + textUI(104), 298, 2); break;
case AM_BAND_MW_AIR: FullLineSprite.drawString(textUI(103) + String(",") + textUI(223), 298, 2); break;
case AM_BAND_SW_AIR: FullLineSprite.drawString(textUI(104) + String(",") + textUI(223), 298, 2); break;
case AM_BAND_LW: FullLineSprite.drawString(textUI(102), 298, 2); break;
case AM_BAND_MW: FullLineSprite.drawString(textUI(103), 298, 2); break;
case AM_BAND_SW: FullLineSprite.drawString(textUI(104), 298, 2); break;
case AM_BAND_AIR: FullLineSprite.drawString(textUI(223), 298, 2); break;
case AM_BAND_NONE: FullLineSprite.drawString(textUI(83), 298, 2); break;
}
break;
#else
switch (bandAM) { switch (bandAM) {
case AM_BAND_ALL: FullLineSprite.drawString(textUI(102) + String(",") + textUI(103) + String(",") + textUI(104), 298, 2); break; case AM_BAND_ALL: FullLineSprite.drawString(textUI(102) + String(",") + textUI(103) + String(",") + textUI(104), 298, 2); break;
case AM_BAND_LW_MW: FullLineSprite.drawString(textUI(102) + String(",") + textUI(103), 298, 2); break; case AM_BAND_LW_MW: FullLineSprite.drawString(textUI(102) + String(",") + textUI(103), 298, 2); break;
@@ -1480,8 +1459,6 @@ void ShowOneLine(byte position, byte item, bool selected) {
case AM_BAND_NONE: FullLineSprite.drawString(textUI(83), 298, 2); break; case AM_BAND_NONE: FullLineSprite.drawString(textUI(83), 298, 2); break;
} }
break; break;
#endif
case DISPLAYSETTINGS: case DISPLAYSETTINGS:
FullLineSprite.setTextDatum(TL_DATUM); FullLineSprite.setTextDatum(TL_DATUM);
FullLineSprite.setTextColor(ActiveColor, ActiveColorSmooth, false); FullLineSprite.setTextColor(ActiveColor, ActiveColorSmooth, false);
@@ -2569,27 +2546,6 @@ void ShowOneButton(byte position, byte item, bool selected) {
PSSprite.drawString(shortLine(removeNewline(textUI(101))), 75, 1); PSSprite.drawString(shortLine(removeNewline(textUI(101))), 75, 1);
PSSprite.setTextColor(PrimaryColor, PrimaryColorSmooth, false); PSSprite.setTextColor(PrimaryColor, PrimaryColorSmooth, false);
#ifdef HAS_AIR_BAND
switch (bandAM) {
case AM_BAND_ALL: PSSprite.drawString(textUI(102) + String(",") + textUI(103) + String(",") + textUI(104) + String(",") + textUI(223), 75, 15); break;
case AM_BAND_LW_MW_SW: PSSprite.drawString(textUI(102) + String(",") + textUI(103) + String(",") + textUI(104), 75, 15); break;
case AM_BAND_LW_MW_AIR: PSSprite.drawString(textUI(102) + String(",") + textUI(103) + String(",") + textUI(223), 75, 15); break;
case AM_BAND_LW_SW_AIR: PSSprite.drawString(textUI(102) + String(",") + textUI(104) + String(",") + textUI(223), 75, 15); break;
case AM_BAND_MW_SW_AIR: PSSprite.drawString(textUI(103) + String(",") + textUI(104) + String(",") + textUI(223), 75, 15); break;
case AM_BAND_LW_MW: PSSprite.drawString(textUI(102) + String(",") + textUI(103), 75, 15); break;
case AM_BAND_LW_SW: PSSprite.drawString(textUI(102) + String(",") + textUI(104), 75, 15); break;
case AM_BAND_LW_AIR: PSSprite.drawString(textUI(102) + String(",") + textUI(223), 75, 15); break;
case AM_BAND_MW_SW: PSSprite.drawString(textUI(103) + String(",") + textUI(104), 75, 15); break;
case AM_BAND_MW_AIR: PSSprite.drawString(textUI(103) + String(",") + textUI(223), 75, 15); break;
case AM_BAND_SW_AIR: PSSprite.drawString(textUI(104) + String(",") + textUI(223), 75, 15); break;
case AM_BAND_LW: PSSprite.drawString(textUI(102), 75, 15); break;
case AM_BAND_MW: PSSprite.drawString(textUI(103), 75, 15); break;
case AM_BAND_SW: PSSprite.drawString(textUI(104), 75, 15); break;
case AM_BAND_AIR: PSSprite.drawString(textUI(223), 75, 15); break;
case AM_BAND_NONE: PSSprite.drawString(textUI(83), 75, 15); break;
}
break;
#else
switch (bandAM) { switch (bandAM) {
case AM_BAND_ALL: PSSprite.drawString(textUI(102) + String(",") + textUI(103) + String(",") + textUI(104), 75, 15); break; case AM_BAND_ALL: PSSprite.drawString(textUI(102) + String(",") + textUI(103) + String(",") + textUI(104), 75, 15); break;
case AM_BAND_LW_MW: PSSprite.drawString(textUI(102) + String(",") + textUI(103), 75, 15); break; case AM_BAND_LW_MW: PSSprite.drawString(textUI(102) + String(",") + textUI(103), 75, 15); break;
@@ -2601,8 +2557,6 @@ void ShowOneButton(byte position, byte item, bool selected) {
case AM_BAND_NONE: PSSprite.drawString(textUI(83), 75, 15); break; case AM_BAND_NONE: PSSprite.drawString(textUI(83), 75, 15); break;
} }
break; break;
#endif
case DISPLAYSETTINGS: case DISPLAYSETTINGS:
PSSprite.setTextDatum(TC_DATUM); PSSprite.setTextDatum(TC_DATUM);
PSSprite.setTextColor(ActiveColor, ActiveColorSmooth, false); PSSprite.setTextColor(ActiveColor, ActiveColorSmooth, false);
@@ -3374,27 +3328,6 @@ void MenuUpDown(bool dir) {
bandAM--; bandAM--;
if (bandAM > AM_BAND_CNT) bandAM = AM_BAND_NONE; if (bandAM > AM_BAND_CNT) bandAM = AM_BAND_NONE;
} }
#ifdef HAS_AIR_BAND
switch (bandAM) {
case AM_BAND_ALL: OneBigLineSprite.drawString(textUI(102) + String(",") + textUI(103) + String(",") + textUI(104) + String(",") + textUI(223), 135, 0); break;
case AM_BAND_LW_MW_SW: OneBigLineSprite.drawString(textUI(102) + String(",") + textUI(103) + String(",") + textUI(104), 135, 0); break;
case AM_BAND_LW_MW_AIR: OneBigLineSprite.drawString(textUI(102) + String(",") + textUI(103) + String(",") + textUI(223), 135, 0); break;
case AM_BAND_LW_SW_AIR: OneBigLineSprite.drawString(textUI(102) + String(",") + textUI(104) + String(",") + textUI(223), 135, 0); break;
case AM_BAND_MW_SW_AIR: OneBigLineSprite.drawString(textUI(103) + String(",") + textUI(104) + String(",") + textUI(223), 135, 0); break;
case AM_BAND_LW_MW: OneBigLineSprite.drawString(textUI(102) + String(",") + textUI(103), 135, 0); break;
case AM_BAND_LW_SW: OneBigLineSprite.drawString(textUI(102) + String(",") + textUI(104), 135, 0); break;
case AM_BAND_LW_AIR: OneBigLineSprite.drawString(textUI(102) + String(",") + textUI(223), 135, 0); break;
case AM_BAND_MW_SW: OneBigLineSprite.drawString(textUI(103) + String(",") + textUI(104), 135, 0); break;
case AM_BAND_MW_AIR: OneBigLineSprite.drawString(textUI(103) + String(",") + textUI(223), 135, 0); break;
case AM_BAND_SW_AIR: OneBigLineSprite.drawString(textUI(104) + String(",") + textUI(223), 135, 0); break;
case AM_BAND_LW: OneBigLineSprite.drawString(textUI(102), 135, 0); break;
case AM_BAND_MW: OneBigLineSprite.drawString(textUI(103), 135, 0); break;
case AM_BAND_SW: OneBigLineSprite.drawString(textUI(104), 135, 0); break;
case AM_BAND_AIR: OneBigLineSprite.drawString(textUI(223), 135, 0); break;
case AM_BAND_NONE: OneBigLineSprite.drawString(textUI(83), 135, 0); break;
}
#else
switch (bandAM) { switch (bandAM) {
case AM_BAND_ALL: OneBigLineSprite.drawString(textUI(102) + String(",") + textUI(103) + String(",") + textUI(104), 135, 0); break; case AM_BAND_ALL: OneBigLineSprite.drawString(textUI(102) + String(",") + textUI(103) + String(",") + textUI(104), 135, 0); break;
case AM_BAND_LW_MW: OneBigLineSprite.drawString(textUI(102) + String(",") + textUI(103), 135, 0); break; case AM_BAND_LW_MW: OneBigLineSprite.drawString(textUI(102) + String(",") + textUI(103), 135, 0); break;
@@ -3405,7 +3338,6 @@ void MenuUpDown(bool dir) {
case AM_BAND_SW: OneBigLineSprite.drawString(textUI(104), 135, 0); break; case AM_BAND_SW: OneBigLineSprite.drawString(textUI(104), 135, 0); break;
case AM_BAND_NONE: OneBigLineSprite.drawString(textUI(83), 135, 0); break; case AM_BAND_NONE: OneBigLineSprite.drawString(textUI(83), 135, 0); break;
} }
#endif
OneBigLineSprite.pushSprite(24, 118); OneBigLineSprite.pushSprite(24, 118);
break; break;
@@ -4749,27 +4681,6 @@ void DoMenu() {
case ITEM8: case ITEM8:
Infoboxprint(textUI(101)); Infoboxprint(textUI(101));
#ifdef HAS_AIR_BAND
switch (bandAM) {
case AM_BAND_ALL: OneBigLineSprite.drawString(textUI(102) + String(",") + textUI(103) + String(",") + textUI(104) + String(",") + textUI(223), 135, 0); break;
case AM_BAND_LW_MW_SW: OneBigLineSprite.drawString(textUI(102) + String(",") + textUI(103) + String(",") + textUI(104), 135, 0); break;
case AM_BAND_LW_MW_AIR: OneBigLineSprite.drawString(textUI(102) + String(",") + textUI(103) + String(",") + textUI(223), 135, 0); break;
case AM_BAND_LW_SW_AIR: OneBigLineSprite.drawString(textUI(102) + String(",") + textUI(104) + String(",") + textUI(223), 135, 0); break;
case AM_BAND_MW_SW_AIR: OneBigLineSprite.drawString(textUI(103) + String(",") + textUI(104) + String(",") + textUI(223), 135, 0); break;
case AM_BAND_LW_MW: OneBigLineSprite.drawString(textUI(102) + String(",") + textUI(103), 135, 0); break;
case AM_BAND_LW_SW: OneBigLineSprite.drawString(textUI(102) + String(",") + textUI(104), 135, 0); break;
case AM_BAND_LW_AIR: OneBigLineSprite.drawString(textUI(102) + String(",") + textUI(223), 135, 0); break;
case AM_BAND_MW_SW: OneBigLineSprite.drawString(textUI(103) + String(",") + textUI(104), 135, 0); break;
case AM_BAND_MW_AIR: OneBigLineSprite.drawString(textUI(103) + String(",") + textUI(223), 135, 0); break;
case AM_BAND_SW_AIR: OneBigLineSprite.drawString(textUI(104) + String(",") + textUI(223), 135, 0); break;
case AM_BAND_LW: OneBigLineSprite.drawString(textUI(102), 135, 0); break;
case AM_BAND_MW: OneBigLineSprite.drawString(textUI(103), 135, 0); break;
case AM_BAND_SW: OneBigLineSprite.drawString(textUI(104), 135, 0); break;
case AM_BAND_AIR: OneBigLineSprite.drawString(textUI(223), 135, 0); break;
case AM_BAND_NONE: OneBigLineSprite.drawString(textUI(83), 135, 0); break;
}
#else
switch (bandAM) { switch (bandAM) {
case AM_BAND_ALL: OneBigLineSprite.drawString(textUI(102) + String(",") + textUI(103) + String(",") + textUI(104), 135, 0); break; case AM_BAND_ALL: OneBigLineSprite.drawString(textUI(102) + String(",") + textUI(103) + String(",") + textUI(104), 135, 0); break;
case AM_BAND_LW_MW: OneBigLineSprite.drawString(textUI(102) + String(",") + textUI(103), 135, 0); break; case AM_BAND_LW_MW: OneBigLineSprite.drawString(textUI(102) + String(",") + textUI(103), 135, 0); break;
@@ -4780,7 +4691,6 @@ void DoMenu() {
case AM_BAND_SW: OneBigLineSprite.drawString(textUI(104), 135, 0); break; case AM_BAND_SW: OneBigLineSprite.drawString(textUI(104), 135, 0); break;
case AM_BAND_NONE: OneBigLineSprite.drawString(textUI(83), 135, 0); break; case AM_BAND_NONE: OneBigLineSprite.drawString(textUI(83), 135, 0); break;
} }
#endif
OneBigLineSprite.pushSprite(24, 118); OneBigLineSprite.pushSprite(24, 118);
break; break;
+7 -22
View File
@@ -320,7 +320,6 @@ bool isDST(time_t t) {
} }
if (month > 3 && month < 10) return true; if (month > 3 && month < 10) return true;
return false; return false;
} }
@@ -390,9 +389,7 @@ void sendUDPlog() {
String AF = ""; String AF = "";
if (radio.rds.hasAF && radio.af_counter > 0) { if (radio.rds.hasAF && radio.af_counter > 0) {
for (byte i = 0; i < radio.af_counter; i++) { for (byte i = 0; i < radio.af_counter; i++) AF += String(radio.af[i].frequency / 100) + "." + String((radio.af[i].frequency % 100) / 10) + (i == radio.af_counter - 1 ? "" : ";");
AF += String(radio.af[i].frequency / 100) + "." + String((radio.af[i].frequency % 100) / 10) + (i == radio.af_counter - 1 ? "" : ";");
}
} }
String EON = ""; String EON = "";
@@ -419,24 +416,12 @@ void sendUDPlog() {
if (radio.rds.hasRTplus) RTPLUS += radio.rds.RTContent1 + ";" + radio.rds.RTContent2; if (radio.rds.hasRTplus) RTPLUS += radio.rds.RTContent1 + ";" + radio.rds.RTContent2;
// Construct the data row to send via UDP // Construct the data row to send via UDP
String row = CHIP + "," + String row = CHIP + "," + VERSION + "," + String(scandxmode) + "," +
VERSION + "," + currentDateTime + "," + frequencyFormatted + "," + String(radio.rds.picode).substring(0, 4) + "," +
String(scandxmode) + "," + signal + "," + String(radio.getStereoStatus()) + "," + String(radio.rds.hasTA) + "," +
currentDateTime + "," + String(radio.rds.TP) + "," + String(radio.rds.hasTMC) + "," + String(radio.rds.PTY) + "," +
frequencyFormatted + "," + ECC + "," + stationName + "," + radioTextModified + "," +
String(radio.rds.picode).substring(0, 4) + "," + AF + "," + EON + "," + RTPLUS + "\n";
signal + "," +
String(radio.getStereoStatus()) + "," +
String(radio.rds.hasTA) + "," +
String(radio.rds.TP) + "," +
String(radio.rds.hasTMC) + "," +
String(radio.rds.PTY) + "," +
ECC + "," +
stationName + "," +
radioTextModified + "," +
AF + "," +
EON + "," +
RTPLUS + "\n";
// Send the data via UDP if it's new // Send the data via UDP if it's new
if (UDPlogold != row) { if (UDPlogold != row) {
+52 -328
View File
@@ -44,7 +44,6 @@ using fs::FS;
#define EXT_IRQ 14 #define EXT_IRQ 14
#define DYNAMIC_SPI_SPEED #define DYNAMIC_SPI_SPEED
//#define HAS_AIR_BAND
#ifdef ARS #ifdef ARS
TFT_eSPI tft = TFT_eSPI(320, 240); TFT_eSPI tft = TFT_eSPI(320, 240);
@@ -78,9 +77,6 @@ bool memorystore;
bool memreset, memtune; bool memreset, memtune;
bool menu, menuopen; bool menu, menuopen;
bool mwstepsize; bool mwstepsize;
#ifdef HAS_AIR_BAND
bool airstepsize;
#endif
bool nobattery; bool nobattery;
bool NTPupdated; bool NTPupdated;
bool optenc; bool optenc;
@@ -355,11 +351,6 @@ unsigned int frequency_MIBand_75M;
unsigned int frequency_MIBand_90M; unsigned int frequency_MIBand_90M;
unsigned int frequency_MW; unsigned int frequency_MW;
unsigned int frequency_SW; unsigned int frequency_SW;
#ifdef HAS_AIR_BAND
unsigned int frequency_AIR;
unsigned int AIRHighEdgeSet;
unsigned int AIRLowEdgeSet;
#endif
unsigned int frequencyold; unsigned int frequencyold;
unsigned int HighEdgeOIRTSet; unsigned int HighEdgeOIRTSet;
unsigned int HighEdgeSet; unsigned int HighEdgeSet;
@@ -435,29 +426,19 @@ WebServer webserver(80);
#pragma region helpers #pragma region helpers
void Round30K(unsigned int freq) { void Round30K(unsigned int freq) {
if (freq % FREQ_OIRT_STEP_30K == 1) { if (freq % FREQ_OIRT_STEP_30K == 1) frequency_OIRT = (freq + 1);
frequency_OIRT = (freq + 1); else if (freq % FREQ_OIRT_STEP_30K == 0) frequency_OIRT = (freq - 1);
} else if (freq % FREQ_OIRT_STEP_30K == 0) {
frequency_OIRT = (freq - 1);
}
} }
void Round50K(unsigned int freq) { void Round50K(unsigned int freq) {
if (freq % 10 < 3) { if (freq % 10 < 3) frequency = (freq - freq % 10);
frequency = (freq - freq % 10); else if (freq % 10 > 2 && freq % 10 < 8) frequency = (freq - (freq % 10 - 5));
} else if (freq % 10 > 2 && freq % 10 < 8) { else if (freq % 10 > 7) frequency = (freq - (freq % 10) + 10);
frequency = (freq - (freq % 10 - 5));
} else if (freq % 10 > 7) {
frequency = (freq - (freq % 10) + 10);
}
} }
void Round100K(unsigned int freq) { void Round100K(unsigned int freq) {
if (freq % 10 < 5) { if (freq % 10 < 5) frequency = (freq - freq % 10);
frequency = (freq - freq % 10); else frequency = (freq - (freq % 10) + 10);
} else {
frequency = (freq - (freq % 10) + 10);
}
} }
void Round200K(unsigned int freq) { void Round200K(unsigned int freq) {
@@ -470,13 +451,9 @@ void Round200K(unsigned int freq) {
} }
void Round5K(unsigned int freqAM) { void Round5K(unsigned int freqAM) {
if (freqAM % 10 < 3) { if (freqAM % 10 < 3) frequency_AM = (freqAM - freqAM % 10);
frequency_AM = (freqAM - freqAM % 10); else if (freqAM % 10 > 2 && freqAM % 10 < 8) frequency_AM = (freqAM - (freqAM % 10 - 5));
} else if (freqAM % 10 > 2 && freqAM % 10 < 8) { else if (freqAM % 10 > 7) frequency_AM = (freqAM - (freqAM % 10) + 10);
frequency_AM = (freqAM - (freqAM % 10 - 5));
} else if (freqAM % 10 > 7) {
frequency_AM = (freqAM - (freqAM % 10) + 10);
}
} }
void Touch_IRQ_Handler() { void Touch_IRQ_Handler() {
@@ -488,9 +465,6 @@ void StoreFrequency() {
case BAND_LW: freqold = frequency_LW; frequency_AM = frequency_LW; break; case BAND_LW: freqold = frequency_LW; frequency_AM = frequency_LW; break;
case BAND_MW: freqold = frequency_MW; frequency_AM = frequency_MW; break; case BAND_MW: freqold = frequency_MW; frequency_AM = frequency_MW; break;
case BAND_SW: freqold = frequency_SW; frequency_AM = frequency_SW; break; case BAND_SW: freqold = frequency_SW; frequency_AM = frequency_SW; break;
#ifdef HAS_AIR_BAND
case BAND_AIR: freqold = frequency_AIR; frequency_AM = frequency_AIR; break;
#endif
} }
EEPROM.writeUInt(EE_UINT16_FREQUENCY_FM, frequency); EEPROM.writeUInt(EE_UINT16_FREQUENCY_FM, frequency);
EEPROM.writeUInt(EE_UINT16_FREQUENCY_OIRT, frequency_OIRT); EEPROM.writeUInt(EE_UINT16_FREQUENCY_OIRT, frequency_OIRT);
@@ -499,9 +473,6 @@ void StoreFrequency() {
EEPROM.writeUInt(EE_UINT16_FREQUENCY_LW, frequency_LW); EEPROM.writeUInt(EE_UINT16_FREQUENCY_LW, frequency_LW);
EEPROM.writeUInt(EE_UINT16_FREQUENCY_MW, frequency_MW); EEPROM.writeUInt(EE_UINT16_FREQUENCY_MW, frequency_MW);
EEPROM.writeUInt(EE_UINT16_FREQUENCY_SW, frequency_SW); EEPROM.writeUInt(EE_UINT16_FREQUENCY_SW, frequency_SW);
#ifdef HAS_AIR_BAND
EEPROM.writeUInt(EE_UINT16_FREQUENCY_AIR, frequency_AIR);
#endif
EEPROM.commit(); EEPROM.commit();
} }
@@ -672,7 +643,7 @@ void updateSWMIBand() {
} }
void updateCodetect() { void updateCodetect() {
if (band > BAND_GAP && band != BAND_AIR) { if (band > BAND_GAP) {
if (WAM) tftPrint(ALEFT, "CO", 50, 61, PrimaryColor, PrimaryColorSmooth, 16); if (WAM) tftPrint(ALEFT, "CO", 50, 61, PrimaryColor, PrimaryColorSmooth, 16);
else tftPrint(ALEFT, "CO", 50, 61, BackgroundColor, BackgroundColor, 16); else tftPrint(ALEFT, "CO", 50, 61, BackgroundColor, BackgroundColor, 16);
} }
@@ -758,9 +729,6 @@ void setup() {
frequency_LW = EEPROM.readUInt(EE_UINT16_FREQUENCY_LW); frequency_LW = EEPROM.readUInt(EE_UINT16_FREQUENCY_LW);
frequency_MW = EEPROM.readUInt(EE_UINT16_FREQUENCY_MW); frequency_MW = EEPROM.readUInt(EE_UINT16_FREQUENCY_MW);
frequency_SW = EEPROM.readUInt(EE_UINT16_FREQUENCY_SW); frequency_SW = EEPROM.readUInt(EE_UINT16_FREQUENCY_SW);
#ifdef HAS_AIR_BAND
frequency_AIR = EEPROM.readUInt(EE_UINT16_FREQUENCY_AIR);
#endif
XDRGTK_key = EEPROM.readString(EE_STRING_XDRGTK_KEY); XDRGTK_key = EEPROM.readString(EE_STRING_XDRGTK_KEY);
usesquelch = EEPROM.readByte(EE_BYTE_USESQUELCH); usesquelch = EEPROM.readByte(EE_BYTE_USESQUELCH);
showmodulation = EEPROM.readByte(EE_BYTE_SHOWMODULATION); showmodulation = EEPROM.readByte(EE_BYTE_SHOWMODULATION);
@@ -791,9 +759,6 @@ void setup() {
radio.rds.fastps = EEPROM.readByte(EE_BYTE_FASTPS); radio.rds.fastps = EEPROM.readByte(EE_BYTE_FASTPS);
tot = EEPROM.readByte(EE_BYTE_TOT); tot = EEPROM.readByte(EE_BYTE_TOT);
mwstepsize = EEPROM.readByte(EE_BYTE_MWREGION); mwstepsize = EEPROM.readByte(EE_BYTE_MWREGION);
#ifdef HAS_AIR_BAND
airstepsize = EEPROM.readByte(EE_BYTE_AIRSTEPSIZE);
#endif
spispeed = EEPROM.readByte(EE_BYTE_SPISPEED); spispeed = EEPROM.readByte(EE_BYTE_SPISPEED);
amscansens = EEPROM.readByte(EE_BYTE_AMSCANSENS); amscansens = EEPROM.readByte(EE_BYTE_AMSCANSENS);
fmscansens = EEPROM.readByte(EE_BYTE_FMSCANSENS); fmscansens = EEPROM.readByte(EE_BYTE_FMSCANSENS);
@@ -854,12 +819,8 @@ void setup() {
for (int i = 0; i < EE_PRESETS_CNT; i++) presets[i].ms = EEPROM.readByte(i + EE_PRESET_MS_START); for (int i = 0; i < EE_PRESETS_CNT; i++) presets[i].ms = EEPROM.readByte(i + EE_PRESET_MS_START);
for (int i = 0; i < EE_PRESETS_CNT; i++) { for (int i = 0; i < EE_PRESETS_CNT; i++) {
for (int y = 0; y < 9; y++) { for (int y = 0; y < 9; y++) presets[i].RDSPS[y] = EEPROM.readByte((i * 9) + y + EE_PRESETS_RDSPS_START);
presets[i].RDSPS[y] = EEPROM.readByte((i * 9) + y + EE_PRESETS_RDSPS_START); for (int y = 0; y < 5; y++) presets[i].RDSPI[y] = EEPROM.readByte((i * 5) + y + EE_PRESETS_RDSPI_START);
}
for (int y = 0; y < 5; y++) {
presets[i].RDSPI[y] = EEPROM.readByte((i * 5) + y + EE_PRESETS_RDSPI_START);
}
} }
if (USBmode) Serial.begin(19200); else Serial.begin(115200); if (USBmode) Serial.begin(19200); else Serial.begin(115200);
@@ -1074,8 +1035,8 @@ void setup() {
if (TEF != 102 && TEF != 205) SetTunerPatch(); if (TEF != 102 && TEF != 205) SetTunerPatch();
radio.init(TEF); radio.init(TEF);
uint16_t device, hw, sw;
uint16_t device, hw, sw;
radio.getIdentification(&device, &hw, &sw); radio.getIdentification(&device, &hw, &sw);
if (TEF != (highByte(hw) * 100 + highByte(sw))) SetTunerPatch(); if (TEF != (highByte(hw) * 100 + highByte(sw))) SetTunerPatch();
@@ -1127,12 +1088,12 @@ void setup() {
Udp.stop(); Udp.stop();
tft.fillRect(184, 230, 16, 6, SignificantColor); tft.fillRect(184, 230, 16, 6, SignificantColor);
} }
delay(1500); delay(1000);
radio.setVolume(VolSet); radio.setVolume(VolSet);
radio.setOffset(LevelOffset); radio.setOffset(LevelOffset);
radio.setAMOffset(AMLevelOffset); radio.setAMOffset(AMLevelOffset);
if (band > BAND_GAP && band != BAND_AIR) { if (band > BAND_GAP) {
radio.setAMCoChannel(amcodect, amcodectcount); radio.setAMCoChannel(amcodect, amcodectcount);
radio.setAMAttenuation(amgain); radio.setAMAttenuation(amgain);
} }
@@ -1205,9 +1166,7 @@ void loop() {
doTouchEvent(x, y); doTouchEvent(x, y);
firstTouchHandled = true; firstTouchHandled = true;
lastTouchTime = millis(); lastTouchTime = millis();
} else if (touchrepeat) { } else if (touchrepeat && millis() - lastTouchTime >= 500) doTouchEvent(x, y);
if (millis() - lastTouchTime >= 500) doTouchEvent(x, y);
}
} }
} else { } else {
firstTouchHandled = false; firstTouchHandled = false;
@@ -1285,7 +1244,7 @@ void loop() {
} }
if (!scanholdflag) delay(100); if (!scanholdflag) delay(100);
radio.getStatus(SStatus, USN, WAM, OStatus, BW, MStatus, CN); radio.getStatus(&SStatus, &USN, &WAM, &OStatus, &BW, &MStatus, &CN);
if (!initdxscan) { if (!initdxscan) {
switch (scancancel) { switch (scancancel) {
@@ -1357,9 +1316,7 @@ void loop() {
tft.drawBitmap(249, 4, Speaker, 28, 24, GreyoutColor); tft.drawBitmap(249, 4, Speaker, 28, 24, GreyoutColor);
} }
findMemoryAF = false; findMemoryAF = false;
} else { } else frequency = radio.TestAF();
frequency = radio.TestAF();
}
if (freqold != frequency) { if (freqold != frequency) {
ShowFreq(0); ShowFreq(0);
dropout = true; dropout = true;
@@ -1432,16 +1389,12 @@ void loop() {
tftPrint(ALEFT, "100", 160, 144, ActiveColor, ActiveColorSmooth, 16); tftPrint(ALEFT, "100", 160, 144, ActiveColor, ActiveColorSmooth, 16);
tftPrint(ACENTER, "A", 7, 128, ActiveColor, ActiveColorSmooth, 16); tftPrint(ACENTER, "A", 7, 128, ActiveColor, ActiveColorSmooth, 16);
for (byte segments = 0; segments < 94; segments++) { for (byte segments = 0; segments < 94; segments++) {
if (segments > 54) { if (segments > 54 && (((segments - 53) % 10) == 0)) tft.fillRect(16 + (2 * segments), 141, 2, 2, BarSignificantColor);
if (((segments - 53) % 10) == 0) tft.fillRect(16 + (2 * segments), 141, 2, 2, BarSignificantColor); else if(((segments + 1) % 6) == 0) tft.fillRect(16 + (2 * segments), 141, 2, 2, ModBarInsignificantColor);
} else {
if (((segments + 1) % 6) == 0) tft.fillRect(16 + (2 * segments), 141, 2, 2, ModBarInsignificantColor);
} }
} }
} if (radio.rds.region == 0) tftPrint(ALEFT, "PI", 212, 193, ActiveColor, ActiveColorSmooth, 16);
if (radio.rds.region == 0) { else {
tftPrint(ALEFT, "PI", 212, 193, ActiveColor, ActiveColorSmooth, 16);
} else {
tftPrint(ALEFT, "PI", 212, 184, ActiveColor, ActiveColorSmooth, 16); tftPrint(ALEFT, "PI", 212, 184, ActiveColor, ActiveColorSmooth, 16);
tftPrint(ALEFT, "ID", 212, 201, ActiveColor, ActiveColorSmooth, 16); tftPrint(ALEFT, "ID", 212, 201, ActiveColor, ActiveColorSmooth, 16);
} }
@@ -1472,9 +1425,8 @@ void loop() {
tftPrint(ACENTER, "A", 7, 128, GreyoutColor, BackgroundColor, 16); tftPrint(ACENTER, "A", 7, 128, GreyoutColor, BackgroundColor, 16);
tft.fillRect(16, 133, 187, 6, GreyoutColor); tft.fillRect(16, 133, 187, 6, GreyoutColor);
} }
if (radio.rds.region == 0) { if (radio.rds.region == 0) tftPrint(ALEFT, "PI", 212, 193, GreyoutColor, BackgroundColor, 16);
tftPrint(ALEFT, "PI", 212, 193, GreyoutColor, BackgroundColor, 16); else {
} else {
tftPrint(ALEFT, "PI", 212, 184, GreyoutColor, BackgroundColor, 16); tftPrint(ALEFT, "PI", 212, 184, GreyoutColor, BackgroundColor, 16);
tftPrint(ALEFT, "ID", 212, 201, GreyoutColor, BackgroundColor, 16); tftPrint(ALEFT, "ID", 212, 201, GreyoutColor, BackgroundColor, 16);
} }
@@ -1491,11 +1443,8 @@ void loop() {
if (millis() >= lowsignaltimer + 300) { if (millis() >= lowsignaltimer + 300) {
lowsignaltimer = millis(); lowsignaltimer = millis();
if (af || (!screenmute || (screenmute && (XDRGTKTCP || XDRGTKUSB)))) { if (af || (!screenmute || (screenmute && (XDRGTKTCP || XDRGTKUSB)))) {
if (band < BAND_GAP) { if (band < BAND_GAP) radio.getStatus(&SStatus, &USN, &WAM, &OStatus, &BW, &MStatus, &CN);
radio.getStatus(SStatus, USN, WAM, OStatus, BW, MStatus, CN); else radio.getStatusAM(&SStatus, &USN, &WAM, &OStatus, &BW, &MStatus, &CN);
} else {
radio.getStatusAM(SStatus, USN, WAM, OStatus, BW, MStatus, CN);
}
} }
if (!BWtune && !menu) { if (!BWtune && !menu) {
doSquelch(); doSquelch();
@@ -1505,8 +1454,8 @@ void loop() {
} else { } else {
if (af || (!screenmute || (screenmute && (XDRGTKTCP || XDRGTKUSB)))) { if (af || (!screenmute || (screenmute && (XDRGTKTCP || XDRGTKUSB)))) {
if (band < BAND_GAP) radio.getStatus(SStatus, USN, WAM, OStatus, BW, MStatus, CN); if (band < BAND_GAP) radio.getStatus(&SStatus, &USN, &WAM, &OStatus, &BW, &MStatus, &CN);
else radio.getStatusAM(SStatus, USN, WAM, OStatus, BW, MStatus, CN); else radio.getStatusAM(&SStatus, &USN, &WAM, &OStatus, &BW, &MStatus, &CN);
} }
if (!BWtune && !menu) { if (!BWtune && !menu) {
doSquelch(); doSquelch();
@@ -1716,34 +1665,6 @@ void doBandSelectionFM() {
} }
void CheckBandForbiddenAM() { void CheckBandForbiddenAM() {
#ifdef HAS_AIR_BAND
switch (band) {
case BAND_LW:
if (bandAM == AM_BAND_MW_SW_AIR || bandAM == AM_BAND_MW_SW || bandAM == AM_BAND_MW_AIR || bandAM == AM_BAND_SW_AIR || bandAM == AM_BAND_MW || bandAM == AM_BAND_SW || bandAM == AM_BAND_AIR)
bandforbidden = 1;
else
bandforbidden = 0;
break;
case BAND_MW:
if (bandAM == AM_BAND_LW_SW_AIR || bandAM == AM_BAND_LW_SW || bandAM == AM_BAND_LW_AIR || bandAM == AM_BAND_SW_AIR || bandAM == AM_BAND_LW || bandAM == AM_BAND_SW || bandAM == AM_BAND_AIR)
bandforbidden = 1;
else
bandforbidden = 0;
break;
case BAND_SW:
if (bandAM == AM_BAND_LW_MW_AIR || bandAM == AM_BAND_LW_MW || bandAM == AM_BAND_LW_AIR || bandAM == AM_BAND_MW_AIR || bandAM == AM_BAND_LW || bandAM == AM_BAND_MW || bandAM == AM_BAND_AIR)
bandforbidden = 1;
else
bandforbidden = 0;
break;
case BAND_AIR:
if (bandAM == AM_BAND_LW_MW_SW || bandAM == AM_BAND_LW_MW || bandAM == AM_BAND_LW_SW || bandAM == AM_BAND_MW_SW || bandAM == AM_BAND_LW || bandAM == AM_BAND_MW || bandAM == AM_BAND_SW)
bandforbidden = 1;
else
bandforbidden = 0;
break;
}
#else
switch (band) { switch (band) {
case BAND_LW: case BAND_LW:
if (bandAM == AM_BAND_MW_SW || bandAM == AM_BAND_MW || bandAM == AM_BAND_SW) bandforbidden = 1; if (bandAM == AM_BAND_MW_SW || bandAM == AM_BAND_MW || bandAM == AM_BAND_SW) bandforbidden = 1;
@@ -1758,102 +1679,11 @@ void CheckBandForbiddenAM() {
else bandforbidden = 0; else bandforbidden = 0;
break; break;
} }
#endif
} }
void doBandSelectionAM() { void doBandSelectionAM() {
if (band < BAND_GAP) return; if (band < BAND_GAP) return;
#ifdef HAS_AIR_BAND // has air band
switch (bandAM) {
case AM_BAND_ALL:
break;
case AM_BAND_LW_MW_SW:
if (band == BAND_AIR) {
band = BAND_LW;
SelectBand();
}
break;
case AM_BAND_LW_MW_AIR:
if (band == BAND_SW) {
band = BAND_LW;
SelectBand();
}
break;
case AM_BAND_LW_SW_AIR:
if (band == BAND_MW) {
band = BAND_LW;
SelectBand();
}
break;
case AM_BAND_MW_SW_AIR:
if (band == BAND_LW) {
band = BAND_MW;
SelectBand();
}
break;
case AM_BAND_LW_MW:
if (band == BAND_SW || band == BAND_AIR) {
band = BAND_LW;
SelectBand();
}
break;
case AM_BAND_LW_SW:
if (band == BAND_MW || band == BAND_AIR) {
band = BAND_LW;
SelectBand();
}
break;
case AM_BAND_LW_AIR:
if (band == BAND_MW || band == BAND_SW) {
band = BAND_LW;
SelectBand();
}
break;
case AM_BAND_MW_SW:
if (band == BAND_LW || band == BAND_AIR) {
band = BAND_MW;
SelectBand();
}
break;
case AM_BAND_MW_AIR:
if (band == BAND_LW || band == BAND_SW) {
band = BAND_MW;
SelectBand();
}
break;
case AM_BAND_SW_AIR:
if (band == BAND_LW || band == BAND_MW) {
band = BAND_SW;
SelectBand();
}
break;
case AM_BAND_LW:
if (band != BAND_LW) {
band = BAND_LW;
SelectBand();
}
break;
case AM_BAND_MW:
if (band != BAND_MW) {
band = BAND_MW;
SelectBand();
}
break;
case AM_BAND_SW:
if (band != BAND_SW) {
band = BAND_SW;
SelectBand();
}
break;
case AM_BAND_AIR:
if (band != BAND_AIR) {
band = BAND_AIR;
SelectBand();
}
break;
}
#else // has no air band
switch (bandAM) { switch (bandAM) {
case AM_BAND_ALL: case AM_BAND_ALL:
break; break;
@@ -1898,31 +1728,14 @@ void doBandSelectionAM() {
SelectBand(); SelectBand();
break; break;
} }
#endif
} }
void FMjumptoAM() { void FMjumptoAM() {
#ifdef HAS_AIR_BAND
if (bandAM == AM_BAND_ALL || bandAM == AM_BAND_LW_MW_AIR || bandAM == AM_BAND_LW_SW_AIR || bandAM == AM_BAND_LW_MW || bandAM == AM_BAND_LW_SW || bandAM == AM_BAND_LW_AIR || bandAM == AM_BAND_LW) {
band = BAND_LW;
if (stepsize > 3) stepsize = 3;
} else if (bandAM == AM_BAND_MW_SW || bandAM == AM_BAND_MW_AIR || bandAM == AM_BAND_MW) {
band = BAND_MW;
} else if (bandAM == AM_BAND_SW_AIR || bandAM == AM_BAND_SW) {
band = BAND_SW;
} else if (bandAM == AM_BAND_AIR) {
band = BAND_AIR;
}
#else
if (bandAM == AM_BAND_ALL || bandAM == AM_BAND_LW_MW || bandAM == AM_BAND_LW_SW || bandAM == AM_BAND_LW) { if (bandAM == AM_BAND_ALL || bandAM == AM_BAND_LW_MW || bandAM == AM_BAND_LW_SW || bandAM == AM_BAND_LW) {
band = BAND_LW; band = BAND_LW;
if (stepsize > 3) stepsize = 3; if (stepsize > 3) stepsize = 3;
} else if (bandAM == AM_BAND_MW_SW || bandAM == AM_BAND_MW) { } else if (bandAM == AM_BAND_MW_SW || bandAM == AM_BAND_MW) band = BAND_MW;
band = BAND_MW; else if (bandAM == AM_BAND_SW) band = BAND_SW;
} else if (bandAM == AM_BAND_SW) {
band = BAND_SW;
}
#endif
} }
void AMjumptoFM() { void AMjumptoFM() {
@@ -1933,26 +1746,6 @@ void AMjumptoFM() {
void ToggleBand(byte nowBand) { void ToggleBand(byte nowBand) {
switch (nowBand) { switch (nowBand) {
#ifdef HAS_AIR_BAND
case BAND_LW:
if (bandAM == AM_BAND_LW_MW_SW || bandAM == AM_BAND_LW_MW_AIR || bandAM == AM_BAND_LW_MW || bandAM == AM_BAND_ALL) band = BAND_MW;
else if (bandAM == AM_BAND_LW_SW_AIR || bandAM == AM_BAND_LW_SW) band = BAND_SW;
else if (bandAM == AM_BAND_LW_MW_AIR || bandAM == AM_BAND_LW_SW_AIR || bandAM == AM_BAND_LW_AIR) band = BAND_AIR;
else if (bandAM == AM_BAND_LW || bandAM == AM_BAND_NONE) AMjumptoFM();
break;
case BAND_MW:
if (bandAM == AM_BAND_LW_MW_SW || bandAM == AM_BAND_MW_SW_AIR || bandAM == AM_BAND_MW_SW || bandAM == AM_BAND_ALL) band = BAND_SW;
else if (bandAM == AM_BAND_LW_MW_AIR || bandAM == AM_BAND_MW_AIR) band = BAND_AIR;
else if (bandAM == AM_BAND_MW || bandAM == AM_BAND_NONE) AMjumptoFM();
break;
case BAND_SW:
if (bandAM == AM_BAND_LW_SW_AIR || bandAM == AM_BAND_MW_SW_AIR || bandAM == AM_BAND_SW_AIR || bandAM == AM_BAND_ALL) band = BAND_AIR;
else if (bandAM == AM_BAND_LW_MW_SW || bandAM == AM_BAND_LW_SW || bandAM == AM_BAND_MW_SW || bandAM == AM_BAND_SW || bandAM == AM_BAND_NONE) AMjumptoFM();
break;
case BAND_AIR:
AMjumptoFM();
break;
#else // has no air band
case BAND_LW: case BAND_LW:
if (bandAM == AM_BAND_LW_MW || bandAM == AM_BAND_ALL) band = BAND_MW; if (bandAM == AM_BAND_LW_MW || bandAM == AM_BAND_ALL) band = BAND_MW;
else if (bandAM == AM_BAND_LW_SW) band = BAND_SW; else if (bandAM == AM_BAND_LW_SW) band = BAND_SW;
@@ -1977,7 +1770,6 @@ void ToggleBand(byte nowBand) {
else if (bandAM == AM_BAND_SW || bandAM == AM_BAND_NONE) AMjumptoFM(); else if (bandAM == AM_BAND_SW || bandAM == AM_BAND_NONE) AMjumptoFM();
} }
break; break;
#endif
case BAND_OIRT: case BAND_OIRT:
if(bandFM == FM_BAND_ALL || bandFM == FM_BAND_FM) band = BAND_FM; if(bandFM == FM_BAND_ALL || bandFM == FM_BAND_FM) band = BAND_FM;
else if(bandFM == FM_BAND_OIRT && bandAM != AM_BAND_NONE) FMjumptoAM(); else if(bandFM == FM_BAND_OIRT && bandAM != AM_BAND_NONE) FMjumptoAM();
@@ -2433,28 +2225,16 @@ void SelectBand() {
case BAND_LW: freqold = frequency_LW; frequency_AM = frequency_LW; break; case BAND_LW: freqold = frequency_LW; frequency_AM = frequency_LW; break;
case BAND_MW: freqold = frequency_MW; frequency_AM = frequency_MW; break; case BAND_MW: freqold = frequency_MW; frequency_AM = frequency_MW; break;
case BAND_SW: freqold = frequency_SW; frequency_AM = frequency_SW; break; case BAND_SW: freqold = frequency_SW; frequency_AM = frequency_SW; break;
#ifdef HAS_AIR_BAND
case BAND_AIR: freqold = frequency_AIR; frequency_AM = frequency_AIR; break;
#endif
} }
LimitAMFrequency(); LimitAMFrequency();
if (!externaltune && tunemode != TUNE_MEM) CheckBandForbiddenAM(); if (!externaltune && tunemode != TUNE_MEM) CheckBandForbiddenAM();
#ifdef HAS_AIR_BAND
if (band == BAND_AIR) {
radio.SetFreqAIR(10700);
} else {
radio.SetFreqAM(frequency_AM); radio.SetFreqAM(frequency_AM);
}
#else
radio.SetFreqAM(frequency_AM);
#endif
radio.setAMAttenuation(amgain); radio.setAMAttenuation(amgain);
radio.setAMCoChannel(amcodect, amcodectcount); radio.setAMCoChannel(amcodect, amcodectcount);
doBW(); doBW();
if (!screenmute) { if (!screenmute) {
if (radio.rds.region == 0) { if (radio.rds.region == 0) tftPrint(ALEFT, "PI", 212, 193, GreyoutColor, BackgroundColor, 16);
tftPrint(ALEFT, "PI", 212, 193, GreyoutColor, BackgroundColor, 16); else {
} else {
tftPrint(ALEFT, "PI", 212, 184, GreyoutColor, BackgroundColor, 16); tftPrint(ALEFT, "PI", 212, 184, GreyoutColor, BackgroundColor, 16);
tftPrint(ALEFT, "ID", 212, 201, GreyoutColor, BackgroundColor, 16); tftPrint(ALEFT, "ID", 212, 201, GreyoutColor, BackgroundColor, 16);
} }
@@ -2468,9 +2248,6 @@ void SelectBand() {
tft.fillRoundRect(287, 57, 30, 18, 2, GreyoutColor); tft.fillRoundRect(287, 57, 30, 18, 2, GreyoutColor);
tftPrint(ACENTER, "EQ", 301, 59, BackgroundColor, GreyoutColor, 16); tftPrint(ACENTER, "EQ", 301, 59, BackgroundColor, GreyoutColor, 16);
tftReplace(ALEFT, "MHz", "kHz", 258, 76, ActiveColor, ActiveColorSmooth, BackgroundColor, 28); tftReplace(ALEFT, "MHz", "kHz", 258, 76, ActiveColor, ActiveColorSmooth, BackgroundColor, 28);
// todo
// if (band == AM_BAND_AIR) tftPrint(ALEFT, "MHz", 258, 76, ActiveColor, ActiveColorSmooth, 28);
// else tftPrint(ALEFT, "KHz", 258, 76, ActiveColor, ActiveColorSmooth, 28);
} }
} else { } else {
if (tunemode == TUNE_MI_BAND) tunemode = TUNE_MAN; if (tunemode == TUNE_MI_BAND) tunemode = TUNE_MAN;
@@ -2520,20 +2297,12 @@ void SelectBand() {
tftPrint(ALEFT, textUI(105), 70, 32, BackgroundColor, BackgroundColor, 16); tftPrint(ALEFT, textUI(105), 70, 32, BackgroundColor, BackgroundColor, 16);
tftPrint(ALEFT, textUI(106), 70, 32, BackgroundColor, BackgroundColor, 16); tftPrint(ALEFT, textUI(106), 70, 32, BackgroundColor, BackgroundColor, 16);
#ifdef HAS_AIR_BAND
tftPrint(ALEFT, textUI(223), 70, 32, BackgroundColor, BackgroundColor, 16);
#endif
switch (band) { switch (band) {
case BAND_LW: tftPrint(ALEFT, textUI(102), 70, 32, (bandforbidden ? GreyoutColor : PrimaryColor), (bandforbidden ? BackgroundColor : PrimaryColorSmooth), 16); break; case BAND_LW: tftPrint(ALEFT, textUI(102), 70, 32, (bandforbidden ? GreyoutColor : PrimaryColor), (bandforbidden ? BackgroundColor : PrimaryColorSmooth), 16); break;
case BAND_MW: tftPrint(ALEFT, textUI(103), 70, 32, (bandforbidden ? GreyoutColor : PrimaryColor), (bandforbidden ? BackgroundColor : PrimaryColorSmooth), 16); break; case BAND_MW: tftPrint(ALEFT, textUI(103), 70, 32, (bandforbidden ? GreyoutColor : PrimaryColor), (bandforbidden ? BackgroundColor : PrimaryColorSmooth), 16); break;
case BAND_SW: tftPrint(ALEFT, textUI(104), 70, 32, (bandforbidden ? GreyoutColor : PrimaryColor), (bandforbidden ? BackgroundColor : PrimaryColorSmooth), 16); break; case BAND_SW: tftPrint(ALEFT, textUI(104), 70, 32, (bandforbidden ? GreyoutColor : PrimaryColor), (bandforbidden ? BackgroundColor : PrimaryColorSmooth), 16); break;
case BAND_FM: tftPrint(ALEFT, textUI(105), 70, 32, (bandforbidden ? GreyoutColor : PrimaryColor), (bandforbidden ? BackgroundColor : PrimaryColorSmooth), 16); break; case BAND_FM: tftPrint(ALEFT, textUI(105), 70, 32, (bandforbidden ? GreyoutColor : PrimaryColor), (bandforbidden ? BackgroundColor : PrimaryColorSmooth), 16); break;
case BAND_OIRT: tftPrint(ALEFT, textUI(106), 70, 32, (bandforbidden ? GreyoutColor : PrimaryColor), (bandforbidden ? BackgroundColor : PrimaryColorSmooth), 16); break; case BAND_OIRT: tftPrint(ALEFT, textUI(106), 70, 32, (bandforbidden ? GreyoutColor : PrimaryColor), (bandforbidden ? BackgroundColor : PrimaryColorSmooth), 16); break;
#ifdef HAS_AIR_BAND
case BAND_AIR: tftPrint(ALEFT, textUI(223), 70, 32, (bandforbidden ? GreyoutColor : PrimaryColor), (bandforbidden ? BackgroundColor : PrimaryColorSmooth), 16); break;
#endif
} }
} }
leave = false; leave = false;
@@ -2718,7 +2487,7 @@ void ShowStepSize() {
} }
} }
void RoundStep() {//todo air void RoundStep() {
if (band == BAND_FM) { if (band == BAND_FM) {
unsigned int freq = frequency; unsigned int freq = frequency;
switch (fmdefaultstepsize) { switch (fmdefaultstepsize) {
@@ -2882,14 +2651,12 @@ void KeyUp() {
case TUNE_MAN: case TUNE_MAN:
TuneUp(); TuneUp();
break; break;
case TUNE_AUTO: case TUNE_AUTO:
direction = true; direction = true;
seek = true; seek = true;
seekinit = true; seekinit = true;
Seek(direction); Seek(direction);
break; break;
case TUNE_MEM: case TUNE_MEM:
memorypos++; memorypos++;
if (memorypos > EE_PRESETS_CNT - 1) memorypos = 0; if (memorypos > EE_PRESETS_CNT - 1) memorypos = 0;
@@ -3044,7 +2811,6 @@ void DoMemoryPosTune() {
#endif #endif
radio.clearRDS(fullsearchrds); radio.clearRDS(fullsearchrds);
// Process empty stations
if (IsStationEmpty()) { if (IsStationEmpty()) {
memoryposstatus = MEM_DARK; memoryposstatus = MEM_DARK;
return; return;
@@ -3076,13 +2842,6 @@ void DoMemoryPosTune() {
frequency_SW = presets[memorypos].frequency; frequency_SW = presets[memorypos].frequency;
radio.SetFreqAM(frequency_SW); radio.SetFreqAM(frequency_SW);
break; break;
#ifdef HAS_AIR_BAND
case BAND_AIR:
frequency_AIR = presets[memorypos].frequency;
// radio.SetFreq(frequency_AIR); // todo
radio.SetFreqAM(10700); // todo
break;
#endif
} }
if (band == BAND_FM || band == BAND_OIRT) { if (band == BAND_FM || band == BAND_OIRT) {
@@ -3141,9 +2900,6 @@ void ShowFreq(int mode) {
case BAND_LW: frequency_AM = frequency_LW; break; case BAND_LW: frequency_AM = frequency_LW; break;
case BAND_MW: frequency_AM = frequency_MW; break; case BAND_MW: frequency_AM = frequency_MW; break;
case BAND_SW: frequency_AM = frequency_SW; break; case BAND_SW: frequency_AM = frequency_SW; break;
#ifdef HAS_AIR_BAND
case BAND_AIR: frequency_AM = frequency_AIR; break; // todo air
#endif
} }
if (!screenmute) { if (!screenmute) {
@@ -3159,8 +2915,7 @@ void ShowFreq(int mode) {
FrequencySprite.setTextDatum(TR_DATUM); FrequencySprite.setTextDatum(TR_DATUM);
FrequencySprite.setTextColor(FreqColor, FreqColorSmooth, false); FrequencySprite.setTextColor(FreqColor, FreqColorSmooth, false);
if (band == BAND_AIR) FrequencySprite.drawString(String(frequency_AM / 1000) + "." + String(frequency_AM % 1000) + " ", 218, -6); FrequencySprite.drawString(String(frequency_AM) + " ", 218, -6);
else FrequencySprite.drawString(String(frequency_AM) + " ", 218, -6);
FrequencySprite.unloadFont(); FrequencySprite.unloadFont();
FrequencySprite.setTextColor(PrimaryColor, PrimaryColorSmooth, false); FrequencySprite.setTextColor(PrimaryColor, PrimaryColorSmooth, false);
FrequencySprite.setTextDatum(TL_DATUM); FrequencySprite.setTextDatum(TL_DATUM);
@@ -3952,13 +3707,6 @@ void TuneUp() {
temp = FREQ_SW_STEP_5K; temp = FREQ_SW_STEP_5K;
frequency_AM = (frequency_AM / FREQ_SW_STEP_5K) * FREQ_SW_STEP_5K; frequency_AM = (frequency_AM / FREQ_SW_STEP_5K) * FREQ_SW_STEP_5K;
} }
#ifdef HAS_AIR_BAND
else if (frequency_AM < AIRHighEdgeSet && frequency_AM > AIRLowEdgeSet) {
if (airstepsize == 0) temp = FREQ_AIR_STEP_25K;
else temp = FREQ_AIR_STEP_8K33;
}
#endif
} else { } else {
if (band == BAND_OIRT) temp = FREQ_OIRT_STEP_30K; if (band == BAND_OIRT) temp = FREQ_OIRT_STEP_30K;
else { else {
@@ -3971,9 +3719,9 @@ void TuneUp() {
} }
} }
if (stepsize == 1) temp = 1; if (stepsize == 1) temp = 1;
if (stepsize == 2) temp = 10; else if (stepsize == 2) temp = 10;
if (stepsize == 3) temp = 100; else if (stepsize == 3) temp = 100;
if (stepsize == 4) temp = 1000; else if (stepsize == 4) temp = 1000;
if (rotaryaccelerate && rotarycounter > 2) temp *= 2; if (rotaryaccelerate && rotarycounter > 2) temp *= 2;
if (band == BAND_FM) { if (band == BAND_FM) {
@@ -4025,17 +3773,6 @@ void TuneUp() {
radio.SetFreqAM(frequency_AM); radio.SetFreqAM(frequency_AM);
frequency_SW = frequency_AM; frequency_SW = frequency_AM;
} }
#ifdef HAS_AIR_BAND
else if (band == BAND_AIR) {
frequency_AM += temp;
if (frequency_AIR > AIRHighEdgeSet) {
frequency_AM = AIRLowEdgeSet;
EdgeBeeper();
}
radio.SetFreqAM(frequency_AM);
frequency_AIR = frequency_AM;
}
#endif
radio.clearRDS(fullsearchrds); radio.clearRDS(fullsearchrds);
if (RDSSPYUSB) Serial.print("G:\r\nRESET-------\r\n\r\n"); if (RDSSPYUSB) Serial.print("G:\r\nRESET-------\r\n\r\n");
if (RDSSPYTCP) RemoteClient.print("G:\r\nRESET-------\r\n\r\n"); if (RDSSPYTCP) RemoteClient.print("G:\r\nRESET-------\r\n\r\n");
@@ -4074,9 +3811,9 @@ void TuneDown() {
} }
} }
if (stepsize == 1) temp = 1; if (stepsize == 1) temp = 1;
if (stepsize == 2) temp = 10; else if (stepsize == 2) temp = 10;
if (stepsize == 3) temp = 100; else if (stepsize == 3) temp = 100;
if (stepsize == 4) temp = 1000; else if (stepsize == 4) temp = 1000;
if (rotaryaccelerate && rotarycounter > 2) temp *= 2; if (rotaryaccelerate && rotarycounter > 2) temp *= 2;
if (band == BAND_FM) { if (band == BAND_FM) {
@@ -4149,7 +3886,7 @@ void Seek(bool mode) {
} }
if (band < BAND_GAP) { if (band < BAND_GAP) {
radio.getStatus(SStatus, USN, WAM, OStatus, BW, MStatus, CN); radio.getStatus(&SStatus, &USN, &WAM, &OStatus, &BW, &MStatus, &CN);
if ((USN < fmscansens * 30) && (WAM < 230) && (OStatus < 80 && OStatus > -80) && (!usesquelch || (Squelch < SStatus || Squelch == 920))) { if ((USN < fmscansens * 30) && (WAM < 230) && (OStatus < 80 && OStatus > -80) && (!usesquelch || (Squelch < SStatus || Squelch == 920))) {
seek = false; seek = false;
radio.setUnMute(); radio.setUnMute();
@@ -4161,7 +3898,7 @@ void Seek(bool mode) {
if (RDSSPYTCP) RemoteClient.print("G:\r\nRESET-------\r\n\r\n"); if (RDSSPYTCP) RemoteClient.print("G:\r\nRESET-------\r\n\r\n");
} }
} else { } else {
radio.getStatusAM(SStatus, USN, WAM, OStatus, BW, MStatus, CN); radio.getStatusAM(&SStatus, &USN, &WAM, &OStatus, &BW, &MStatus, &CN);
if ((USN < amscansens * 30) && (OStatus < 2 && OStatus > -2) && (!usesquelch || (Squelch < SStatus || Squelch == 920))) { if ((USN < amscansens * 30) && (OStatus < 2 && OStatus > -2) && (!usesquelch || (Squelch < SStatus || Squelch == 920))) {
seek = false; seek = false;
radio.setUnMute(); radio.setUnMute();
@@ -4176,12 +3913,10 @@ void read_encoder() {
if (millis() - rotarytimer >= 15) { if (millis() - rotarytimer >= 15) {
rotarycounteraccelerator = 2; // Steady fast rotarycounteraccelerator = 2; // Steady fast
rotarycounter = 0; rotarycounter = 0;
} } else if (millis() - rotarytimer >= 30) {
if (millis() - rotarytimer >= 30) {
rotarycounteraccelerator = 4; rotarycounteraccelerator = 4;
rotarycounter = 0; rotarycounter = 0;
} } else if (millis() - rotarytimer >= 45) {
if (millis() - rotarytimer >= 45) {
rotarycounteraccelerator = 6; // Quick flicks rotarycounteraccelerator = 6; // Quick flicks
rotarycounter = 0; rotarycounter = 0;
} }
@@ -4256,7 +3991,7 @@ void MuteScreen(bool setting) {
void DefaultSettings() { void DefaultSettings() {
EEPROM.writeByte(EE_BYTE_CHECKBYTE, EE_CHECKBYTE_VALUE); EEPROM.writeByte(EE_BYTE_CHECKBYTE, EE_CHECKBYTE_VALUE);
EEPROM.writeUInt(EE_UINT16_FREQUENCY_FM, 10000); EEPROM.writeUInt(EE_UINT16_FREQUENCY_FM, 9500);
EEPROM.writeUInt(EE_UINT16_FREQUENCY_OIRT, FREQ_FM_OIRT_START); EEPROM.writeUInt(EE_UINT16_FREQUENCY_OIRT, FREQ_FM_OIRT_START);
EEPROM.writeByte(EE_BYTE_VOLSET, 0); EEPROM.writeByte(EE_BYTE_VOLSET, 0);
EEPROM.writeUInt(EE_UINT16_CONVERTERSET, 0); EEPROM.writeUInt(EE_UINT16_CONVERTERSET, 0);
@@ -4362,11 +4097,6 @@ void DefaultSettings() {
EEPROM.writeByte(EE_BYTE_CLOCKAMPM, 0); EEPROM.writeByte(EE_BYTE_CLOCKAMPM, 0);
EEPROM.writeUInt(EE_UINT16_PICTLOCK, 0); EEPROM.writeUInt(EE_UINT16_PICTLOCK, 0);
#ifdef HAS_AIR_BAND
EEPROM.writeUInt(EE_UINT16_FREQUENCY_AIR, 135350);
EEPROM.writeByte(EE_BYTE_AIRSTEPSIZE, 0);
#endif
#ifdef DYNAMIC_SPI_SPEED #ifdef DYNAMIC_SPI_SPEED
EEPROM.writeByte(EE_BYTE_SPISPEED, 7); EEPROM.writeByte(EE_BYTE_SPISPEED, 7);
#else #else
@@ -4405,10 +4135,10 @@ void tftReplace(int8_t offset, const String & textold, const String & text, int1
const uint8_t *selectedFont = nullptr; const uint8_t *selectedFont = nullptr;
if (language == LANGUAGE_CHS) { if (language == LANGUAGE_CHS) {
if (fontsize == 16) selectedFont = FONT16_CHS; if (fontsize == 16) selectedFont = FONT16_CHS;
if (fontsize == 28) selectedFont = FONT28_CHS; else if (fontsize == 28) selectedFont = FONT28_CHS;
} else { } else {
if (fontsize == 16) selectedFont = FONT16; if (fontsize == 16) selectedFont = FONT16;
if (fontsize == 28) selectedFont = FONT28; else if (fontsize == 28) selectedFont = FONT28;
} }
if (fontsize == 48) selectedFont = FONT48; if (fontsize == 48) selectedFont = FONT48;
@@ -4441,10 +4171,10 @@ void tftPrint(int8_t offset, const String & text, int16_t x, int16_t y, int colo
const uint8_t *selectedFont = nullptr; const uint8_t *selectedFont = nullptr;
if (language == LANGUAGE_CHS) { if (language == LANGUAGE_CHS) {
if (fontsize == 16) selectedFont = FONT16_CHS; if (fontsize == 16) selectedFont = FONT16_CHS;
if (fontsize == 28) selectedFont = FONT28_CHS; else if (fontsize == 28) selectedFont = FONT28_CHS;
} else { } else {
if (fontsize == 16) selectedFont = FONT16; if (fontsize == 16) selectedFont = FONT16;
if (fontsize == 28) selectedFont = FONT28; else if (fontsize == 28) selectedFont = FONT28;
} }
if (fontsize == 48) selectedFont = FONT48; if (fontsize == 48) selectedFont = FONT48;
@@ -4486,7 +4216,6 @@ void UpdateFonts(byte mode) {
OneBigLineSprite.loadFont(FONT28); OneBigLineSprite.loadFont(FONT28);
} }
break; break;
case 1: case 1:
FullLineSprite.unloadFont(); FullLineSprite.unloadFont();
OneBigLineSprite.unloadFont(); OneBigLineSprite.unloadFont();
@@ -4572,9 +4301,6 @@ void saveData() {
EEPROM.writeByte(EE_BYTE_FASTPS, radio.rds.fastps); EEPROM.writeByte(EE_BYTE_FASTPS, radio.rds.fastps);
EEPROM.writeByte(EE_BYTE_TOT, tot); EEPROM.writeByte(EE_BYTE_TOT, tot);
EEPROM.writeByte(EE_BYTE_MWREGION, mwstepsize); EEPROM.writeByte(EE_BYTE_MWREGION, mwstepsize);
#ifdef HAS_AIR_BAND
EEPROM.writeByte(EE_BYTE_AIRSTEPSIZE, airstepsize);
#endif
EEPROM.writeByte(EE_BYTE_SPISPEED, spispeed); EEPROM.writeByte(EE_BYTE_SPISPEED, spispeed);
EEPROM.writeByte(EE_BYTE_AMSCANSENS, amscansens); EEPROM.writeByte(EE_BYTE_AMSCANSENS, amscansens);
EEPROM.writeByte(EE_BYTE_FMSCANSENS, fmscansens); EEPROM.writeByte(EE_BYTE_FMSCANSENS, fmscansens);
@@ -4747,9 +4473,7 @@ uint8_t doAutoMemory(uint16_t startfreq, uint16_t stopfreq, uint8_t startmem, ui
tftPrint(ARIGHT, textUI(272), 120, 155, ActiveColor, ActiveColorSmooth, 16); tftPrint(ARIGHT, textUI(272), 120, 155, ActiveColor, ActiveColorSmooth, 16);
for (frequency = startfreq * 10; frequency <= stopfreq * 10; frequency += 10) { for (frequency = startfreq * 10; frequency <= stopfreq * 10; frequency += 10) {
if (stopScanning) { if (stopScanning) break;
break;
}
currentIteration++; currentIteration++;
percent = (currentIteration * 100) / totalIterations; percent = (currentIteration * 100) / totalIterations;
@@ -4757,7 +4481,7 @@ uint8_t doAutoMemory(uint16_t startfreq, uint16_t stopfreq, uint8_t startmem, ui
radio.SetFreq(frequency); radio.SetFreq(frequency);
radio.clearRDS(fullsearchrds); radio.clearRDS(fullsearchrds);
delay(50); delay(50);
radio.getStatus(SStatus, USN, WAM, OStatus, BW, MStatus, CN); radio.getStatus(&SStatus, &USN, &WAM, &OStatus, &BW, &MStatus, &CN);
if ((USN < fmscansens * 30) && (WAM < 230) && (OStatus < 80 && OStatus > -80)) { if ((USN < fmscansens * 30) && (WAM < 230) && (OStatus < 80 && OStatus > -80)) {
for (byte y = 0; y < 20; y++) { for (byte y = 0; y < 20; y++) {
delay(50); delay(50);
+4 -3
View File
@@ -1,6 +1,7 @@
#include "rds.h" #include "rds.h"
#include "constants.h" #include "constants.h"
#include <TimeLib.h> #include <TimeLib.h>
#include "utils.h"
String HexStringold; String HexStringold;
float smoothBER = 0; float smoothBER = 0;
@@ -551,7 +552,7 @@ void showPS() {
} }
// Handle scrolling logic for long PS // Handle scrolling logic for long PS
if (PSSprite.textWidth(radio.trimTrailingSpaces(radio.rds.stationNameLong)) < 150) { if (PSSprite.textWidth(trimTrailingSpaces(radio.rds.stationNameLong)) < 150) {
xPos5 = 0; xPos5 = 0;
PSSprite.fillSprite(BackgroundColor); PSSprite.fillSprite(BackgroundColor);
PSSprite.setTextColor(RDSstatus ? RDSColor : RDSDropoutColor, RDSstatus ? RDSColorSmooth : RDSDropoutColorSmooth, false); PSSprite.setTextColor(RDSstatus ? RDSColor : RDSDropoutColor, RDSstatus ? RDSColorSmooth : RDSDropoutColorSmooth, false);
@@ -703,7 +704,7 @@ void showRadioText() {
if (radio.rds.hasRT && if (radio.rds.hasRT &&
(radio.rds.stationText.length() > 0 || radio.rds.stationText32.length() > 0)) { (radio.rds.stationText.length() > 0 || radio.rds.stationText32.length() > 0)) {
if (RDSSprite.textWidth(radio.trimTrailingSpaces(RTString)) < 270) { if (RDSSprite.textWidth(trimTrailingSpaces(RTString)) < 270) {
xPos = 0; xPos = 0;
FullLineSprite.fillSprite(BackgroundColor); FullLineSprite.fillSprite(BackgroundColor);
FullLineSprite.setTextDatum(TL_DATUM); FullLineSprite.setTextDatum(TL_DATUM);
@@ -958,7 +959,7 @@ void ShowAFEON() {
} }
} }
if (FullLineSprite.textWidth(radio.trimTrailingSpaces(AIDString)) < 270) { if (FullLineSprite.textWidth(trimTrailingSpaces(AIDString)) < 270) {
xPos = 0; xPos = 0;
FullLineSprite.fillSprite(BackgroundColor); FullLineSprite.fillSprite(BackgroundColor);
FullLineSprite.setTextColor(ActiveColor, ActiveColorSmooth, false); FullLineSprite.setTextColor(ActiveColor, ActiveColorSmooth, false);
+16 -16
View File
@@ -14,8 +14,8 @@ void doTouchEvent(uint16_t x, uint16_t y) {
ModeButtonPress(); ModeButtonPress();
return; return;
} }
if (menuopen) { // Menu navigation if (menuopen) {
if (x > 18 && x < 78 && y > 150 && y < 190) KeyDown(); // --------------- if (x > 18 && x < 78 && y > 150 && y < 190) KeyDown();
if (x > 240 && x < 300 && y > 150 && y < 190) KeyUp(); if (x > 240 && x < 300 && y > 150 && y < 190) KeyUp();
if ((x > 240 && x < 300 && y > 40 && y < 80) || (x > 130 && x < 190 && y > 150 && y < 190)) { if ((x > 240 && x < 300 && y > 40 && y < 80) || (x > 130 && x < 190 && y > 150 && y < 190)) {
touchrepeat = false; touchrepeat = false;
@@ -93,18 +93,18 @@ void doTouchEvent(uint16_t x, uint16_t y) {
} }
} }
if (!menu && !BWtune) { // All pages except menu if (!menu && !BWtune) {
if (x > 30 && x < 65 && y > 0 && y < 30 && band < BAND_GAP) { // --------------------- if (x > 30 && x < 65 && y > 0 && y < 30 && band < BAND_GAP) {
doStereoToggle(); // Stereo toggle doStereoToggle();
return; return;
} else if (x > 155 && x < 250 && y > 0 && y < 30) { } else if (x > 155 && x < 250 && y > 0 && y < 30) {
BuildBWSelector(); // Set bandwidth BuildBWSelector();
BWtune = true; BWtune = true;
return; return;
} }
} }
if (BWtune) { // BW menu if (BWtune) {
if (y > 35 && y < 65) { if (y > 35 && y < 65) {
if (x > 7 && x < 77) BWtemp = 1; if (x > 7 && x < 77) BWtemp = 1;
if (x > 87 && x < 157) BWtemp = 2; if (x > 87 && x < 157) BWtemp = 2;
@@ -177,26 +177,26 @@ void doTouchEvent(uint16_t x, uint16_t y) {
return; return;
} }
if (!BWtune && !menu && !advancedRDS && !seek && !afscreen) { // Normal radio mode if (!BWtune && !menu && !advancedRDS && !seek && !afscreen) {
if (x > 0 && x < 320 && y > 180 && y < 240 && band < BAND_GAP) { // ----------------- if (x > 0 && x < 320 && y > 180 && y < 240 && band < BAND_GAP) {
leave = true; leave = true;
BuildAdvancedRDS(); // Switch to Advanced RDS View BuildAdvancedRDS();
return; return;
} else if (x > 60 && x < 240 && y > 40 && y < 100) { } else if (x > 60 && x < 240 && y > 40 && y < 100) {
doBandToggle(); // Toggle bands doBandToggle();
return; return;
} else if (x > 0 && x < 30 && y > 25 && y < 90) { } else if (x > 0 && x < 30 && y > 25 && y < 90) {
doTuneMode(); // Toggle tune mode doTuneMode();
return; return;
} else if (x > 250 && x < 320 && y > 50 && y < 80) { } else if (x > 250 && x < 320 && y > 50 && y < 80) {
toggleiMSEQ(); // Toggle iMQ/EQ toggleiMSEQ();
} }
} }
if (!BWtune && !menu && advancedRDS && !seek && !afscreen) { // Advanced RDS mode if (!BWtune && !menu && advancedRDS && !seek && !afscreen) {
if (x > 0 && x < 320 && y > 120 && y < 170) { // ----------------- if (x > 0 && x < 320 && y > 120 && y < 170) {
leave = true; leave = true;
BuildDisplay(); // Switch to normal radio view BuildDisplay();
SelectBand(); SelectBand();
return; return;
} else if (x > 0 && x < 320 && y > 180 && y < 240) { } else if (x > 0 && x < 320 && y > 180 && y < 240) {
+79
View File
@@ -48,3 +48,82 @@ uint16_t HSVtoRGB565(float h, float s, float v) {
return ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3); return ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3);
} }
String convertToUTF8(const wchar_t* input) {
String output;
while (*input) {
uint32_t unicode = *input;
if (unicode < 0x80) output += (char)unicode;
else if (unicode < 0x800) {
output += (char)(0xC0 | (unicode >> 6));
output += (char)(0x80 | (unicode & 0x3F));
} else if (unicode < 0x10000) {
output += (char)(0xE0 | (unicode >> 12));
output += (char)(0x80 | ((unicode >> 6) & 0x3F));
output += (char)(0x80 | (unicode & 0x3F));
} else {
output += (char)(0xF0 | (unicode >> 18));
output += (char)(0x80 | ((unicode >> 12) & 0x3F));
output += (char)(0x80 | ((unicode >> 6) & 0x3F));
output += (char)(0x80 | (unicode & 0x3F));
}
input++;
}
return output;
}
String trimTrailingSpaces(String str) {
int end = str.length() - 1;
while (end >= 0 && isspace(str[end])) end--;
return str.substring(0, end + 1);
}
String ucs2ToUtf8(const char* ucs2Input) {
String utf8Output;
size_t length = 0;
while (ucs2Input[length] != '\0' || ucs2Input[length + 1] != '\0') length += 2;
for (size_t i = 0; i < length; i += 2) {
uint16_t ucs2Char = ((uint8_t)ucs2Input[i] << 8) | (uint8_t)ucs2Input[i + 1];
if (ucs2Char <= 0x7F) utf8Output += (char)ucs2Char;
else if (ucs2Char <= 0x7FF) {
utf8Output += (char)(0xC0 | (ucs2Char >> 6));
utf8Output += (char)(0x80 | (ucs2Char & 0x3F));
} else {
utf8Output += (char)(0xE0 | (ucs2Char >> 12));
utf8Output += (char)(0x80 | ((ucs2Char >> 6) & 0x3F));
utf8Output += (char)(0x80 | (ucs2Char & 0x3F));
}
}
return utf8Output;
}
String extractUTF8Substring(const String & utf8String, size_t start, size_t length, bool underscore) {
String substring;
size_t utf8Length = utf8String.length();
size_t utf8Index = 0;
size_t charIndex = 0;
while (utf8Index < utf8Length && charIndex < start + length) {
uint8_t currentByte = utf8String.charAt(utf8Index);
uint8_t numBytes = 0;
if (currentByte < 0x80) numBytes = 1;
else if ((currentByte >> 5) == 0x6) numBytes = 2;
else if ((currentByte >> 4) == 0xE) numBytes = 3;
else if ((currentByte >> 3) == 0x1E) numBytes = 4;
if (charIndex >= start) substring += utf8String.substring(utf8Index, utf8Index + numBytes);
utf8Index += numBytes;
charIndex++;
}
if (underscore) {
while (substring.length() < length) substring += '_';
}
return substring;
}
-11
View File
@@ -1,11 +0,0 @@
This directory is intended for PlatformIO Test Runner and project tests.
Unit Testing is a software testing method by which individual units of
source code, sets of one or more MCU program modules together with associated
control data, usage procedures, and operating procedures, are tested to
determine whether they are fit for use. Unit testing finds problems early
in the development cycle.
More information about PlatformIO Unit Testing:
- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html