0
mirror of https://github.com/OneOfEleven/uv-k5-firmware-custom.git synced 2025-04-28 06:11:24 +03:00

177 lines
5.0 KiB
C
Raw Normal View History

2023-09-09 08:03:56 +01:00
/* Copyright 2023 Dual Tachyon
* https://github.com/DualTachyon
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "app/fm.h"
#include "driver/backlight.h"
#include "driver/bk1080.h"
2023-09-09 08:03:56 +01:00
#include "driver/st7565.h"
#include "external/printf/printf.h"
#include "misc.h"
#include "settings.h"
#include "ui/fmradio.h"
#include "ui/helper.h"
#include "ui/inputbox.h"
#include "ui/ui.h"
void UI_DisplayFM(void)
{
2023-09-13 02:01:35 +01:00
unsigned int i;
char str[22];
2023-09-09 08:03:56 +01:00
2023-10-08 20:23:37 +01:00
memset(g_frame_buffer, 0, sizeof(g_frame_buffer));
2023-09-09 08:03:56 +01:00
#ifdef ENABLE_KEYLOCK
2023-11-02 10:00:51 +00:00
if (g_eeprom.config.setting.key_lock && g_keypad_locked > 0)
{ // tell user how to unlock the keyboard
2023-11-10 13:23:32 +00:00
BACKLIGHT_turn_on(0);
UI_PrintString("Long press #", 0, LCD_WIDTH - 1, 1, 8);
UI_PrintString("to unlock", 0, LCD_WIDTH - 1, 3, 8);
ST7565_BlitFullScreen();
return;
}
#endif
// *************************************
2023-10-11 20:44:35 +01:00
// upper text line
UI_PrintString("FM", 0, LCD_WIDTH - 1, 0, 12);
// *************************************
2023-10-11 20:44:35 +01:00
// middle text line
2023-10-08 20:23:37 +01:00
if (g_ask_to_save)
2023-09-13 02:01:35 +01:00
{
2023-11-02 10:00:51 +00:00
const unsigned int freq = g_eeprom.config.setting.fm_radio.selected_frequency;
sprintf(str, "SAVE %u.%u ?", freq / 10, freq % 10);
2023-09-13 02:01:35 +01:00
}
else
2023-10-08 20:23:37 +01:00
if (g_ask_to_delete)
2023-09-13 02:01:35 +01:00
{
strcpy(str, "DELETE ?");
2023-09-13 02:01:35 +01:00
}
else
{
memset(str, 0, sizeof(str));
2023-10-30 14:12:27 +00:00
if (g_fm_scan_state_dir == FM_SCAN_STATE_DIR_OFF)
2023-09-13 02:01:35 +01:00
{
2023-11-02 10:00:51 +00:00
if (g_eeprom.config.setting.fm_radio.channel_mode == 0)
2023-09-13 02:01:35 +01:00
{
2023-11-02 10:00:51 +00:00
for (i = 0; i < ARRAY_SIZE(g_eeprom.config.setting.fm_channel); i++)
2023-09-13 02:01:35 +01:00
{
2023-11-02 10:00:51 +00:00
if (g_eeprom.config.setting.fm_radio.selected_frequency == g_eeprom.config.setting.fm_channel[i])
2023-09-13 02:01:35 +01:00
{
sprintf(str, "VFO (CH %u)", 1 + i);
2023-09-09 08:03:56 +01:00
break;
}
}
2023-09-13 02:01:35 +01:00
2023-11-02 10:00:51 +00:00
if (i >= ARRAY_SIZE(g_eeprom.config.setting.fm_channel))
strcpy(str, "VFO");
2023-09-09 08:03:56 +01:00
}
2023-09-13 02:01:35 +01:00
else
2023-11-02 10:00:51 +00:00
sprintf(str, "CH %u", 1 + g_eeprom.config.setting.fm_radio.selected_channel);
2023-09-13 02:01:35 +01:00
}
else
if (!g_fm_auto_scan)
strcpy(str, "FREQ SCAN");
else
sprintf(str, "A-SCAN %2u", 1 + g_fm_channel_position);
2023-09-09 08:03:56 +01:00
}
UI_PrintString(str, 0, LCD_WIDTH - 1, 2, 10);
2023-09-09 08:03:56 +01:00
// *************************************
2023-10-11 20:44:35 +01:00
// lower text line
memset(str, 0, sizeof(str));
2023-10-11 20:44:35 +01:00
if (g_ask_to_save)
{ // channel mode
const unsigned int chan = g_fm_channel_position;
2023-11-02 10:00:51 +00:00
const uint32_t freq = g_eeprom.config.setting.fm_channel[chan];
UI_GenerateChannelString(str, chan, ' ');
2023-10-30 14:12:27 +00:00
if (FM_check_valid_channel(chan))
sprintf(str + strlen(str), " (%u.%u)", freq / 10, freq % 10);
2023-10-11 20:44:35 +01:00
}
else
2023-11-02 10:00:51 +00:00
if (g_eeprom.config.setting.fm_radio.channel_mode != 0 && g_input_box_index > 0)
2023-10-11 19:07:25 +01:00
{ // user is entering a channel number
UI_GenerateChannelString(str, g_fm_channel_position, ' ');
2023-09-13 02:01:35 +01:00
}
else
2023-10-08 20:23:37 +01:00
if (!g_ask_to_delete)
2023-09-13 02:01:35 +01:00
{
2023-10-08 20:23:37 +01:00
if (g_input_box_index == 0)
2023-10-11 20:44:35 +01:00
{ // frequency mode
2023-11-02 10:00:51 +00:00
const uint32_t freq = g_eeprom.config.setting.fm_radio.selected_frequency;
NUMBER_ToDigits(freq * 10000, str);
2023-10-29 22:33:38 +00:00
#ifdef ENABLE_TRIM_TRAILING_ZEROS
2023-11-09 05:59:50 +00:00
UI_DisplayFrequencyBig(str, 30, 4, false, true, 6);
2023-10-29 22:33:38 +00:00
#else
2023-11-09 05:59:50 +00:00
UI_DisplayFrequencyBig(str, 23, 4, false, true, 6);
2023-10-29 22:33:38 +00:00
#endif
2023-09-09 08:03:56 +01:00
}
2023-09-13 02:01:35 +01:00
else
2023-10-11 19:07:25 +01:00
{ // user is entering a frequency
2023-11-09 05:59:50 +00:00
UI_DisplayFrequencyBig(g_input_box, 23, 4, true, false, 6);
}
2023-09-09 08:03:56 +01:00
}
2023-09-13 02:01:35 +01:00
else
2023-10-11 20:44:35 +01:00
{ // delete channel
2023-11-02 10:00:51 +00:00
const uint32_t chan = g_eeprom.config.setting.fm_radio.selected_channel;
const uint32_t freq = g_eeprom.config.setting.fm_channel[chan];
sprintf(str, "CH %u (%u.%u)", 1 + chan, freq / 10, freq % 10);
2023-09-13 02:01:35 +01:00
}
2023-10-11 19:07:25 +01:00
UI_PrintString(str, 0, LCD_WIDTH - 1, 4, (strlen(str) >= 8) ? 8 : 10);
// *************************************
2023-10-31 10:07:29 +00:00
if (!g_ask_to_delete &&
!g_ask_to_save &&
(g_fm_scan_state_dir != FM_SCAN_STATE_DIR_OFF || g_fm_resume_tick_500ms > 0))
{
2023-10-31 06:56:21 +00:00
const uint16_t rssi_status = BK1080_ReadRegister(BK1080_REG_10);
const uint16_t dev_snr = BK1080_ReadRegister(BK1080_REG_07);
const int16_t freq_offset = (int16_t)dev_snr / 16;
const uint8_t snr = dev_snr & 0x000f;
// const uint8_t stc = (rssi_status >> 14) & 1u;
// const uint8_t sf_bl = (rssi_status >> 13) & 1u;
const uint8_t afc_railed = (rssi_status >> 12) & 1u;
const uint8_t ste = (rssi_status >> 9) & 1u;
const uint8_t st = (rssi_status >> 8) & 1u;
const uint8_t rssi = rssi_status & 0x00ff;
sprintf(str, "%s %s %c %2udBuV %2u",
ste ? "STE" : "ste",
st ? "ST" : "st",
afc_railed ? 'R' : 'r',
rssi,
snr);
UI_PrintStringSmall(str, 0, 0, 6);
sprintf(str, "%c%d", (freq_offset > 0) ? '+' : (freq_offset < 0) ? '-' : ' ', abs(freq_offset));
UI_PrintStringSmall(str, 0, 0, 5);
}
2023-10-29 22:33:38 +00:00
// *************************************
2023-09-13 02:01:35 +01:00
2023-09-09 08:03:56 +01:00
ST7565_BlitFullScreen();
}