diff --git a/include/Tuner_Drv_Lithio.h b/include/Tuner_Drv_Lithio.h index f0fbc68..d69a170 100644 --- a/include/Tuner_Drv_Lithio.h +++ b/include/Tuner_Drv_Lithio.h @@ -80,7 +80,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); 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 *audiolevel, int8_t *snr); +void devTEF_Radio_Get_Quality_Data(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(); 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); \ No newline at end of file diff --git a/src/TEF6686.cpp b/src/TEF6686.cpp index af49e51..82fe76a 100644 --- a/src/TEF6686.cpp +++ b/src/TEF6686.cpp @@ -26,7 +26,7 @@ void TEF6686::TestAFEON() { timing = 0; devTEF_Set_Cmd(TEF_FM, Cmd_Tune_To, 2, 3, af[x].frequency); while (timing == 0 && !bitRead(timing, 15)) { - devTEF_Radio_Get_Quality_Status(&status, &aflevel, &afusn, &afwam, &afoffset, NULL, NULL, NULL); + devTEF_Radio_Get_Quality_Data(&status, &aflevel, &afusn, &afwam, &afoffset, NULL, NULL, NULL); timing = lowByte(status); } if (afoffset > -125 || afoffset < 125) { @@ -56,14 +56,14 @@ uint16_t TEF6686::TestAF() { int16_t aflevel, afoffset, currentoffset, currentlevel; byte timing; - devTEF_Radio_Get_Quality_Status(&status, ¤tlevel, ¤tusn, ¤twam, ¤toffset, NULL, NULL, NULL); + devTEF_Radio_Get_Quality_Data(&status, ¤tlevel, ¤tusn, ¤twam, ¤toffset, NULL, NULL, NULL); devTEF_Radio_Get_RDS_Status(&rds.rdsStat, &rds.rdsA, &rds.rdsB, &rds.rdsC, &rds.rdsD, &rds.rdsErr); for (int x = 0; x < af_counter; x++) { timing = 0; devTEF_Set_Cmd(TEF_FM, Cmd_Tune_To, 2, 3, af[x].frequency); while (timing == 0 && !bitRead(timing, 15)) { - devTEF_Radio_Get_Quality_Status(&status, &aflevel, &afusn, &afwam, &afoffset, NULL, NULL, NULL); + devTEF_Radio_Get_Quality_Data(&status, &aflevel, &afusn, &afwam, &afoffset, NULL, NULL, NULL); timing = lowByte(status); } af[x].score = aflevel - afusn - afwam; @@ -351,7 +351,7 @@ void TEF6686::setStHiBlendOffset(uint8_t start) { } void TEF6686::getStatus(int16_t *level, uint16_t *USN, uint16_t *WAM, int16_t *offset, uint16_t *bandwidth, uint16_t *audiolevel, int8_t *snr) { - devTEF_Radio_Get_Quality_Status(NULL, level, USN, WAM, offset, bandwidth, audiolevel, snr); + devTEF_Radio_Get_Quality_Data(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 *audiolevel, int8_t *snr) { diff --git a/src/Tuner_Drv_Lithio.cpp b/src/Tuner_Drv_Lithio.cpp index ba3d355..c81bcaa 100644 --- a/src/Tuner_Drv_Lithio.cpp +++ b/src/Tuner_Drv_Lithio.cpp @@ -33,19 +33,24 @@ uint8_t devTEF_APPL_Get_Operation_Status() { 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 *audiolevel, int8_t *snr) { +void devTEF_Radio_Get_Quality_Data(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]; - devTEF_Get_Cmd(TEF_FM, Cmd_Get_Quality_Status, buf, sizeof(buf)); + devTEF_Get_Cmd(TEF_FM, Cmd_Get_Quality_Data, buf, sizeof(buf)); + + int16_t _level = Convert8bto16b(buf + 2); + if (_level < -200) _level = -200; + if (_level > 1200) _level = 1200; + uint16_t _usn = Convert8bto16b(buf + 4); + uint16_t _wam = Convert8bto16b(buf + 6); + if(status != NULL) *status = Convert8bto16b(buf); - if(level != NULL) *level = Convert8bto16b(buf + 2); - if(usn != NULL) *usn = Convert8bto16b(buf + 4); - if(wam != NULL) *wam = Convert8bto16b(buf + 6); + if(level != NULL) *level = _level; + if(usn != NULL) *usn = _usn; + if(wam != NULL) *wam = _wam; if(offset != NULL) *offset = Convert8bto16b(buf + 8); if(bandwidth != NULL) *bandwidth = Convert8bto16b(buf + 10) / 10; if(audiolevel != NULL) *audiolevel = Convert8bto16b(buf + 12) / 10; - if (*level < -200) *level = -200; - 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 = (int8_t)(_level * 0.075f - (_usn * 0.038f) - (_wam * 0.018f)); } 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) { diff --git a/src/main.cpp b/src/main.cpp index c3fec89..42dcbc3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -722,13 +722,13 @@ void ShowSignalLevel() { SNRupdatetimer = millis(); if (!advancedRDS) { if (CN > (CNold + 1) || CN < (CNold - 1)) { - if (CNold == 0) tftPrint16(ARIGHT, "--", 234, 165, BackgroundColor, BackgroundColor); else tftPrint16(ARIGHT, String(CNold), 234, 165, BackgroundColor, BackgroundColor); + if (CNold == -126) tftPrint16(ARIGHT, "--", 234, 165, BackgroundColor, BackgroundColor); else tftPrint16(ARIGHT, String(CNold), 234, 165, BackgroundColor, BackgroundColor); if (tuned) { - if (CN == 0) tftPrint16(ARIGHT, "--", 234, 165, PrimaryColor, PrimaryColorSmooth); else tftPrint16(ARIGHT, String(CN), 234, 165, PrimaryColor, PrimaryColorSmooth); + tftPrint16(ARIGHT, String(CN), 234, 165, PrimaryColor, PrimaryColorSmooth); CNold = CN; } else { tftPrint16(ARIGHT, "--", 234, 165, PrimaryColor, PrimaryColorSmooth); - CNold = 0; + CNold = -126; } }