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-10 05:49:39 +01:00
|
|
|
|
2023-09-09 08:03:56 +01:00
|
|
|
#include "driver/st7565.h"
|
|
|
|
#include "external/printf/printf.h"
|
|
|
|
#include "font.h"
|
|
|
|
#include "ui/helper.h"
|
|
|
|
#include "ui/inputbox.h"
|
|
|
|
|
2023-09-10 09:57:49 +01:00
|
|
|
#ifndef ARRAY_SIZE
|
|
|
|
#define ARRAY_SIZE(arr) (sizeof(arr)/sizeof((arr)[0]))
|
|
|
|
#endif
|
|
|
|
|
2023-10-11 19:07:25 +01:00
|
|
|
void UI_GenerateChannelString(char *pString, const uint8_t Channel, const char separating_char)
|
2023-09-09 08:03:56 +01:00
|
|
|
{
|
2023-09-09 12:40:19 +01:00
|
|
|
unsigned int i;
|
2023-09-09 08:03:56 +01:00
|
|
|
|
2023-10-11 19:07:25 +01:00
|
|
|
if (pString == NULL)
|
|
|
|
return;
|
|
|
|
|
2023-10-08 20:23:37 +01:00
|
|
|
if (g_input_box_index == 0)
|
2023-09-09 12:40:19 +01:00
|
|
|
{
|
2023-10-11 19:07:25 +01:00
|
|
|
sprintf(pString, "CH%c%02u", separating_char, Channel + 1);
|
2023-09-09 08:03:56 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
pString[0] = 'C';
|
|
|
|
pString[1] = 'H';
|
2023-10-11 19:07:25 +01:00
|
|
|
pString[2] = separating_char;
|
2023-09-09 12:40:19 +01:00
|
|
|
for (i = 0; i < 2; i++)
|
2023-10-11 19:07:25 +01:00
|
|
|
pString[i + 3] = (g_input_box[i] == 10) ? '_' : g_input_box[i] + '0';
|
2023-09-09 08:03:56 +01:00
|
|
|
}
|
|
|
|
|
2023-10-11 19:07:25 +01:00
|
|
|
void UI_GenerateChannelStringEx(char *pString, const char *prefix, const uint8_t ChannelNumber)
|
2023-09-09 08:03:56 +01:00
|
|
|
{
|
2023-10-11 19:07:25 +01:00
|
|
|
if (pString == NULL)
|
|
|
|
return;
|
|
|
|
|
2023-10-08 20:23:37 +01:00
|
|
|
if (g_input_box_index > 0)
|
2023-09-09 12:40:19 +01:00
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
for (i = 0; i < 3; i++)
|
2023-10-08 20:23:37 +01:00
|
|
|
pString[i] = (g_input_box[i] == 10) ? '-' : g_input_box[i] + '0';
|
2023-09-09 08:03:56 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-10-11 19:07:25 +01:00
|
|
|
pString[0] = 0;
|
|
|
|
|
|
|
|
if (prefix)
|
|
|
|
strcpy(pString, prefix);
|
|
|
|
|
2023-09-09 12:40:19 +01:00
|
|
|
if (ChannelNumber == 0xFF)
|
|
|
|
strcpy(pString, "NULL");
|
|
|
|
else
|
2023-10-11 19:07:25 +01:00
|
|
|
sprintf(pString + strlen(prefix), "%03u", ChannelNumber + 1);
|
2023-09-09 08:03:56 +01:00
|
|
|
}
|
|
|
|
|
2023-09-12 15:31:37 +01:00
|
|
|
void UI_PrintString(const char *pString, uint8_t Start, uint8_t End, uint8_t Line, uint8_t Width)
|
2023-09-09 08:03:56 +01:00
|
|
|
{
|
2023-09-09 12:14:15 +01:00
|
|
|
size_t i;
|
|
|
|
size_t Length = strlen(pString);
|
2023-09-09 08:03:56 +01:00
|
|
|
|
2023-09-12 15:31:37 +01:00
|
|
|
if (End > Start)
|
2023-09-09 08:03:56 +01:00
|
|
|
Start += (((End - Start) - (Length * Width)) + 1) / 2;
|
2023-09-09 12:14:15 +01:00
|
|
|
|
|
|
|
for (i = 0; i < Length; i++)
|
|
|
|
{
|
|
|
|
if (pString[i] >= ' ' && pString[i] < 127)
|
|
|
|
{
|
2023-09-22 07:04:56 +01:00
|
|
|
const unsigned int index = pString[i] - ' ';
|
2023-09-09 12:40:19 +01:00
|
|
|
const unsigned int ofs = (unsigned int)Start + (i * Width);
|
2023-10-08 20:23:37 +01:00
|
|
|
memmove(g_frame_buffer[Line + 0] + ofs, &g_font_big[index][0], 8);
|
|
|
|
memmove(g_frame_buffer[Line + 1] + ofs, &g_font_big[index][8], 7);
|
2023-09-09 08:03:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-12 15:31:37 +01:00
|
|
|
void UI_PrintStringSmall(const char *pString, uint8_t Start, uint8_t End, uint8_t Line)
|
2023-09-09 08:03:56 +01:00
|
|
|
{
|
2023-09-10 05:49:39 +01:00
|
|
|
const size_t Length = strlen(pString);
|
|
|
|
size_t i;
|
|
|
|
|
2023-09-12 15:31:37 +01:00
|
|
|
if (End > Start)
|
2023-09-10 05:49:39 +01:00
|
|
|
Start += (((End - Start) - (Length * 8)) + 1) / 2;
|
2023-09-09 08:03:56 +01:00
|
|
|
|
2023-10-08 20:23:37 +01:00
|
|
|
const unsigned int char_width = ARRAY_SIZE(g_font_small[0]);
|
2023-09-24 01:36:43 +01:00
|
|
|
const unsigned int char_spacing = char_width + 1;
|
2023-10-08 20:23:37 +01:00
|
|
|
uint8_t *pFb = g_frame_buffer[Line] + Start;
|
2023-09-16 14:53:55 +01:00
|
|
|
for (i = 0; i < Length; i++)
|
2023-09-11 23:48:08 +01:00
|
|
|
{
|
2023-09-16 14:53:55 +01:00
|
|
|
if (pString[i] >= 32)
|
2023-09-10 05:49:39 +01:00
|
|
|
{
|
2023-09-22 07:04:56 +01:00
|
|
|
const unsigned int index = (unsigned int)pString[i] - 32;
|
2023-10-08 20:23:37 +01:00
|
|
|
if (index < ARRAY_SIZE(g_font_small))
|
|
|
|
memmove(pFb + (i * char_spacing) + 1, &g_font_small[index], char_width);
|
2023-09-10 05:49:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-09-09 08:03:56 +01:00
|
|
|
|
2023-09-24 01:36:43 +01: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;
|
|
|
|
|
2023-10-08 20:23:37 +01:00
|
|
|
const unsigned int char_width = ARRAY_SIZE(g_font_small_bold[0]);
|
2023-09-24 01:36:43 +01:00
|
|
|
const unsigned int char_spacing = char_width + 1;
|
2023-10-08 20:23:37 +01:00
|
|
|
uint8_t *pFb = g_frame_buffer[Line] + Start;
|
2023-09-24 01:36:43 +01:00
|
|
|
for (i = 0; i < Length; i++)
|
|
|
|
{
|
|
|
|
if (pString[i] >= 32)
|
|
|
|
{
|
|
|
|
const unsigned int index = (unsigned int)pString[i] - 32;
|
2023-10-08 20:23:37 +01:00
|
|
|
if (index < ARRAY_SIZE(g_font_small_bold))
|
|
|
|
memmove(pFb + (i * char_spacing) + 1, &g_font_small_bold[index], char_width);
|
2023-09-24 01:36:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2023-09-19 07:59:06 +01:00
|
|
|
void UI_PrintStringSmallBuffer(const char *pString, uint8_t *buffer)
|
|
|
|
{
|
|
|
|
size_t i;
|
2023-10-08 20:23:37 +01:00
|
|
|
const unsigned int char_width = ARRAY_SIZE(g_font_small[0]);
|
2023-09-24 01:36:43 +01:00
|
|
|
const unsigned int char_spacing = char_width + 1;
|
2023-09-19 07:59:06 +01:00
|
|
|
for (i = 0; i < strlen(pString); i++)
|
|
|
|
{
|
|
|
|
if (pString[i] >= 32)
|
|
|
|
{
|
2023-09-22 07:04:56 +01:00
|
|
|
const unsigned int index = (unsigned int)pString[i] - 32;
|
2023-10-08 20:23:37 +01:00
|
|
|
if (index < ARRAY_SIZE(g_font_small))
|
|
|
|
memmove(buffer + (i * char_spacing) + 1, &g_font_small[index], char_width);
|
2023-09-19 07:59:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-08 20:23:37 +01:00
|
|
|
void UI_DisplayFrequency(const char *pDigits, uint8_t X, uint8_t Y, bool bDisplayLeadingZero, bool flag)
|
2023-09-10 05:49:39 +01:00
|
|
|
{
|
|
|
|
const unsigned int char_width = 13;
|
2023-10-08 20:23:37 +01:00
|
|
|
uint8_t *pFb0 = g_frame_buffer[Y] + X;
|
2023-09-10 05:49:39 +01:00
|
|
|
uint8_t *pFb1 = pFb0 + 128;
|
|
|
|
bool bCanDisplay = false;
|
|
|
|
unsigned int i = 0;
|
|
|
|
|
|
|
|
// MHz
|
|
|
|
while (i < 3)
|
|
|
|
{
|
|
|
|
const unsigned int Digit = pDigits[i++];
|
|
|
|
if (bDisplayLeadingZero || bCanDisplay || Digit > 0)
|
2023-09-09 12:40:19 +01:00
|
|
|
{
|
2023-09-09 08:03:56 +01:00
|
|
|
bCanDisplay = true;
|
2023-10-08 20:23:37 +01:00
|
|
|
memmove(pFb0, g_font_big_digits[Digit], char_width);
|
|
|
|
memmove(pFb1, g_font_big_digits[Digit] + char_width, char_width);
|
2023-09-09 12:40:19 +01:00
|
|
|
}
|
|
|
|
else
|
2023-10-08 20:23:37 +01:00
|
|
|
if (flag)
|
2023-09-09 12:40:19 +01:00
|
|
|
{
|
2023-09-09 08:03:56 +01:00
|
|
|
pFb0 -= 6;
|
2023-09-10 05:49:39 +01:00
|
|
|
pFb1 -= 6;
|
2023-09-09 08:03:56 +01:00
|
|
|
}
|
2023-09-10 05:49:39 +01:00
|
|
|
pFb0 += char_width;
|
|
|
|
pFb1 += char_width;
|
2023-09-09 08:03:56 +01:00
|
|
|
}
|
|
|
|
|
2023-09-10 05:49:39 +01:00
|
|
|
// decimal point
|
|
|
|
*pFb1 = 0x60; pFb0++; pFb1++;
|
|
|
|
*pFb1 = 0x60; pFb0++; pFb1++;
|
|
|
|
*pFb1 = 0x60; pFb0++; pFb1++;
|
|
|
|
|
|
|
|
// kHz
|
|
|
|
while (i < 6)
|
|
|
|
{
|
|
|
|
const unsigned int Digit = pDigits[i++];
|
2023-10-08 20:23:37 +01:00
|
|
|
memmove(pFb0, g_font_big_digits[Digit], char_width);
|
|
|
|
memmove(pFb1, g_font_big_digits[Digit] + char_width, char_width);
|
2023-09-10 05:49:39 +01:00
|
|
|
pFb0 += char_width;
|
|
|
|
pFb1 += char_width;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void UI_DisplayFrequencySmall(const char *pDigits, uint8_t X, uint8_t Y, bool bDisplayLeadingZero)
|
|
|
|
{
|
2023-10-08 20:23:37 +01:00
|
|
|
const unsigned int char_width = ARRAY_SIZE(g_font_small[0]);
|
2023-09-24 02:05:22 +01:00
|
|
|
const unsigned int spacing = 1 + char_width;
|
2023-10-08 20:23:37 +01:00
|
|
|
uint8_t *pFb = g_frame_buffer[Y] + X;
|
2023-09-10 05:49:39 +01:00
|
|
|
bool bCanDisplay = false;
|
|
|
|
unsigned int i = 0;
|
|
|
|
|
|
|
|
// MHz
|
|
|
|
while (i < 3)
|
|
|
|
{
|
2023-09-22 07:04:56 +01:00
|
|
|
const unsigned int c = pDigits[i++];
|
|
|
|
if (bDisplayLeadingZero || bCanDisplay || c > 0)
|
2023-09-10 05:49:39 +01:00
|
|
|
{
|
2023-09-22 05:51:15 +01:00
|
|
|
#if 0
|
2023-10-08 20:23:37 +01:00
|
|
|
memmove(pFb + 1, g_font_small_digits[c], char_width);
|
2023-09-22 05:51:15 +01:00
|
|
|
#else
|
2023-09-22 07:04:56 +01:00
|
|
|
const unsigned int index = (c < 10) ? '0' - 32 + c : '-' - 32;
|
2023-10-08 20:23:37 +01:00
|
|
|
memmove(pFb + 1, g_font_small[index], char_width);
|
2023-09-22 05:51:15 +01:00
|
|
|
#endif
|
2023-09-24 02:05:22 +01:00
|
|
|
pFb += spacing;
|
2023-09-22 05:51:15 +01:00
|
|
|
bCanDisplay = true;
|
2023-09-10 05:49:39 +01:00
|
|
|
}
|
|
|
|
}
|
2023-09-09 08:03:56 +01:00
|
|
|
|
2023-09-10 05:49:39 +01:00
|
|
|
// decimal point
|
|
|
|
pFb++;
|
|
|
|
pFb++;
|
|
|
|
*pFb++ = 0x60;
|
|
|
|
*pFb++ = 0x60;
|
|
|
|
pFb++;
|
|
|
|
|
|
|
|
// kHz
|
|
|
|
while (i < 8)
|
2023-09-09 12:14:15 +01:00
|
|
|
{
|
2023-09-22 07:04:56 +01:00
|
|
|
const unsigned int c = pDigits[i++];
|
2023-09-22 05:51:15 +01:00
|
|
|
#if 0
|
2023-10-08 20:23:37 +01:00
|
|
|
memmove(pFb + 1, g_font_small_digits[c], char_width);
|
2023-09-22 05:51:15 +01:00
|
|
|
#else
|
2023-09-22 07:04:56 +01:00
|
|
|
const unsigned int index = (c < 10) ? '0' - 32 + c : '-' - 32;
|
2023-10-08 20:23:37 +01:00
|
|
|
memmove(pFb + 1, g_font_small[index], char_width);
|
2023-09-22 05:51:15 +01:00
|
|
|
#endif
|
2023-09-24 02:05:22 +01:00
|
|
|
pFb += spacing;
|
2023-09-09 08:03:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-08 20:23:37 +01:00
|
|
|
void UI_Displaysmall_digits(const uint8_t size, const char *str, const uint8_t x, const uint8_t y, const bool display_leading_zeros)
|
2023-09-09 08:03:56 +01:00
|
|
|
{
|
2023-10-08 20:23:37 +01:00
|
|
|
const unsigned int char_width = ARRAY_SIZE(g_font_small[0]);
|
2023-09-24 02:05:22 +01:00
|
|
|
const unsigned int spacing = 1 + char_width;
|
2023-09-12 16:53:47 +01:00
|
|
|
bool display = display_leading_zeros;
|
|
|
|
unsigned int xx;
|
2023-09-10 05:49:39 +01:00
|
|
|
unsigned int i;
|
2023-09-12 16:53:47 +01:00
|
|
|
for (i = 0, xx = x; i < size; i++)
|
|
|
|
{
|
|
|
|
const unsigned int c = (unsigned int)str[i];
|
|
|
|
if (c > 0)
|
2023-09-22 07:04:56 +01:00
|
|
|
display = true; // non '0'
|
2023-09-22 05:51:15 +01:00
|
|
|
if (display && c < 11)
|
2023-09-12 16:53:47 +01:00
|
|
|
{
|
2023-09-22 05:51:15 +01:00
|
|
|
#if 0
|
2023-10-08 20:23:37 +01:00
|
|
|
memmove(g_frame_buffer[y] + xx, g_font_small_digits[c], char_width);
|
2023-09-22 05:51:15 +01:00
|
|
|
#else
|
|
|
|
const unsigned int index = (c < 10) ? '0' - 32 + c : '-' - 32;
|
2023-10-08 20:23:37 +01:00
|
|
|
memmove(g_frame_buffer[y] + xx + 1, g_font_small[index], char_width);
|
2023-09-22 05:51:15 +01:00
|
|
|
#endif
|
2023-09-24 02:05:22 +01:00
|
|
|
xx += spacing;
|
2023-09-12 16:53:47 +01:00
|
|
|
}
|
|
|
|
}
|
2023-09-09 08:03:56 +01:00
|
|
|
}
|