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-10 04:49:39 +00:00
|
|
|
|
2023-09-09 07:03:56 +00:00
|
|
|
#include "driver/st7565.h"
|
|
|
|
#include "external/printf/printf.h"
|
|
|
|
#include "font.h"
|
|
|
|
#include "ui/helper.h"
|
|
|
|
#include "ui/inputbox.h"
|
|
|
|
|
2023-09-10 08:57:49 +00:00
|
|
|
#ifndef ARRAY_SIZE
|
|
|
|
#define ARRAY_SIZE(arr) (sizeof(arr)/sizeof((arr)[0]))
|
|
|
|
#endif
|
|
|
|
|
2023-09-09 12:58:21 +00:00
|
|
|
void UI_GenerateChannelString(char *pString, const uint8_t Channel)
|
2023-09-09 07:03:56 +00:00
|
|
|
{
|
2023-09-09 11:40:19 +00:00
|
|
|
unsigned int i;
|
2023-09-09 07:03:56 +00:00
|
|
|
|
2023-09-09 11:40:19 +00:00
|
|
|
if (gInputBoxIndex == 0)
|
|
|
|
{
|
2023-09-13 01:01:35 +00:00
|
|
|
sprintf(pString, "CH-%02u", Channel + 1);
|
2023-09-09 07:03:56 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
pString[0] = 'C';
|
|
|
|
pString[1] = 'H';
|
|
|
|
pString[2] = '-';
|
2023-09-09 11:40:19 +00:00
|
|
|
for (i = 0; i < 2; i++)
|
|
|
|
pString[i + 3] = (gInputBox[i] == 10) ? '-' : gInputBox[i] + '0';
|
2023-09-09 07:03:56 +00:00
|
|
|
}
|
|
|
|
|
2023-09-09 12:58:21 +00:00
|
|
|
void UI_GenerateChannelStringEx(char *pString, const bool bShowPrefix, const uint8_t ChannelNumber)
|
2023-09-09 07:03:56 +00:00
|
|
|
{
|
2023-09-14 18:38:28 +00:00
|
|
|
if (gInputBoxIndex > 0)
|
2023-09-09 11:40:19 +00:00
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
for (i = 0; i < 3; i++)
|
|
|
|
pString[i] = (gInputBox[i] == 10) ? '-' : gInputBox[i] + '0';
|
2023-09-09 07:03:56 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-09-09 11:40:19 +00:00
|
|
|
if (bShowPrefix)
|
2023-09-13 01:01:35 +00:00
|
|
|
sprintf(pString, "CH-%03u", ChannelNumber + 1);
|
2023-09-09 11:40:19 +00:00
|
|
|
else
|
|
|
|
if (ChannelNumber == 0xFF)
|
|
|
|
strcpy(pString, "NULL");
|
|
|
|
else
|
2023-09-13 01:01:35 +00:00
|
|
|
sprintf(pString, "%03u", ChannelNumber + 1);
|
2023-09-09 07:03:56 +00:00
|
|
|
}
|
|
|
|
|
2023-09-12 14:31:37 +00:00
|
|
|
void UI_PrintString(const char *pString, uint8_t Start, uint8_t End, uint8_t Line, uint8_t Width)
|
2023-09-09 07:03:56 +00:00
|
|
|
{
|
2023-09-09 11:14:15 +00:00
|
|
|
size_t i;
|
|
|
|
size_t Length = strlen(pString);
|
2023-09-09 07:03:56 +00:00
|
|
|
|
2023-09-12 14:31:37 +00:00
|
|
|
if (End > Start)
|
2023-09-09 07:03:56 +00:00
|
|
|
Start += (((End - Start) - (Length * Width)) + 1) / 2;
|
2023-09-09 11:14:15 +00:00
|
|
|
|
|
|
|
for (i = 0; i < Length; i++)
|
|
|
|
{
|
2023-10-20 14:52:15 +00:00
|
|
|
const unsigned int ofs = (unsigned int)Start + (i * Width);
|
|
|
|
if (pString[i] > ' ' && pString[i] < 127)
|
2023-09-09 11:14:15 +00:00
|
|
|
{
|
2023-10-20 14:52:15 +00:00
|
|
|
const unsigned int index = pString[i] - ' ' - 1;
|
|
|
|
memmove(gFrameBuffer[Line + 0] + ofs, &gFontBig[index][0], 7);
|
|
|
|
memmove(gFrameBuffer[Line + 1] + ofs, &gFontBig[index][7], 7);
|
2023-09-09 07:03:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-12 14:31:37 +00:00
|
|
|
void UI_PrintStringSmall(const char *pString, uint8_t Start, uint8_t End, uint8_t Line)
|
2023-09-09 07:03:56 +00:00
|
|
|
{
|
2023-09-10 04:49:39 +00:00
|
|
|
const size_t Length = strlen(pString);
|
|
|
|
size_t i;
|
|
|
|
|
2023-09-12 14:31:37 +00:00
|
|
|
if (End > Start)
|
2023-09-10 04:49:39 +00:00
|
|
|
Start += (((End - Start) - (Length * 8)) + 1) / 2;
|
2023-09-09 07:03:56 +00:00
|
|
|
|
2023-09-16 13:53:55 +00:00
|
|
|
const unsigned int char_width = ARRAY_SIZE(gFontSmall[0]);
|
2023-09-24 00:36:43 +00:00
|
|
|
const unsigned int char_spacing = char_width + 1;
|
2023-09-16 13:53:55 +00:00
|
|
|
uint8_t *pFb = gFrameBuffer[Line] + Start;
|
|
|
|
for (i = 0; i < Length; i++)
|
2023-09-11 22:48:08 +00:00
|
|
|
{
|
2023-10-20 14:52:15 +00:00
|
|
|
if (pString[i] > ' ')
|
2023-09-10 04:49:39 +00:00
|
|
|
{
|
2023-10-20 14:52:15 +00:00
|
|
|
const unsigned int index = (unsigned int)pString[i] - ' ' - 1;
|
2023-09-22 06:04:56 +00:00
|
|
|
if (index < ARRAY_SIZE(gFontSmall))
|
2023-09-24 00:36:43 +00:00
|
|
|
memmove(pFb + (i * char_spacing) + 1, &gFontSmall[index], char_width);
|
2023-09-10 04:49:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-09-09 07:03:56 +00:00
|
|
|
|
2023-09-24 00:36:43 +00:00
|
|
|
#ifdef ENABLE_SMALL_BOLD
|
|
|
|
void UI_PrintStringSmallBold(const char *pString, uint8_t Start, uint8_t End, uint8_t Line)
|
|
|
|
{
|
|
|
|
const size_t Length = strlen(pString);
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
if (End > Start)
|
|
|
|
Start += (((End - Start) - (Length * 8)) + 1) / 2;
|
|
|
|
|
|
|
|
const unsigned int char_width = ARRAY_SIZE(gFontSmallBold[0]);
|
|
|
|
const unsigned int char_spacing = char_width + 1;
|
|
|
|
uint8_t *pFb = gFrameBuffer[Line] + Start;
|
|
|
|
for (i = 0; i < Length; i++)
|
|
|
|
{
|
2023-10-20 14:52:15 +00:00
|
|
|
if (pString[i] > ' ')
|
2023-09-24 00:36:43 +00:00
|
|
|
{
|
2023-10-20 14:52:15 +00:00
|
|
|
const unsigned int index = (unsigned int)pString[i] - ' ' - 1;
|
2023-09-24 00:36:43 +00:00
|
|
|
if (index < ARRAY_SIZE(gFontSmallBold))
|
|
|
|
memmove(pFb + (i * char_spacing) + 1, &gFontSmallBold[index], char_width);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2023-09-19 06:59:06 +00:00
|
|
|
void UI_PrintStringSmallBuffer(const char *pString, uint8_t *buffer)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
const unsigned int char_width = ARRAY_SIZE(gFontSmall[0]);
|
2023-09-24 00:36:43 +00:00
|
|
|
const unsigned int char_spacing = char_width + 1;
|
2023-09-19 06:59:06 +00:00
|
|
|
for (i = 0; i < strlen(pString); i++)
|
|
|
|
{
|
2023-10-20 14:52:15 +00:00
|
|
|
if (pString[i] > ' ')
|
2023-09-19 06:59:06 +00:00
|
|
|
{
|
2023-10-20 14:52:15 +00:00
|
|
|
const unsigned int index = (unsigned int)pString[i] - ' ' - 1;
|
2023-09-22 06:04:56 +00:00
|
|
|
if (index < ARRAY_SIZE(gFontSmall))
|
2023-09-24 00:36:43 +00:00
|
|
|
memmove(buffer + (i * char_spacing) + 1, &gFontSmall[index], char_width);
|
2023-09-19 06:59:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-18 18:43:02 +00:00
|
|
|
void UI_DisplayFrequency(const char *string, uint8_t X, uint8_t Y, bool center)
|
2023-09-10 04:49:39 +00:00
|
|
|
{
|
|
|
|
const unsigned int char_width = 13;
|
|
|
|
uint8_t *pFb0 = gFrameBuffer[Y] + X;
|
|
|
|
uint8_t *pFb1 = pFb0 + 128;
|
|
|
|
bool bCanDisplay = false;
|
2023-10-18 18:43:02 +00:00
|
|
|
|
|
|
|
uint8_t len = strlen(string);
|
|
|
|
for(int i = 0; i < len; i++) {
|
2023-10-20 14:52:15 +00:00
|
|
|
char c = string[i];
|
|
|
|
if(c=='-') c = '9' + 1;
|
2023-10-18 18:43:02 +00:00
|
|
|
if (bCanDisplay || c != ' ')
|
2023-09-09 11:40:19 +00:00
|
|
|
{
|
2023-09-09 07:03:56 +00:00
|
|
|
bCanDisplay = true;
|
2023-10-20 14:52:15 +00:00
|
|
|
if(c>='0' && c<='9' + 1) {
|
|
|
|
memcpy(pFb0 + 2, gFontBigDigits[c-'0'], char_width - 3);
|
|
|
|
memcpy(pFb1 + 2, gFontBigDigits[c-'0'] + char_width - 3, char_width - 3);
|
2023-10-18 18:43:02 +00:00
|
|
|
}
|
|
|
|
else if(c=='.') {
|
|
|
|
*pFb1 = 0x60; pFb0++; pFb1++;
|
|
|
|
*pFb1 = 0x60; pFb0++; pFb1++;
|
|
|
|
*pFb1 = 0x60; pFb0++; pFb1++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2023-09-09 11:40:19 +00:00
|
|
|
}
|
2023-10-18 18:43:02 +00:00
|
|
|
else if (center) {
|
2023-09-09 07:03:56 +00:00
|
|
|
pFb0 -= 6;
|
2023-09-10 04:49:39 +00:00
|
|
|
pFb1 -= 6;
|
2023-09-09 07:03:56 +00:00
|
|
|
}
|
2023-09-10 04:49:39 +00:00
|
|
|
pFb0 += char_width;
|
|
|
|
pFb1 += char_width;
|
2023-09-09 07:03:56 +00:00
|
|
|
}
|
|
|
|
}
|