Minor Tweak to print_uptime in LCD.ino - 3-digit minute

This forum is dedicated to software development related to MultiWii.
It is not the right place to submit a setup problem.
Software download
Post Reply
Autonym
Posts: 12
Joined: Wed Nov 06, 2013 7:05 pm

Minor Tweak to print_uptime in LCD.ino - 3-digit minute

Post by Autonym »

This is a special-use modification that I don't expect to see in the main branch, but this change was useful to me, and I thought I'd share it. I'm not an uber-coder, this is my first, simple tweak.

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.

User avatar
Hamburger
Posts: 2582
Joined: Tue Mar 01, 2011 2:14 pm
Location: air
Contact:

Re: Minor Tweak to print_uptime in LCD.ino - 3-digit minute

Post by Hamburger »

ok, cool. This would work up to about 270 minutes. Good to see you even checked against the line overrun.
I can easily add it to the main branch for next version - that could even get other pilots started to aim for long flight times.

Autonym
Posts: 12
Joined: Wed Nov 06, 2013 7:05 pm

Re: Minor Tweak to print_uptime in LCD.ino - 3-digit minute

Post by Autonym »

With seconds being an uint16_t, shouldn't give us a max value of 32,768 seconds (~546 minutes) before roll-over?

Perhaps I'm missing something in my noobishness.

Either/Or, doesn't really matter - it goes a long time! :)

Thanks for your consideration!

(edit: unit16 = 16 bits, doh!)

User avatar
Hamburger
Posts: 2582
Joined: Tue Mar 01, 2011 2:14 pm
Location: air
Contact:

Re: Minor Tweak to print_uptime in LCD.ino - 3-digit minute

Post by Hamburger »

Right.
I somehow thought along 16k. My error.

Uint16 should be sufficient for most copters.

Post Reply