0
mirror of https://github.com/OneOfEleven/uv-k5-firmware-custom.git synced 2025-04-28 14:21:25 +03:00

141 lines
3.5 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 <string.h>
2023-09-14 09:56:30 +01:00
2023-09-09 08:03:56 +01:00
#include "app/fm.h"
#include "driver/backlight.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 String[16];
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
if (g_eeprom.key_lock && g_keypad_locked > 0)
{ // tell user how to unlock the keyboard
backlight_turn_on();
UI_PrintString("Long press #", 0, LCD_WIDTH, 1, 8);
UI_PrintString("to unlock", 0, LCD_WIDTH, 3, 8);
ST7565_BlitFullScreen();
return;
}
// *************************************
2023-10-11 20:44:35 +01:00
// upper text line
UI_PrintString("FM", 0, 127, 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-10-11 20:44:35 +01:00
const unsigned int freq = g_eeprom.fm_frequency_playing;
sprintf(String, "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
{
2023-10-11 20:44:35 +01:00
strcpy(String, "DELETE ?");
2023-09-13 02:01:35 +01:00
}
else
{
memset(String, 0, sizeof(String));
2023-10-08 20:23:37 +01:00
if (g_fm_scan_state == FM_SCAN_OFF)
2023-09-13 02:01:35 +01:00
{
2023-10-08 17:14:13 +01:00
if (!g_eeprom.fm_is_channel_mode)
2023-09-13 02:01:35 +01:00
{
for (i = 0; i < ARRAY_SIZE(g_fm_channels); i++)
2023-09-13 02:01:35 +01:00
{
2023-10-08 20:23:37 +01:00
if (g_eeprom.fm_frequency_playing == g_fm_channels[i])
2023-09-13 02:01:35 +01:00
{
2023-10-11 20:44:35 +01:00
sprintf(String, "VFO (CH %u)", 1 + i);
2023-09-09 08:03:56 +01:00
break;
}
}
2023-09-13 02:01:35 +01:00
if (i >= ARRAY_SIZE(g_fm_channels))
2023-09-09 08:03:56 +01:00
strcpy(String, "VFO");
}
2023-09-13 02:01:35 +01:00
else
2023-10-11 20:44:35 +01:00
sprintf(String, "CH %u", 1 + g_eeprom.fm_selected_channel);
2023-09-13 02:01:35 +01:00
}
else
if (!g_fm_auto_scan)
strcpy(String, "M-SCAN");
else
2023-10-11 20:44:35 +01:00
sprintf(String, "A-SCAN %u", 1 + g_fm_channel_position);
2023-09-09 08:03:56 +01:00
}
2023-09-12 15:31:37 +01:00
UI_PrintString(String, 0, 127, 2, 10);
2023-09-09 08:03:56 +01:00
// *************************************
2023-10-11 20:44:35 +01:00
// lower text line
2023-09-13 02:01:35 +01:00
memset(String, 0, sizeof(String));
2023-10-11 20:44:35 +01:00
if (g_ask_to_save)
{ // channel mode
const unsigned int chan = g_fm_channel_position;
const uint32_t freq = g_fm_channels[chan];
UI_GenerateChannelString(String, chan, ' ');
if (FM_CheckValidChannel(chan))
sprintf(String + strlen(String), " (%u.%u)", freq / 10, freq % 10);
}
else
if (g_eeprom.fm_is_channel_mode && g_input_box_index > 0)
2023-10-11 19:07:25 +01:00
{ // user is entering a channel number
UI_GenerateChannelString(String, 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
const uint32_t freq = g_eeprom.fm_frequency_playing;
NUMBER_ToDigits(freq * 10000, String);
2023-09-09 08:03:56 +01:00
UI_DisplayFrequency(String, 23, 4, false, true);
}
2023-09-13 02:01:35 +01:00
else
2023-10-11 19:07:25 +01:00
{ // user is entering a frequency
2023-10-08 20:23:37 +01:00
UI_DisplayFrequency(g_input_box, 23, 4, true, false);
}
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
const uint32_t chan = g_eeprom.fm_selected_channel;
const uint32_t freq = g_fm_channels[chan];
sprintf(String, "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
2023-10-11 20:44:35 +01:00
UI_PrintString(String, 0, 127, 4, (strlen(String) >= 8) ? 8 : 10);
// *************************************
2023-09-13 02:01:35 +01:00
2023-09-09 08:03:56 +01:00
ST7565_BlitFullScreen();
}