uv-k5-firmware-custom/ui/rssi.c

149 lines
3.6 KiB
C
Raw Normal View History

2023-09-09 07:03:56 +00: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-17 14:36:23 +00:00
2023-09-09 07:03:56 +00:00
#include "bitmaps.h"
#include "driver/st7565.h"
2023-09-17 14:36:23 +00:00
#include "external/printf/printf.h"
2023-09-09 07:03:56 +00:00
#include "functions.h"
#include "misc.h"
#include "settings.h"
2023-09-17 14:36:23 +00:00
#include "ui/helper.h"
2023-09-09 07:03:56 +00:00
#include "ui/rssi.h"
#include "ui/ui.h"
2023-09-17 14:36:23 +00:00
#ifdef ENABLE_DBM
void UI_UpdateRSSI(uint16_t RSSI)
{ // dBm
//
// this doesn't yet quite fit into the available screen space
char s[8];
const uint8_t line = (gEeprom.RX_CHANNEL == 0) ? 3 : 7;
if (gEeprom.KEY_LOCK && gKeypadLocked > 0)
return; // the screen is currently in use
2023-09-17 14:36:23 +00:00
gVFO_RSSI[gEeprom.RX_CHANNEL] = RSSI;
gVFO_RSSI_Level[gEeprom.RX_CHANNEL] = 0;
if (RSSI > 0)
{ // drop the '.5'
const int16_t dBm = (int16_t)(RSSI / 2) - 160;
sprintf(s, "%-3d", dBm);
}
else
strcpy(s, " ");
UI_PrintStringSmall(s, 2, 0, line);
}
#else
void Render(const uint8_t rssi, const uint8_t RssiLevel, const uint8_t VFO)
{ // bar graph
2023-09-09 07:03:56 +00:00
uint8_t *pLine;
2023-09-09 10:17:45 +00:00
uint8_t Line;
2023-09-09 07:03:56 +00:00
if (gEeprom.KEY_LOCK && gKeypadLocked > 0)
return; // the screen is currently in use
2023-09-09 10:17:45 +00:00
if (gCurrentFunction == FUNCTION_TRANSMIT || gScreenToDisplay != DISPLAY_MAIN)
return; // it's still in use
2023-09-09 07:03:56 +00:00
2023-09-09 10:17:45 +00:00
if (VFO == 0)
{
2023-09-09 07:03:56 +00:00
pLine = gFrameBuffer[2];
2023-09-09 19:45:38 +00:00
Line = 3;
2023-09-09 10:17:45 +00:00
}
else
{
2023-09-09 07:03:56 +00:00
pLine = gFrameBuffer[6];
2023-09-09 19:45:38 +00:00
Line = 7;
2023-09-09 07:03:56 +00:00
}
memset(pLine, 0, 23);
2023-09-17 14:36:23 +00:00
2023-09-09 10:17:45 +00:00
if (RssiLevel == 0)
{
2023-09-17 14:36:23 +00:00
pLine = NULL;
2023-09-09 10:17:45 +00:00
}
else
{
2023-09-17 14:36:23 +00:00
//if (RssiLevel >= 1)
memmove(pLine, BITMAP_Antenna, 5);
if (RssiLevel >= 2)
2023-09-17 08:54:24 +00:00
memmove(pLine + 5, BITMAP_AntennaLevel1, sizeof(BITMAP_AntennaLevel1));
if (RssiLevel >= 3)
2023-09-17 08:54:24 +00:00
memmove(pLine + 8, BITMAP_AntennaLevel2, sizeof(BITMAP_AntennaLevel2));
if (RssiLevel >= 4)
2023-09-17 08:54:24 +00:00
memmove(pLine + 11, BITMAP_AntennaLevel3, sizeof(BITMAP_AntennaLevel3));
if (RssiLevel >= 5)
2023-09-17 08:54:24 +00:00
memmove(pLine + 14, BITMAP_AntennaLevel4, sizeof(BITMAP_AntennaLevel4));
if (RssiLevel >= 6)
2023-09-17 08:54:24 +00:00
memmove(pLine + 17, BITMAP_AntennaLevel5, sizeof(BITMAP_AntennaLevel5));
if (RssiLevel >= 7)
2023-09-17 08:54:24 +00:00
memmove(pLine + 20, BITMAP_AntennaLevel6, sizeof(BITMAP_AntennaLevel6));
2023-09-09 07:03:56 +00:00
}
ST7565_DrawLine(0, Line, 23, pLine);
2023-09-09 07:03:56 +00:00
}
void UI_UpdateRSSI(uint16_t RSSI)
{
2023-09-17 14:36:23 +00:00
gVFO_RSSI[gEeprom.RX_CHANNEL] = RSSI;
//const int16_t dBm = (int16_t)(RSSI / 2) - 160;
2023-09-17 14:36:23 +00:00
//const unsigned int band = gRxVfo->Band;
2023-09-10 08:57:49 +00:00
const unsigned int band = 0;
const uint16_t level0 = gEEPROM_RSSI_CALIB[band][0];
const uint16_t level1 = gEEPROM_RSSI_CALIB[band][1];
const uint16_t level2 = gEEPROM_RSSI_CALIB[band][2];
const uint16_t level3 = gEEPROM_RSSI_CALIB[band][3];
const uint16_t level01 = (level0 + level1) / 2;
const uint16_t level12 = (level1 + level2) / 2;
const uint16_t level23 = (level2 + level3) / 2;
2023-09-09 10:17:45 +00:00
uint8_t Level = 0;
2023-09-09 07:03:56 +00:00
if (RSSI >= level3) Level = 7;
else
if (RSSI >= level23) Level = 6;
2023-09-09 10:17:45 +00:00
else
if (RSSI >= level2) Level = 5;
2023-09-09 10:17:45 +00:00
else
if (RSSI >= level12) Level = 4;
2023-09-09 10:17:45 +00:00
else
if (RSSI >= level1) Level = 3;
else
if (RSSI >= level01) Level = 2;
else
if (RSSI >= level0) Level = 1;
2023-09-09 07:03:56 +00:00
2023-09-09 10:17:45 +00:00
if (gVFO_RSSI_Level[gEeprom.RX_CHANNEL] != Level)
{
2023-09-09 07:03:56 +00:00
gVFO_RSSI_Level[gEeprom.RX_CHANNEL] = Level;
2023-09-17 14:36:23 +00:00
Render(RSSI, Level, gEeprom.RX_CHANNEL);
2023-09-09 07:03:56 +00:00
}
}
2023-09-17 14:36:23 +00:00
#endif