1
mirror of https://github.com/egzumer/uv-k5-firmware-custom.git synced 2025-12-12 20:49:47 +04:00
Files
uv-k5-firmware-custom/ui/main.c

822 lines
22 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-27 17:29:49 +01:00
#include <stdlib.h> // abs()
2023-09-09 08:03:56 +01:00
2023-11-27 22:52:54 +01:00
#include "app/chFrScanner.h"
2023-09-09 08:03:56 +01:00
#include "app/dtmf.h"
2023-12-14 20:12:42 +01:00
#ifdef ENABLE_AM_FIX
#include "am_fix.h"
#endif
2023-09-09 08:03:56 +01:00
#include "bitmaps.h"
#include "board.h"
#include "driver/bk4819.h"
2023-09-09 08:03:56 +01:00
#include "driver/st7565.h"
#include "external/printf/printf.h"
#include "functions.h"
2023-09-18 14:31:14 +01:00
#include "helper/battery.h"
2023-09-09 08:03:56 +01:00
#include "misc.h"
#include "radio.h"
#include "settings.h"
#include "ui/helper.h"
#include "ui/inputbox.h"
#include "ui/main.h"
2023-09-23 12:25:06 +01:00
#include "ui/ui.h"
2023-09-09 08:03:56 +01:00
center_line_t center_line = CENTER_LINE_NONE;
2023-09-30 11:22:19 +01:00
2023-12-02 17:45:47 +00:00
const int8_t dBmCorrTable[7] = {
-15, // band 1
-25, // band 2
-20, // band 3
-4, // band 4
-7, // band 5
-6, // band 6
-1 // band 7
};
const char *VfoStateStr[] = {
[VFO_STATE_NORMAL]="",
[VFO_STATE_BUSY]="BUSY",
[VFO_STATE_BAT_LOW]="BAT LOW",
[VFO_STATE_TX_DISABLE]="TX DISABLE",
[VFO_STATE_TIMEOUT]="TIMEOUT",
[VFO_STATE_ALARM]="ALARM",
[VFO_STATE_VOLTAGE_HIGH]="VOLT HIGH"
};
// ***************************************************************************
2023-10-27 19:00:42 +02:00
static void DrawSmallAntennaAndBars(uint8_t *p, unsigned int level)
2023-10-04 10:01:07 +01:00
{
2023-10-27 18:35:45 +02:00
if(level>6)
level = 6;
memcpy(p, BITMAP_Antenna, ARRAY_SIZE(BITMAP_Antenna));
for(uint8_t i = 1; i <= level; i++) {
char bar = (0xff << (6-i)) & 0x7F;
memset(p + 2 + i*3, bar, 2);
2023-10-04 10:01:07 +01:00
}
}
#if defined ENABLE_AUDIO_BAR || defined ENABLE_RSSI_BAR
static void DrawLevelBar(uint8_t xpos, uint8_t line, uint8_t level)
{
const char hollowBar[] = {
0b01111111,
0b01000001,
0b01000001,
0b01111111
};
uint8_t *p_line = gFrameBuffer[line];
level = MIN(level, 13);
for(uint8_t i = 0; i < level; i++) {
if(i < 9) {
for(uint8_t j = 0; j < 4; j++)
p_line[xpos + i * 5 + j] = (~(0x7F >> (i+1))) & 0x7F;
}
else {
memcpy(p_line + (xpos + i * 5), &hollowBar, ARRAY_SIZE(hollowBar));
}
}
}
#endif
2023-10-04 10:01:07 +01:00
#ifdef ENABLE_AUDIO_BAR
2023-10-19 21:42:56 +02:00
unsigned int sqrt16(unsigned int value)
{ // return square root of 'value'
unsigned int shift = 16; // number of bits supplied in 'value' .. 2 ~ 32
unsigned int bit = 1u << --shift;
unsigned int sqrti = 0;
while (bit)
{
const unsigned int temp = ((sqrti << 1) | bit) << shift--;
if (value >= temp) {
value -= temp;
sqrti |= bit;
}
2023-10-19 21:42:56 +02:00
bit >>= 1;
}
2023-10-19 21:42:56 +02:00
return sqrti;
}
2023-10-19 21:42:56 +02:00
void UI_DisplayAudioBar(void)
{
if (gSetting_mic_bar)
{
if(gLowBattery && !gLowBatteryConfirmed)
return;
2023-10-19 21:42:56 +02:00
const unsigned int line = 3;
2023-10-19 21:42:56 +02:00
if (gCurrentFunction != FUNCTION_TRANSMIT ||
gScreenToDisplay != DISPLAY_MAIN
#ifdef ENABLE_DTMF_CALLING
|| gDTMF_CallState != DTMF_CALL_STATE_NONE
#endif
)
2023-10-19 21:42:56 +02:00
{
return; // screen is in use
}
#if defined(ENABLE_ALARM) || defined(ENABLE_TX1750)
2023-10-19 21:42:56 +02:00
if (gAlarmState != ALARM_STATE_OFF)
return;
#endif
2023-10-19 21:42:56 +02:00
const unsigned int voice_amp = BK4819_GetVoiceAmplitudeOut(); // 15:0
2023-10-19 21:42:56 +02:00
// make non-linear to make more sensitive at low values
const unsigned int level = MIN(voice_amp * 8, 65535u);
const unsigned int sqrt_level = MIN(sqrt16(level), 124u);
uint8_t bars = 13 * sqrt_level / 124;
2023-10-19 21:42:56 +02:00
uint8_t *p_line = gFrameBuffer[line];
memset(p_line, 0, LCD_WIDTH);
DrawLevelBar(62, line, bars);
2023-10-19 21:42:56 +02:00
if (gCurrentFunction == FUNCTION_TRANSMIT)
ST7565_BlitFullScreen();
}
2023-10-19 21:42:56 +02:00
}
#endif
2023-12-05 23:13:21 +01:00
void DisplayRSSIBar(const bool now)
2023-10-19 21:42:56 +02:00
{
2023-10-27 18:35:45 +02:00
#if defined(ENABLE_RSSI_BAR)
2023-12-05 23:13:21 +01:00
const unsigned int txt_width = 7 * 8; // 8 text chars
const unsigned int bar_x = 2 + txt_width + 4; // X coord of bar graph
const unsigned int line = 3;
uint8_t *p_line = gFrameBuffer[line];
char str[16];
const char plus[] = {
0b00011000,
0b00011000,
0b01111110,
0b01111110,
0b01111110,
0b00011000,
0b00011000,
};
2023-10-27 18:35:45 +02:00
2023-12-05 23:13:21 +01:00
if (gEeprom.KEY_LOCK && gKeypadLocked > 0)
return; // display is in use
2023-10-27 18:35:45 +02:00
2023-12-05 23:13:21 +01:00
if (gCurrentFunction == FUNCTION_TRANSMIT ||
gScreenToDisplay != DISPLAY_MAIN
#ifdef ENABLE_DTMF_CALLING
2023-12-05 23:13:21 +01:00
|| gDTMF_CallState != DTMF_CALL_STATE_NONE
#endif
2023-12-05 23:13:21 +01:00
)
return; // display is in use
2023-11-20 21:02:14 +01:00
2023-12-05 23:13:21 +01:00
if (now)
memset(p_line, 0, LCD_WIDTH);
2023-10-19 21:42:56 +02:00
2023-12-09 15:40:38 +01:00
const int16_t s0_dBm = -gEeprom.S0_LEVEL; // S0 .. base level
const int16_t rssi_dBm =
2023-12-06 17:54:32 +01:00
BK4819_GetRSSI_dBm()
#ifdef ENABLE_AM_FIX
2023-12-06 23:08:57 +01:00
+ ((gSetting_AM_fix && gRxVfo->Modulation == MODULATION_AM) ? AM_fix_get_gain_diff() : 0)
#endif
2023-12-06 17:54:32 +01:00
+ dBmCorrTable[gRxVfo->Band];
2023-12-09 15:40:38 +01:00
int s0_9 = gEeprom.S0_LEVEL - gEeprom.S9_LEVEL;
const uint8_t s_level = MIN(MAX((int32_t)(rssi_dBm - s0_dBm)*100 / (s0_9*100/9), 0), 9); // S0 - S9
uint8_t overS9dBm = MIN(MAX(rssi_dBm + gEeprom.S9_LEVEL, 0), 99);
2023-12-05 23:13:21 +01:00
uint8_t overS9Bars = MIN(overS9dBm/10, 4);
2023-12-05 23:13:21 +01:00
if(overS9Bars == 0) {
sprintf(str, "% 4d S%d", rssi_dBm, s_level);
}
else {
sprintf(str, "% 4d %2d", rssi_dBm, overS9dBm);
memcpy(p_line + 2 + 7*5, &plus, ARRAY_SIZE(plus));
2023-10-25 14:26:46 +02:00
}
2023-10-19 21:42:56 +02:00
2023-12-05 23:13:21 +01:00
UI_PrintStringSmall(str, 2, 0, line);
DrawLevelBar(bar_x, line, s_level + overS9Bars);
if (now)
ST7565_BlitLine(line);
#else
int16_t rssi = BK4819_GetRSSI();
2023-10-27 18:35:45 +02:00
uint8_t Level;
2023-10-27 15:32:14 +02:00
2023-10-27 18:35:45 +02:00
if (rssi >= gEEPROM_RSSI_CALIB[gRxVfo->Band][3]) {
Level = 6;
} else if (rssi >= gEEPROM_RSSI_CALIB[gRxVfo->Band][2]) {
Level = 4;
} else if (rssi >= gEEPROM_RSSI_CALIB[gRxVfo->Band][1]) {
Level = 2;
} else if (rssi >= gEEPROM_RSSI_CALIB[gRxVfo->Band][0]) {
Level = 1;
2023-10-27 15:32:14 +02:00
} else {
2023-10-27 18:35:45 +02:00
Level = 0;
2023-10-27 15:32:14 +02:00
}
2023-10-27 18:35:45 +02:00
uint8_t *pLine = (gEeprom.RX_VFO == 0)? gFrameBuffer[2] : gFrameBuffer[6];
if (now)
memset(pLine, 0, 23);
2023-10-27 19:00:42 +02:00
DrawSmallAntennaAndBars(pLine, Level);
2023-10-27 18:35:45 +02:00
if (now)
ST7565_BlitFullScreen();
2023-12-05 23:13:21 +01:00
#endif
2023-10-27 15:32:14 +02:00
2023-12-05 23:13:21 +01:00
}
2023-12-04 22:58:27 +01:00
#ifdef ENABLE_AGC_SHOW_DATA
static void PrintAGC(bool now)
{
char buf[20];
memset(gFrameBuffer[3], 0, 128);
union {
struct {
uint16_t _ : 5;
uint16_t agcSigStrength : 7;
int16_t gainIdx : 3;
2023-12-04 22:58:27 +01:00
uint16_t agcEnab : 1;
};
uint16_t __raw;
} reg7e;
reg7e.__raw = BK4819_ReadRegister(0x7E);
uint8_t gainAddr = reg7e.gainIdx < 0 ? 0x14 : 0x10 + reg7e.gainIdx;
union {
struct {
uint16_t pga:3;
uint16_t mixer:2;
uint16_t lna:3;
uint16_t lnaS:2;
};
uint16_t __raw;
} agcGainReg;
agcGainReg.__raw = BK4819_ReadRegister(gainAddr);
int8_t lnaShortTab[] = {-28, -24, -19, 0};
int8_t lnaTab[] = {-24, -19, -14, -9, -6, -4, -2, 0};
int8_t mixerTab[] = {-8, -6, -3, 0};
int8_t pgaTab[] = {-33, -27, -21, -15, -9, -6, -3, 0};
int16_t agcGain = lnaShortTab[agcGainReg.lnaS] + lnaTab[agcGainReg.lna] + mixerTab[agcGainReg.mixer] + pgaTab[agcGainReg.pga];
sprintf(buf, "%d%2d %2d %2d %3d", reg7e.agcEnab, reg7e.gainIdx, -agcGain, reg7e.agcSigStrength, BK4819_GetRSSI());
UI_PrintStringSmall(buf, 2, 0, 3);
if(now)
ST7565_BlitLine(3);
}
#endif
void UI_MAIN_TimeSlice500ms(void)
{
2023-12-05 23:13:21 +01:00
if(gScreenToDisplay==DISPLAY_MAIN) {
2023-12-04 22:58:27 +01:00
#ifdef ENABLE_AGC_SHOW_DATA
2023-12-05 23:13:21 +01:00
PrintAGC(true);
return;
2023-12-04 22:58:27 +01:00
#endif
2023-12-05 23:13:21 +01:00
if(FUNCTION_IsRx()) {
2023-12-05 23:13:21 +01:00
DisplayRSSIBar(true);
}
2023-12-05 23:13:21 +01:00
}
2023-12-04 22:58:27 +01:00
}
// ***************************************************************************
2023-09-09 08:03:56 +01:00
void UI_DisplayMain(void)
{
2023-10-24 03:43:09 +02:00
char String[22];
2023-09-28 22:22:06 +01:00
center_line = CENTER_LINE_NONE;
// clear the screen
2023-09-09 08:03:56 +01:00
memset(gFrameBuffer, 0, sizeof(gFrameBuffer));
2023-11-01 00:11:04 +01:00
if(gLowBattery && !gLowBatteryConfirmed) {
UI_DisplayPopup("LOW BATTERY");
ST7565_BlitFullScreen();
return;
}
2023-09-13 18:45:52 +01:00
if (gEeprom.KEY_LOCK && gKeypadLocked > 0)
{ // tell user how to unlock the keyboard
UI_PrintString("Long press #", 0, LCD_WIDTH, 1, 8);
UI_PrintString("to unlock", 0, LCD_WIDTH, 3, 8);
2023-09-09 08:03:56 +01:00
ST7565_BlitFullScreen();
return;
}
2023-10-19 21:22:10 +02:00
unsigned int activeTxVFO = gRxVfoIsActive ? gEeprom.RX_VFO : gEeprom.TX_VFO;
for (unsigned int vfo_num = 0; vfo_num < 2; vfo_num++)
2023-09-09 08:03:56 +01:00
{
const unsigned int line0 = 0; // text screen line
const unsigned int line1 = 4;
const unsigned int line = (vfo_num == 0) ? line0 : line1;
2023-12-05 17:17:52 +01:00
const bool isMainVFO = (vfo_num == gEeprom.TX_VFO);
uint8_t *p_line0 = gFrameBuffer[line + 0];
uint8_t *p_line1 = gFrameBuffer[line + 1];
2023-12-05 17:17:52 +01:00
enum Vfo_txtr_mode mode = VFO_MODE_NONE;
2023-10-19 21:42:56 +02:00
if (activeTxVFO != vfo_num) // this is not active TX VFO
2023-09-09 08:03:56 +01:00
{
2023-11-27 22:52:54 +01:00
#ifdef ENABLE_SCAN_RANGES
if(gScanRangeStart) {
UI_PrintString("ScnRng", 5, 0, line, 8);
sprintf(String, "%3u.%05u", gScanRangeStart / 100000, gScanRangeStart % 100000);
UI_PrintStringSmall(String, 56, 0, line);
sprintf(String, "%3u.%05u", gScanRangeStop / 100000, gScanRangeStop % 100000);
UI_PrintStringSmall(String, 56, 0, line + 1);
2023-11-27 22:52:54 +01:00
continue;
}
#endif
if (gDTMF_InputMode
#ifdef ENABLE_DTMF_CALLING
|| gDTMF_CallState != DTMF_CALL_STATE_NONE || gDTMF_IsTx
#endif
) {
// show DTMF stuff
#ifdef ENABLE_DTMF_CALLING
2023-09-09 08:03:56 +01:00
char Contact[16];
char *pPrintStr = "";
if (!gDTMF_InputMode) {
if (gDTMF_CallState == DTMF_CALL_STATE_CALL_OUT) {
pPrintStr = DTMF_FindContact(gDTMF_String, Contact) ? Contact : gDTMF_String;
} else if (gDTMF_CallState == DTMF_CALL_STATE_RECEIVED || gDTMF_CallState == DTMF_CALL_STATE_RECEIVED_STAY){
pPrintStr = DTMF_FindContact(gDTMF_Callee, Contact) ? Contact : gDTMF_Callee;
}else if (gDTMF_IsTx) {
pPrintStr = gDTMF_String;
}
}
2023-09-09 08:03:56 +01:00
UI_PrintString(pPrintStr, 2, 0, 2 + (vfo_num * 3), 8);
pPrintStr = "";
if (!gDTMF_InputMode) {
if (gDTMF_CallState == DTMF_CALL_STATE_CALL_OUT) {
pPrintStr = (gDTMF_State == DTMF_STATE_CALL_OUT_RSP) ? "CALL OUT(RSP)" : "CALL OUT";
} else if (gDTMF_CallState == DTMF_CALL_STATE_RECEIVED || gDTMF_CallState == DTMF_CALL_STATE_RECEIVED_STAY) {
2023-09-30 11:22:19 +01:00
sprintf(String, "CALL FRM:%s", (DTMF_FindContact(gDTMF_Caller, Contact)) ? Contact : gDTMF_Caller);
pPrintStr = String;
} else if (gDTMF_IsTx) {
pPrintStr = (gDTMF_State == DTMF_STATE_TX_SUCC) ? "DTMF TX(SUCC)" : "DTMF TX";
}
2023-09-09 08:03:56 +01:00
}
else
#endif
{
2023-09-09 08:03:56 +01:00
sprintf(String, ">%s", gDTMF_InputBox);
pPrintStr = String;
2023-09-09 08:03:56 +01:00
}
2023-09-10 13:52:41 +01:00
UI_PrintString(pPrintStr, 2, 0, 0 + (vfo_num * 3), 8);
center_line = CENTER_LINE_IN_USE;
2023-09-09 08:03:56 +01:00
continue;
}
2023-09-09 13:58:21 +01:00
2023-09-10 13:52:41 +01:00
// highlight the selected/used VFO with a marker
2023-10-19 21:42:56 +02:00
if (isMainVFO)
2023-12-12 23:23:39 +01:00
memcpy(p_line0 + 0, BITMAP_VFO_Default, sizeof(BITMAP_VFO_Default));
2023-09-09 08:03:56 +01:00
}
2023-10-19 21:42:56 +02:00
else // active TX VFO
2023-09-10 13:52:41 +01:00
{ // highlight the selected/used VFO with a marker
2023-10-19 21:42:56 +02:00
if (isMainVFO)
2023-12-12 23:23:39 +01:00
memcpy(p_line0 + 0, BITMAP_VFO_Default, sizeof(BITMAP_VFO_Default));
2023-09-12 15:31:37 +01:00
else
2023-12-12 23:23:39 +01:00
memcpy(p_line0 + 0, BITMAP_VFO_NotDefault, sizeof(BITMAP_VFO_NotDefault));
2023-09-09 08:03:56 +01:00
}
if (gCurrentFunction == FUNCTION_TRANSMIT)
2023-09-11 00:02:57 +01:00
{ // transmitting
2023-10-19 14:26:27 +02:00
#ifdef ENABLE_ALARM
if (gAlarmState == ALARM_STATE_SITE_ALARM)
2023-12-05 17:17:52 +01:00
mode = VFO_MODE_RX;
2023-10-19 14:26:27 +02:00
else
#endif
2023-09-09 08:03:56 +01:00
{
if (activeTxVFO == vfo_num)
2023-09-10 13:52:41 +01:00
{ // show the TX symbol
2023-12-05 17:17:52 +01:00
mode = VFO_MODE_TX;
2023-10-19 21:42:56 +02:00
#ifdef ENABLE_SMALL_BOLD
UI_PrintStringSmallBold("TX", 14, 0, line);
#else
UI_PrintStringSmall("TX", 14, 0, line);
#endif
2023-09-09 08:03:56 +01:00
}
}
}
else
2023-09-12 15:31:37 +01:00
{ // receiving .. show the RX symbol
2023-12-05 17:17:52 +01:00
mode = VFO_MODE_RX;
2023-12-07 12:12:19 +01:00
if (FUNCTION_IsRx() && gEeprom.RX_VFO == vfo_num) {
2023-10-19 21:42:56 +02:00
#ifdef ENABLE_SMALL_BOLD
UI_PrintStringSmallBold("RX", 14, 0, line);
#else
UI_PrintStringSmall("RX", 14, 0, line);
#endif
}
2023-09-09 08:03:56 +01:00
}
2023-10-24 18:35:27 +02:00
if (IS_MR_CHANNEL(gEeprom.ScreenChannel[vfo_num]))
2023-09-11 00:02:57 +01:00
{ // channel mode
2023-09-12 15:31:37 +01:00
const unsigned int x = 2;
const bool inputting = gInputBoxIndex != 0 && gEeprom.TX_VFO == vfo_num;
if (!inputting)
2023-10-18 20:43:02 +02:00
sprintf(String, "M%u", gEeprom.ScreenChannel[vfo_num] + 1);
2023-09-09 08:03:56 +01:00
else
2023-10-19 21:42:56 +02:00
sprintf(String, "M%.3s", INPUTBOX_GetAscii()); // show the input text
2023-10-18 20:43:02 +02:00
UI_PrintStringSmall(String, x, 0, line + 1);
2023-09-09 08:03:56 +01:00
}
2023-10-19 21:42:56 +02:00
else if (IS_FREQ_CHANNEL(gEeprom.ScreenChannel[vfo_num]))
{ // frequency mode
2023-09-11 00:02:57 +01:00
// show the frequency band number
2023-10-18 20:43:02 +02:00
const unsigned int x = 2;
2023-12-03 13:18:13 +01:00
char * buf = gEeprom.VfoInfo[vfo_num].pRX->Frequency < _1GHz_in_KHz ? "" : "+";
2023-10-19 14:26:27 +02:00
sprintf(String, "F%u%s", 1 + gEeprom.ScreenChannel[vfo_num] - FREQ_CHANNEL_FIRST, buf);
2023-10-01 12:44:22 +01:00
UI_PrintStringSmall(String, x, 0, line + 1);
2023-09-09 08:03:56 +01:00
}
2023-10-19 21:42:56 +02:00
#ifdef ENABLE_NOAA
else
{
if (gInputBoxIndex == 0 || gEeprom.TX_VFO != vfo_num)
{ // channel number
sprintf(String, "N%u", 1 + gEeprom.ScreenChannel[vfo_num] - NOAA_CHANNEL_FIRST);
}
2023-09-09 08:03:56 +01:00
else
2023-10-19 21:42:56 +02:00
{ // user entering channel number
sprintf(String, "N%u%u", '0' + gInputBox[0], '0' + gInputBox[1]);
2023-09-09 08:03:56 +01:00
}
2023-10-19 21:42:56 +02:00
UI_PrintStringSmall(String, 7, 0, line + 1);
}
#endif
2023-09-09 08:03:56 +01:00
2023-09-12 15:31:37 +01:00
// ************
enum VfoState_t state = VfoState[vfo_num];
2023-09-09 08:03:56 +01:00
2023-10-19 21:42:56 +02:00
#ifdef ENABLE_ALARM
if (gCurrentFunction == FUNCTION_TRANSMIT && gAlarmState == ALARM_STATE_SITE_ALARM) {
2023-10-19 21:22:10 +02:00
if (activeTxVFO == vfo_num)
2023-10-19 21:42:56 +02:00
state = VFO_STATE_ALARM;
}
#endif
2023-09-09 13:58:21 +01:00
2023-10-20 00:15:11 +02:00
uint32_t frequency = gEeprom.VfoInfo[vfo_num].pRX->Frequency;
if (state != VFO_STATE_NORMAL)
2023-09-09 08:03:56 +01:00
{
if (state < ARRAY_SIZE(VfoStateStr))
UI_PrintString(VfoStateStr[state], 31, 0, line, 8);
2023-09-09 08:03:56 +01:00
}
2023-10-19 21:42:56 +02:00
else if (gInputBoxIndex > 0 && IS_FREQ_CHANNEL(gEeprom.ScreenChannel[vfo_num]) && gEeprom.TX_VFO == vfo_num)
{ // user entering a frequency
2023-10-18 20:43:02 +02:00
const char * ascii = INPUTBOX_GetAscii();
2023-12-03 13:18:13 +01:00
bool isGigaF = frequency>=_1GHz_in_KHz;
2023-10-20 00:15:11 +02:00
sprintf(String, "%.*s.%.3s", 3 + isGigaF, ascii, ascii + 3 + isGigaF);
#ifdef ENABLE_BIG_FREQ
if(!isGigaF) {
// show the remaining 2 small frequency digits
UI_PrintStringSmall(String + 7, 113, 0, line + 1);
String[7] = 0;
// show the main large frequency digits
UI_DisplayFrequency(String, 32, line, false);
}
else
#endif
{
// show the frequency in the main font
UI_PrintString(String, 32, 0, line, 8);
}
continue;
}
else
{
if (gCurrentFunction == FUNCTION_TRANSMIT)
{ // transmitting
if (activeTxVFO == vfo_num)
frequency = gEeprom.VfoInfo[vfo_num].pTX->Frequency;
2023-09-09 08:03:56 +01:00
}
2023-10-24 18:35:27 +02:00
if (IS_MR_CHANNEL(gEeprom.ScreenChannel[vfo_num]))
{ // it's a channel
2023-10-19 14:26:27 +02:00
// show the scan list assigment symbols
2023-11-22 21:30:54 +01:00
const ChannelAttributes_t att = gMR_ChannelAttributes[gEeprom.ScreenChannel[vfo_num]];
if (att.scanlist1)
2023-12-12 23:23:39 +01:00
memcpy(p_line0 + 113, BITMAP_ScanList1, sizeof(BITMAP_ScanList1));
2023-11-22 21:30:54 +01:00
if (att.scanlist2)
2023-12-12 23:23:39 +01:00
memcpy(p_line0 + 120, BITMAP_ScanList2, sizeof(BITMAP_ScanList2));
2023-10-19 14:26:27 +02:00
// compander symbol
2023-10-19 21:42:56 +02:00
#ifndef ENABLE_BIG_FREQ
2023-11-22 21:30:54 +01:00
if (att.compander)
2023-12-12 23:23:39 +01:00
memcpy(p_line0 + 120 + LCD_WIDTH, BITMAP_compand, sizeof(BITMAP_compand));
2023-10-19 21:42:56 +02:00
#else
// TODO: // find somewhere else to put the symbol
#endif
switch (gEeprom.CHANNEL_DISPLAY_MODE)
{
case MDF_FREQUENCY: // show the channel frequency
2023-10-18 20:43:02 +02:00
sprintf(String, "%3u.%05u", frequency / 100000, frequency % 100000);
#ifdef ENABLE_BIG_FREQ
2023-12-03 13:18:13 +01:00
if(frequency < _1GHz_in_KHz) {
// show the remaining 2 small frequency digits
2023-10-18 20:43:02 +02:00
UI_PrintStringSmall(String + 7, 113, 0, line + 1);
String[7] = 0;
// show the main large frequency digits
UI_DisplayFrequency(String, 32, line, false);
}
else
#endif
{
// show the frequency in the main font
2023-10-01 12:44:22 +01:00
UI_PrintString(String, 32, 0, line, 8);
2023-10-18 20:43:02 +02:00
}
break;
2023-09-09 13:58:21 +01:00
case MDF_CHANNEL: // show the channel number
sprintf(String, "CH-%03u", gEeprom.ScreenChannel[vfo_num] + 1);
2023-10-01 12:44:22 +01:00
UI_PrintString(String, 32, 0, line, 8);
break;
case MDF_NAME: // show the channel name
case MDF_NAME_FREQ: // show the channel name and frequency
2023-09-22 13:52:17 +01:00
2023-12-02 22:41:47 +01:00
SETTINGS_FetchChannelName(String, gEeprom.ScreenChannel[vfo_num]);
if (String[0] == 0)
{ // no channel name, show the channel number instead
2023-09-13 02:01:35 +01:00
sprintf(String, "CH-%03u", gEeprom.ScreenChannel[vfo_num] + 1);
}
2023-09-22 13:52:17 +01:00
2023-10-19 21:42:56 +02:00
if (gEeprom.CHANNEL_DISPLAY_MODE == MDF_NAME) {
2023-10-01 12:44:22 +01:00
UI_PrintString(String, 32, 0, line, 8);
}
2023-10-19 21:42:56 +02:00
else {
#ifdef ENABLE_SMALL_BOLD
UI_PrintStringSmallBold(String, 32 + 4, 0, line);
#else
UI_PrintStringSmall(String, 32 + 4, 0, line);
#endif
// show the channel frequency below the channel number/name
sprintf(String, "%03u.%05u", frequency / 100000, frequency % 100000);
2023-10-01 12:44:22 +01:00
UI_PrintStringSmall(String, 32 + 4, 0, line + 1);
}
2023-09-22 13:52:17 +01:00
break;
2023-09-09 08:03:56 +01:00
}
}
else
{ // frequency mode
2023-10-18 20:43:02 +02:00
sprintf(String, "%3u.%05u", frequency / 100000, frequency % 100000);
#ifdef ENABLE_BIG_FREQ
2023-12-03 13:18:13 +01:00
if(frequency < _1GHz_in_KHz) {
// show the remaining 2 small frequency digits
2023-10-18 20:43:02 +02:00
UI_PrintStringSmall(String + 7, 113, 0, line + 1);
String[7] = 0;
// show the main large frequency digits
UI_DisplayFrequency(String, 32, line, false);
}
else
#endif
{
// show the frequency in the main font
2023-10-01 12:44:22 +01:00
UI_PrintString(String, 32, 0, line, 8);
2023-10-18 20:43:02 +02:00
}
2023-10-04 16:37:11 +01:00
// show the channel symbols
2023-11-22 21:30:54 +01:00
const ChannelAttributes_t att = gMR_ChannelAttributes[gEeprom.ScreenChannel[vfo_num]];
if (att.compander)
2023-10-19 21:42:56 +02:00
#ifdef ENABLE_BIG_FREQ
2023-12-12 23:23:39 +01:00
memcpy(p_line0 + 120, BITMAP_compand, sizeof(BITMAP_compand));
2023-10-19 21:42:56 +02:00
#else
2023-12-12 23:23:39 +01:00
memcpy(p_line0 + 120 + LCD_WIDTH, BITMAP_compand, sizeof(BITMAP_compand));
2023-10-19 21:42:56 +02:00
#endif
}
2023-09-09 08:03:56 +01:00
}
2023-09-12 15:31:37 +01:00
// ************
2023-09-10 13:52:41 +01:00
{ // show the TX/RX level
uint8_t Level = 0;
2023-09-09 08:03:56 +01:00
2023-12-05 17:17:52 +01:00
if (mode == VFO_MODE_TX)
2023-09-10 13:52:41 +01:00
{ // TX power level
switch (gRxVfo->OUTPUT_POWER)
{
case OUTPUT_POWER_LOW: Level = 2; break;
case OUTPUT_POWER_MID: Level = 4; break;
case OUTPUT_POWER_HIGH: Level = 6; break;
2023-09-10 13:52:41 +01:00
}
}
else
2023-12-05 17:17:52 +01:00
if (mode == VFO_MODE_RX)
2023-09-10 13:52:41 +01:00
{ // RX signal level
#ifndef ENABLE_RSSI_BAR
2023-09-17 15:36:23 +01:00
// bar graph
if (gVFO_RSSI_bar_level[vfo_num] > 0)
Level = gVFO_RSSI_bar_level[vfo_num];
2023-09-17 15:36:23 +01:00
#endif
2023-09-10 13:52:41 +01:00
}
2023-10-27 18:35:45 +02:00
if(Level)
2023-10-27 19:00:42 +02:00
DrawSmallAntennaAndBars(p_line1 + LCD_WIDTH, Level);
2023-09-09 08:03:56 +01:00
}
2023-09-12 15:31:37 +01:00
// ************
2023-09-17 15:36:23 +01:00
String[0] = '\0';
// show the modulation symbol
const char * s = "";
const ModulationMode_t mod = gEeprom.VfoInfo[vfo_num].Modulation;
switch (mod){
case MODULATION_FM: {
2023-12-05 17:17:52 +01:00
const FREQ_Config_t *pConfig = (mode == VFO_MODE_TX) ? gEeprom.VfoInfo[vfo_num].pTX : gEeprom.VfoInfo[vfo_num].pRX;
const unsigned int code_type = pConfig->CodeType;
const char *code_list[] = {"", "CT", "DCS", "DCR"};
if (code_type < ARRAY_SIZE(code_list))
s = code_list[code_type];
break;
}
default:
s = gModulationStr[mod];
break;
}
UI_PrintStringSmall(s, LCD_WIDTH + 24, 0, line + 1);
2023-09-09 08:03:56 +01:00
if (state == VFO_STATE_NORMAL || state == VFO_STATE_ALARM)
{ // show the TX power
const char pwr_list[] = "LMH";
const unsigned int i = gEeprom.VfoInfo[vfo_num].OUTPUT_POWER;
String[0] = (i < ARRAY_SIZE(pwr_list)) ? pwr_list[i] : '\0';
String[1] = '\0';
2023-10-01 12:44:22 +01:00
UI_PrintStringSmall(String, LCD_WIDTH + 46, 0, line + 1);
2023-09-09 08:03:56 +01:00
}
2023-09-25 18:08:21 +01:00
if (gEeprom.VfoInfo[vfo_num].freq_config_RX.Frequency != gEeprom.VfoInfo[vfo_num].freq_config_TX.Frequency)
2023-09-10 13:52:41 +01:00
{ // show the TX offset symbol
const char dir_list[] = "\0+-";
const unsigned int i = gEeprom.VfoInfo[vfo_num].TX_OFFSET_FREQUENCY_DIRECTION;
String[0] = (i < sizeof(dir_list)) ? dir_list[i] : '?';
2023-09-16 17:16:36 +01:00
String[1] = '\0';
2023-10-01 12:44:22 +01:00
UI_PrintStringSmall(String, LCD_WIDTH + 54, 0, line + 1);
2023-09-09 08:03:56 +01:00
}
2023-09-10 13:52:41 +01:00
// show the TX/RX reverse symbol
if (gEeprom.VfoInfo[vfo_num].FrequencyReverse)
2023-10-01 12:44:22 +01:00
UI_PrintStringSmall("R", LCD_WIDTH + 62, 0, line + 1);
2023-09-09 08:03:56 +01:00
2023-09-18 00:48:40 +01:00
{ // show the narrow band symbol
String[0] = '\0';
if (gEeprom.VfoInfo[vfo_num].CHANNEL_BANDWIDTH == BANDWIDTH_NARROW)
2023-09-18 00:48:40 +01:00
{
String[0] = 'N';
String[1] = '\0';
2023-09-18 00:48:40 +01:00
}
2023-10-01 12:44:22 +01:00
UI_PrintStringSmall(String, LCD_WIDTH + 70, 0, line + 1);
2023-09-18 00:48:40 +01:00
}
#ifdef ENABLE_DTMF_CALLING
2023-09-30 11:22:19 +01:00
// show the DTMF decoding symbol
if (gEeprom.VfoInfo[vfo_num].DTMF_DECODING_ENABLE || gSetting_KILLED)
2023-10-01 12:44:22 +01:00
UI_PrintStringSmall("DTMF", LCD_WIDTH + 78, 0, line + 1);
#endif
2023-09-09 08:03:56 +01:00
2023-09-10 13:52:41 +01:00
// show the audio scramble symbol
2023-09-17 15:36:23 +01:00
if (gEeprom.VfoInfo[vfo_num].SCRAMBLING_TYPE > 0 && gSetting_ScrambleEnable)
2023-10-01 12:44:22 +01:00
UI_PrintStringSmall("SCR", LCD_WIDTH + 106, 0, line + 1);
2023-09-09 08:03:56 +01:00
}
2023-12-04 22:58:27 +01:00
#ifdef ENABLE_AGC_SHOW_DATA
center_line = CENTER_LINE_IN_USE;
PrintAGC(false);
#endif
if (center_line == CENTER_LINE_NONE)
{ // we're free to use the middle line
2023-12-07 12:12:19 +01:00
const bool rx = FUNCTION_IsRx();
2023-09-22 13:52:17 +01:00
2023-10-19 21:42:56 +02:00
#ifdef ENABLE_AUDIO_BAR
if (gSetting_mic_bar && gCurrentFunction == FUNCTION_TRANSMIT) {
center_line = CENTER_LINE_AUDIO_BAR;
UI_DisplayAudioBar();
}
else
#endif
2023-10-04 22:08:13 +01:00
2023-10-19 21:42:56 +02:00
#if defined(ENABLE_AM_FIX) && defined(ENABLE_AM_FIX_SHOW_DATA)
2023-11-03 12:18:31 +01:00
if (rx && gEeprom.VfoInfo[gEeprom.RX_VFO].Modulation == MODULATION_AM && gSetting_AM_fix)
2023-10-19 21:42:56 +02:00
{
if (gScreenToDisplay != DISPLAY_MAIN
#ifdef ENABLE_DTMF_CALLING
|| gDTMF_CallState != DTMF_CALL_STATE_NONE
#endif
)
2023-10-19 21:42:56 +02:00
return;
2023-10-19 21:42:56 +02:00
center_line = CENTER_LINE_AM_FIX_DATA;
AM_fix_print_data(gEeprom.RX_VFO, String);
UI_PrintStringSmall(String, 2, 0, 3);
}
else
#endif
2023-10-19 21:42:56 +02:00
#ifdef ENABLE_RSSI_BAR
if (rx) {
center_line = CENTER_LINE_RSSI;
2023-12-05 23:13:21 +01:00
DisplayRSSIBar(false);
2023-10-19 21:42:56 +02:00
}
else
#endif
2023-10-02 01:28:56 +01:00
if (rx || gCurrentFunction == FUNCTION_FOREGROUND || gCurrentFunction == FUNCTION_POWER_SAVE)
2023-09-29 09:58:32 +01:00
{
2023-09-30 11:22:19 +01:00
#if 1
if (gSetting_live_DTMF_decoder && gDTMF_RX_live[0] != 0)
{ // show live DTMF decode
const unsigned int len = strlen(gDTMF_RX_live);
const unsigned int idx = (len > (17 - 5)) ? len - (17 - 5) : 0; // limit to last 'n' chars
2023-10-04 22:08:13 +01:00
if (gScreenToDisplay != DISPLAY_MAIN
#ifdef ENABLE_DTMF_CALLING
|| gDTMF_CallState != DTMF_CALL_STATE_NONE
#endif
)
2023-10-04 22:08:13 +01:00
return;
2023-10-03 00:14:36 +01:00
center_line = CENTER_LINE_DTMF_DEC;
2023-09-30 11:22:19 +01:00
strcpy(String, "DTMF ");
strcat(String, gDTMF_RX_live + idx);
UI_PrintStringSmall(String, 2, 0, 3);
}
#else
if (gSetting_live_DTMF_decoder && gDTMF_RX_index > 0)
{ // show live DTMF decode
const unsigned int len = gDTMF_RX_index;
const unsigned int idx = (len > (17 - 5)) ? len - (17 - 5) : 0; // limit to last 'n' chars
2023-10-04 22:08:13 +01:00
if (gScreenToDisplay != DISPLAY_MAIN ||
gDTMF_CallState != DTMF_CALL_STATE_NONE)
return;
2023-10-03 00:14:36 +01:00
center_line = CENTER_LINE_DTMF_DEC;
2023-09-30 11:22:19 +01:00
strcpy(String, "DTMF ");
strcat(String, gDTMF_RX + idx);
UI_PrintStringSmall(String, 2, 0, 3);
}
#endif
2023-10-19 21:42:56 +02:00
#ifdef ENABLE_SHOW_CHARGE_LEVEL
else if (gChargingWithTypeC)
{ // charging .. show the battery state
if (gScreenToDisplay != DISPLAY_MAIN
#ifdef ENABLE_DTMF_CALLING
|| gDTMF_CallState != DTMF_CALL_STATE_NONE
#endif
)
2023-10-19 21:42:56 +02:00
return;
2023-10-19 21:42:56 +02:00
center_line = CENTER_LINE_CHARGE_DATA;
2023-10-19 21:42:56 +02:00
sprintf(String, "Charge %u.%02uV %u%%",
gBatteryVoltageAverage / 100, gBatteryVoltageAverage % 100,
BATTERY_VoltsToPercent(gBatteryVoltageAverage));
UI_PrintStringSmall(String, 2, 0, 3);
}
#endif
2023-09-24 01:58:03 +01:00
}
}
2023-09-17 15:36:23 +01:00
2023-09-09 08:03:56 +01:00
ST7565_BlitFullScreen();
}
// ***************************************************************************