Minor code size reduction. Adding some const correctness.

This commit is contained in:
Dominic Clifton 2015-01-15 10:48:54 +00:00
parent 138fd963a7
commit 947bb0d918
5 changed files with 15 additions and 11 deletions

View File

@ -69,7 +69,7 @@ static void putchw(void *putp, putcf putf, int n, char z, char *bf)
putf(putp, ch);
}
void tfp_format(void *putp, putcf putf, char *fmt, va_list va)
void tfp_format(void *putp, putcf putf, const char *fmt, va_list va)
{
char bf[12];
@ -154,7 +154,7 @@ void init_printf(void *putp, void (*putf) (void *, char))
stdout_putp = putp;
}
void tfp_printf(char *fmt, ...)
void tfp_printf(const char *fmt, ...)
{
va_list va;
va_start(va, fmt);
@ -168,7 +168,7 @@ static void putcp(void *p, char c)
*(*((char **) p))++ = c;
}
void tfp_sprintf(char *s, char *fmt, ...)
void tfp_sprintf(char *s, const char *fmt, ...)
{
va_list va;

View File

@ -107,10 +107,10 @@ regs Kusti, 23.10.2004
void init_printf(void *putp, void (*putf) (void *, char));
void tfp_printf(char *fmt, ...);
void tfp_sprintf(char *s, char *fmt, ...);
void tfp_printf(const char *fmt, ...);
void tfp_sprintf(char *s, const char *fmt, ...);
void tfp_format(void *putp, void (*putf) (void *, char), char *fmt, va_list va);
void tfp_format(void *putp, void (*putf) (void *, char), const char *fmt, va_list va);
#define printf tfp_printf
#define sprintf tfp_sprintf

View File

@ -90,7 +90,7 @@ int a2d(char ch)
return -1;
}
char a2i(char ch, char **src, int base, int *nump)
char a2i(char ch, const char **src, int base, int *nump)
{
char *p = *src;
int num = 0;

View File

@ -20,7 +20,7 @@ void uli2a(unsigned long int num, unsigned int base, int uc, char *bf);
void li2a(long num, char *bf);
void ui2a(unsigned int num, unsigned int base, int uc, char *bf);
void i2a(int num, char *bf);
char a2i(char ch, char **src, int base, int *nump);
char a2i(char ch, const char **src, int base, int *nump);
char *ftoa(float x, char *floatString);
float fastA2F(const char *p);

View File

@ -378,24 +378,28 @@ void showBatteryPage(void)
void showSensorsPage(void)
{
uint8_t rowIndex = PAGE_TITLE_LINE_COUNT;
static const char *format = "%c = %5d %5d %5d";
i2c_OLED_set_line(rowIndex++);
i2c_OLED_send_string(" X Y Z");
if (sensors(SENSOR_ACC)) {
tfp_sprintf(lineBuffer, "A = %5d %5d %5d", accSmooth[X], accSmooth[Y], accSmooth[Z]);
tfp_sprintf(lineBuffer, format, 'A', accSmooth[X], accSmooth[Y], accSmooth[Z]);
padLineBuffer();
i2c_OLED_set_line(rowIndex++);
i2c_OLED_send_string(lineBuffer);
}
if (sensors(SENSOR_GYRO)) {
tfp_sprintf(lineBuffer, "G = %5d %5d %5d", gyroADC[X], gyroADC[Y], gyroADC[Z]);
tfp_sprintf(lineBuffer, format, 'G', gyroADC[X], gyroADC[Y], gyroADC[Z]);
padLineBuffer();
i2c_OLED_set_line(rowIndex++);
i2c_OLED_send_string(lineBuffer);
}
#ifdef MAG
if (sensors(SENSOR_MAG)) {
tfp_sprintf(lineBuffer, "M = %5d %5d %5d", magADC[X], magADC[Y], magADC[Z]);
tfp_sprintf(lineBuffer, format, 'M', magADC[X], magADC[Y], magADC[Z]);
padLineBuffer();
i2c_OLED_set_line(rowIndex++);
i2c_OLED_send_string(lineBuffer);