-
-
Notifications
You must be signed in to change notification settings - Fork 19.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Renamed timestamp_t to duration_t #4390
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
/** | ||
* Marlin 3D Printer Firmware | ||
* Copyright (C) 2016 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/>. | ||
* | ||
*/ | ||
|
||
#ifndef __DURATION_T__ | ||
#define __DURATION_T__ | ||
|
||
struct duration_t { | ||
/** | ||
* @brief Duration is stored in seconds | ||
*/ | ||
uint32_t value; | ||
|
||
/** | ||
* @brief Constructor | ||
*/ | ||
duration_t() | ||
: duration_t(0) {}; | ||
|
||
/** | ||
* @brief Constructor | ||
* | ||
* @param seconds The number of seconds | ||
*/ | ||
duration_t(uint32_t const &seconds) { | ||
this->value = seconds; | ||
} | ||
|
||
/** | ||
* @brief Equality comparison | ||
* @details Overloads the equality comparison operator | ||
* | ||
* @param value The number of seconds to compare to | ||
* @return True if both durations are equal | ||
*/ | ||
bool operator==(const uint32_t &value) const { | ||
return (this->value == value); | ||
} | ||
|
||
/** | ||
* @brief Inequality comparison | ||
* @details Overloads the inequality comparison operator | ||
* | ||
* @param value The number of seconds to compare to | ||
* @return False if both durations are equal | ||
*/ | ||
bool operator!=(const uint32_t &value) const { | ||
return ! this->operator==(value); | ||
} | ||
|
||
/** | ||
* @brief Formats the duration as years | ||
* @return The number of years | ||
*/ | ||
inline uint8_t year() const { | ||
return this->day() / 365; | ||
} | ||
|
||
/** | ||
* @brief Formats the duration as days | ||
* @return The number of days | ||
*/ | ||
inline uint16_t day() const { | ||
return this->hour() / 24; | ||
} | ||
|
||
/** | ||
* @brief Formats the duration as hours | ||
* @return The number of hours | ||
*/ | ||
inline uint32_t hour() const { | ||
return this->minute() / 60; | ||
} | ||
|
||
/** | ||
* @brief Formats the duration as minutes | ||
* @return The number of minutes | ||
*/ | ||
inline uint32_t minute() const { | ||
return this->second() / 60; | ||
} | ||
|
||
/** | ||
* @brief Formats the duration as seconds | ||
* @return The number of seconds | ||
*/ | ||
inline uint32_t second() const { | ||
return this->value; | ||
} | ||
|
||
/** | ||
* @brief Formats the duration as a string | ||
* @details String will be formated using a "full" representation of duration | ||
* | ||
* @param buffer The 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 | ||
*/ | ||
void toString(char *buffer) const { | ||
int y = this->year(), | ||
d = this->day() % 365, | ||
h = this->hour() % 24, | ||
m = this->minute() % 60, | ||
s = this->second() % 60; | ||
|
||
if (y) sprintf_P(buffer, PSTR("%iy %id %ih %im %is"), y, d, h, m, s); | ||
else if (d) sprintf_P(buffer, PSTR("%id %ih %im %is"), d, h, m, s); | ||
else if (h) sprintf_P(buffer, PSTR("%ih %im %is"), h, m, s); | ||
else if (m) sprintf_P(buffer, PSTR("%im %is"), m, s); | ||
else sprintf_P(buffer, PSTR("%is"), s); | ||
} | ||
|
||
/** | ||
* @brief Formats the duration as a string | ||
* @details String will be formated using a "digital" representation of duration | ||
* | ||
* @param buffer The array pointed to must be able to accommodate 10 bytes | ||
* | ||
* Output examples: | ||
* 1234567890 (strlen) | ||
* 1193046:59 | ||
*/ | ||
void toDigital(char *buffer) const { | ||
int h = this->hour() % 24, | ||
m = this->minute() % 60; | ||
|
||
sprintf_P(buffer, PSTR("%02i:%02i"), h, m); | ||
} | ||
}; | ||
|
||
#endif // __DURATION_T__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So
MSG_PRINT_TIME
isn't used anymore, right? Should be removed from language files ASAP (#4395)