My use case is that I was doing "burn-in" testing of the board with all components attached/assembled, but not arming or flying - just a steady-state run test to ensure there were no glitches, shorts, reboots, or resets. I wanted to monitor uptime using the OLED display and discovered that it rolled-over after 99 minutes, which normally would be just fine (who flies on a single battery for over an hour and a half?) but with I'd leave it running on my bench with an AC/DC power adapter and then come back 2-hours later to check it and wouldn't know for sure if it had rebooted or not - I needed a third digit for minutes.
Here's the original code:
Code: Select all
void print_uptime(uint16_t sec) {
uint16_t m, s;
char line[6] = "--:--";
m = sec / 60;
s = sec - (60 * m);
line[0] = digit10(m);
line[1] = digit1(m);
line[3] = digit10(s);
line[4] = digit1(s);
LCDprintChar(line);
}
Clean, easy-to-read, I like it.
Here's my modification:
Code: Select all
void print_uptime(uint16_t sec) {
uint16_t m, s;
char line[7] = "---:--";
m = sec / 60;
s = sec - (60 * m);
line[0] = digit100(m);
line[1] = digit10(m);
line[2] = digit1(m);
line[4] = digit10(s);
line[5] = digit1(s);
LCDprintChar(line);
}
Notable changes:
1. Extra dash on the minute value for the line[] character array
2. New value for line[0] and line[1], and a new line[2]
3. Seconds placeholder line[3] and line[4] shifted to line[4] and line[5] to account for the extra minutes digit
Simple, simple adjustment. This modification allows the display of uptime in excess of 16 hours - hopefully enough for anybody. I debated adding 'hour' support but decided this was sufficient.
I went on a limb and guessed there was a "digit100" function - and I was right! (yay me!)
This works as-is, but to maintain compatibility with other functions of the display code, I also had to remove one of the two spaces from the code that calls print_uptime for the multi-line display:
Code: Select all
case 8:// uptime, eeprom set#
strcpy_P(line1,PSTR("Up ")); LCDprintChar(line1); print_uptime(millis() / 1000 );
strcpy_P(line1,PSTR(" Cset -")); line1[7] = digit1(global_conf.currentSet); LCDprintChar(line1);
Note the two spaces before Cset? That's space I can take to keep this display from overrunning the width. Tweaked to:
Code: Select all
case 8:// uptime, eeprom set#
strcpy_P(line1,PSTR("Up ")); LCDprintChar(line1); print_uptime(millis() / 1000 );
strcpy_P(line1,PSTR(" Cset -")); line1[7] = digit1(global_conf.currentSet); LCDprintChar(line1);
print_uptime is also used in a double-line display, but since I don't have one, I can't test to see if there are adverse affects of this minor mod. Use at your own risk, YMMV, etc.