//void updateUptime()
//{
//  sysUptime_mins++;
//  if (sysUptime_mins == 60)
//  {
//    sysUptime_mins = 0;
//    sysUptime_hours++;
//  }
//  if (sysUptime_hours == 24)
//  {
//    sysUptime_hours = 0;
//    sysUptime_days++;
//  }
//}

//void buildUptimeString()
//{
//  if (sysUptime_days > 0)
//    sprintf(uptimeStr, "%dd %02d:%02d", sysUptime_days, sysUptime_hours, sysUptime_mins);
//  else
//    sprintf(uptimeStr, "%02d:%02d", sysUptime_hours, sysUptime_mins);
//}


void updateUptime()
{
  if (millis() >= 3000000000) // save expected rollover
  {
    sysUptime.highMillis = 1;
  }
  if (millis() <= 100000 && sysUptime.highMillis == 1) // save actual rollover
  {
    sysUptime.rollover++;
    sysUptime.highMillis = 0;
  }

  unsigned long secsUp = millis() / 1000;
  sysUptime.sec = secsUp % 60;
  sysUptime.min = (secsUp / 60) % 60;
  sysUptime.hour = (secsUp / (60 * 60)) % 24;
  sysUptime.day = (sysUptime.rollover * 50) + (secsUp / (60 * 60 * 24)); // millis rollover ~50days
}

char* getUptimeStr(bool includeSeconds) {
  updateUptime();
  if(includeSeconds) {
    if(sysUptime.day == 0) sprintf(sysUptime.uptimeStr, "%02u:%02u:%02u", sysUptime.hour, sysUptime.min, sysUptime.sec);
    else sprintf(sysUptime.uptimeStr, "%ud %02u:%02u:%02u", sysUptime.day, sysUptime.hour, sysUptime.min, sysUptime.sec);
  }
  else {
    if(sysUptime.day == 0) sprintf(sysUptime.uptimeStr, "%02u:%02u", sysUptime.hour, sysUptime.min);
    else sprintf(sysUptime.uptimeStr, "%ud %02u:%02u", sysUptime.day, sysUptime.hour, sysUptime.min);
  }
  return sysUptime.uptimeStr;
}
