updates, and on dp666 the date should be wrong on startup

This commit is contained in:
2026-01-23 19:17:20 +01:00
parent bb0675b8a3
commit 2d03316910
24 changed files with 411 additions and 474 deletions
+4 -4
View File
@@ -462,7 +462,7 @@ typedef struct _rds_ {
bool rdsDerror; bool rdsDerror;
Detector<bool, 1> hasArtificialhead{false}; Detector<bool, 1> hasArtificialhead{false};
Detector<bool, 1> hasCompressed{false}; Detector<bool, 1> hasCompressed{false};
bool hasDynamicPTY; Detector<bool, 1> hasDynamicPTY{false};
Detector<bool, 1> hasStereo{false}; Detector<bool, 1> hasStereo{false};
bool hasRDS; bool hasRDS;
bool hasECC; bool hasECC;
@@ -534,9 +534,9 @@ class TEF6686 {
void SetFreq(uint16_t frequency); void SetFreq(uint16_t frequency);
void SetFreqAM(uint16_t frequency); void SetFreqAM(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 *audiolevel, 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 *audiolevel, int8_t *snr);
void getIdentification(uint16_t *device, uint16_t *hw_version, uint16_t *sw_version); uint16_t getIdentification(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);
void setMono(bool mono); void setMono(bool mono);
+1 -1
View File
@@ -78,7 +78,7 @@ 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_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_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 *audiolevel, int8_t *snr);
uint8_t devTEF_APPL_Get_Operation_Status(); uint8_t devTEF_APPL_Get_Operation_Status();
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); 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);
void 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); void 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);
+41 -1
View File
@@ -39,6 +39,46 @@
#define TIMER_SNR_TIMER 30 #define TIMER_SNR_TIMER 30
#define TIMER_BAT_TIMER 750 #define TIMER_BAT_TIMER 750
// Signal quality thresholds for scanning
#define SCAN_SIGNAL_THRESHOLD_USN_MULTIPLIER 30
#define SCAN_SIGNAL_THRESHOLD_WAM 230
#define SCAN_SIGNAL_THRESHOLD_OSTATUS 80
#define SCAN_SIGNAL_THRESHOLD_OSTATUS_WIDE 100
// Timing constants (milliseconds)
#define DELAY_TUNE_MS 50
#define DELAY_UI_UPDATE_MS 200
#define DELAY_BUTTON_DEBOUNCE_MS 50
#define DELAY_BUTTON_DEBOUNCE_EXTRA_MS 75
#define DELAY_KEYPAD_TIMEOUT_MS 2000
#define DELAY_RDS_READ_MS 50
#define DELAY_TOUCH_REPEAT_MS 500
#define TOT_MULTIPLIER_MS 60000
#define NTP_UPDATE_INTERVAL_MS 1800000
#define UDP_LOG_INTERVAL_MS 500
#define SCAN_HOLD_DEFAULT_MS 500
// UI layout coordinates
#define STEREO_ICON_X 32
#define STEREO_ICON_Y 5
#define WIFI_ICON_X 282
#define WIFI_ICON_Y 3
#define WIFI_ICON_WIDTH 30
#define WIFI_ICON_HEIGHT 25
#define SPEAKER_ICON_X 249
#define SPEAKER_ICON_Y 4
#define SPEAKER_ICON_WIDTH 28
#define SPEAKER_ICON_HEIGHT 24
// Touch thresholds
#define TOUCH_RAW_Z_THRESHOLD 250
// Battery detection
#define BATTERY_DETECT_THRESHOLD 200
// Squelch values
#define SQUELCH_MAX_VALUE 920
#define BAT_LEVEL_STAGE 8 #define BAT_LEVEL_STAGE 8
#define BATTERY_LOW_VALUE 3.2 #define BATTERY_LOW_VALUE 3.2
#define BATTERY_FULL_VALUE 4.12 #define BATTERY_FULL_VALUE 4.12
@@ -283,7 +323,7 @@
#define EE_BYTE_RDS_FILTER 2137 #define EE_BYTE_RDS_FILTER 2137
#define EE_BYTE_RDS_PIERRORS 2138 #define EE_BYTE_RDS_PIERRORS 2138
#define EE_BYTE_USESQUELCH 2139 #define EE_BYTE_USESQUELCH 2139
#define EE_BYTE_SHOWMODULATION 2140 #define EE_BYTE_SHOWAUDIO 2140
#define EE_BYTE_AM_NB 2141 #define EE_BYTE_AM_NB 2141
#define EE_BYTE_FM_NB 2142 #define EE_BYTE_FM_NB 2142
#define EE_BYTE_AUDIOMODE 2143 #define EE_BYTE_AUDIOMODE 2143
+4 -4
View File
@@ -26,7 +26,7 @@ extern bool autosquelch, batterydetect, beepresetstart;
extern bool beepresetstop, BWreset, bwtouchtune; extern bool beepresetstop, BWreset, bwtouchtune;
extern bool BWtune, change, clockampm; extern bool BWtune, change, clockampm;
extern bool direction, dropout; extern bool direction, dropout;
extern bool dynamicPTYold, edgebeep, externaltune; extern bool edgebeep, externaltune;
extern bool findMemoryAF; extern bool findMemoryAF;
extern bool firstTouchHandled; extern bool firstTouchHandled;
extern bool flashing; extern bool flashing;
@@ -138,7 +138,7 @@ extern byte scanhold;
extern byte scanmodeold; extern byte scanmodeold;
extern byte screensaverOptions[5]; extern byte screensaverOptions[5];
extern byte screensaverset; extern byte screensaverset;
extern byte showmodulation; extern byte showaudio;
extern byte showrdserrors; extern byte showrdserrors;
extern byte showSWMIBand; extern byte showSWMIBand;
extern byte submenu; extern byte submenu;
@@ -317,8 +317,8 @@ extern unsigned long flashingtimer;
extern unsigned long keypadtimer; extern unsigned long keypadtimer;
extern unsigned long lastTouchTime; extern unsigned long lastTouchTime;
extern unsigned long lowsignaltimer; extern unsigned long lowsignaltimer;
extern unsigned long ModulationpreviousMillis; extern unsigned long AudiopreviousMillis;
extern unsigned long ModulationpeakPreviousMillis; extern unsigned long AudiopeakPreviousMillis;
extern unsigned long NTPtimer; extern unsigned long NTPtimer;
extern unsigned long peakholdmillis; extern unsigned long peakholdmillis;
extern unsigned long processed_rdsblocksold[33]; extern unsigned long processed_rdsblocksold[33];
+8 -8
View File
@@ -685,7 +685,7 @@ static const char* const myLanguage[22][298] PROGMEM = {
"Filtr RDS", // 57 "Filtr RDS", // 57
"Pokaż błędy PI", // 58 "Pokaż błędy PI", // 58
"Użyj blokady szumów", // 59 "Użyj blokady szumów", // 59
"Wskaźnik modulacji", // 60 "Miernik fonii", // 60
"Reduktor szumów AM", // 61 "Reduktor szumów AM", // 61
"Reduktor szumów FM", // 62 "Reduktor szumów FM", // 62
"Załadowano domyślne", // 63 "Załadowano domyślne", // 63
@@ -985,7 +985,7 @@ static const char* const myLanguage[22][298] PROGMEM = {
"RDS filter", // 57 "RDS filter", // 57
"Prikaži PI greške", // 58 "Prikaži PI greške", // 58
"Prikaži squelch", // 59 "Prikaži squelch", // 59
"Mjerač modulacije", // 60 "Mjerač zvuka", // 60
"AM prigušivač šuma", // 61 "AM prigušivač šuma", // 61
"FM prigušivač šuma", // 62 "FM prigušivač šuma", // 62
"Zadane postavke učitane", // 63 "Zadane postavke učitane", // 63
@@ -2785,7 +2785,7 @@ static const char* const myLanguage[22][298] PROGMEM = {
"Filtre RDS", // 57 "Filtre RDS", // 57
"Afficher les erreurs\nde décodage PI", // 58 "Afficher les erreurs\nde décodage PI", // 58
"Utiliser le squelch", // 59 "Utiliser le squelch", // 59
"Mesure de la modulation", // 60 "Mesure de l'intensité sonore", // 60
"Réducteur de bruit AM", // 61 "Réducteur de bruit AM", // 61
"Réducteur de bruit FM", // 62 "Réducteur de bruit FM", // 62
"Réglages par défaut\nchargés", // 63 "Réglages par défaut\nchargés", // 63
@@ -3985,7 +3985,7 @@ static const char* const myLanguage[22][298] PROGMEM = {
"Filtro RDS", // 57 "Filtro RDS", // 57
"Mostra errori PI", // 58 "Mostra errori PI", // 58
"Usa squelch", // 59 "Usa squelch", // 59
"Misuratore modulazione", // 60 "Misuratore del suono", // 60
"Filtro anti-rumore AM", // 61 "Filtro anti-rumore AM", // 61
"Filtro anti-rumore FM", // 62 "Filtro anti-rumore FM", // 62
"Impostazioni predefinite caricate", // 63 "Impostazioni predefinite caricate", // 63
@@ -4585,7 +4585,7 @@ static const char* const myLanguage[22][298] PROGMEM = {
"RDS-filter", // 57 "RDS-filter", // 57
"Vis PI-feil", // 58 "Vis PI-feil", // 58
"Bruk squelch", // 59 "Bruk squelch", // 59
"Modulasjonsmåler", // 60 "Lydmåler", // 60
"AM-støydemper", // 61 "AM-støydemper", // 61
"FM-støydemper", // 62 "FM-støydemper", // 62
"Standarder lastet", // 63 "Standarder lastet", // 63
@@ -5785,7 +5785,7 @@ static const char* const myLanguage[22][298] PROGMEM = {
"RDS-suodatin", // 57 "RDS-suodatin", // 57
"Näytä PI-virheet", // 58 "Näytä PI-virheet", // 58
"Käytä squelchiä", // 59 "Käytä squelchiä", // 59
"Modulaatiomittari", // 60 "Äänimittari", // 60
"AM Melupeitto", // 61 "AM Melupeitto", // 61
"FM Melupeitto", // 62 "FM Melupeitto", // 62
"Oletusarvot ladattu", // 63 "Oletusarvot ladattu", // 63
@@ -6085,7 +6085,7 @@ static const char* const myLanguage[22][298] PROGMEM = {
"RDS-filter", // 57 "RDS-filter", // 57
"Vis PI-fejl", // 58 "Vis PI-fejl", // 58
"Brug squelch", // 59 "Brug squelch", // 59
"Modulationsmåler", // 60 "Lydmåler", // 60
"AM-støjfjerner", // 61 "AM-støjfjerner", // 61
"FM-støjfjerner", // 62 "FM-støjfjerner", // 62
"Standardindstillinger\nindlæst", // 63 "Standardindstillinger\nindlæst", // 63
@@ -6385,7 +6385,7 @@ static const char* const myLanguage[22][298] PROGMEM = {
"RDS-filter", // 57 "RDS-filter", // 57
"Visa PI-fel", // 58 "Visa PI-fel", // 58
"Använd brusspärr", // 59 "Använd brusspärr", // 59
"Modulationsmätare", // 60 "Ljudmätare", // 60
"AM noise blanker", // 61 "AM noise blanker", // 61
"FM noise blanker", // 62 "FM noise blanker", // 62
"Standarder laddade", // 63 "Standarder laddade", // 63
-4
View File
@@ -27,11 +27,7 @@
#include <sys/time.h> #include <sys/time.h>
#include "esp_attr.h" #include "esp_attr.h"
#ifdef RTC_DATA_ATTR
RTC_DATA_ATTR static bool overflow; RTC_DATA_ATTR static bool overflow;
#else
static bool overflow;
#endif
/*! /*!
@brief set the internal RTC time @brief set the internal RTC time
-22
View File
@@ -38,33 +38,11 @@ extern "C" {
* @param hash uint8_t[20] * @param hash uint8_t[20]
*/ */
void sha1(uint8_t * data, uint32_t size, uint8_t hash[20]) { void sha1(uint8_t * data, uint32_t size, uint8_t hash[20]) {
SHA1_CTX ctx; SHA1_CTX ctx;
#ifdef DEBUG_SHA1
os_printf("DATA:");
for(uint16_t i = 0; i < size; i++) {
os_printf("%02X", data[i]);
}
os_printf("\n");
os_printf("DATA:");
for(uint16_t i = 0; i < size; i++) {
os_printf("%c", data[i]);
}
os_printf("\n");
#endif
SHA1Init(&ctx); SHA1Init(&ctx);
SHA1Update(&ctx, data, size); SHA1Update(&ctx, data, size);
SHA1Final(hash, &ctx); SHA1Final(hash, &ctx);
#ifdef DEBUG_SHA1
os_printf("SHA1:");
for(uint16_t i = 0; i < 20; i++) {
os_printf("%02X", hash[i]);
}
os_printf("\n\n");
#endif
} }
void sha1(char * data, uint32_t size, uint8_t hash[20]) { void sha1(char * data, uint32_t size, uint8_t hash[20]) {
+1 -6
View File
@@ -22,10 +22,7 @@
* *
*/ */
#ifndef HASH_H_ #pragma once
#define HASH_H_
//#define DEBUG_SHA1
void sha1(uint8_t * data, uint32_t size, uint8_t hash[20]); void sha1(uint8_t * data, uint32_t size, uint8_t hash[20]);
void sha1(char * data, uint32_t size, uint8_t hash[20]); void sha1(char * data, uint32_t size, uint8_t hash[20]);
@@ -38,5 +35,3 @@ String sha1(char* data, uint32_t size);
String sha1(const uint8_t* data, uint32_t size); String sha1(const uint8_t* data, uint32_t size);
String sha1(const char* data, uint32_t size); String sha1(const char* data, uint32_t size);
String sha1(String data); String sha1(String data);
#endif /* HASH_H_ */
+10 -72
View File
@@ -23,34 +23,18 @@
34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F 34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F
*/ */
/* #define LITTLE_ENDIAN * This should be #define'd already, if true. */
/* #define SHA1HANDSOFF * Copies data before messing with it. */
#define SHA1HANDSOFF
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdint.h> #include <stdint.h>
#ifndef ESP32
#include <c_types.h>
#endif
#include "sha1.h" #include "sha1.h"
//#include <endian.h>
#define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits)))) #define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits))))
/* blk0() and blk() perform the initial expand. */ /* blk0() and blk() perform the initial expand. */
/* I got the idea of expanding during the round function from SSLeay */ /* I got the idea of expanding during the round function from SSLeay */
#if BYTE_ORDER == LITTLE_ENDIAN
#define blk0(i) (block->l[i] = (rol(block->l[i],24)&0xFF00FF00) \ #define blk0(i) (block->l[i] = (rol(block->l[i],24)&0xFF00FF00) \
|(rol(block->l[i],8)&0x00FF00FF)) |(rol(block->l[i],8)&0x00FF00FF))
#elif BYTE_ORDER == BIG_ENDIAN
#define blk0(i) block->l[i]
#else
#error "Endianness not defined!"
#endif
#define blk(i) (block->l[i&15] = rol(block->l[(i+13)&15]^block->l[(i+8)&15] \ #define blk(i) (block->l[i&15] = rol(block->l[(i+13)&15]^block->l[(i+8)&15] \
^block->l[(i+2)&15]^block->l[i&15],1)) ^block->l[(i+2)&15]^block->l[i&15],1))
@@ -61,26 +45,14 @@
#define R3(v,w,x,y,z,i) z+=(((w|x)&y)|(w&x))+blk(i)+0x8F1BBCDC+rol(v,5);w=rol(w,30); #define R3(v,w,x,y,z,i) z+=(((w|x)&y)|(w&x))+blk(i)+0x8F1BBCDC+rol(v,5);w=rol(w,30);
#define R4(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=rol(w,30); #define R4(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=rol(w,30);
STATIC void ICACHE_FLASH_ATTR SHA1Transform(uint32_t state[5], uint8_t buffer[64]) {
/* Hash a single 512-bit block. This is the core of the algorithm. */
STATIC void ICACHE_FLASH_ATTR SHA1Transform(uint32_t state[5], uint8_t buffer[64])
{
uint32_t a, b, c, d, e; uint32_t a, b, c, d, e;
typedef union { typedef union {
unsigned char c[64]; unsigned char c[64];
uint32_t l[16]; uint32_t l[16];
} CHAR64LONG16; } CHAR64LONG16;
#ifdef SHA1HANDSOFF
CHAR64LONG16 block[1]; /* use array to appear as a pointer */ CHAR64LONG16 block[1]; /* use array to appear as a pointer */
memcpy(block, buffer, 64); memcpy(block, buffer, 64);
#else
/* The following had better never be used because it causes the
* pointer-to-const buffer to be cast into a pointer to non-const.
* And the result is written through. I threw a "const" in, hoping
* this will cause a diagnostic.
*/
CHAR64LONG16* block = (const CHAR64LONG16*)buffer;
#endif
/* Copy context->state[] to working vars */ /* Copy context->state[] to working vars */
a = state[0]; a = state[0];
b = state[1]; b = state[1];
@@ -116,18 +88,11 @@ CHAR64LONG16* block = (const CHAR64LONG16*)buffer;
state[4] += e; state[4] += e;
/* Wipe variables */ /* Wipe variables */
a = b = c = d = e = 0; a = b = c = d = e = 0;
#ifdef SHA1HANDSOFF
memset(block, '\0', sizeof(block)); memset(block, '\0', sizeof(block));
#endif
} }
STATIC void ICACHE_FLASH_ATTR SHA1Init(SHA1_CTX* context) {
/* SHA1Init - Initialize new context */ context->state[0] = 0x67452301; // six seven
STATIC void ICACHE_FLASH_ATTR SHA1Init(SHA1_CTX* context)
{
/* SHA1 initialization constants */
context->state[0] = 0x67452301;
context->state[1] = 0xEFCDAB89; context->state[1] = 0xEFCDAB89;
context->state[2] = 0x98BADCFE; context->state[2] = 0x98BADCFE;
context->state[3] = 0x10325476; context->state[3] = 0x10325476;
@@ -135,13 +100,8 @@ STATIC void ICACHE_FLASH_ATTR SHA1Init(SHA1_CTX* context)
context->count[0] = context->count[1] = 0; context->count[0] = context->count[1] = 0;
} }
STATIC void ICACHE_FLASH_ATTR SHA1Update(SHA1_CTX* context, uint8_t* data, uint32_t len) {
/* Run your data through this. */ uint32_t i, j;
STATIC void ICACHE_FLASH_ATTR SHA1Update(SHA1_CTX* context, uint8_t* data, uint32_t len)
{
uint32_t i;
uint32_t j;
j = context->count[0]; j = context->count[0];
if ((context->count[0] += len << 3) < j) if ((context->count[0] += len << 3) < j)
@@ -151,9 +111,7 @@ STATIC void ICACHE_FLASH_ATTR SHA1Update(SHA1_CTX* context, uint8_t* data, uint3
if ((j + len) > 63) { if ((j + len) > 63) {
memcpy(&context->buffer[j], data, (i = 64-j)); memcpy(&context->buffer[j], data, (i = 64-j));
SHA1Transform(context->state, context->buffer); SHA1Transform(context->state, context->buffer);
for ( ; i + 63 < len; i += 64) { for ( ; i + 63 < len; i += 64) SHA1Transform(context->state, &data[i]);
SHA1Transform(context->state, &data[i]);
}
j = 0; j = 0;
} }
else i = 0; else i = 0;
@@ -163,34 +121,15 @@ STATIC void ICACHE_FLASH_ATTR SHA1Update(SHA1_CTX* context, uint8_t* data, uint3
/* Add padding and return the message digest. */ /* Add padding and return the message digest. */
STATIC void ICACHE_FLASH_ATTR SHA1Final(unsigned char digest[20], SHA1_CTX* context) STATIC void ICACHE_FLASH_ATTR SHA1Final(unsigned char digest[20], SHA1_CTX* context) {
{ unsigned i;
unsigned i; unsigned char finalcount[8];
unsigned char finalcount[8]; unsigned char c;
unsigned char c;
#if 0 /* untested "improvement" by DHR */
/* Convert context->count to a sequence of bytes
* in finalcount. Second element first, but
* big-endian order within element.
* But we do it all backwards.
*/
unsigned char *fcp = &finalcount[8];
for (i = 0; i < 2; i++)
{
uint32_t t = context->count[i];
int j;
for (j = 0; j < 4; t >>= 8, j++)
*--fcp = (unsigned char) t;
}
#else
for (i = 0; i < 8; i++) { for (i = 0; i < 8; i++) {
finalcount[i] = (unsigned char)((context->count[(i >= 4 ? 0 : 1)] finalcount[i] = (unsigned char)((context->count[(i >= 4 ? 0 : 1)]
>> ((3-(i & 3)) * 8) ) & 255); /* Endian independent */ >> ((3-(i & 3)) * 8) ) & 255); /* Endian independent */
} }
#endif
c = 0200; c = 0200;
SHA1Update(context, &c, 1); SHA1Update(context, &c, 1);
while ((context->count[0] & 504) != 448) { while ((context->count[0] & 504) != 448) {
@@ -206,4 +145,3 @@ unsigned char c;
memset(context, '\0', sizeof(*context)); memset(context, '\0', sizeof(*context));
memset(&finalcount, '\0', sizeof(finalcount)); memset(&finalcount, '\0', sizeof(finalcount));
} }
/* ================ end of sha1.c ================ */
+1 -10
View File
@@ -13,15 +13,10 @@
100% Public Domain 100% Public Domain
*/ */
#ifndef SHA1_H_ #pragma once
#define SHA1_H_
#ifdef ESP32
#define ICACHE_FLASH_ATTR #define ICACHE_FLASH_ATTR
#define STATIC static #define STATIC static
#else
#define STATIC
#endif
typedef struct { typedef struct {
uint32_t state[5]; uint32_t state[5];
@@ -33,7 +28,3 @@ STATIC void SHA1Transform(uint32_t state[5], uint8_t buffer[64]);
STATIC void SHA1Init(SHA1_CTX* context); STATIC void SHA1Init(SHA1_CTX* context);
STATIC void SHA1Update(SHA1_CTX* context, uint8_t* data, uint32_t len); STATIC void SHA1Update(SHA1_CTX* context, uint8_t* data, uint32_t len);
STATIC void SHA1Final(unsigned char digest[20], SHA1_CTX* context); STATIC void SHA1Final(unsigned char digest[20], SHA1_CTX* context);
#endif /* SHA1_H_ */
/* ================ end of sha1.h ================ */
-48
View File
@@ -1,48 +0,0 @@
#define TFT_NOP 0x00
#define TFT_INVOFF 0x20
#define TFT_INVON 0x21
#define TFT_CASET 0x2A
#define TFT_PASET 0x2B
#define TFT_RAMWR 0x2C
#define TFT_RAMRD 0x2E
#define TFT_IDXRD 0xDD
#define TFT_MADCTL 0x36
#define TFT_MAD_MY 0x80
#define TFT_MAD_MX 0x40
#define TFT_MAD_MV 0x20
#define TFT_MAD_ML 0x10
#define TFT_MAD_BGR 0x08
#define TFT_MAD_MH 0x04
#define TFT_MAD_RGB 0x00
#define ILI9341_SLPOUT 0x11
#define ILI9341_NORON 0x13
#define ILI9341_GAMMASET 0x26
#define ILI9341_DISPON 0x29
#define ILI9341_MADCTL 0x36
#define ILI9341_PIXFMT 0x3A
#define ILI9341_FRMCTR1 0xB1
#define ILI9341_DFUNCTR 0xB6
#define ILI9341_PWCTR1 0xC0
#define ILI9341_PWCTR2 0xC1
#define ILI9341_VMCTR1 0xC5
#define ILI9341_VMCTR2 0xC7
#define ILI9341_GMCTRP1 0xE0
#define ILI9341_GMCTRN1 0xE1
#define ILI9341_MADCTL_MY 0x80
#define ILI9341_MADCTL_MX 0x40
#define ILI9341_MADCTL_MV 0x20
#define ILI9341_MADCTL_ML 0x10
#define ILI9341_MADCTL_RGB 0x00
#define ILI9341_MADCTL_BGR 0x08
#define ILI9341_MADCTL_MH 0x04
+1 -1
View File
@@ -105,7 +105,7 @@
writecommand(ILI9341_SLPOUT); //Exit Sleep writecommand(ILI9341_SLPOUT); //Exit Sleep
end_tft_write(); end_tft_write();
delay(80); delay(60);
begin_tft_write(); begin_tft_write();
writecommand(ILI9341_DISPON); //Display on writecommand(ILI9341_DISPON); //Display on
+9 -20
View File
@@ -316,7 +316,7 @@ TFT_eSPI::TFT_eSPI(int16_t w, int16_t h) {
textwrapX = false; textwrapX = false;
textdatum = TL_DATUM; textdatum = TL_DATUM;
_swapBytes = false; _swapBytes = true;
booted = true; booted = true;
@@ -404,7 +404,7 @@ void TFT_eSPI::init() {
gpio_set_level((gpio_num_t)TFT_RST, 1); gpio_set_level((gpio_num_t)TFT_RST, 1);
} }
delay(50); // Wait for reset to complete delay(35); // Wait for reset to complete
begin_tft_write(); begin_tft_write();
@@ -3079,7 +3079,7 @@ TFT_eSprite::TFT_eSprite(TFT_eSPI *tft) {
_iwidth = 0; // Initialise width and height to 0 (it does not exist yet) _iwidth = 0; // Initialise width and height to 0 (it does not exist yet)
_iheight = 0; _iheight = 0;
_bpp = 16; _bpp = 16;
_swapBytes = false; // Do not swap pushImage colour bytes by default _swapBytes = true; // Do not swap pushImage colour bytes by default
_created = false; _created = false;
_vpOoB = true; _vpOoB = true;
@@ -3310,40 +3310,29 @@ void TFT_eSprite::pushSprite(int32_t x, int32_t y)
{ {
if (!_created) return; if (!_created) return;
if (_bpp == 16) if (_bpp == 16) {
{
bool oldSwapBytes = _tft->getSwapBytes(); bool oldSwapBytes = _tft->getSwapBytes();
_tft->setSwapBytes(false); _tft->setSwapBytes(false);
_tft->pushImage(x, y, _dwidth, _dheight, _img ); _tft->pushImage(x, y, _dwidth, _dheight, _img );
_tft->setSwapBytes(oldSwapBytes); _tft->setSwapBytes(oldSwapBytes);
} } else if (_bpp == 4) {
else if (_bpp == 4)
{
_tft->pushImage(x, y, _dwidth, _dheight, _img4, false, _colorMap); _tft->pushImage(x, y, _dwidth, _dheight, _img4, false, _colorMap);
} } else _tft->pushImage(x, y, _dwidth, _dheight, _img8, (bool)(_bpp == 8));
else _tft->pushImage(x, y, _dwidth, _dheight, _img8, (bool)(_bpp == 8));
} }
void TFT_eSprite::pushSprite(int32_t x, int32_t y, uint16_t transp) void TFT_eSprite::pushSprite(int32_t x, int32_t y, uint16_t transp)
{ {
if (!_created) return; if (!_created) return;
if (_bpp == 16) if (_bpp == 16) {
{
bool oldSwapBytes = _tft->getSwapBytes(); bool oldSwapBytes = _tft->getSwapBytes();
_tft->setSwapBytes(false); _tft->setSwapBytes(false);
_tft->pushImage(x, y, _dwidth, _dheight, _img, transp ); _tft->pushImage(x, y, _dwidth, _dheight, _img, transp );
_tft->setSwapBytes(oldSwapBytes); _tft->setSwapBytes(oldSwapBytes);
} } else if (_bpp == 8) {
else if (_bpp == 8)
{
transp = (uint8_t)((transp & 0xE000)>>8 | (transp & 0x0700)>>6 | (transp & 0x0018)>>3); transp = (uint8_t)((transp & 0xE000)>>8 | (transp & 0x0700)>>6 | (transp & 0x0018)>>3);
_tft->pushImage(x, y, _dwidth, _dheight, _img8, (uint8_t)transp, (bool)true); _tft->pushImage(x, y, _dwidth, _dheight, _img8, (uint8_t)transp, (bool)true);
} } else if (_bpp == 4) _tft->pushImage(x, y, _dwidth, _dheight, _img4, (uint8_t)(transp & 0x0F), false, _colorMap);
else if (_bpp == 4)
{
_tft->pushImage(x, y, _dwidth, _dheight, _img4, (uint8_t)(transp & 0x0F), false, _colorMap);
}
else _tft->pushImage(x, y, _dwidth, _dheight, _img8, 0, (bool)false); else _tft->pushImage(x, y, _dwidth, _dheight, _img8, 0, (bool)false);
} }
+48 -1
View File
@@ -52,7 +52,54 @@
#define TFT_WIDTH 240 #define TFT_WIDTH 240
#define TFT_HEIGHT 320 #define TFT_HEIGHT 320
#include <ILI9341_Defines.h> #define TFT_NOP 0x00
#define TFT_INVOFF 0x20
#define TFT_INVON 0x21
#define TFT_CASET 0x2A
#define TFT_PASET 0x2B
#define TFT_RAMWR 0x2C
#define TFT_RAMRD 0x2E
#define TFT_IDXRD 0xDD
#define TFT_MADCTL 0x36
#define TFT_MAD_MY 0x80
#define TFT_MAD_MX 0x40
#define TFT_MAD_MV 0x20
#define TFT_MAD_ML 0x10
#define TFT_MAD_BGR 0x08
#define TFT_MAD_MH 0x04
#define TFT_MAD_RGB 0x00
#define ILI9341_SLPOUT 0x11
#define ILI9341_NORON 0x13
#define ILI9341_GAMMASET 0x26
#define ILI9341_DISPON 0x29
#define ILI9341_MADCTL 0x36
#define ILI9341_PIXFMT 0x3A
#define ILI9341_FRMCTR1 0xB1
#define ILI9341_DFUNCTR 0xB6
#define ILI9341_PWCTR1 0xC0
#define ILI9341_PWCTR2 0xC1
#define ILI9341_VMCTR1 0xC5
#define ILI9341_VMCTR2 0xC7
#define ILI9341_GMCTRP1 0xE0
#define ILI9341_GMCTRN1 0xE1
#define ILI9341_MADCTL_MY 0x80
#define ILI9341_MADCTL_MX 0x40
#define ILI9341_MADCTL_MV 0x20
#define ILI9341_MADCTL_ML 0x10
#define ILI9341_MADCTL_RGB 0x00
#define ILI9341_MADCTL_BGR 0x08
#define ILI9341_MADCTL_MH 0x04
#include <pgmspace.h> #include <pgmspace.h>
+88 -90
View File
@@ -24,13 +24,13 @@ void TEF6686::TestAFEON() {
setMute(); setMute();
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, 4, 3, af[x].frequency); devTEF_Set_Cmd(TEF_FM, Cmd_Tune_To, 2, 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, NULL, NULL, NULL); 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) {
devTEF_Set_Cmd(TEF_FM, Cmd_Tune_To, 4, 4, af[x].frequency); devTEF_Set_Cmd(TEF_FM, Cmd_Tune_To, 2, 4, af[x].frequency);
delay(187); delay(187);
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);
@@ -46,7 +46,7 @@ void TEF6686::TestAFEON() {
} }
} }
} }
devTEF_Set_Cmd(TEF_FM, Cmd_Tune_To, 4, 4, currentfreq); devTEF_Set_Cmd(TEF_FM, Cmd_Tune_To, 2, 4, currentfreq);
setUnMute(); setUnMute();
} }
@@ -61,7 +61,7 @@ uint16_t TEF6686::TestAF() {
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, 4, 3, af[x].frequency); devTEF_Set_Cmd(TEF_FM, Cmd_Tune_To, 2, 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, NULL, NULL, NULL); devTEF_Radio_Get_Quality_Status(&status, &aflevel, &afusn, &afwam, &afoffset, NULL, NULL, NULL);
timing = lowByte(status); timing = lowByte(status);
@@ -81,7 +81,7 @@ uint16_t TEF6686::TestAF() {
} }
if (af_counter != 0 && af[highestIndex].afvalid && af[highestIndex].score > (currentlevel - currentusn - currentwam) && (af[highestIndex].score - (currentlevel - currentusn - currentwam)) >= 70) { if (af_counter != 0 && af[highestIndex].afvalid && af[highestIndex].score > (currentlevel - currentusn - currentwam) && (af[highestIndex].score - (currentlevel - currentusn - currentwam)) >= 70) {
devTEF_Set_Cmd(TEF_FM, Cmd_Tune_To, 4, 4, af[highestIndex].frequency); devTEF_Set_Cmd(TEF_FM, Cmd_Tune_To, 2, 4, af[highestIndex].frequency);
delay(187); delay(187);
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);
if (bitRead(rds.rdsStat, 9)) { if (bitRead(rds.rdsStat, 9)) {
@@ -96,9 +96,9 @@ uint16_t TEF6686::TestAF() {
af_counter = 0; af_counter = 0;
} else { } else {
af[highestIndex].afvalid = false; af[highestIndex].afvalid = false;
devTEF_Set_Cmd(TEF_FM, Cmd_Tune_To, 4, 4, currentfreq); devTEF_Set_Cmd(TEF_FM, Cmd_Tune_To, 2, 4, currentfreq);
} }
} else devTEF_Set_Cmd(TEF_FM, Cmd_Tune_To, 4, 4, currentfreq); } else devTEF_Set_Cmd(TEF_FM, Cmd_Tune_To, 2, 4, currentfreq);
} }
} }
return currentfreq; return currentfreq;
@@ -109,7 +109,7 @@ void TEF6686::init(byte TEF) {
Wire.setClock(400000); Wire.setClock(400000);
Tuner_Reset(); Tuner_Reset();
while(devTEF_APPL_Get_Operation_Status() != 0) delay(2); while(devTEF_APPL_Get_Operation_Status() != 0) delay(1);
uint32_t clock = 12000000; uint32_t clock = 12000000;
@@ -128,108 +128,107 @@ void TEF6686::init(byte TEF) {
// Start the firmware // Start the firmware
devTEF_Set_Cmd(TEF_INIT, 0, 0); devTEF_Set_Cmd(TEF_INIT, 0, 0);
while(devTEF_APPL_Get_Operation_Status() != 1) delay(2); // Wait for it to load while(devTEF_APPL_Get_Operation_Status() != 1) delay(1); // Wait for it to load
if(clock != 9216000) devTEF_Set_Cmd(TEF_APPL, Cmd_Set_ReferenceClock, 6, (clock >> 16) & 0xffff, clock & 0xffff, (clock == 55466670) ? 1 : 0); if(clock != 9216000) devTEF_Set_Cmd(TEF_APPL, Cmd_Set_ReferenceClock, 3, (clock >> 16) & 0xffff, clock & 0xffff, (clock == 55466670) ? 1 : 0);
devTEF_Set_Cmd(TEF_APPL, Cmd_Set_Activate, 2, 1); // Setup done, start radio devTEF_Set_Cmd(TEF_APPL, Cmd_Set_Activate, 1, 1); // Setup done, start radio
while(devTEF_APPL_Get_Operation_Status() != 2) delay(2); // Wait for it to start while(devTEF_APPL_Get_Operation_Status() != 2) delay(1); // Wait for it to start
Wire.setClock(old_clock); Wire.setClock(old_clock);
devTEF_Set_Cmd(TEF_FM, Cmd_Set_Highcut_Mph, 6, 0, 360, 300); devTEF_Set_Cmd(TEF_FM, Cmd_Set_Highcut_Mph, 3, 0, 360, 300);
devTEF_Set_Cmd(TEF_FM, Cmd_Set_Highcut_Max, 4, 0, 4000); devTEF_Set_Cmd(TEF_FM, Cmd_Set_Highcut_Max, 2, 0, 4000);
devTEF_Set_Cmd(TEF_FM, Cmd_Set_LowCut_Max, 4, 0, 100); devTEF_Set_Cmd(TEF_FM, Cmd_Set_LowCut_Max, 2, 0, 100);
devTEF_Set_Cmd(TEF_FM, Cmd_Set_Stereo_Time, 8, 60, 120, 100, 200); devTEF_Set_Cmd(TEF_FM, Cmd_Set_Stereo_Time, 4, 60, 120, 100, 200);
devTEF_Set_Cmd(TEF_FM, Cmd_Set_StHiBlend_Time, 8, 500, 2000, 200, 200); devTEF_Set_Cmd(TEF_FM, Cmd_Set_StHiBlend_Time, 4, 500, 2000, 200, 200);
devTEF_Set_Cmd(TEF_FM, Cmd_Set_StHiBlend_Level, 6, 0, 600, 240); devTEF_Set_Cmd(TEF_FM, Cmd_Set_StHiBlend_Level, 3, 0, 600, 240);
devTEF_Set_Cmd(TEF_FM, Cmd_Set_StHiBlend_Noise, 6, 0, 160, 140); devTEF_Set_Cmd(TEF_FM, Cmd_Set_StHiBlend_Noise, 3, 0, 160, 140);
devTEF_Set_Cmd(TEF_FM, Cmd_Set_StHiBlend_Mph, 6, 0, 160, 140); devTEF_Set_Cmd(TEF_FM, Cmd_Set_StHiBlend_Mph, 3, 0, 160, 140);
devTEF_Set_Cmd(TEF_FM, Cmd_Set_StHiBlend_Max, 4, 0, 4000); devTEF_Set_Cmd(TEF_FM, Cmd_Set_StHiBlend_Max, 2, 0, 4000);
devTEF_Set_Cmd(TEF_AUDIO, Cmd_Set_Ana_Out, 4, 128, 1); devTEF_Set_Cmd(TEF_AUDIO, Cmd_Set_Ana_Out, 2, 128, 1);
devTEF_Set_Cmd(TEF_AUDIO, Cmd_Set_Output_Source, 4, 128, 224); devTEF_Set_Cmd(TEF_AUDIO, Cmd_Set_Output_Source, 2, 128, 224);
uint16_t device; uint16_t device = getIdentification(NULL, NULL);
getIdentification(&device, NULL, NULL);
if(device == 1 || device == 3) fullsearchrds = true; if(device == 1 || device == 3) fullsearchrds = true;
} }
void TEF6686::getIdentification(uint16_t *device, uint16_t *hw_version, uint16_t *sw_version) { uint16_t TEF6686::getIdentification(uint16_t *hw_version, uint16_t *sw_version) {
uint8_t buf[6]; uint8_t buf[6];
devTEF_Get_Cmd(TEF_APPL, Cmd_Get_Identification, buf, sizeof(buf)); devTEF_Get_Cmd(TEF_APPL, Cmd_Get_Identification, buf, sizeof(buf));
if(device != NULL) *device = Convert8bto16b(buf);
if(hw_version != NULL) *hw_version = Convert8bto16b(buf + 2); if(hw_version != NULL) *hw_version = Convert8bto16b(buf + 2);
if(sw_version != NULL) *sw_version = Convert8bto16b(buf + 4); if(sw_version != NULL) *sw_version = Convert8bto16b(buf + 4);
return Convert8bto16b(buf);
} }
void TEF6686::power(bool mode) { void TEF6686::power(bool mode) {
devTEF_Set_Cmd(TEF_APPL, Cmd_Set_OperationMode, 2, mode); devTEF_Set_Cmd(TEF_APPL, Cmd_Set_OperationMode, 1, mode);
} }
void TEF6686::extendBW(bool yesno) { void TEF6686::extendBW(bool yesno) {
devTEF_Set_Cmd(TEF_FM, Cmd_Set_Bandwidth_Options, 2, (yesno ? 400 : 950)); devTEF_Set_Cmd(TEF_FM, Cmd_Set_Bandwidth_Options, 1, (yesno ? 400 : 950));
} }
void TEF6686::SetFreq(uint16_t frequency) { void TEF6686::SetFreq(uint16_t frequency) {
devTEF_Set_Cmd(TEF_FM, Cmd_Tune_To, 4, 1, frequency); devTEF_Set_Cmd(TEF_FM, Cmd_Tune_To, 2, 1, frequency);
currentfreq = ((frequency + 5) / 10) * 10; currentfreq = ((frequency + 5) / 10) * 10;
currentfreq2 = frequency; currentfreq2 = frequency;
} }
void TEF6686::SetFreqAM(uint16_t frequency) { void TEF6686::SetFreqAM(uint16_t frequency) {
devTEF_Set_Cmd(TEF_AM, Cmd_Tune_To, 4, 1, frequency); devTEF_Set_Cmd(TEF_AM, Cmd_Tune_To, 2, 1, frequency);
} }
void TEF6686::setOffset(int8_t offset) { void TEF6686::setOffset(int8_t offset) {
devTEF_Set_Cmd(TEF_FM, Cmd_Set_LevelOffset, 2, (offset * 10) - 70); devTEF_Set_Cmd(TEF_FM, Cmd_Set_LevelOffset, 1, (offset * 10) - 70);
} }
void TEF6686::setAMOffset(int8_t offset) { void TEF6686::setAMOffset(int8_t offset) {
devTEF_Set_Cmd(TEF_AM, Cmd_Set_LevelOffset, 2, (offset * 10) - 70); devTEF_Set_Cmd(TEF_AM, Cmd_Set_LevelOffset, 1, (offset * 10) - 70);
} }
void TEF6686::setFMBandw(uint16_t bandwidth) { void TEF6686::setFMBandw(uint16_t bandwidth) {
devTEF_Set_Cmd(TEF_FM, Cmd_Set_Bandwidth, 4, 0, bandwidth * 10); devTEF_Set_Cmd(TEF_FM, Cmd_Set_Bandwidth, 2, 0, bandwidth * 10);
} }
void TEF6686::setAMBandw(uint16_t bandwidth) { void TEF6686::setAMBandw(uint16_t bandwidth) {
devTEF_Set_Cmd(TEF_AM, Cmd_Set_Bandwidth, 4, 0, bandwidth * 10); devTEF_Set_Cmd(TEF_AM, Cmd_Set_Bandwidth, 2, 0, bandwidth * 10);
} }
void TEF6686::setAMCoChannel(uint16_t start, uint8_t level) { void TEF6686::setAMCoChannel(uint16_t start, uint8_t level) {
uint8_t mode = 1; uint8_t mode = 1;
if(start == 0) mode = 0; if(start == 0) mode = 0;
devTEF_Set_Cmd(TEF_AM, Cmd_Set_CoChannelDet, 8, mode, 2, start * 10, 1000, level); devTEF_Set_Cmd(TEF_AM, Cmd_Set_CoChannelDet, 4, mode, 2, start * 10, 1000, level);
} }
void TEF6686::setSoftmuteAM(uint8_t mode) { void TEF6686::setSoftmuteAM(uint8_t mode) {
devTEF_Set_Cmd(TEF_AM, Cmd_Set_Softmute_Max, 4, mode, 250); devTEF_Set_Cmd(TEF_AM, Cmd_Set_Softmute_Max, 2, mode, 250);
} }
void TEF6686::setSoftmuteFM(uint8_t mode) { void TEF6686::setSoftmuteFM(uint8_t mode) {
devTEF_Set_Cmd(TEF_FM, Cmd_Set_Softmute_Max, 4, mode, 200); devTEF_Set_Cmd(TEF_FM, Cmd_Set_Softmute_Max, 2, mode, 200);
} }
void TEF6686::setAMNoiseBlanker(uint16_t start) { void TEF6686::setAMNoiseBlanker(uint16_t start) {
devTEF_Set_Cmd(TEF_AM, Cmd_Set_NoiseBlanker, 4, (start == 0) ? 0 : 1, (start == 0) ? 1000 : start * 10); devTEF_Set_Cmd(TEF_AM, Cmd_Set_NoiseBlanker, 2, (start == 0) ? 0 : 1, (start == 0) ? 1000 : start * 10);
devTEF_Set_Cmd(TEF_AM, Cmd_Set_NoiseBlanker_Audio, 4, (start == 0) ? 0 : 1, 1000); devTEF_Set_Cmd(TEF_AM, Cmd_Set_NoiseBlanker_Audio, 2, (start == 0) ? 0 : 1, 1000);
} }
void TEF6686::setAMAttenuation(uint16_t start) { void TEF6686::setAMAttenuation(uint16_t start) {
devTEF_Set_Cmd(TEF_AM, Cmd_Set_Antenna, 2, start * 10); devTEF_Set_Cmd(TEF_AM, Cmd_Set_Antenna, 1, start * 10);
} }
void TEF6686::setFMABandw() { void TEF6686::setFMABandw() {
devTEF_Set_Cmd(TEF_FM, Cmd_Set_Bandwidth, 4, 1, 3110); devTEF_Set_Cmd(TEF_FM, Cmd_Set_Bandwidth, 2, 1, 3110);
} }
void TEF6686::setiMS(bool mph) { void TEF6686::setiMS(bool mph) {
devTEF_Set_Cmd(TEF_FM, Cmd_Set_MphSuppression, 2, mph); devTEF_Set_Cmd(TEF_FM, Cmd_Set_MphSuppression, 1, mph);
} }
void TEF6686::setEQ(bool eq) { void TEF6686::setEQ(bool eq) {
devTEF_Set_Cmd(TEF_FM, Cmd_Set_ChannelEqualizer, 2, eq); devTEF_Set_Cmd(TEF_FM, Cmd_Set_ChannelEqualizer, 1, eq);
} }
bool TEF6686::getStereoStatus() { bool TEF6686::getStereoStatus() {
@@ -244,117 +243,117 @@ bool TEF6686::getStereoStatus() {
} }
void TEF6686::setMono(bool mono) { void TEF6686::setMono(bool mono) {
devTEF_Set_Cmd(TEF_FM, Cmd_Set_Stereo_Min, 4, mono ? 2 : 0); devTEF_Set_Cmd(TEF_FM, Cmd_Set_Stereo_Min, 2, mono ? 2 : 0);
} }
void TEF6686::setVolume(int8_t volume) { void TEF6686::setVolume(int8_t volume) {
devTEF_Set_Cmd(TEF_AUDIO, Cmd_Set_Volume, 2, volume * 10); devTEF_Set_Cmd(TEF_AUDIO, Cmd_Set_Volume, 1, volume * 10);
} }
void TEF6686::setMute() { void TEF6686::setMute() {
mute = true; mute = true;
if (mpxmode) devTEF_Set_Cmd(TEF_FM, Cmd_Set_Specials, 2, 0); if (mpxmode) devTEF_Set_Cmd(TEF_FM, Cmd_Set_Specials, 1, 0);
devTEF_Set_Cmd(TEF_AUDIO, Cmd_Set_Mute, 2, 1); devTEF_Set_Cmd(TEF_AUDIO, Cmd_Set_Mute, 1, 1);
} }
void TEF6686::setUnMute() { void TEF6686::setUnMute() {
mute = false; mute = false;
if (mpxmode) devTEF_Set_Cmd(TEF_FM, Cmd_Set_Specials, 2, 1); if (mpxmode) devTEF_Set_Cmd(TEF_FM, Cmd_Set_Specials, 1, 1);
devTEF_Set_Cmd(TEF_AUDIO, Cmd_Set_Mute, 2, 0); devTEF_Set_Cmd(TEF_AUDIO, Cmd_Set_Mute, 1, 0);
} }
void TEF6686::setAGC(uint8_t agc) { void TEF6686::setAGC(uint8_t agc) {
devTEF_Set_Cmd(TEF_FM, Cmd_Set_RFAGC, 2, agc * 10); devTEF_Set_Cmd(TEF_FM, Cmd_Set_RFAGC, 1, agc * 10);
} }
void TEF6686::setAMAGC(uint8_t agc) { void TEF6686::setAMAGC(uint8_t agc) {
devTEF_Set_Cmd(TEF_AM, Cmd_Set_RFAGC, 2, agc * 10); devTEF_Set_Cmd(TEF_AM, Cmd_Set_RFAGC, 1, agc * 10);
} }
void TEF6686::setDeemphasis(RADIO_FM_DEEMPHASIS timeconstant) { void TEF6686::setDeemphasis(RADIO_FM_DEEMPHASIS timeconstant) {
switch (timeconstant) { switch (timeconstant) {
case DEEMPHASIS_50: devTEF_Set_Cmd(TEF_FM, Cmd_Set_Deemphasis, 2, 500); break; case DEEMPHASIS_50: devTEF_Set_Cmd(TEF_FM, Cmd_Set_Deemphasis, 1, 500); break;
case DEEMPHASIS_75: devTEF_Set_Cmd(TEF_FM, Cmd_Set_Deemphasis, 2, 750); break; case DEEMPHASIS_75: devTEF_Set_Cmd(TEF_FM, Cmd_Set_Deemphasis, 1, 750); break;
default: devTEF_Set_Cmd(TEF_FM, Cmd_Set_Deemphasis, 2, 0); break; default: devTEF_Set_Cmd(TEF_FM, Cmd_Set_Deemphasis, 1, 0); break;
} }
} }
void TEF6686::setAudio(uint8_t audio) { void TEF6686::setAudio(uint8_t audio) {
devTEF_Set_Cmd(TEF_FM, Cmd_Set_Specials, 2, audio); devTEF_Set_Cmd(TEF_FM, Cmd_Set_Specials, 1, audio);
mpxmode = (audio != 0); mpxmode = (audio != 0);
} }
void TEF6686::setFMSI(uint8_t mode) { void TEF6686::setFMSI(uint8_t mode) {
if(mode > 2) mode = 2; if(mode > 2) mode = 2;
if(mode < 1) mode = 1; if(mode < 1) mode = 1;
devTEF_Set_Cmd(TEF_FM, Cmd_Set_StereoImprovement, 2, mode-1); devTEF_Set_Cmd(TEF_FM, Cmd_Set_StereoImprovement, 1, mode-1);
} }
void TEF6686::setFMSI_Time(uint16_t attack, uint16_t decay) { void TEF6686::setFMSI_Time(uint16_t attack, uint16_t decay) {
devTEF_Set_Cmd(TEF_FM, Cmd_Set_StBandBlend_Time, 4, attack, decay); devTEF_Set_Cmd(TEF_FM, Cmd_Set_StBandBlend_Time, 2, attack, decay);
} }
void TEF6686::setFMSI_Gain(uint16_t band1, uint16_t band2, uint16_t band3, uint16_t band4) { void TEF6686::setFMSI_Gain(uint16_t band1, uint16_t band2, uint16_t band3, uint16_t band4) {
devTEF_Set_Cmd(TEF_FM, Cmd_Set_StBandBlend_Gain, 8, band1 * 10, band2 * 10, band3 * 10, band4 * 10); devTEF_Set_Cmd(TEF_FM, Cmd_Set_StBandBlend_Gain, 4, band1 * 10, band2 * 10, band3 * 10, band4 * 10);
} }
void TEF6686::setFMSI_Bias(int16_t band1, int16_t band2, int16_t band3, int16_t band4) { void TEF6686::setFMSI_Bias(int16_t band1, int16_t band2, int16_t band3, int16_t band4) {
devTEF_Set_Cmd(TEF_FM, Cmd_Set_StBandBlend_Bias, 8, band1 - 250, band2 - 250, band3 - 250, band4 - 250); devTEF_Set_Cmd(TEF_FM, Cmd_Set_StBandBlend_Bias, 4, band1 - 250, band2 - 250, band3 - 250, band4 - 250);
} }
void TEF6686::setFMNoiseBlanker(uint16_t start) { void TEF6686::setFMNoiseBlanker(uint16_t start) {
devTEF_Set_Cmd(TEF_FM, Cmd_Set_NoiseBlanker, 4, (start == 0) ? 0 : 1, (start == 0) ? 1000 : (start * 10)); devTEF_Set_Cmd(TEF_FM, Cmd_Set_NoiseBlanker, 2, (start == 0) ? 0 : 1, (start == 0) ? 1000 : (start * 10));
} }
void TEF6686::setStereoLevel(uint8_t start) { void TEF6686::setStereoLevel(uint8_t start) {
if (start == 0) { if (start == 0) {
devTEF_Set_Cmd(TEF_FM, Cmd_Set_Stereo_Level, 6, 0, start * 10, 60); devTEF_Set_Cmd(TEF_FM, Cmd_Set_Stereo_Level, 3, 0, start * 10, 60);
devTEF_Set_Cmd(TEF_FM, Cmd_Set_Stereo_Noise, 6, 0, 240, 200); devTEF_Set_Cmd(TEF_FM, Cmd_Set_Stereo_Noise, 3, 0, 240, 200);
devTEF_Set_Cmd(TEF_FM, Cmd_Set_Stereo_Mph, 6, 0, 240, 200); devTEF_Set_Cmd(TEF_FM, Cmd_Set_Stereo_Mph, 3, 0, 240, 200);
} else { } else {
devTEF_Set_Cmd(TEF_FM, Cmd_Set_Stereo_Level, 6, 3, start * 10, 60); devTEF_Set_Cmd(TEF_FM, Cmd_Set_Stereo_Level, 3, 3, start * 10, 60);
devTEF_Set_Cmd(TEF_FM, Cmd_Set_Stereo_Noise, 6, 3, 240, 200); devTEF_Set_Cmd(TEF_FM, Cmd_Set_Stereo_Noise, 3, 3, 240, 200);
devTEF_Set_Cmd(TEF_FM, Cmd_Set_Stereo_Mph, 6, 3, 240, 200); devTEF_Set_Cmd(TEF_FM, Cmd_Set_Stereo_Mph, 3, 3, 240, 200);
} }
} }
void TEF6686::setHighCutOffset(uint8_t start) { void TEF6686::setHighCutOffset(uint8_t start) {
if (start == 0) { if (start == 0) {
devTEF_Set_Cmd(TEF_FM, Cmd_Set_Highcut_Level, 6, 0, start * 10, 300); devTEF_Set_Cmd(TEF_FM, Cmd_Set_Highcut_Level, 3, 0, start * 10, 300);
devTEF_Set_Cmd(TEF_FM, Cmd_Set_Highcut_Noise, 6, 0, 360, 300); devTEF_Set_Cmd(TEF_FM, Cmd_Set_Highcut_Noise, 3, 0, 360, 300);
devTEF_Set_Cmd(TEF_FM, Cmd_Set_Highcut_Mph, 6, 0, 360, 300); devTEF_Set_Cmd(TEF_FM, Cmd_Set_Highcut_Mph, 3, 0, 360, 300);
} else { } else {
devTEF_Set_Cmd(TEF_FM, Cmd_Set_Highcut_Level, 6, 3, start * 10, 300); devTEF_Set_Cmd(TEF_FM, Cmd_Set_Highcut_Level, 3, 3, start * 10, 300);
devTEF_Set_Cmd(TEF_FM, Cmd_Set_Highcut_Noise, 6, 3, 360, 300); devTEF_Set_Cmd(TEF_FM, Cmd_Set_Highcut_Noise, 3, 3, 360, 300);
devTEF_Set_Cmd(TEF_FM, Cmd_Set_Highcut_Mph, 6, 3, 360, 300); devTEF_Set_Cmd(TEF_FM, Cmd_Set_Highcut_Mph, 3, 3, 360, 300);
} }
} }
void TEF6686::setHighCutLevel(uint16_t limit) { void TEF6686::setHighCutLevel(uint16_t limit) {
devTEF_Set_Cmd(TEF_FM, Cmd_Set_Highcut_Max, 4, 1, limit * 100); devTEF_Set_Cmd(TEF_FM, Cmd_Set_Highcut_Max, 2, 1, limit * 100);
} }
void TEF6686::setStHiBlendLevel(uint16_t limit) { void TEF6686::setStHiBlendLevel(uint16_t limit) {
devTEF_Set_Cmd(TEF_FM, Cmd_Set_StHiBlend_Max, 4, 1, limit * 100); devTEF_Set_Cmd(TEF_FM, Cmd_Set_StHiBlend_Max, 2, 1, limit * 100);
} }
void TEF6686::setStHiBlendOffset(uint8_t start) { void TEF6686::setStHiBlendOffset(uint8_t start) {
if (start == 0) { if (start == 0) {
devTEF_Set_Cmd(TEF_FM, Cmd_Set_StHiBlend_Level, 6, 0, start * 10, 300); devTEF_Set_Cmd(TEF_FM, Cmd_Set_StHiBlend_Level, 3, 0, start * 10, 300);
devTEF_Set_Cmd(TEF_FM, Cmd_Set_StHiBlend_Noise, 6, 0, 360, 300); devTEF_Set_Cmd(TEF_FM, Cmd_Set_StHiBlend_Noise, 3, 0, 360, 300);
devTEF_Set_Cmd(TEF_FM, Cmd_Set_StHiBlend_Mph, 6, 0, 360, 300); devTEF_Set_Cmd(TEF_FM, Cmd_Set_StHiBlend_Mph, 3, 0, 360, 300);
} else { } else {
devTEF_Set_Cmd(TEF_FM, Cmd_Set_StHiBlend_Level, 6, 3, start * 10, 300); devTEF_Set_Cmd(TEF_FM, Cmd_Set_StHiBlend_Level, 3, 3, start * 10, 300);
devTEF_Set_Cmd(TEF_FM, Cmd_Set_StHiBlend_Noise, 6, 3, 360, 300); devTEF_Set_Cmd(TEF_FM, Cmd_Set_StHiBlend_Noise, 3, 3, 360, 300);
devTEF_Set_Cmd(TEF_FM, Cmd_Set_StHiBlend_Mph, 6, 3, 360, 300); devTEF_Set_Cmd(TEF_FM, Cmd_Set_StHiBlend_Mph, 3, 3, 360, 300);
} }
} }
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 *audiolevel, int8_t *snr) {
devTEF_Radio_Get_Quality_Status(NULL, level, USN, WAM, offset, bandwidth, modulation, snr); devTEF_Radio_Get_Quality_Status(NULL, level, USN, WAM, offset, bandwidth, audiolevel, 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 *audiolevel, int8_t *snr) {
uint8_t buf[14]; uint8_t buf[14];
devTEF_Get_Cmd(TEF_AM, Cmd_Get_Quality_Data, buf, sizeof(buf)); devTEF_Get_Cmd(TEF_AM, Cmd_Get_Quality_Data, buf, sizeof(buf));
if(level != NULL) *level = Convert8bto16b(buf + 2); if(level != NULL) *level = Convert8bto16b(buf + 2);
@@ -362,7 +361,7 @@ void TEF6686::getStatusAM(int16_t *level, uint16_t *noise, uint16_t *cochannel,
if(cochannel != NULL) *cochannel = Convert8bto16b(buf + 6); if(cochannel != NULL) *cochannel = Convert8bto16b(buf + 6);
if(offset != NULL) *offset = Convert8bto16b(buf + 8); if(offset != NULL) *offset = Convert8bto16b(buf + 8);
if(bandwidth != NULL) *bandwidth = Convert8bto16b(buf + 10) / 10; if(bandwidth != NULL) *bandwidth = Convert8bto16b(buf + 10) / 10;
if(modulation != NULL) *modulation = Convert8bto16b(buf + 12) / 10; if(audiolevel != NULL) *audiolevel = Convert8bto16b(buf + 12) / 10;
if(level != NULL && *level < -200) *level = -200; if(level != NULL && *level < -200) *level = -200;
if(level != NULL && *level > 1200) *level = 1200; if(level != NULL && *level > 1200) *level = 1200;
if(snr != NULL) *snr = int(0.46222375 * (float)(*level) / 10 - 0.082495118 * (float)(*noise / 50) / 10) + 10; if(snr != NULL) *snr = int(0.46222375 * (float)(*level) / 10 - 0.082495118 * (float)(*noise / 50) / 10) + 10;
@@ -449,7 +448,7 @@ void TEF6686::readRDS(byte showrdserrors) {
fs::File file; fs::File file;
if (rds.region == 1 && SPIFFS.begin(true)) { if (rds.region == 1 && SPIFFS.begin(true)) {
delay(2); delay(1);
if (currentfreq2 < 9000) file = SPIFFS.open("/USA_87-90.csv"); if (currentfreq2 < 9000) file = SPIFFS.open("/USA_87-90.csv");
else if (currentfreq2 > 9000 && currentfreq2 < 9200) file = SPIFFS.open("/USA_90-92.csv"); else if (currentfreq2 > 9000 && currentfreq2 < 9200) file = SPIFFS.open("/USA_90-92.csv");
else if (currentfreq2 > 9200 && currentfreq2 < 9400) file = SPIFFS.open("/USA_92-94.csv"); else if (currentfreq2 > 9200 && currentfreq2 < 9400) file = SPIFFS.open("/USA_92-94.csv");
@@ -461,7 +460,6 @@ void TEF6686::readRDS(byte showrdserrors) {
else if (currentfreq2 > 10400 && currentfreq2 < 10600) file = SPIFFS.open("/USA_104-106.csv"); else if (currentfreq2 > 10400 && currentfreq2 < 10600) file = SPIFFS.open("/USA_104-106.csv");
else if (currentfreq2 > 10600) file = SPIFFS.open("/USA_106-108.csv"); else if (currentfreq2 > 10600) file = SPIFFS.open("/USA_106-108.csv");
delay(2);
if (file) { if (file) {
int i = 0; int i = 0;
while (file.available() && !isprint(file.peek())) { while (file.available() && !isprint(file.peek())) {
@@ -1562,7 +1560,7 @@ void TEF6686::readRDS(byte showrdserrors) {
} }
void TEF6686::clearRDS() { void TEF6686::clearRDS() {
devTEF_Set_Cmd(TEF_FM, Cmd_Set_RDS, 6, fullsearchrds ? 3 : 1, 1, 0); devTEF_Set_Cmd(TEF_FM, Cmd_Set_RDS, 3, fullsearchrds ? 3 : 1, 1, 0);
rds.piBuffer.clear(); rds.piBuffer.clear();
rds.stationName = rds.stationText = rds.stationNameLong = ""; rds.stationName = rds.stationText = rds.stationNameLong = "";
rds.PTYN = rds.stationText32 = rds.RTContent1 = rds.RTContent2 = "";; rds.PTYN = rds.stationText32 = rds.RTContent1 = rds.RTContent2 = "";;
@@ -1651,11 +1649,11 @@ void TEF6686::clearRDS() {
void TEF6686::tone(uint16_t time, int16_t amplitude, uint16_t frequency) { void TEF6686::tone(uint16_t time, int16_t amplitude, uint16_t frequency) {
auto was_muted = mute; auto was_muted = mute;
devTEF_Set_Cmd(TEF_AUDIO, Cmd_Set_Mute, 2, 0); devTEF_Set_Cmd(TEF_AUDIO, Cmd_Set_Mute, 1, 0);
devTEF_Radio_Set_Wavegen(1, amplitude, frequency); devTEF_Radio_Set_Wavegen(1, amplitude, frequency);
delay(time); delay(time);
devTEF_Radio_Set_Wavegen(0, 0, 0); devTEF_Radio_Set_Wavegen(0, 0, 0);
if(was_muted) devTEF_Set_Cmd(TEF_AUDIO, Cmd_Set_Mute, 2, 1); if(was_muted) devTEF_Set_Cmd(TEF_AUDIO, Cmd_Set_Mute, 1, 1);
} }
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) {
+15 -18
View File
@@ -2,41 +2,38 @@
#include <stdarg.h> #include <stdarg.h>
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, ...) {
uint16_t i, temp; if(len > 10) return;
uint8_t buf[20]; uint8_t buf[22];
va_list vArgs; va_list vArgs;
va_start(vArgs, len); va_start(vArgs, len);
buf[0] = module; buf[0] = module;
buf[1] = cmd; buf[1] = cmd;
buf[2] = 1; buf[2] = 1;
for (i = 0; i < len; i++) { for (uint16_t i = 0; i < len; i++) {
temp = va_arg(vArgs, int); uint16_t temp = va_arg(vArgs, int);
buf[3 + i++] = High_16bto8b(temp); buf[3 + 2*i] = High_16bto8b(temp);
buf[3 + i] = Low_16bto8b(temp); buf[3 + 2*i + 1] = Low_16bto8b(temp);
} }
va_end(vArgs); va_end(vArgs);
Tuner_WriteBuffer(buf, len + 3); Tuner_WriteBuffer(buf, len * 2 + 3);
} }
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) {
uint8_t buf[3]; uint8_t buf[3] = {module, cmd, 1};
buf[0] = module;
buf[1] = cmd;
buf[2] = 1;
Tuner_WriteBuffer(buf, 3); Tuner_WriteBuffer(buf, sizeof(buf));
return Tuner_ReadBuffer(receive, len); return Tuner_ReadBuffer(receive, len);
} }
uint8_t devTEF_APPL_Get_Operation_Status() { uint8_t devTEF_APPL_Get_Operation_Status() {
uint8_t buf[2]; uint8_t buf[2];
while(!devTEF_Get_Cmd(TEF_APPL, Cmd_Get_Operation_Status, buf, sizeof(buf))) delay(3); while(!devTEF_Get_Cmd(TEF_APPL, Cmd_Get_Operation_Status, buf, sizeof(buf))) delay(1);
return Convert8bto16b(buf); return Convert8bto16b(buf);
} }
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) { 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 *audiolevel, int8_t *snr) {
uint8_t buf[14]; uint8_t buf[14];
devTEF_Get_Cmd(TEF_FM, Cmd_Get_Quality_Data, buf, sizeof(buf)); devTEF_Get_Cmd(TEF_FM, Cmd_Get_Quality_Data, buf, sizeof(buf));
if(status != NULL) *status = Convert8bto16b(buf); if(status != NULL) *status = Convert8bto16b(buf);
@@ -45,7 +42,7 @@ void devTEF_Radio_Get_Quality_Status(uint16_t *status, int16_t *level, uint16_t
if(wam != NULL) *wam = Convert8bto16b(buf + 6); if(wam != NULL) *wam = Convert8bto16b(buf + 6);
if(offset != NULL) *offset = Convert8bto16b(buf + 8); if(offset != NULL) *offset = Convert8bto16b(buf + 8);
if(bandwidth != NULL) *bandwidth = Convert8bto16b(buf + 10) / 10; if(bandwidth != NULL) *bandwidth = Convert8bto16b(buf + 10) / 10;
if(mod != NULL) *mod = Convert8bto16b(buf + 12) / 10; if(audiolevel != NULL) *audiolevel = Convert8bto16b(buf + 12) / 10;
if (*level < -200) *level = -200; if (*level < -200) *level = -200;
if (*level > 1200) *level = 1200; if (*level > 1200) *level = 1200;
if(snr != NULL) *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;
@@ -74,7 +71,7 @@ void devTEF_Radio_Get_RDS_Data(uint16_t *status, uint16_t *A_block, uint16_t *B_
} }
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) {
devTEF_Set_Cmd(TEF_AUDIO, Cmd_Set_Input, 2, mode ? 240 : 0); devTEF_Set_Cmd(TEF_AUDIO, Cmd_Set_Input, 1, mode ? 240 : 0);
if (mode) devTEF_Set_Cmd(TEF_AUDIO, Cmd_Set_WaveGen, 12, 5, 0, amplitude * 10, freq, amplitude * 10, freq); if (mode) devTEF_Set_Cmd(TEF_AUDIO, Cmd_Set_WaveGen, 6, 5, 0, amplitude * 10, freq, amplitude * 10, freq);
else devTEF_Set_Cmd(TEF_AUDIO, Cmd_Set_WaveGen, 12, 0); else devTEF_Set_Cmd(TEF_AUDIO, Cmd_Set_WaveGen, 6, 0);
} }
+1 -1
View File
@@ -13,7 +13,7 @@ bool Tuner_WriteBuffer(unsigned char *buf, uint16_t len) {
bool Tuner_ReadBuffer(unsigned char *buf, uint16_t len) { bool Tuner_ReadBuffer(unsigned char *buf, uint16_t len) {
Wire.requestFrom(TEF668X_ADDRESS, len); Wire.requestFrom(TEF668X_ADDRESS, len);
if (Wire.available() == len) { if (Wire.available() >= len) {
for (uint16_t i = 0; i < len; i++) buf[i] = Wire.read(); for (uint16_t i = 0; i < len; i++) buf[i] = Wire.read();
return true; return true;
} }
+17 -35
View File
@@ -411,7 +411,7 @@ void XDRGTKRoutine() {
} }
} }
if (XDRGTKdata) { if(XDRGTKdata) {
switch (buff[0]) switch (buff[0])
{ {
case 'A': { case 'A': {
@@ -423,8 +423,8 @@ void XDRGTKRoutine() {
radio.setAGC(92); radio.setAGC(92);
fmagc = 92; fmagc = 92;
} else { } else {
radio.setAMAGC(102); radio.setAMAGC(100);
amagc = 102; amagc = 100;
} }
break; break;
case 1: case 1:
@@ -508,35 +508,18 @@ void XDRGTKRoutine() {
} case 'F': { } case 'F': {
XDRBWset = atoi(buff + 1); XDRBWset = atoi(buff + 1);
DataPrint("F" + String(XDRBWset) + "\n"); DataPrint("F" + String(XDRBWset) + "\n");
if (XDRBWset < 0) { if (XDRBWset < 0) BWset = 0;
BWset = 0; else if (XDRBWset < 16) BWset = XDRBWset + 1;
} else if (XDRBWset < 16) {
BWset = XDRBWset + 1;
}
doBW(); doBW();
break; break;
} case 'G': { } case 'G': {
byte offsetg = atoi(buff + 1); uint8_t offsetg = strtoul(buff + 1, NULL, 2);
if (offsetg == 0) { iMSset = (offsetg & 2) == 2;
iMSset = 1; EQset = (offsetg & 1) == 1;
EQset = 1; if (offsetg == 0) DataPrint("G00\n");
DataPrint("G00\n"); else if (offsetg == 2) DataPrint("G10\n");
} else if (offsetg == 1) DataPrint("G01\n");
if (offsetg == 10) { else if (offsetg == 3) DataPrint("G11\n");
iMSset = 1;
EQset = 0;
DataPrint("G10\n");
}
if (offsetg == 1) {
iMSset = 0;
EQset = 1;
DataPrint("G01\n");
}
if (offsetg == 11) {
iMSset = 0;
EQset = 0;
DataPrint("G11\n");
}
updateiMS(); updateiMS();
updateEQ(); updateEQ();
break; break;
@@ -747,7 +730,7 @@ void XDRGTKRoutine() {
doBW(); doBW();
break; break;
case 'w': { case 'w': {
unsigned int bwtemp = atoi(buff + 2); uint32_t bwtemp = atoi(buff + 2);
switch (bwtemp) { switch (bwtemp) {
case 0: BWset = 0; break; case 0: BWset = 0; break;
case 56000: BWset = 1; break; case 56000: BWset = 1; break;
@@ -770,7 +753,6 @@ void XDRGTKRoutine() {
doBW(); doBW();
break; break;
} }
case '\0': case '\0':
radio.setMute(); radio.setMute();
if (!screenmute) tft.drawBitmap(249, 4, Speaker, 28, 24, PrimaryColor); if (!screenmute) tft.drawBitmap(249, 4, Speaker, 28, 24, PrimaryColor);
@@ -808,7 +790,7 @@ void XDRGTKRoutine() {
} }
break; break;
} case 'W': { } case 'W': {
unsigned int bwtemp = atoi(buff + 1); uint32_t bwtemp = atoi(buff + 1);
switch (bwtemp) { switch (bwtemp) {
case 0: BWset = 0; break; case 0: BWset = 0; break;
case 56000: BWset = 1; break; case 56000: BWset = 1; break;
@@ -851,8 +833,8 @@ void XDRGTKRoutine() {
if (BAND_FM) DataPrint("T" + String((frequency + ConverterSet * 100) * 10) + "\n"); if (BAND_FM) DataPrint("T" + String((frequency + ConverterSet * 100) * 10) + "\n");
else if (BAND_OIRT) DataPrint("T" + String(frequency_OIRT * 10) + "\n"); else if (BAND_OIRT) DataPrint("T" + String(frequency_OIRT * 10) + "\n");
else DataPrint("T" + String(frequency_AM) + "\n"); else DataPrint("T" + String(frequency_AM) + "\n");
if (StereoToggle) DataPrint("B0\n"); else DataPrint("B1\n"); if(StereoToggle) DataPrint("B0\n"); else DataPrint("B1\n");
if (XDRGTKMuteScreen) MuteScreen(1); if(XDRGTKMuteScreen) MuteScreen(1);
break; break;
} case 'X': { } case 'X': {
XDRGTKTCP = false; XDRGTKTCP = false;
@@ -889,7 +871,7 @@ void XDRGTKRoutine() {
void passwordcrypt() { void passwordcrypt() {
int generated = 0; int generated = 0;
while (generated < 16) { while(generated < 16) {
byte randomValue = random(0, 26); byte randomValue = random(0, 26);
char letter = randomValue + 'a'; char letter = randomValue + 'a';
if (randomValue > 26) letter = (randomValue - 26); if (randomValue > 26) letter = (randomValue - 26);
+4 -4
View File
@@ -15,7 +15,7 @@ bool beepresetstart;
bool beepresetstop, BWreset, bwtouchtune; bool beepresetstop, BWreset, bwtouchtune;
bool BWtune, change, clockampm; bool BWtune, change, clockampm;
bool direction, dropout; bool direction, dropout;
bool dynamicPTYold, edgebeep, externaltune; bool edgebeep, externaltune;
bool findMemoryAF; bool findMemoryAF;
bool firstTouchHandled = false; bool firstTouchHandled = false;
bool flashing; bool flashing;
@@ -127,7 +127,7 @@ byte scanhold;
byte scanmodeold; byte scanmodeold;
byte screensaverOptions[5] = {0, 3, 10, 30, 60}; byte screensaverOptions[5] = {0, 3, 10, 30, 60};
byte screensaverset; byte screensaverset;
byte showmodulation; byte showaudio;
byte showrdserrors; byte showrdserrors;
byte showSWMIBand; byte showSWMIBand;
byte submenu; byte submenu;
@@ -306,8 +306,8 @@ unsigned long flashingtimer;
unsigned long keypadtimer; unsigned long keypadtimer;
unsigned long lastTouchTime = 0; unsigned long lastTouchTime = 0;
unsigned long lowsignaltimer; unsigned long lowsignaltimer;
unsigned long ModulationpreviousMillis; unsigned long AudiopreviousMillis;
unsigned long ModulationpeakPreviousMillis; unsigned long AudiopeakPreviousMillis;
unsigned long NTPtimer; unsigned long NTPtimer;
unsigned long peakholdmillis; unsigned long peakholdmillis;
unsigned long processed_rdsblocksold[33]; unsigned long processed_rdsblocksold[33];
+11 -11
View File
@@ -893,7 +893,7 @@ 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);
FullLineSprite.drawString((showmodulation ? textUI(28) : textUI(27)), 298, 2); FullLineSprite.drawString((showaudio ? textUI(28) : textUI(27)), 298, 2);
break; break;
case RDSSETTINGS: case RDSSETTINGS:
@@ -1972,7 +1972,7 @@ void ShowOneButton(byte position, byte item, bool selected) {
PSSprite.drawString(shortLine(removeNewline(textUI(60))), 75, 1); PSSprite.drawString(shortLine(removeNewline(textUI(60))), 75, 1);
PSSprite.setTextColor(PrimaryColor, PrimaryColorSmooth, false); PSSprite.setTextColor(PrimaryColor, PrimaryColorSmooth, false);
PSSprite.drawString((showmodulation ? textUI(28) : textUI(27)), 75, 15); PSSprite.drawString((showaudio ? textUI(28) : textUI(27)), 75, 15);
break; break;
case RDSSETTINGS: case RDSSETTINGS:
@@ -2969,7 +2969,6 @@ void BuildAdvancedRDS() {
stationIDold = " "; stationIDold = " ";
stationStateold = " "; stationStateold = " ";
af_counterold = 254; af_counterold = 254;
dynamicPTYold = false;
hasafold = false; hasafold = false;
haseonold = false; haseonold = false;
BWreset = true; BWreset = true;
@@ -2987,6 +2986,7 @@ void BuildAdvancedRDS() {
radio.rds.PTYN.call(); radio.rds.PTYN.call();
radio.rds.ECC.call(); radio.rds.ECC.call();
radio.rds.hasArtificialhead.call(); radio.rds.hasArtificialhead.call();
radio.rds.hasDynamicPTY.call();
radio.rds.hasCompressed.call(); radio.rds.hasCompressed.call();
radio.rds.hasStereo.call(); radio.rds.hasStereo.call();
radio.rds.TP.call(); radio.rds.TP.call();
@@ -3021,18 +3021,18 @@ void BuildDisplay() {
tft.drawLine(257, 144, 257, 180, FrameColor); tft.drawLine(257, 144, 257, 180, FrameColor);
tft.drawLine(248, 30, 248, 0, FrameColor); tft.drawLine(248, 30, 248, 0, FrameColor);
if (!showmodulation) tft.drawLine(16, 143, 189, 143, GreyoutColor); else tft.drawLine(16, 143, 189, 143, ActiveColor); if (!showaudio) tft.drawLine(16, 143, 189, 143, GreyoutColor); else tft.drawLine(16, 143, 189, 143, ActiveColor);
for (byte segments = 0; segments < 93; segments++) { for (byte segments = 0; segments < 93; segments++) {
if (segments > 54) { if (segments > 54) {
if (((segments - 53) % 10) == 0) { if (((segments - 53) % 10) == 0) {
tft.fillRect(22 + (2 * segments), 112, 2, 2, BarSignificantColor); tft.fillRect(22 + (2 * segments), 112, 2, 2, BarSignificantColor);
if (!showmodulation) tft.fillRect(22 + (2 * segments), 141, 2, 2, GreyoutColor); else tft.fillRect(22 + (2 * segments), 141, 2, 2, BarSignificantColor); if (!showaudio) tft.fillRect(22 + (2 * segments), 141, 2, 2, GreyoutColor); else tft.fillRect(22 + (2 * segments), 141, 2, 2, BarSignificantColor);
} }
} else { } else {
if (((segments + 1) % 6) == 0) { if (((segments + 1) % 6) == 0) {
tft.fillRect(22 + (2 * segments), 112, 2, 2, BarInsignificantColor); tft.fillRect(22 + (2 * segments), 112, 2, 2, BarInsignificantColor);
if (!showmodulation) tft.fillRect(22 + (2 * segments), 141, 2, 2, GreyoutColor); else tft.fillRect(22 + (2 * segments), 141, 2, 2, BarInsignificantColor); if (!showaudio) tft.fillRect(22 + (2 * segments), 141, 2, 2, GreyoutColor); else tft.fillRect(22 + (2 * segments), 141, 2, 2, BarInsignificantColor);
} }
} }
} }
@@ -3054,7 +3054,7 @@ void BuildDisplay() {
tftPrint(ALEFT, "+10", 127, 115, ActiveColor, ActiveColorSmooth, 16); tftPrint(ALEFT, "+10", 127, 115, ActiveColor, ActiveColorSmooth, 16);
tftPrint(ALEFT, "+30", 160, 115, ActiveColor, ActiveColorSmooth, 16); tftPrint(ALEFT, "+30", 160, 115, ActiveColor, ActiveColorSmooth, 16);
if (!showmodulation) { if (!showaudio) {
tftPrint(ACENTER, "A", 7, 128, GreyoutColor, BackgroundColor, 16); tftPrint(ACENTER, "A", 7, 128, GreyoutColor, BackgroundColor, 16);
tftPrint(ALEFT, "10", 24, 144, GreyoutColor, BackgroundColor, 16); tftPrint(ALEFT, "10", 24, 144, GreyoutColor, BackgroundColor, 16);
tftPrint(ALEFT, "30", 54, 144, GreyoutColor, BackgroundColor, 16); tftPrint(ALEFT, "30", 54, 144, GreyoutColor, BackgroundColor, 16);
@@ -3545,9 +3545,9 @@ void MenuUpDown(bool dir) {
break; break;
case ITEM3: case ITEM3:
showmodulation = !showmodulation; showaudio = !showaudio;
OneBigLineSprite.drawString((showmodulation ? textUI(28) : textUI(27)), 135, 0); OneBigLineSprite.drawString((showaudio ? textUI(28) : textUI(27)), 135, 0);
OneBigLineSprite.pushSprite(24, 118); OneBigLineSprite.pushSprite(24, 118);
break; break;
@@ -4816,7 +4816,7 @@ void DoMenu() {
case ITEM3: case ITEM3:
Infoboxprint(textUI(60)); Infoboxprint(textUI(60));
OneBigLineSprite.drawString((showmodulation ? textUI(28) : textUI(27)), 135, 0); OneBigLineSprite.drawString((showaudio ? textUI(28) : textUI(27)), 135, 0);
OneBigLineSprite.pushSprite(24, 118); OneBigLineSprite.pushSprite(24, 118);
break; break;
@@ -5511,7 +5511,7 @@ void DoMenu() {
} else { } else {
if (menupage == CONNECTIVITY && menuoption == ITEM2) { if (menupage == CONNECTIVITY && menuoption == ITEM2) {
tryWiFi(); tryWiFi();
delay(2000); delay(1750);
} }
if (menupage == DISPLAYSETTINGS && menuoption == ITEM5) { if (menupage == DISPLAYSETTINGS && menuoption == ITEM5) {
doTheme(); doTheme();
+125 -95
View File
@@ -38,12 +38,19 @@ void panic(Args... args) {
} }
#pragma region helpers #pragma region helpers
inline bool isSignalQualityGood(int usn, int wam, int ostatus, int threshold_multiplier = SCAN_SIGNAL_THRESHOLD_USN_MULTIPLIER, int ostatus_threshold = SCAN_SIGNAL_THRESHOLD_OSTATUS) {
return (usn < fmscansens * threshold_multiplier) &&
(wam < SCAN_SIGNAL_THRESHOLD_WAM) &&
(ostatus < ostatus_threshold) &&
(ostatus > -ostatus_threshold);
}
inline void Round30K(unsigned int freq) { inline void Round30K(unsigned int freq) {
if (freq % FREQ_OIRT_STEP_30K == 1) frequency_OIRT = (freq + 1); if (freq % FREQ_OIRT_STEP_30K == 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) { inline void Round50K(unsigned int freq) {
if (freq % 10 < 3) frequency = (freq - freq % 10); if (freq % 10 < 3) 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) frequency = (freq - (freq % 10 - 5));
else if (freq % 10 > 7) frequency = (freq - (freq % 10) + 10); else if (freq % 10 > 7) frequency = (freq - (freq % 10) + 10);
@@ -95,7 +102,7 @@ void doLog() {
case 2: ShowFreq(4); break; case 2: ShowFreq(4); break;
} }
delay(200); delay(DELAY_UI_UPDATE_MS);
ShowFreq(0); ShowFreq(0);
} }
autologged = true; autologged = true;
@@ -112,33 +119,58 @@ const char* textUI(uint16_t number) {
else return (const char*)pgm_read_ptr(&(myLanguage[language][number])); else return (const char*)pgm_read_ptr(&(myLanguage[language][number]));
} }
inline bool shouldHighlightBWButton(byte temp, byte set) {
return (set == temp) ||
(temp == 17 && set == 0) ||
(temp == 18 && !iMSset) ||
(temp == 19 && !EQset);
}
inline const char* getBWButtonLabel(byte temp, bool isFM) {
constexpr byte BW_OK_BUTTON = 20;
if (temp == BW_OK_BUTTON) return "OK";
return isFM ? BWButtonLabelsFM[temp - 1] : BWButtonLabelsAM[temp - 1];
}
void doBWtuneUp() { void doBWtuneUp() {
rotary = 0; rotary = 0;
constexpr byte BW_OK_BUTTON = 20;
constexpr byte BW_AM_MAX = 4;
if (band < BAND_GAP) { if (band < BAND_GAP) {
drawButton((BWsettemp == 20 ? "OK" : BWButtonLabelsFM[BWsettemp - 1]), BWsettemp - 1, (BWset == BWsettemp || (BWsettemp == 17 && BWset == 0) || (BWsettemp == 18 && !iMSset) || (BWsettemp == 19 && !EQset) ? true : false), false); // FM band
drawButton(getBWButtonLabel(BWsettemp, true), BWsettemp - 1, shouldHighlightBWButton(BWsettemp, BWset), false);
BWsettemp++; BWsettemp++;
if (BWsettemp > 20) BWsettemp = 1; if (BWsettemp > BW_OK_BUTTON) BWsettemp = 1;
drawButton((BWsettemp == 20 ? "OK" : BWButtonLabelsFM[BWsettemp - 1]), BWsettemp - 1, (BWset == BWsettemp || (BWsettemp == 17 && BWset == 0) || (BWsettemp == 18 && !iMSset) || (BWsettemp == 19 && !EQset) ? true : false), true); drawButton(getBWButtonLabel(BWsettemp, true), BWsettemp - 1, shouldHighlightBWButton(BWsettemp, BWset), true);
} else { } else {
drawButton((BWsettemp == 20 ? "OK" : BWButtonLabelsAM[BWsettemp - 1]), BWsettemp - 1, (BWset == BWsettemp ? true : false), false); // AM band
drawButton(getBWButtonLabel(BWsettemp, false), BWsettemp - 1, (BWset == BWsettemp), false);
BWsettemp++; BWsettemp++;
if (BWsettemp > 4 && BWsettemp < 20) BWsettemp = 20; else if (BWsettemp > 20) BWsettemp = 1; if (BWsettemp > BW_AM_MAX && BWsettemp < BW_OK_BUTTON) BWsettemp = BW_OK_BUTTON;
drawButton((BWsettemp == 20 ? "OK" : BWButtonLabelsAM[BWsettemp - 1]), BWsettemp - 1, (BWset == BWsettemp ? true : false), true); else if (BWsettemp > BW_OK_BUTTON) BWsettemp = 1;
drawButton(getBWButtonLabel(BWsettemp, false), BWsettemp - 1, (BWset == BWsettemp), true);
} }
} }
void doBWtuneDown() { void doBWtuneDown() {
rotary = 0; rotary = 0;
constexpr byte BW_OK_BUTTON = 20;
constexpr byte BW_AM_MAX = 4;
if (band < BAND_GAP) { if (band < BAND_GAP) {
drawButton((BWsettemp == 20 ? "OK" : BWButtonLabelsFM[BWsettemp - 1]), BWsettemp - 1, (BWset == BWsettemp || (BWsettemp == 17 && BWset == 0) || (BWsettemp == 18 && !iMSset) || (BWsettemp == 19 && !EQset) ? true : false), false); // FM band
drawButton(getBWButtonLabel(BWsettemp, true), BWsettemp - 1, shouldHighlightBWButton(BWsettemp, BWset), false);
BWsettemp--; BWsettemp--;
if (BWsettemp > 20 || BWsettemp == 0) BWsettemp = 20; if (BWsettemp > BW_OK_BUTTON || BWsettemp == 0) BWsettemp = BW_OK_BUTTON;
drawButton((BWsettemp == 20 ? "OK" : BWButtonLabelsFM[BWsettemp - 1]), BWsettemp - 1, (BWset == BWsettemp || (BWsettemp == 17 && BWset == 0) || (BWsettemp == 18 && !iMSset) || (BWsettemp == 19 && !EQset) ? true : false), true); drawButton(getBWButtonLabel(BWsettemp, true), BWsettemp - 1, shouldHighlightBWButton(BWsettemp, BWset), true);
} else { } else {
drawButton((BWsettemp == 20 ? "OK" : BWButtonLabelsAM[BWsettemp - 1]), BWsettemp - 1, (BWset == BWsettemp ? true : false), false); // AM band
drawButton(getBWButtonLabel(BWsettemp, false), BWsettemp - 1, (BWset == BWsettemp), false);
BWsettemp--; BWsettemp--;
if (BWsettemp > 4 && BWsettemp < 20) BWsettemp = 4; else if (BWsettemp == 0) BWsettemp = 20; if (BWsettemp > BW_AM_MAX && BWsettemp < BW_OK_BUTTON) BWsettemp = BW_AM_MAX;
drawButton((BWsettemp == 20 ? "OK" : BWButtonLabelsAM[BWsettemp - 1]), BWsettemp - 1, (BWset == BWsettemp ? true : false), true); else if (BWsettemp == 0) BWsettemp = BW_OK_BUTTON;
drawButton(getBWButtonLabel(BWsettemp, false), BWsettemp - 1, (BWset == BWsettemp), true);
} }
} }
@@ -146,8 +178,8 @@ void ShowStereoStatus() {
if (StereoToggle) { if (StereoToggle) {
if (band < BAND_GAP) Stereostatus = radio.getStereoStatus(); else Stereostatus = false; if (band < BAND_GAP) Stereostatus = radio.getStereoStatus(); else Stereostatus = false;
if (Stereostatus != Stereostatusold) { if (Stereostatus != Stereostatusold) {
if (Stereostatus && !screenmute) tft.drawBitmap(32, 5, Stereo, 32, 22, StereoColor); if (Stereostatus && !screenmute) tft.drawBitmap(STEREO_ICON_X, STEREO_ICON_Y, Stereo, 32, 22, StereoColor);
else if (!screenmute) tft.drawBitmap(32, 5, Stereo, 32, 22, GreyoutColor); else if (!screenmute) tft.drawBitmap(STEREO_ICON_X, STEREO_ICON_Y, Stereo, 32, 22, GreyoutColor);
Stereostatusold = Stereostatus; Stereostatusold = Stereostatus;
} }
} }
@@ -156,20 +188,20 @@ void ShowStereoStatus() {
void ShowRSSI() { void ShowRSSI() {
if (wifi) rssi = WiFi.RSSI(); else rssi = 0; if (wifi) rssi = WiFi.RSSI(); else rssi = 0;
if (rssiold != rssi) { if (rssiold != rssi) {
rssiold = rssi; if (!wifi && batterydetect) tft.drawBitmap(WIFI_ICON_X, WIFI_ICON_Y, WiFi4, WIFI_ICON_WIDTH, WIFI_ICON_HEIGHT, BackgroundColor);
if (!wifi && batterydetect) tft.drawBitmap(282, 3, WiFi4, 30, 25, BackgroundColor); else if (rssi == 0) tft.drawBitmap(WIFI_ICON_X, WIFI_ICON_Y, WiFi4, WIFI_ICON_WIDTH, WIFI_ICON_HEIGHT, GreyoutColor);
else if (rssi == 0) tft.drawBitmap(282, 3, WiFi4, 30, 25, GreyoutColor); else if (rssi > -50 && rssi < 0) tft.drawBitmap(WIFI_ICON_X, WIFI_ICON_Y, WiFi4, WIFI_ICON_WIDTH, WIFI_ICON_HEIGHT, WifiColorHigh);
else if (rssi > -50 && rssi < 0) tft.drawBitmap(282, 3, WiFi4, 30, 25, WifiColorHigh);
else if (rssi > -60) { else if (rssi > -60) {
tft.drawBitmap(282, 3, WiFi4, 30, 25, GreyoutColor); tft.drawBitmap(WIFI_ICON_X, WIFI_ICON_Y, WiFi4, WIFI_ICON_WIDTH, WIFI_ICON_HEIGHT, GreyoutColor);
tft.drawBitmap(282, 3, WiFi3, 30, 25, WifiColorHigh); tft.drawBitmap(WIFI_ICON_X, WIFI_ICON_Y, WiFi3, WIFI_ICON_WIDTH, WIFI_ICON_HEIGHT, WifiColorHigh);
} else if (rssi > -70) { } else if (rssi > -70) {
tft.drawBitmap(282, 3, WiFi4, 30, 25, GreyoutColor); tft.drawBitmap(WIFI_ICON_X, WIFI_ICON_Y, WiFi4, WIFI_ICON_WIDTH, WIFI_ICON_HEIGHT, GreyoutColor);
tft.drawBitmap(282, 3, WiFi2, 30, 25, WifiColorLow); tft.drawBitmap(WIFI_ICON_X, WIFI_ICON_Y, WiFi2, WIFI_ICON_WIDTH, WIFI_ICON_HEIGHT, WifiColorLow);
} else if (rssi < -70) { } else if (rssi < -70) {
tft.drawBitmap(282, 3, WiFi4, 30, 25, GreyoutColor); tft.drawBitmap(WIFI_ICON_X, WIFI_ICON_Y, WiFi4, WIFI_ICON_WIDTH, WIFI_ICON_HEIGHT, GreyoutColor);
tft.drawBitmap(282, 3, WiFi1, 30, 25, WifiColorLow); tft.drawBitmap(WIFI_ICON_X, WIFI_ICON_Y, WiFi1, WIFI_ICON_WIDTH, WIFI_ICON_HEIGHT, WifiColorLow);
} }
rssiold = rssi;
} }
} }
@@ -237,8 +269,8 @@ inline void updateCodetect() {
void SetTunerPatch() { void SetTunerPatch() {
if(FORBIDDEN_TUNER(TEF)) { if(FORBIDDEN_TUNER(TEF)) {
radio.init(102); radio.init(102);
uint16_t device, hw, sw; uint16_t hw, sw;
radio.getIdentification(&device, &hw, &sw); radio.getIdentification(&hw, &sw);
TEF = highByte(hw) * 100 + highByte(sw); TEF = highByte(hw) * 100 + highByte(sw);
tft.fillScreen(BackgroundColor); tft.fillScreen(BackgroundColor);
analogWrite(CONTRASTPIN, map(ContrastSet, 0, 100, 15, 255)); analogWrite(CONTRASTPIN, map(ContrastSet, 0, 100, 15, 255));
@@ -292,7 +324,6 @@ void WakeToSleep(bool yes) {
switch (poweroptions) { switch (poweroptions) {
case LCD_OFF: case LCD_OFF:
MuteScreen(1); MuteScreen(1);
StoreFrequency();
break; break;
case LCD_BRIGHTNESS_1_PERCENT: case LCD_BRIGHTNESS_1_PERCENT:
analogWrite(CONTRASTPIN, map(ContrastSet / 100, 0, 100, 15, 255)); analogWrite(CONTRASTPIN, map(ContrastSet / 100, 0, 100, 15, 255));
@@ -554,8 +585,8 @@ void BANDBUTTONPress() {
} }
} }
} }
while (digitalRead(BANDBUTTON) == LOW) delay(50); while (digitalRead(BANDBUTTON) == LOW) delay(DELAY_BUTTON_DEBOUNCE_MS);
delay(75); delay(DELAY_BUTTON_DEBOUNCE_EXTRA_MS);
} }
void LimitAMFrequency() { void LimitAMFrequency() {
@@ -613,8 +644,8 @@ void BWButtonPress() {
} }
} }
} }
while (digitalRead(BWBUTTON) == LOW) delay(50); while (digitalRead(BWBUTTON) == LOW) delay(DELAY_BUTTON_DEBOUNCE_MS);
delay(75); delay(DELAY_BUTTON_DEBOUNCE_EXTRA_MS);
} }
void doStereoToggle() { void doStereoToggle() {
@@ -749,22 +780,19 @@ void toggleiMSEQ() {
updateiMS(); updateiMS();
updateEQ(); updateEQ();
iMSEQ = 0; iMSEQ = 0;
} } else if (iMSEQ == 3) {
if (iMSEQ == 3) {
iMSset = 1; iMSset = 1;
EQset = 0; EQset = 0;
updateiMS(); updateiMS();
updateEQ(); updateEQ();
iMSEQ = 4; iMSEQ = 4;
} } else if (iMSEQ == 2) {
if (iMSEQ == 2) {
iMSset = 0; iMSset = 0;
EQset = 1; EQset = 1;
updateiMS(); updateiMS();
updateEQ(); updateEQ();
iMSEQ = 3; iMSEQ = 3;
} } else if (iMSEQ == 1) {
if (iMSEQ == 1) {
iMSset = 1; iMSset = 1;
EQset = 1; EQset = 1;
updateiMS(); updateiMS();
@@ -853,7 +881,6 @@ void ShowNum(int val) {
} }
byte numval[16] = {2, 3, 127, 5, 6, 0, 9, 13, 8, 7, 4, 1, 0, 0, 0, 0}; byte numval[16] = {2, 3, 127, 5, 6, 0, 9, 13, 8, 7, 4, 1, 0, 0, 0, 0};
int GetNum() { int GetNum() {
if(!gpio_chip) return -1; if(!gpio_chip) return -1;
// Get input port 0 and 1 // Get input port 0 and 1
@@ -1224,7 +1251,7 @@ void later_setup_periph() {
} }
uint16_t device, hw, sw; uint16_t device, hw, sw;
radio.getIdentification(&device, &hw, &sw); device = radio.getIdentification(&hw, &sw);
if (TEF != (highByte(hw) * 100 + highByte(sw))) SetTunerPatch(); if (TEF != (highByte(hw) * 100 + highByte(sw))) SetTunerPatch();
if (lowByte(device) == 14) { if (lowByte(device) == 14) {
@@ -1274,7 +1301,7 @@ void later_setup_periph() {
} }
} else console.print("RX8010SJ is not available at address " + String(RX8010SJ_ADDRESS, HEX)); } else console.print("RX8010SJ is not available at address " + String(RX8010SJ_ADDRESS, HEX));
if(analogRead(BATTERY_PIN) < 200) batterydetect = false; if(analogRead(BATTERY_PIN) < BATTERY_DETECT_THRESHOLD) batterydetect = false;
else console.print("Battery detected."); else console.print("Battery detected.");
} }
@@ -1374,13 +1401,10 @@ void setup() {
attachInterrupt(digitalPinToInterrupt(ROTARY_PIN_A), read_encoder, CHANGE); attachInterrupt(digitalPinToInterrupt(ROTARY_PIN_A), read_encoder, CHANGE);
attachInterrupt(digitalPinToInterrupt(ROTARY_PIN_B), read_encoder, CHANGE); attachInterrupt(digitalPinToInterrupt(ROTARY_PIN_B), read_encoder, CHANGE);
tft.setSwapBytes(true);
SPIFFS.begin(); SPIFFS.begin();
FrequencySprite.createSprite(200, 50); FrequencySprite.createSprite(200, 50);
FrequencySprite.setTextDatum(TR_DATUM); FrequencySprite.setTextDatum(TR_DATUM);
FrequencySprite.setSwapBytes(true);
FrequencySprite.loadFont(FREQFONT0, 0); FrequencySprite.loadFont(FREQFONT0, 0);
FrequencySprite.loadFont(FREQFONT1, 1); FrequencySprite.loadFont(FREQFONT1, 1);
FrequencySprite.loadFont(FREQFONT2, 2); FrequencySprite.loadFont(FREQFONT2, 2);
@@ -1389,29 +1413,23 @@ void setup() {
FrequencySprite.loadFont(FREQFONT5, 5); FrequencySprite.loadFont(FREQFONT5, 5);
GeneralTextSprite.createSprite(308, 28); GeneralTextSprite.createSprite(308, 28);
GeneralTextSprite.setSwapBytes(true);
GeneralTextSprite.loadFont(FONT48, 2); GeneralTextSprite.loadFont(FONT48, 2);
PSSprite.createSprite(150, 32); PSSprite.createSprite(150, 32);
PSSprite.setSwapBytes(true);
PSSprite.loadFont(FONT16, 0); PSSprite.loadFont(FONT16, 0);
PSSprite.loadFont(FONT16_CHS, 1); PSSprite.loadFont(FONT16_CHS, 1);
PSSprite.loadFont(FONT28, 2); PSSprite.loadFont(FONT28, 2);
PSSprite.loadFont(FONT28_CHS, 3); PSSprite.loadFont(FONT28_CHS, 3);
SquelchSprite.createSprite(27, 19); SquelchSprite.createSprite(27, 19);
SquelchSprite.setSwapBytes(true);
FullLineSprite.createSprite(308, 19); FullLineSprite.createSprite(308, 19);
FullLineSprite.setSwapBytes(true);
OneBigLineSprite.createSprite(270, 30); OneBigLineSprite.createSprite(270, 30);
OneBigLineSprite.setSwapBytes(true);
SignalSprite.createSprite(80, 48); SignalSprite.createSprite(80, 48);
SignalSprite.loadFont(FONT28, 0); SignalSprite.loadFont(FONT28, 0);
SignalSprite.setTextColor(PrimaryColor, PrimaryColorSmooth, false); SignalSprite.setTextColor(PrimaryColor, PrimaryColorSmooth, false);
SignalSprite.setSwapBytes(true);
UpdateFonts(); UpdateFonts();
tft.fillScreen(BackgroundColor); tft.fillScreen(BackgroundColor);
@@ -1491,17 +1509,17 @@ void setup() {
for (int x = 0; x <= ContrastSet; x++) { for (int x = 0; x <= ContrastSet; x++) {
analogWrite(CONTRASTPIN, map(x, 0, 100, 15, 255)); analogWrite(CONTRASTPIN, map(x, 0, 100, 15, 255));
delay(8); delay(5);
} }
console.print("Firmware " + String(VERSION)); console.print("Firmware " + String(VERSION));
console.print("Compiled at " + String(__TIME__) + " " + String(__DATE__));
if(!tef_found) { if(!tef_found) {
console.print(textUI(6)); console.print(textUI(6));
while (true) delay(1); while (true) delay(100);
} }
TEF = EEPROM.readByte(EE_BYTE_TEF); TEF = EEPROM.readByte(EE_BYTE_TEF);
if(FORBIDDEN_TUNER(TEF)) SetTunerPatch(); if(FORBIDDEN_TUNER(TEF)) SetTunerPatch();
@@ -1513,7 +1531,7 @@ void setup() {
} }
if (wifi) { if (wifi) {
console.print("Trying WiFi, setting clock to 160 MHz"); console.print("Trying WiFi");
tryWiFi(); tryWiFi();
delay(1750); delay(1750);
} else { } else {
@@ -1521,7 +1539,7 @@ void setup() {
Udp.stop(); Udp.stop();
} }
while(digitalRead(ROTARY_BUTTON) == LOW) delay(75); while(digitalRead(ROTARY_BUTTON) == LOW) delay(100);
console.print("Init done."); console.print("Init done.");
@@ -1553,25 +1571,28 @@ void setup() {
console.reset(); console.reset();
} }
void ShowModLevel(); void ShowAudioLevel();
void doSquelch(); void doSquelch();
void loop() {
void handleWiFi() {
if (wifi && !menu) { if (wifi && !menu) {
webserver.handleClient(); webserver.handleClient();
if (millis() >= udplogtimer + 500) { if (millis() >= udplogtimer + UDP_LOG_INTERVAL_MS) {
sendUDPlog(); sendUDPlog();
udplogtimer = millis(); udplogtimer = millis();
} }
if (millis() >= NTPtimer + 1800000) { if (millis() >= NTPtimer + NTP_UPDATE_INTERVAL_MS) {
NTPupdate(); NTPupdate();
NTPtimer = millis(); NTPtimer = millis();
} }
} }
}
void handleTouch() {
if (hardwaremodel == PORTABLE_TOUCH_ILI9341 && touch_detect) { if (hardwaremodel == PORTABLE_TOUCH_ILI9341 && touch_detect) {
if (tft.getTouchRawZ() > 250) { if (tft.getTouchRawZ() > TOUCH_RAW_Z_THRESHOLD) {
uint16_t x, y; uint16_t x, y;
tft.getTouch(&x, &y); tft.getTouch(&x, &y);
if (x > 0 || y > 0) { if (x > 0 || y > 0) {
@@ -1579,34 +1600,45 @@ void loop() {
doTouchEvent(x, y); doTouchEvent(x, y);
firstTouchHandled = true; firstTouchHandled = true;
lastTouchTime = millis(); lastTouchTime = millis();
} else if (touchrepeat && millis() - lastTouchTime >= 500) doTouchEvent(x, y); } else if (touchrepeat && millis() - lastTouchTime >= DELAY_TOUCH_REPEAT_MS) {
doTouchEvent(x, y);
}
} }
} else { } else {
firstTouchHandled = false; firstTouchHandled = false;
touch_detect = false; touch_detect = false;
} }
} }
}
Communication(); void handleTimers() {
// tottimer is like the time of the last interaction // tottimer is like the time of the last interaction
if (tot != 0 && millis() >= tottimer + (tot * 60000)) deepSleep(); if (tot != 0 && millis() >= tottimer + (tot * TOT_MULTIPLIER_MS)) {
deepSleep();
}
if (freq_in != 0 && millis() >= keypadtimer + 2000) { if (freq_in != 0 && millis() >= keypadtimer + DELAY_KEYPAD_TIMEOUT_MS) {
freq_in = 0; freq_in = 0;
ShowFreq(0); ShowFreq(0);
} }
}
void loop() {
handleWiFi();
handleTouch();
Communication();
handleTimers();
if (scandxmode) { if (scandxmode) {
unsigned long waitTime = (scanhold == 0) ? 500 : (scanhold * 1000); unsigned long waitTime = (scanhold == 0) ? SCAN_HOLD_DEFAULT_MS : (scanhold * 1000);
if (!scanholdflag) scanholdflag = (USN < fmscansens * 30) && (WAM < 230) && (OStatus < 80) && (OStatus > -80); if (!scanholdflag) scanholdflag = isSignalQualityGood(USN, WAM, OStatus);
bool bypassMillisCheck = scanholdonsignal && !scanholdflag; bool bypassMillisCheck = scanholdonsignal && !scanholdflag;
bool shouldScan = bypassMillisCheck || (!bypassMillisCheck && (millis() >= scantimer + waitTime)); bool shouldScan = bypassMillisCheck || (!bypassMillisCheck && (millis() >= scantimer + waitTime));
if (shouldScan) { if (shouldScan) {
if (scanmute && scanholdonsignal) { if (scanmute && scanholdonsignal) {
radio.setMute(); radio.setMute();
if (!screenmute) tft.drawBitmap(249, 4, Speaker, 28, 24, PrimaryColor); if (!screenmute) tft.drawBitmap(SPEAKER_ICON_X, SPEAKER_ICON_Y, Speaker, SPEAKER_ICON_WIDTH, SPEAKER_ICON_HEIGHT, PrimaryColor);
SQ = true; SQ = true;
} }
scanholdflag = false; scanholdflag = false;
@@ -1663,7 +1695,7 @@ void loop() {
if (RDSstatus && radio.rds.correctPI != 0) cancelDXScan(); if (RDSstatus && radio.rds.correctPI != 0) cancelDXScan();
break; break;
case SIGNAL: case SIGNAL:
if ((USN < fmscansens * 30) && (WAM < 230) && (OStatus < 80 && OStatus > -80) && (Squelch < SStatus || Squelch == 920)) cancelDXScan(); if (isSignalQualityGood(USN, WAM, OStatus) && (Squelch < SStatus || Squelch == SQUELCH_MAX_VALUE)) cancelDXScan();
break; break;
} }
} }
@@ -1700,7 +1732,7 @@ void loop() {
radio.SetFreq(x); radio.SetFreq(x);
unsigned long millisold = millis(); unsigned long millisold = millis();
while (millis() - millisold < 187) { while (millis() - millisold < 187) {
if (!screenmute && !advancedRDS) ShowModLevel(); if (!screenmute && !advancedRDS) ShowAudioLevel();
} }
if (radio.rds.correctPI == radio.getBlockA()) { if (radio.rds.correctPI == radio.getBlockA()) {
frequency = x; frequency = x;
@@ -1792,7 +1824,7 @@ void loop() {
if ((SStatus / 10 > LowLevelSet) && !LowLevelInit && !BWtune && !menu && band < BAND_GAP) { if ((SStatus / 10 > LowLevelSet) && !LowLevelInit && !BWtune && !menu && band < BAND_GAP) {
if (!screenmute && !advancedRDS && !rdsstatscreen && !afscreen) { if (!screenmute && !advancedRDS && !rdsstatscreen && !afscreen) {
if (showmodulation) { if (showaudio) {
tftPrint(ALEFT, "10", 24, 144, ActiveColor, ActiveColorSmooth, 16); tftPrint(ALEFT, "10", 24, 144, ActiveColor, ActiveColorSmooth, 16);
tftPrint(ALEFT, "30", 54, 144, ActiveColor, ActiveColorSmooth, 16); tftPrint(ALEFT, "30", 54, 144, ActiveColor, ActiveColorSmooth, 16);
tftPrint(ALEFT, "50", 84, 144, ActiveColor, ActiveColorSmooth, 16); tftPrint(ALEFT, "50", 84, 144, ActiveColor, ActiveColorSmooth, 16);
@@ -1815,7 +1847,7 @@ void loop() {
tftPrint(ALEFT, "PS", 3, 193, ActiveColor, ActiveColorSmooth, 16); tftPrint(ALEFT, "PS", 3, 193, ActiveColor, ActiveColorSmooth, 16);
tftPrint(ALEFT, "RT", 3, 221, ActiveColor, ActiveColorSmooth, 16); tftPrint(ALEFT, "RT", 3, 221, ActiveColor, ActiveColorSmooth, 16);
tftPrint(ALEFT, "PTY", 3, 163, ActiveColor, ActiveColorSmooth, 16); tftPrint(ALEFT, "PTY", 3, 163, ActiveColor, ActiveColorSmooth, 16);
if (!showmodulation) tft.drawLine(16, 143, 189, 143, GreyoutColor); else tft.drawLine(16, 143, 189, 143, ActiveColor); if (!showaudio) tft.drawLine(16, 143, 189, 143, GreyoutColor); else tft.drawLine(16, 143, 189, 143, ActiveColor);
} }
LowLevelInit = true; LowLevelInit = true;
} }
@@ -1823,7 +1855,7 @@ void loop() {
if ((SStatus / 10 <= LowLevelSet) && band < BAND_GAP) { if ((SStatus / 10 <= LowLevelSet) && band < BAND_GAP) {
if (LowLevelInit && !BWtune && !menu) { if (LowLevelInit && !BWtune && !menu) {
if (!screenmute && !rdsstatscreen && !afscreen && !advancedRDS) { if (!screenmute && !rdsstatscreen && !afscreen && !advancedRDS) {
if(showmodulation) { if(showaudio) {
tftPrint(ALEFT, "10", 24, 144, GreyoutColor, BackgroundColor, 16); tftPrint(ALEFT, "10", 24, 144, GreyoutColor, BackgroundColor, 16);
tftPrint(ALEFT, "30", 54, 144, GreyoutColor, BackgroundColor, 16); tftPrint(ALEFT, "30", 54, 144, GreyoutColor, BackgroundColor, 16);
tftPrint(ALEFT, "50", 84, 144, GreyoutColor, BackgroundColor, 16); tftPrint(ALEFT, "50", 84, 144, GreyoutColor, BackgroundColor, 16);
@@ -1875,7 +1907,7 @@ void loop() {
doSquelch(); doSquelch();
if (millis() >= tuningtimer + 200) readRds(); if (millis() >= tuningtimer + 200) readRds();
GetData(); GetData();
if (!screenmute && !rdsstatscreen && !afscreen && !advancedRDS) ShowModLevel(); if (!screenmute && !rdsstatscreen && !afscreen && !advancedRDS) ShowAudioLevel();
} }
} }
@@ -2466,7 +2498,7 @@ void ModeButtonPress() {
if (menuopen) { if (menuopen) {
if (menupage == CONNECTIVITY && menuoption == ITEM2 && wifi) { if (menupage == CONNECTIVITY && menuoption == ITEM2 && wifi) {
tryWiFi(); tryWiFi();
delay(2000); delay(1750);
} }
if (menupage == DISPLAYSETTINGS && menuoption == ITEM5) doTheme(); if (menupage == DISPLAYSETTINGS && menuoption == ITEM5) doTheme();
menuopen = false; menuopen = false;
@@ -2582,7 +2614,7 @@ void ButtonPress() {
case 1: ShowFreq(3); break; case 1: ShowFreq(3); break;
case 2: ShowFreq(4); break; case 2: ShowFreq(4); break;
} }
delay(200); delay(DELAY_UI_UPDATE_MS);
EdgeBeeper(); EdgeBeeper();
while (digitalRead(ROTARY_BUTTON) == LOW) delay(50); while (digitalRead(ROTARY_BUTTON) == LOW) delay(50);
ShowFreq(0); ShowFreq(0);
@@ -2925,8 +2957,8 @@ void ShowFreq(int mode) {
FrequencySprite.setTextDatum(TR_DATUM); FrequencySprite.setTextDatum(TR_DATUM);
FrequencySprite.setTextColor(FreqColor, FreqColorSmooth, false); FrequencySprite.setTextColor(FreqColor, FreqColorSmooth, false);
} else { } else {
FrequencySprite.setTextColor(ActiveColor, ActiveColorSmooth, false);
FrequencySprite.setTextDatum(TC_DATUM); FrequencySprite.setTextDatum(TC_DATUM);
FrequencySprite.setTextColor(ActiveColor, ActiveColorSmooth, false);
} }
switch (mode) { switch (mode) {
@@ -3006,15 +3038,14 @@ void ShowSignalLevel() {
CNold = 0; CNold = 0;
} }
} }
byte MPprint = constrain(map(MP, 0, 1000, 0, 99), 0, 99);
byte MPprint = constrain(map(MP, 0, 1000, 0, 99), 0, 99);
if (MPprint != MPold) { if (MPprint != MPold) {
tftReplace(ARIGHT, String(MPold), (band < BAND_GAP ? String(MPprint) : "--"), 299, 165, PrimaryColor, PrimaryColorSmooth, BackgroundColor, 16); tftReplace(ARIGHT, String(MPold), (band < BAND_GAP ? String(MPprint) : "--"), 299, 165, PrimaryColor, PrimaryColorSmooth, BackgroundColor, 16);
MPold = MPprint; MPold = MPprint;
} }
byte USprint = constrain(map(US, 0, 1000, 0, 99), 0, 99); byte USprint = constrain(map(US, 0, 1000, 0, 99), 0, 99);
if (USprint != USold) { if (USprint != USold) {
tftReplace(ARIGHT, String(USold), (band < BAND_GAP ? String(USprint) : "--"), 299, 147, PrimaryColor, PrimaryColorSmooth, BackgroundColor, 16); tftReplace(ARIGHT, String(USold), (band < BAND_GAP ? String(USprint) : "--"), 299, 147, PrimaryColor, PrimaryColorSmooth, BackgroundColor, 16);
USold = USprint; USold = USprint;
@@ -3028,7 +3059,6 @@ void ShowSignalLevel() {
if (unit == 2) SStatusprint = round((float(SStatus) / 10.0 - 10.0 * log10(75) - 90.0) * 10.0); if (unit == 2) SStatusprint = round((float(SStatus) / 10.0 - 10.0 * log10(75) - 90.0) * 10.0);
static int DisplayedSignalSegments = 0; static int DisplayedSignalSegments = 0;
if (SStatusprint > (SStatusold + 3) || SStatusprint < (SStatusold - 3)) { if (SStatusprint > (SStatusold + 3) || SStatusprint < (SStatusold - 3)) {
if (advancedRDS) tftReplace(ARIGHT, String(SStatusold / 10) + "." + String(abs(SStatusold % 10)), String(SStatusprint / 10) + "." + String(abs(SStatusprint % 10)), 273, 51, PrimaryColor, PrimaryColorSmooth, BackgroundColor, 16); if (advancedRDS) tftReplace(ARIGHT, String(SStatusold / 10) + "." + String(abs(SStatusold % 10)), String(SStatusprint / 10) + "." + String(abs(SStatusprint % 10)), 273, 51, PrimaryColor, PrimaryColorSmooth, BackgroundColor, 16);
else { else {
@@ -3176,8 +3206,8 @@ void ShowOffset() {
} }
} }
void ShowModLevel() { void ShowAudioLevel() {
if (showmodulation) { if(showaudio) {
int segments; int segments;
MStatus = (MStatus > 120) ? 120 : MStatus; MStatus = (MStatus > 120) ? 120 : MStatus;
@@ -3185,9 +3215,9 @@ void ShowModLevel() {
segments = constrain(map(MStatus, 0, 120, 0, 86), 0, 86); segments = constrain(map(MStatus, 0, 120, 0, 86), 0, 86);
if (segments < DisplayedSegments && (millis() - ModulationpreviousMillis >= 20)) { if (segments < DisplayedSegments && (millis() - AudiopreviousMillis >= 20)) {
DisplayedSegments = max(DisplayedSegments - 3, segments); DisplayedSegments = max(DisplayedSegments - 3, segments);
ModulationpreviousMillis = millis(); AudiopreviousMillis = millis();
} else if (segments > DisplayedSegments) DisplayedSegments = segments; } else if (segments > DisplayedSegments) DisplayedSegments = segments;
DisplayedSegments = constrain(DisplayedSegments, 0, 86); DisplayedSegments = constrain(DisplayedSegments, 0, 86);
@@ -3198,9 +3228,9 @@ void ShowModLevel() {
} }
if (millis() - peakholdmillis >= 1000) { if (millis() - peakholdmillis >= 1000) {
if (millis() - ModulationpeakPreviousMillis >= 20) { if (millis() - AudiopeakPreviousMillis >= 20) {
peakholdold = max(peakholdold - 3, DisplayedSegments); peakholdold = max(peakholdold - 3, DisplayedSegments);
ModulationpeakPreviousMillis = millis(); AudiopeakPreviousMillis = millis();
} }
} }
@@ -3250,7 +3280,7 @@ void doSquelch() {
if (autosquelch) { if (autosquelch) {
if (band < BAND_GAP) { if (band < BAND_GAP) {
if ((USN < fmscansens * 30) && (WAM < 230) && (OStatus < 100 && OStatus > -100) && (!scandxmode || (scandxmode && !scanmute))) { if (isSignalQualityGood(USN, WAM, OStatus, SCAN_SIGNAL_THRESHOLD_USN_MULTIPLIER, SCAN_SIGNAL_THRESHOLD_OSTATUS_WIDE) && (!scandxmode || (scandxmode && !scanmute))) {
if (SQ || BWreset) { if (SQ || BWreset) {
if (!seek) radio.setUnMute(); if (!seek) radio.setUnMute();
if (!screenmute && !seek) tft.drawBitmap(249, 4, Speaker, 28, 24, GreyoutColor); if (!screenmute && !seek) tft.drawBitmap(249, 4, Speaker, 28, 24, GreyoutColor);
@@ -3316,7 +3346,7 @@ void doSquelch() {
} }
if (!screenmute && usesquelch && !advancedRDS && !afscreen && !rdsstatscreen) { if (!screenmute && usesquelch && !advancedRDS && !afscreen && !rdsstatscreen) {
if (Squelch != Squelchold) { if (Squelch != Squelchold) {
SquelchSprite.setTextColor(PrimaryColor, PrimaryColorSmooth, false); SquelchSprite.setTextColor(PrimaryColor, PrimaryColorSmooth);
SquelchSprite.fillSprite(BackgroundColor); SquelchSprite.fillSprite(BackgroundColor);
if (Squelch == -1) SquelchSprite.drawString("ST", 0, 0); if (Squelch == -1) SquelchSprite.drawString("ST", 0, 0);
@@ -3517,7 +3547,7 @@ void ShowBattery() {
float v = analogReadMilliVolts(BATTERY_PIN) * 0.002; // 0.002 converts to volts plus corrects the /2 voltage divider float v = analogReadMilliVolts(BATTERY_PIN) * 0.002; // 0.002 converts to volts plus corrects the /2 voltage divider
byte battery = map(constrain(v, BATTERY_LOW_VALUE, BATTERY_FULL_VALUE), BATTERY_LOW_VALUE, BATTERY_FULL_VALUE, 0, BAT_LEVEL_STAGE); byte battery = map(constrain(v, BATTERY_LOW_VALUE, BATTERY_FULL_VALUE), BATTERY_LOW_VALUE, BATTERY_FULL_VALUE, 0, BAT_LEVEL_STAGE);
byte batteryprobe = map(constrain(v, BATTERY_LOW_VALUE, BATTERY_FULL_VALUE), BATTERY_LOW_VALUE, BATTERY_FULL_VALUE, 0, 20); byte batteryprobe = map(constrain(v, BATTERY_LOW_VALUE, BATTERY_FULL_VALUE), BATTERY_LOW_VALUE, BATTERY_FULL_VALUE, 0, 50);
if (batteryold != batteryprobe) { if (batteryold != batteryprobe) {
if (batterydetect) { if (batterydetect) {
if (battery == 0) { if (battery == 0) {
@@ -3746,12 +3776,12 @@ void Seek(bool mode) {
ShowFreq(0); ShowFreq(0);
if (XDRGTKUSB || XDRGTKTCP) { if (XDRGTKUSB || XDRGTKTCP) {
if (band == BAND_FM) DataPrint("M0\nT" + String(frequency * 10) + "\n"); else if (band == BAND_OIRT) DataPrint("M0\nT" + String(frequency_OIRT * 10) + "\n"); else DataPrint("M1\nT" + String(frequency_AM) + "\n"); if(band == BAND_FM) DataPrint("M0\nT" + String(frequency * 10) + "\n"); else if(band == BAND_OIRT) DataPrint("M0\nT" + String(frequency_OIRT * 10) + "\n"); else DataPrint("M1\nT" + String(frequency_AM) + "\n");
} }
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 (isSignalQualityGood(USN, WAM, OStatus) && (!usesquelch || (Squelch < SStatus || Squelch == SQUELCH_MAX_VALUE))) {
seek = false; seek = false;
radio.setUnMute(); radio.setUnMute();
if (!screenmute) tft.drawBitmap(249, 4, Speaker, 28, 24, GreyoutColor); if (!screenmute) tft.drawBitmap(249, 4, Speaker, 28, 24, GreyoutColor);
@@ -3903,11 +3933,11 @@ uint8_t doAutoMemory(uint16_t startfreq, uint16_t stopfreq, uint8_t startmem, ui
radio.SetFreq(frequency); radio.SetFreq(frequency);
radio.clearRDS(); radio.clearRDS();
delay(50); delay(DELAY_TUNE_MS);
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 (isSignalQualityGood(USN, WAM, OStatus)) {
for (byte y = 0; y < 20; y++) { for (byte y = 0; y < 20; y++) {
delay(50); delay(DELAY_RDS_READ_MS);
radio.readRDS(showrdserrors); radio.readRDS(showrdserrors);
} }
+3 -3
View File
@@ -67,7 +67,7 @@ void saveData() {
EEPROM.writeByte(EE_BYTE_RDS_FILTER, radio.rds.filter); EEPROM.writeByte(EE_BYTE_RDS_FILTER, radio.rds.filter);
EEPROM.writeByte(EE_BYTE_RDS_PIERRORS, radio.rds.pierrors); EEPROM.writeByte(EE_BYTE_RDS_PIERRORS, radio.rds.pierrors);
EEPROM.writeByte(EE_BYTE_USESQUELCH, usesquelch); EEPROM.writeByte(EE_BYTE_USESQUELCH, usesquelch);
EEPROM.writeByte(EE_BYTE_SHOWMODULATION, showmodulation); EEPROM.writeByte(EE_BYTE_SHOWAUDIO, showaudio);
EEPROM.writeByte(EE_BYTE_AM_NB, amnb); EEPROM.writeByte(EE_BYTE_AM_NB, amnb);
EEPROM.writeByte(EE_BYTE_FM_NB, fmnb); EEPROM.writeByte(EE_BYTE_FM_NB, fmnb);
EEPROM.writeByte(EE_BYTE_AUDIOMODE, audiomode); EEPROM.writeByte(EE_BYTE_AUDIOMODE, audiomode);
@@ -172,7 +172,7 @@ void loadData() {
frequency_SW = EEPROM.readUInt(EE_UINT16_FREQUENCY_SW); frequency_SW = EEPROM.readUInt(EE_UINT16_FREQUENCY_SW);
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); showaudio = EEPROM.readByte(EE_BYTE_SHOWAUDIO);
amnb = EEPROM.readByte(EE_BYTE_AM_NB); amnb = EEPROM.readByte(EE_BYTE_AM_NB);
fmnb = EEPROM.readByte(EE_BYTE_FM_NB); fmnb = EEPROM.readByte(EE_BYTE_FM_NB);
audiomode = EEPROM.readByte(EE_BYTE_AUDIOMODE); audiomode = EEPROM.readByte(EE_BYTE_AUDIOMODE);
@@ -282,7 +282,7 @@ void DefaultSettings() {
EEPROM.writeUInt(EE_UINT16_FREQUENCY_SW, 1800); EEPROM.writeUInt(EE_UINT16_FREQUENCY_SW, 1800);
EEPROM.writeString(EE_STRING_XDRGTK_KEY, "password"); EEPROM.writeString(EE_STRING_XDRGTK_KEY, "password");
EEPROM.writeByte(EE_BYTE_USESQUELCH, 1); EEPROM.writeByte(EE_BYTE_USESQUELCH, 1);
EEPROM.writeByte(EE_BYTE_SHOWMODULATION, 1); EEPROM.writeByte(EE_BYTE_SHOWAUDIO, 1);
EEPROM.writeByte(EE_BYTE_AM_NB, 0); EEPROM.writeByte(EE_BYTE_AM_NB, 0);
EEPROM.writeByte(EE_BYTE_FM_NB, 0); EEPROM.writeByte(EE_BYTE_FM_NB, 0);
EEPROM.writeByte(EE_BYTE_AUDIOMODE, 0); EEPROM.writeByte(EE_BYTE_AUDIOMODE, 0);
+8 -9
View File
@@ -17,21 +17,20 @@ void ShowAdvancedRDS() {
if (radio.rds.rdsDerror) tft.fillCircle(200, 41, 5, SignificantColor); else tft.fillCircle(200, 41, 5, InsignificantColor); if (radio.rds.rdsDerror) tft.fillCircle(200, 41, 5, SignificantColor); else tft.fillCircle(200, 41, 5, InsignificantColor);
} }
if (radio.rds.hasDynamicPTY != dynamicPTYold) { if(radio.rds.hasDynamicPTY.changed(0)) {
if (radio.rds.hasDynamicPTY) tft.fillCircle(310, 137, 5, InsignificantColor); else tft.fillCircle(310, 137, 5, SignificantColor); if(radio.rds.hasDynamicPTY.get()) tft.fillCircle(310, 137, 5, InsignificantColor); else tft.fillCircle(310, 137, 5, SignificantColor);
dynamicPTYold = radio.rds.hasDynamicPTY;
} }
if (radio.rds.hasArtificialhead.changed(0)) { if(radio.rds.hasArtificialhead.changed(0)) {
if (radio.rds.hasArtificialhead) tft.fillCircle(310, 153, 5, InsignificantColor); else tft.fillCircle(310, 153, 5, SignificantColor); if(radio.rds.hasArtificialhead) tft.fillCircle(310, 153, 5, InsignificantColor); else tft.fillCircle(310, 153, 5, SignificantColor);
} }
if (radio.rds.hasCompressed.changed(0)) { if(radio.rds.hasCompressed.changed(0)) {
if (radio.rds.hasCompressed) tft.fillCircle(310, 168, 5, InsignificantColor); else tft.fillCircle(310, 168, 5, SignificantColor); if(radio.rds.hasCompressed) tft.fillCircle(310, 168, 5, InsignificantColor); else tft.fillCircle(310, 168, 5, SignificantColor);
} }
if (radio.rds.hasStereo.changed(0)) { if(radio.rds.hasStereo.changed(0)) {
if (radio.rds.hasStereo) tft.fillCircle(310, 183, 5, InsignificantColor); else tft.fillCircle(310, 183, 5, SignificantColor); if(radio.rds.hasStereo) tft.fillCircle(310, 183, 5, InsignificantColor); else tft.fillCircle(310, 183, 5, SignificantColor);
} }
if (radio.rds.PTYN.changed(0) || rdsreset) { if (radio.rds.PTYN.changed(0) || rdsreset) {
+9 -4
View File
@@ -45,6 +45,9 @@ inline byte sumValueFromBinary(byte binary, byte length) {
void sync_from_rx_rtc(int32_t offset = 0) { void sync_from_rx_rtc(int32_t offset = 0) {
if(!rx_rtc_avail) return; if(!rx_rtc_avail) return;
auto old_clock = Wire.getClock();
Wire.setClock(400000);
struct tm timeinfo; struct tm timeinfo;
memset(&timeinfo, 0, sizeof(timeinfo)); memset(&timeinfo, 0, sizeof(timeinfo));
@@ -66,10 +69,12 @@ void sync_from_rx_rtc(int32_t offset = 0) {
timeinfo.tm_mday = sumValueFromBinary(Wire.read(), 6); timeinfo.tm_mday = sumValueFromBinary(Wire.read(), 6);
timeinfo.tm_mon = sumValueFromBinary(Wire.read(), 5) - 1; timeinfo.tm_mon = sumValueFromBinary(Wire.read(), 5) - 1;
timeinfo.tm_year = sumValueFromBinary(Wire.read(), 8) + 100; timeinfo.tm_year = sumValueFromBinary(Wire.read(), 8) + 126;
rtc.setTime(mktime(&timeinfo) + offset); rtc.setTime(mktime(&timeinfo) + offset);
} }
Wire.setClock(old_clock);
} }
bool init_rtc() { bool init_rtc() {
@@ -102,7 +107,7 @@ bool init_rtc() {
Wire.write(1 << 2); Wire.write(1 << 2);
Wire.write(toBCD(14)); Wire.write(toBCD(14));
Wire.write(1); Wire.write(1);
Wire.write(toBCD(26)); Wire.write(0);
Wire.endTransmission(); Wire.endTransmission();
writeToModule(0x1F, 0); // Unset stop bit writeToModule(0x1F, 0); // Unset stop bit
return true; return true;
@@ -111,7 +116,7 @@ bool init_rtc() {
writeToModule(0x1F, 0); writeToModule(0x1F, 0);
return true; return true;
} }
sync_from_rx_rtc(); sync_from_rx_rtc(1); // mystery offset
return false; return false;
} }
@@ -128,7 +133,7 @@ void set_time(time_t time) {
Wire.write(1 << timeinfo->tm_wday); Wire.write(1 << timeinfo->tm_wday);
Wire.write(toBCD(timeinfo->tm_mday)); Wire.write(toBCD(timeinfo->tm_mday));
Wire.write(toBCD(timeinfo->tm_mon + 1)); Wire.write(toBCD(timeinfo->tm_mon + 1));
Wire.write(toBCD((1900 + timeinfo->tm_year) % 100)); Wire.write(toBCD((1900 + timeinfo->tm_year - 26) % 100));
Wire.endTransmission(); Wire.endTransmission();
writeToModule(0x1F, 0); writeToModule(0x1F, 0);
} }