1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-14 20:10:08 +03:00

[Horus] A few TODOs fixed (some sprintf removed)

This commit is contained in:
Bertrand Songis 2016-01-28 23:12:26 +01:00
parent d6c17a7ead
commit b7e4a3c63b
7 changed files with 45 additions and 34 deletions

View file

@ -433,9 +433,8 @@ void putsTimer(coord_t x, coord_t y, putstime_t tme, LcdFlags att)
void drawStringWithIndex(coord_t x, coord_t y, const pm_char * str, int idx, LcdFlags att, const char * prefix)
{
// TODO quick & dirty, dangerous
char s[32];
sprintf(s, "%s%s%d", prefix, str, abs(idx));
char s[64];
strAppendNumber(strAppend(strAppend(s, prefix), str), abs(idx));
lcdDrawText(x, y, s, att);
}
@ -457,7 +456,7 @@ void putsMixerSource(coord_t x, coord_t y, uint8_t idx, LcdFlags att)
s[1+LEN_INPUT_NAME] = '\0';
}
else {
sprintf(s+1, "%02d", idx);
strAppendNumber(s+1, idx, 2);
}
lcdDrawText(x, y, s, att);
}
@ -546,8 +545,7 @@ char * getStringAtIndex(char * dest, const char * s, int idx)
char * getStringWithIndex(char * dest, const char * s, int idx)
{
// TODO reimplement without the sprintf
sprintf(dest, "%s%d", s, abs(idx));
strAppendNumber(strAppend(dest, s), abs(idx));
return dest;
}

View file

@ -347,7 +347,11 @@ bool menuGeneralSdManager(evt_t _event)
if (reusableBuffer.sdmanager.lines[i][0]) {
if (IS_DIRECTORY(reusableBuffer.sdmanager.lines[i])) {
char s[sizeof(reusableBuffer.sdmanager.lines[0])+2];
sprintf(s, "[%s]", reusableBuffer.sdmanager.lines[i]);
char * ptr = s;
*ptr++ = '[';
ptr = strAppend(ptr, reusableBuffer.sdmanager.lines[i]);
*ptr++ = ']';
*ptr = '\0';
lcdDrawText(MENUS_MARGIN_LEFT, y, s, attr);
}
else {

View file

@ -248,7 +248,7 @@ bool menuModelCurveOne(evt_t event)
lcdDrawSolidFilledRect(point.x, CURVE_CENTER_Y-CURVE_SIDE_WIDTH, 2, 2*CURVE_SIDE_WIDTH+2, CURVE_CURSOR_COLOR);
char text[5];
sprintf(text, "%d", points[i]);
strAppendNumber(text, points[i]);
if (point.x >= CURVE_CENTER_X) {
drawCurveVerticalScale(point.x-15);
@ -271,7 +271,7 @@ bool menuModelCurveOne(evt_t event)
drawCurvePoint(point.x-3, point.y-4, CURVE_CURSOR_COLOR);
sprintf(text, "%d", x);
strAppendNumber(text, x);
drawCurveCoord(limit(CURVE_CENTER_X-CURVE_SIDE_WIDTH-1, point.x-CURVE_COORD_WIDTH/2, CURVE_CENTER_X+CURVE_SIDE_WIDTH-CURVE_COORD_WIDTH+1), CURVE_CENTER_Y+CURVE_SIDE_WIDTH+2, text, selectionMode==1);
if (s_editMode > 0) {

View file

@ -190,17 +190,17 @@ bool menuModelExpoOne(evt_t event)
char texty[5];
int x = getValue(ed->srcRaw);
if (ed->srcRaw >= MIXSRC_FIRST_TELEM) {
sprintf(textx, "%d", calcRESXto100(x));
strAppendNumber(textx, calcRESXto100(x));
// TODO putsTelemetryChannelValue(LCD_W-8, 6*FH, ed->srcRaw - MIXSRC_FIRST_TELEM, x);
if (ed->scale > 0) x = (x * 1024) / convertTelemValue(ed->srcRaw - MIXSRC_FIRST_TELEM + 1, ed->scale);
}
else {
sprintf(textx, "%d", calcRESXto100(x));
strAppendNumber(textx, calcRESXto100(x));
}
x = limit(-1024, x, 1024);
int y = limit<int>(-1024, expoFn(x), 1024);
sprintf(texty, "%d", calcRESXto100(y));
strAppendNumber(texty, calcRESXto100(y));
x = divRoundClosest(x*CURVE_SIDE_WIDTH, RESX);
y = CURVE_CENTER_Y + getCurveYCoord(expoFn, x, CURVE_SIDE_WIDTH);
@ -569,4 +569,3 @@ bool menuModelExposAll(evt_t event)
return true;
}

View file

@ -94,7 +94,7 @@ int findNextFileIndex(char * filename, const char * directory)
char extension[LEN_FILE_EXTENSION+1];
strncpy(extension, getFileExtension(filename), sizeof(extension));
do {
char * pos = strAppendNumber(indexPos, ++index);
char * pos = strAppendNumber(indexPos, ++index, 2);
strAppend(pos, extension);
if (!isFileAvailable(filename, directory)) {
return index;

View file

@ -145,13 +145,23 @@ char *strcat_zchar(char * dest, const char * name, uint8_t size, const char *def
#endif
#endif
char * strAppendNumber(char * dest, unsigned int value)
char * strAppendNumber(char * dest, unsigned int value, uint8_t digits, uint8_t radix)
{
div_t qr = div(value, 10);
*dest++ = '0' + qr.quot;
*dest++ = '0' + qr.rem;
*dest = '\0';
return dest;
if (digits == 0) {
unsigned int tmp = value;
digits = 1;
while (tmp >= 10) {
++digits;
tmp /= radix;
}
}
dest[digits] = '\0';
while(digits > 0) {
div_t qr = div(value, radix);
dest[--digits] = (qr.rem >= 10 ? 'A' : '0') + qr.rem;
value = qr.quot;
}
return dest + digits;
}
#if defined(CPUARM) || defined(SDCARD)

View file

@ -19,7 +19,7 @@
*/
char * strAppend(char * dest, const char * source, int len=0);
char * strAppendNumber(char * dest, unsigned int number);
char * strAppendNumber(char * dest, unsigned int value, uint8_t digits=0, uint8_t radix=10);
char * strSetCursor(char * dest, int position);
char * strAppendDate(char * str, bool time=false);
char * strAppendFilename(char * dest, const char * filename, const int size);