mirror of
https://github.com/opentx/opentx.git
synced 2025-07-15 04:15:26 +03:00
parent
dbaa4058df
commit
cd1716b941
2 changed files with 56 additions and 17 deletions
|
@ -111,7 +111,7 @@ void ModelCell::loadBitmap()
|
||||||
getTimerString(timer, 0);
|
getTimerString(timer, 0);
|
||||||
for (uint8_t i = 0; i < MAX_TIMERS; i++) {
|
for (uint8_t i = 0; i < MAX_TIMERS; i++) {
|
||||||
if (partialmodel.timers[i].mode != 0 && partialmodel.timers[i].persistent) {
|
if (partialmodel.timers[i].mode != 0 && partialmodel.timers[i].persistent) {
|
||||||
getTimerString(timer, partialmodel.timers[i].value);
|
getTimerString(timer, partialmodel.timers[i].value, 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -170,6 +170,10 @@ char * strAppendStringWithIndex(char * dest, const char * s, int idx)
|
||||||
return strAppendUnsigned(strAppend(dest, s), abs(idx));
|
return strAppendUnsigned(strAppend(dest, s), abs(idx));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constexpr int32_t secondsPerDay = 24 * 3600;
|
||||||
|
constexpr int32_t secondsPer99Hours = 99*3600 + 59*60 + 59;
|
||||||
|
constexpr int32_t secondsPerYear = 365 * secondsPerDay;
|
||||||
|
|
||||||
char * getTimerString(char * dest, int32_t tme, uint8_t hours)
|
char * getTimerString(char * dest, int32_t tme, uint8_t hours)
|
||||||
{
|
{
|
||||||
char * s = dest;
|
char * s = dest;
|
||||||
|
@ -180,28 +184,63 @@ char * getTimerString(char * dest, int32_t tme, uint8_t hours)
|
||||||
*s++ = '-';
|
*s++ = '-';
|
||||||
}
|
}
|
||||||
|
|
||||||
qr = div((int)tme, 60);
|
if (tme < secondsPerDay) {
|
||||||
|
qr = div((int) tme, 60);
|
||||||
|
|
||||||
if (hours) {
|
if (hours) {
|
||||||
div_t qr2 = div(qr.quot, 60);
|
div_t qr2 = div(qr.quot, 60);
|
||||||
|
*s++ = '0' + (qr2.quot / 10);
|
||||||
|
*s++ = '0' + (qr2.quot % 10);
|
||||||
|
*s++ = ':';
|
||||||
|
qr.quot = qr2.rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!hours && qr.quot > 99) {
|
||||||
|
*s++ = '0' + (qr.quot / 100);
|
||||||
|
qr.quot = qr.quot % 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
*s++ = '0' + (qr.quot / 10);
|
||||||
|
*s++ = '0' + (qr.quot % 10);
|
||||||
|
*s++ = ':';
|
||||||
|
*s++ = '0' + (qr.rem / 10);
|
||||||
|
*s++ = '0' + (qr.rem % 10);
|
||||||
|
*s = '\0';
|
||||||
|
}
|
||||||
|
else if (tme < secondsPer99Hours) {
|
||||||
|
qr = div((int) tme, 3600);
|
||||||
|
div_t qr2 = div(qr.rem, 60);
|
||||||
|
*s++ = '0' + (qr.quot / 10);
|
||||||
|
*s++ = '0' + (qr.quot % 10);
|
||||||
|
*s++ = 'H';
|
||||||
*s++ = '0' + (qr2.quot / 10);
|
*s++ = '0' + (qr2.quot / 10);
|
||||||
*s++ = '0' + (qr2.quot % 10);
|
*s++ = '0' + (qr2.quot % 10);
|
||||||
*s++ = ':';
|
*s = '\0';
|
||||||
qr.quot = qr2.rem;
|
|
||||||
}
|
}
|
||||||
|
else if (tme < secondsPerYear) {
|
||||||
if (!hours && qr.quot > 99) {
|
qr = div((int) tme, secondsPerDay);
|
||||||
|
div_t qr2 = div(qr.rem, 60);
|
||||||
*s++ = '0' + (qr.quot / 100);
|
*s++ = '0' + (qr.quot / 100);
|
||||||
qr.quot = qr.quot % 100;
|
*s++ = '0' + (qr.quot / 10);
|
||||||
|
*s++ = '0' + (qr.quot % 10);
|
||||||
|
*s++ = 'D';
|
||||||
|
*s++ = '0' + (qr2.quot / 10);
|
||||||
|
*s++ = '0' + (qr2.quot % 10);
|
||||||
|
*s++ = 'H';
|
||||||
|
*s = '\0';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
qr = div((int) tme, secondsPerYear);
|
||||||
|
div_t qr2 = div(qr.rem, secondsPerDay);
|
||||||
|
*s++ = '0' + (qr.quot / 10);
|
||||||
|
*s++ = '0' + (qr.quot % 10);
|
||||||
|
*s++ = 'Y';
|
||||||
|
*s++ = 'Y';
|
||||||
|
*s++ = '0' + (qr2.quot / 10);
|
||||||
|
*s++ = '0' + (qr2.quot % 10);
|
||||||
|
*s++ = 'D';
|
||||||
|
*s = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
*s++ = '0' + (qr.quot / 10);
|
|
||||||
*s++ = '0' + (qr.quot % 10);
|
|
||||||
*s++ = ':';
|
|
||||||
*s++ = '0' + (qr.rem / 10);
|
|
||||||
*s++ = '0' + (qr.rem % 10);
|
|
||||||
*s = '\0';
|
|
||||||
|
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue