Skip to content

Commit

Permalink
Unify PrintSmall functions
Browse files Browse the repository at this point in the history
Size: 60420 -> 60364
  • Loading branch information
JuantAldea authored and egzumer committed Dec 25, 2023
1 parent 78a45d9 commit 7a7010d
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 136 deletions.
2 changes: 1 addition & 1 deletion app/spectrum.c
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ static void DrawStatus() {

static void DrawF(uint32_t f) {
sprintf(String, "%u.%05u", f / 100000, f % 100000);
UI_PrintStringSmall(String, 8, 127, 0);
UI_PrintStringSmallNormal(String, 8, 127, 0);

sprintf(String, "%3s", gModulationStr[settings.modulationType]);
GUI_DisplaySmallest(String, 116, 1, false, true);
Expand Down
2 changes: 0 additions & 2 deletions bitmaps.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,4 @@ extern const uint8_t BITMAP_ScanList1[6];
extern const uint8_t BITMAP_ScanList2[6];

extern const uint8_t BITMAP_compand[6];

#endif

2 changes: 1 addition & 1 deletion misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ extern uint16_t gEEPROM_RSSI_CALIB[7][4];
extern uint16_t gEEPROM_1F8A;
extern uint16_t gEEPROM_1F8C;

typedef union {
typedef union {
struct {
uint8_t
band : 4,
Expand Down
2 changes: 1 addition & 1 deletion ui/aircopy.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void UI_DisplayAircopy(void)
uint32_t frequency = gRxVfo->freq_config_RX.Frequency;
sprintf(String, "%3u.%05u", frequency / 100000, frequency % 100000);
// show the remaining 2 small frequency digits
UI_PrintStringSmall(String + 7, 97, 0, 3);
UI_PrintStringSmallNormal(String + 7, 97, 0, 3);
String[7] = 0;
// show the main large frequency digits
UI_DisplayFrequency(String, 16, 2, false);
Expand Down
101 changes: 48 additions & 53 deletions ui/helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,19 @@ void UI_GenerateChannelStringEx(char *pString, const bool bShowPrefix, const uin
}
}

void UI_PrintStringBuffer(const char *pString, uint8_t * buffer, uint32_t char_width, const uint8_t *font)
{
const size_t Length = strlen(pString);
const unsigned int char_spacing = char_width + 1;
for (size_t i = 0; i < Length; i++) {
const unsigned int index = pString[i] - ' ' - 1;
if (pString[i] > ' ' && pString[i] < 127) {
const uint32_t offset = i * char_spacing + 1;
memcpy(buffer + offset, font + index * char_width, char_width);
}
}
}

void UI_PrintString(const char *pString, uint8_t Start, uint8_t End, uint8_t Line, uint8_t Width)
{
size_t i;
Expand All @@ -85,68 +98,51 @@ void UI_PrintString(const char *pString, uint8_t Start, uint8_t End, uint8_t Lin
}
}

void UI_PrintStringSmall(const char *pString, uint8_t Start, uint8_t End, uint8_t Line)
void UI_PrintStringSmall(const char *pString, uint8_t Start, uint8_t End, uint8_t Line, uint8_t char_width, const uint8_t *font)
{
const size_t Length = strlen(pString);
size_t i;

const unsigned int char_width = ARRAY_SIZE(gFontSmall[0]);
const unsigned int char_spacing = char_width + 1;

if (End > Start)
Start += (((End - Start) - (Length * char_spacing)) + 1) / 2;
if (End > Start) {
Start += (((End - Start) - Length * char_spacing) + 1) / 2;
}

UI_PrintStringBuffer(pString, gFrameBuffer[Line] + Start, char_width, font);
}

uint8_t *pFb = gFrameBuffer[Line] + Start;
for (i = 0; i < Length; i++)
{
if (pString[i] > ' ')
{
const unsigned int index = (unsigned int)pString[i] - ' ' - 1;
if (index < ARRAY_SIZE(gFontSmall))
memcpy(pFb + (i * char_spacing) + 1, &gFontSmall[index], char_width);
}
}
void UI_PrintStringSmallNormal(const char *pString, uint8_t Start, uint8_t End, uint8_t Line)
{
UI_PrintStringSmall(pString, Start, End, Line, ARRAY_SIZE(gFontSmall[0]), (const uint8_t *)gFontSmall);
}

void UI_PrintStringSmallBold(const char *pString, uint8_t Start, uint8_t End, uint8_t Line)
{
#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;
const uint8_t *font = (uint8_t *)gFontSmallBold;
const uint8_t char_width = ARRAY_SIZE(gFontSmallBold[0]);
#else
const uint8_t *font = (uint8_t *)gFontSmall;
const uint8_t char_width = ARRAY_SIZE(gFontSmall[0]);
#endif

if (End > Start)
Start += (((End - Start) - (Length * 8)) + 1) / 2;
UI_PrintStringSmall(pString, Start, End, Line, char_width, font);
}

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++)
{
if (pString[i] > ' ')
{
const unsigned int index = (unsigned int)pString[i] - ' ' - 1;
if (index < ARRAY_SIZE(gFontSmallBold))
memcpy(pFb + (i * char_spacing) + 1, &gFontSmallBold[index], char_width);
}
}
}
#endif
void UI_PrintStringSmallBufferNormal(const char *pString, uint8_t * buffer)
{
UI_PrintStringBuffer(pString, buffer, ARRAY_SIZE(gFontSmall[0]), (uint8_t *)gFontSmall);
}

void UI_PrintStringSmallBuffer(const char *pString, uint8_t *buffer)
void UI_PrintStringSmallBufferBold(const char *pString, uint8_t * buffer)
{
size_t i;
const unsigned int char_width = ARRAY_SIZE(gFontSmall[0]);
const unsigned int char_spacing = char_width + 1;
for (i = 0; i < strlen(pString); i++)
{
if (pString[i] > ' ')
{
const unsigned int index = (unsigned int)pString[i] - ' ' - 1;
if (index < ARRAY_SIZE(gFontSmall))
memcpy(buffer + (i * char_spacing) + 1, &gFontSmall[index], char_width);
}
}
#ifdef ENABLE_SMALL_BOLD
const uint8_t *font = (uint8_t *)gFontSmallBold;
const uint8_t char_width = ARRAY_SIZE(gFontSmallBold[0]);
#else
const uint8_t *font = (uint8_t *)gFontSmall;
const uint8_t char_width = ARRAY_SIZE(gFontSmall[0]);
#endif
UI_PrintStringBuffer(pString, buffer, char_width, font);
}

void UI_DisplayFrequency(const char *string, uint8_t X, uint8_t Y, bool center)
Expand Down Expand Up @@ -230,11 +226,10 @@ void UI_DrawRectangleBuffer(uint8_t (*buffer)[128], int16_t x1, int16_t y1, int1
UI_DrawLineBuffer(buffer, x1,y2, x2,y2, black);
}


void UI_DisplayPopup(const char *string)
{
for(uint8_t i = 0; i < 7; i++) {
memset(gFrameBuffer[i], 0x00, 128);
}
UI_DisplayClear();

// for(uint8_t i = 1; i < 5; i++) {
// memset(gFrameBuffer[i]+8, 0x00, 111);
Expand All @@ -251,7 +246,7 @@ void UI_DisplayPopup(const char *string)
// }
// DrawRectangle(9,9, 118,38, true);
UI_PrintString(string, 9, 118, 2, 8);
UI_PrintStringSmall("Press EXIT", 9, 118, 6);
UI_PrintStringSmallNormal("Press EXIT", 9, 118, 6);
}

void UI_DisplayClear()
Expand Down
9 changes: 4 additions & 5 deletions ui/helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@
void UI_GenerateChannelString(char *pString, const uint8_t Channel);
void UI_GenerateChannelStringEx(char *pString, const bool bShowPrefix, const uint8_t ChannelNumber);
void UI_PrintString(const char *pString, uint8_t Start, uint8_t End, uint8_t Line, uint8_t Width);
void UI_PrintStringSmall(const char *pString, uint8_t Start, uint8_t End, uint8_t Line);
#ifdef ENABLE_SMALL_BOLD
void UI_PrintStringSmallBold(const char *pString, uint8_t Start, uint8_t End, uint8_t Line);
#endif
void UI_PrintStringSmallBuffer(const char *pString, uint8_t *buffer);
void UI_PrintStringSmallNormal(const char *pString, uint8_t Start, uint8_t End, uint8_t Line);
void UI_PrintStringSmallBold(const char *pString, uint8_t Start, uint8_t End, uint8_t Line);
void UI_PrintStringSmallBufferNormal(const char *pString, uint8_t *buffer);
void UI_PrintStringSmallBufferBold(const char *pString, uint8_t * buffer);
void UI_DisplayFrequency(const char *string, uint8_t X, uint8_t Y, bool center);

void UI_DisplayPopup(const char *string);
Expand Down
Loading

0 comments on commit 7a7010d

Please sign in to comment.