chore: replace f_puts and f_printf functions to save FLASH space (#5459)

This commit is contained in:
philmoz
2024-08-20 09:51:06 +10:00
committed by GitHub
parent 06db4c7989
commit 5ca2419e0d
4 changed files with 48 additions and 20 deletions
+27
View File
@@ -20,6 +20,7 @@
#include <inttypes.h>
#include <cinttypes>
#include <stdarg.h>
const char * getFileExtension(const char * filename, uint8_t size, uint8_t extMaxLen, uint8_t * fnlen, uint8_t * extlen)
{
@@ -107,3 +108,29 @@ FRESULT sdReadDir(DIR * dir, FILINFO * fno, bool & firstTime)
firstTime = false;
return res;
}
#if !defined(BOOT) && !defined(SIMU)
// Replace FatFS implementation of f_puts and f_printf
int f_puts(const char* s, FIL* fp)
{
unsigned int written;
unsigned int len = strlen(s);
FRESULT result = f_write(fp, s, len, &written);
return (len == written && result == FR_OK) ? 0 : EOF;
}
#define MAX_FPRINTF_LEN 100
int f_printf (FIL* fp, const TCHAR* str, ...)
{
char s[MAX_FPRINTF_LEN];
va_list argptr;
va_start(argptr, str);
vsnprintf(s, MAX_FPRINTF_LEN, str, argptr);
va_end(argptr);
return f_puts(s, fp);
}
#endif
+4 -6
View File
@@ -183,7 +183,6 @@ void writeHeader()
f_puts("Time,", &g_oLogFile);
#endif
char label[TELEM_LABEL_LEN+7];
for (int i=0; i<MAX_TELEMETRY_SENSORS; i++) {
if (isTelemetryFieldAvailable(i)) {
@@ -207,16 +206,16 @@ void writeHeader()
auto n_inputs = adcGetMaxInputs(ADC_INPUT_MAIN);
for (uint8_t i = 0; i < n_inputs; i++) {
const char* p = analogGetCanonicalName(ADC_INPUT_MAIN, i);
while (*p) { f_putc(*(p++), &g_oLogFile); }
f_putc(',', &g_oLogFile);
f_puts(p, &g_oLogFile);
f_puts(",", &g_oLogFile);
}
n_inputs = adcGetMaxInputs(ADC_INPUT_FLEX);
for (uint8_t i = 0; i < n_inputs; i++) {
if (!IS_POT_AVAILABLE(i)) continue;
const char* p = analogGetCanonicalName(ADC_INPUT_FLEX, i);
while (*p) { f_putc(*(p++), &g_oLogFile); }
f_putc(',', &g_oLogFile);
f_puts(p, &g_oLogFile);
f_puts(",", &g_oLogFile);
}
for (uint8_t i = 0; i < switchGetMaxSwitches(); i++) {
@@ -288,7 +287,6 @@ void logsWrite()
return;
}
#if defined(RTCLOCK)
{
static struct gtm utm;
+17 -10
View File
@@ -1404,19 +1404,26 @@ void ModelsList::updateCurrentModelCell()
bool ModelsList::readNextLine(char *line, int maxlen)
{
if (f_gets(line, maxlen, &file) != NULL) {
int curlen = strlen(line) - 1;
if (line[curlen] ==
'\n') { // remove unwanted chars if file was edited using windows
if (line[curlen - 1] == '\r') {
line[curlen - 1] = 0;
} else {
line[curlen] = 0;
while (maxlen > 0) {
unsigned int br;
FRESULT res = f_read(&file, line, 1, &br);
if (res == FR_OK && br == 1) {
// Return if line read
if (*line == 0 || *line == '\n') {
*line = 0;
return true;
}
// Move to next char unless '\r' read
if (*line != '\r') {
line += 1;
maxlen -= 1;
}
} else {
return false;
}
return true;
}
return false;
*line = 0;
return true;
}
/**
-4
View File
@@ -63,11 +63,7 @@
/* This option switches f_forward() function. (0:Disable or 1:Enable) */
#if defined(BOOT)
#define FF_USE_STRFUNC 0
#else
#define FF_USE_STRFUNC 1
#endif
#define FF_PRINT_LLI 1
#define FF_PRINT_FLOAT 1
#define FF_STRF_ENCODE 3