- Spectrum: GUI_DisplaySmallest() now draws with gFontSmall (7 px per character) for the status bar; the spectrum layout needs the 3x5 font (4 px), so it gets its own renderer again. Its labels were overlapping. - make BANDSCOPE=1: spectrum instead of the FM radio. Both do not fit in 60 KB together (FM radio is 4.9 KB). Debug log off and -finline-limit=1 in that edition; it fits with a few bytes to spare. - OOK sender on F+7 / long 7 (the VOX key is free, VOX is not built); F+EXIT is back to only cancelling F. - POCSAG deviation tuning keys behind POCSAG_DEVIATION_TUNING (default 0). - Smaller code: shared end of SMS/POCSAG transmissions, non-inlined fast SPI wait, compact OOK field tables, sprintf message header, shorter OOK strings. - Makefile: EXTRA_CFLAGS for passing defines. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
91 lines
3.5 KiB
C
91 lines
3.5 KiB
C
//
|
|
// Created by bruno on 3/30/25.
|
|
//
|
|
|
|
#include "messages.h"
|
|
#include "../external/printf/printf.h"
|
|
|
|
|
|
// Convert a 32-bit number to a string (10 digits, zero-padded)
|
|
void u32_to_str(uint32_t num, char *str) {
|
|
for (int i = 9; i >= 0; i--) {
|
|
str[i] = '0' + (num % 10);
|
|
num /= 10;
|
|
}
|
|
str[10] = '\0';
|
|
}
|
|
|
|
// Convert an 8-bit number to a 2-digit string (zero-padded)
|
|
void u8_to_str(uint8_t num, char *str) {
|
|
str[0] = '0' + (num / 100); // Hundreds place
|
|
str[1] = '0' + ((num / 10) % 10); // Tens place
|
|
str[2] = '0' + (num % 10); // Ones place
|
|
str[3] = '\0';
|
|
}
|
|
|
|
|
|
// Print text wrapped over `lines` display lines starting at `line`.
|
|
static void UI_PrintWrapped(const char *text, const uint8_t line, const uint8_t lines) {
|
|
char chunk[MESSAGES_LINE_CHARS + 1U];
|
|
const size_t length = strlen(text);
|
|
|
|
for (uint8_t l = 0; l < lines && l * MESSAGES_LINE_CHARS < length; l++) {
|
|
strncpy(chunk, text + l * MESSAGES_LINE_CHARS, MESSAGES_LINE_CHARS);
|
|
chunk[MESSAGES_LINE_CHARS] = '\0';
|
|
UI_PrintStringSmallNormal(chunk, 1, 0, line + l);
|
|
}
|
|
}
|
|
|
|
void UI_DisplayMessages(void) {
|
|
char String[19];
|
|
UI_DisplayClear();
|
|
if (gEnteringSMS != SMS_NOT_ENTERING) {
|
|
if (gEnteringSMS == SMS_ENTERING_DEST) {
|
|
UI_PrintString(MODEM_IS_POCSAG(gEeprom.FSKMode) ? "RIC" : "SMS dest", 0, 0, 0 /*, 8 */);
|
|
u32_to_str(dataPacket.dest, String);
|
|
UI_PrintStringSmallNormal(String, 0, 0, 2);
|
|
} else if (gEnteringSMS == SMS_ENTERING_MESSAGE) {
|
|
const size_t length = strlen(gMessageText);
|
|
UI_PrintString(MODEM_IS_POCSAG(gEeprom.FSKMode) ? "Page text" : "SMS data", 0, 0, 0 /*, 8 */);
|
|
UI_PrintWrapped(gMessageText, 1, MESSAGES_TEXT_LINES);
|
|
// cursor block after the last character
|
|
const uint8_t cursorLine = 1U + length / MESSAGES_LINE_CHARS;
|
|
if (length < MESSAGES_TEXT_LENGTH && cursorLine < 8U)
|
|
memset(gFrameBuffer[cursorLine] + 2 + (7 * (length % MESSAGES_LINE_CHARS)),
|
|
gKeyTimeout == 0 ? 0xFF : 0x80, 6);
|
|
}
|
|
} else {
|
|
char text[MESSAGES_TEXT_LENGTH + 1U];
|
|
uint8_t Data[8];
|
|
EEPROM_ReadBuffer(SEQParameterEEPROM, Data, 8);
|
|
uint8_t msgIndex = Data[1]; // index of latest written message
|
|
|
|
// Determine oldest message index (next to be overwritten)
|
|
uint8_t startIndex = (msgIndex + 1) % MESSAGES_COUNT;
|
|
|
|
// Pages run from oldest to newest
|
|
uint8_t pageOffset = gActiveMessageBank * MESSAGES_PER_PAGE;
|
|
|
|
for (uint8_t ixa = 0; ixa < MESSAGES_PER_PAGE; ixa++) {
|
|
// If out of stored range, stop
|
|
if (pageOffset + ixa >= MESSAGES_COUNT)
|
|
break;
|
|
|
|
// Logical order from oldest to newest
|
|
gActiveMessage = (startIndex + pageOffset + ixa) % MESSAGES_COUNT;
|
|
MESSAGES_GET();
|
|
|
|
// header: sender (POCSAG: "P:" + RIC), sequence, position in the list, EEPROM slot
|
|
sprintf(String, (loadedPacket.flags & MESSAGE_FLAG_POCSAG) ? "P:%07lu -%03u-%X-%X" : "%010lu-%03u-%X-%X",
|
|
(unsigned long) loadedPacket.src, loadedPacket.seq, ixa + pageOffset, gActiveMessage);
|
|
|
|
// header line, then the text wrapped over MESSAGES_TEXT_LINES lines
|
|
const uint8_t line = ixa * (1U + MESSAGES_TEXT_LINES);
|
|
UI_PrintString(String, 2, 0, line);
|
|
MESSAGES_GetText(text);
|
|
UI_PrintWrapped(text, line + 1U, MESSAGES_TEXT_LINES);
|
|
}
|
|
}
|
|
ST7565_BlitFullScreen();
|
|
}
|