chore: replace f_puts and f_printf functions to save FLASH space (#5459)
This commit is contained in:
@@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <cinttypes>
|
#include <cinttypes>
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
const char * getFileExtension(const char * filename, uint8_t size, uint8_t extMaxLen, uint8_t * fnlen, uint8_t * extlen)
|
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;
|
firstTime = false;
|
||||||
return res;
|
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
@@ -183,7 +183,6 @@ void writeHeader()
|
|||||||
f_puts("Time,", &g_oLogFile);
|
f_puts("Time,", &g_oLogFile);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
char label[TELEM_LABEL_LEN+7];
|
char label[TELEM_LABEL_LEN+7];
|
||||||
for (int i=0; i<MAX_TELEMETRY_SENSORS; i++) {
|
for (int i=0; i<MAX_TELEMETRY_SENSORS; i++) {
|
||||||
if (isTelemetryFieldAvailable(i)) {
|
if (isTelemetryFieldAvailable(i)) {
|
||||||
@@ -207,16 +206,16 @@ void writeHeader()
|
|||||||
auto n_inputs = adcGetMaxInputs(ADC_INPUT_MAIN);
|
auto n_inputs = adcGetMaxInputs(ADC_INPUT_MAIN);
|
||||||
for (uint8_t i = 0; i < n_inputs; i++) {
|
for (uint8_t i = 0; i < n_inputs; i++) {
|
||||||
const char* p = analogGetCanonicalName(ADC_INPUT_MAIN, i);
|
const char* p = analogGetCanonicalName(ADC_INPUT_MAIN, i);
|
||||||
while (*p) { f_putc(*(p++), &g_oLogFile); }
|
f_puts(p, &g_oLogFile);
|
||||||
f_putc(',', &g_oLogFile);
|
f_puts(",", &g_oLogFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
n_inputs = adcGetMaxInputs(ADC_INPUT_FLEX);
|
n_inputs = adcGetMaxInputs(ADC_INPUT_FLEX);
|
||||||
for (uint8_t i = 0; i < n_inputs; i++) {
|
for (uint8_t i = 0; i < n_inputs; i++) {
|
||||||
if (!IS_POT_AVAILABLE(i)) continue;
|
if (!IS_POT_AVAILABLE(i)) continue;
|
||||||
const char* p = analogGetCanonicalName(ADC_INPUT_FLEX, i);
|
const char* p = analogGetCanonicalName(ADC_INPUT_FLEX, i);
|
||||||
while (*p) { f_putc(*(p++), &g_oLogFile); }
|
f_puts(p, &g_oLogFile);
|
||||||
f_putc(',', &g_oLogFile);
|
f_puts(",", &g_oLogFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint8_t i = 0; i < switchGetMaxSwitches(); i++) {
|
for (uint8_t i = 0; i < switchGetMaxSwitches(); i++) {
|
||||||
@@ -288,7 +287,6 @@ void logsWrite()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if defined(RTCLOCK)
|
#if defined(RTCLOCK)
|
||||||
{
|
{
|
||||||
static struct gtm utm;
|
static struct gtm utm;
|
||||||
|
|||||||
@@ -1404,19 +1404,26 @@ void ModelsList::updateCurrentModelCell()
|
|||||||
|
|
||||||
bool ModelsList::readNextLine(char *line, int maxlen)
|
bool ModelsList::readNextLine(char *line, int maxlen)
|
||||||
{
|
{
|
||||||
if (f_gets(line, maxlen, &file) != NULL) {
|
while (maxlen > 0) {
|
||||||
int curlen = strlen(line) - 1;
|
unsigned int br;
|
||||||
if (line[curlen] ==
|
FRESULT res = f_read(&file, line, 1, &br);
|
||||||
'\n') { // remove unwanted chars if file was edited using windows
|
if (res == FR_OK && br == 1) {
|
||||||
if (line[curlen - 1] == '\r') {
|
// Return if line read
|
||||||
line[curlen - 1] = 0;
|
if (*line == 0 || *line == '\n') {
|
||||||
} else {
|
*line = 0;
|
||||||
line[curlen] = 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Vendored
-4
@@ -63,11 +63,7 @@
|
|||||||
/* This option switches f_forward() function. (0:Disable or 1:Enable) */
|
/* This option switches f_forward() function. (0:Disable or 1:Enable) */
|
||||||
|
|
||||||
|
|
||||||
#if defined(BOOT)
|
|
||||||
#define FF_USE_STRFUNC 0
|
#define FF_USE_STRFUNC 0
|
||||||
#else
|
|
||||||
#define FF_USE_STRFUNC 1
|
|
||||||
#endif
|
|
||||||
#define FF_PRINT_LLI 1
|
#define FF_PRINT_LLI 1
|
||||||
#define FF_PRINT_FLOAT 1
|
#define FF_PRINT_FLOAT 1
|
||||||
#define FF_STRF_ENCODE 3
|
#define FF_STRF_ENCODE 3
|
||||||
|
|||||||
Reference in New Issue
Block a user