Prusa MINI Firmware overview
duration_t Struct Reference

#include <duration_t.h>

Inheritance diagram for duration_t:
Collaboration diagram for duration_t:

Public Member Functions

 duration_t ()
 Constructor. More...
 
 duration_t (uint32_t const &seconds)
 Constructor. More...
 
bool operator== (const uint32_t &value) const
 Equality comparison. More...
 
bool operator!= (const uint32_t &value) const
 Inequality comparison. More...
 
uint8_t year () const
 Formats the duration as years. More...
 
uint16_t day () const
 Formats the duration as days. More...
 
uint32_t hour () const
 Formats the duration as hours. More...
 
uint32_t minute () const
 Formats the duration as minutes. More...
 
uint32_t second () const
 Formats the duration as seconds. More...
 
char * toString (char *const buffer) const
 Formats the duration as a string. More...
 
uint8_t toDigital (char *buffer, bool with_days=false) const
 Formats the duration as a string. More...
 

Public Attributes

uint32_t value
 Duration is stored in seconds. More...
 

Detailed Description

Marlin 3D Printer Firmware Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]

Based on Sprinter and grbl. Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Constructor & Destructor Documentation

◆ duration_t() [1/2]

duration_t::duration_t ( )

Constructor.

36  : duration_t(0) {};

◆ duration_t() [2/2]

duration_t::duration_t ( uint32_t const seconds)

Constructor.

Parameters
secondsThe number of seconds
43  {
44  this->value = seconds;
45  }

Member Function Documentation

◆ operator==()

bool duration_t::operator== ( const uint32_t &  value) const

Equality comparison.

Overloads the equality comparison operator

Parameters
valueThe number of seconds to compare to
Returns
True if both durations are equal
54  {
55  return (this->value == value);
56  }
Here is the caller graph for this function:

◆ operator!=()

bool duration_t::operator!= ( const uint32_t &  value) const

Inequality comparison.

Overloads the inequality comparison operator

Parameters
valueThe number of seconds to compare to
Returns
False if both durations are equal
65  {
66  return ! this->operator==(value);
67  }
Here is the call graph for this function:

◆ year()

uint8_t duration_t::year ( ) const

Formats the duration as years.

Returns
The number of years
73  {
74  return this->day() / 365;
75  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ day()

uint16_t duration_t::day ( ) const

Formats the duration as days.

Returns
The number of days
81  {
82  return this->hour() / 24;
83  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ hour()

uint32_t duration_t::hour ( ) const

Formats the duration as hours.

Returns
The number of hours
89  {
90  return this->minute() / 60;
91  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ minute()

uint32_t duration_t::minute ( ) const

Formats the duration as minutes.

Returns
The number of minutes
97  {
98  return this->second() / 60;
99  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ second()

uint32_t duration_t::second ( ) const

Formats the duration as seconds.

Returns
The number of seconds
105  {
106  return this->value;
107  }
Here is the caller graph for this function:

◆ toString()

char* duration_t::toString ( char *const  buffer) const

Formats the duration as a string.

String will be formated using a "full" representation of duration

Parameters
bufferThe array pointed to must be able to accommodate 21 bytes

Output examples: 123456789012345678901 (strlen) 135y 364d 23h 59m 59s 364d 23h 59m 59s 23h 59m 59s 59m 59s 59s

123  {
124  int y = this->year(),
125  d = this->day() % 365,
126  h = this->hour() % 24,
127  m = this->minute() % 60,
128  s = this->second() % 60;
129 
130  if (y) sprintf_P(buffer, PSTR("%iy %id %ih %im %is"), y, d, h, m, s);
131  else if (d) sprintf_P(buffer, PSTR("%id %ih %im %is"), d, h, m, s);
132  else if (h) sprintf_P(buffer, PSTR("%ih %im %is"), h, m, s);
133  else if (m) sprintf_P(buffer, PSTR("%im %is"), m, s);
134  else sprintf_P(buffer, PSTR("%is"), s);
135  return buffer;
136  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ toDigital()

uint8_t duration_t::toDigital ( char *  buffer,
bool  with_days = false 
) const

Formats the duration as a string.

String will be formated using a "digital" representation of duration

Parameters
bufferThe array pointed to must be able to accommodate 10 bytes

Output examples: 123456789 (strlen) 99:59 11d 12:33

149  {
150  uint16_t h = uint16_t(this->hour()),
151  m = uint16_t(this->minute() % 60UL);
152  if (with_days) {
153  uint16_t d = this->day();
154  sprintf_P(buffer, PSTR("%hud %02hu:%02hu"), d, h % 24, m);
155  return d >= 10 ? 9 : 8;
156  }
157  else if (h < 100) {
158  sprintf_P(buffer, PSTR("%02hu:%02hu"), h, m);
159  return 5;
160  }
161  else {
162  sprintf_P(buffer, PSTR("%hu:%02hu"), h, m);
163  return 6;
164  }
165  }
Here is the call graph for this function:

Member Data Documentation

◆ value

uint32_t duration_t::value

Duration is stored in seconds.

duration_t::hour
uint32_t hour() const
Formats the duration as hours.
Definition: duration_t.h:89
duration_t::year
uint8_t year() const
Formats the duration as years.
Definition: duration_t.h:73
duration_t::minute
uint32_t minute() const
Formats the duration as minutes.
Definition: duration_t.h:97
sprintf_P
#define sprintf_P(s,...)
Definition: pgmspace.h:72
duration_t::operator==
bool operator==(const uint32_t &value) const
Equality comparison.
Definition: duration_t.h:54
PSTR
#define PSTR(str)
Definition: pgmspace.h:31
duration_t::day
uint16_t day() const
Formats the duration as days.
Definition: duration_t.h:81
duration_t::value
uint32_t value
Duration is stored in seconds.
Definition: duration_t.h:30
duration_t::duration_t
duration_t()
Constructor.
Definition: duration_t.h:35
duration_t::second
uint32_t second() const
Formats the duration as seconds.
Definition: duration_t.h:105