My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

duration_t.h 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #ifndef __DURATION_T__
  23. #define __DURATION_T__
  24. struct duration_t {
  25. /**
  26. * @brief Duration is stored in seconds
  27. */
  28. uint32_t value;
  29. /**
  30. * @brief Constructor
  31. */
  32. duration_t()
  33. : duration_t(0) {};
  34. /**
  35. * @brief Constructor
  36. *
  37. * @param seconds The number of seconds
  38. */
  39. duration_t(uint32_t const &seconds) {
  40. this->value = seconds;
  41. }
  42. /**
  43. * @brief Equality comparison
  44. * @details Overloads the equality comparison operator
  45. *
  46. * @param value The number of seconds to compare to
  47. * @return True if both durations are equal
  48. */
  49. bool operator==(const uint32_t &value) const {
  50. return (this->value == value);
  51. }
  52. /**
  53. * @brief Inequality comparison
  54. * @details Overloads the inequality comparison operator
  55. *
  56. * @param value The number of seconds to compare to
  57. * @return False if both durations are equal
  58. */
  59. bool operator!=(const uint32_t &value) const {
  60. return ! this->operator==(value);
  61. }
  62. /**
  63. * @brief Formats the duration as years
  64. * @return The number of years
  65. */
  66. inline uint8_t year() const {
  67. return this->day() / 365;
  68. }
  69. /**
  70. * @brief Formats the duration as days
  71. * @return The number of days
  72. */
  73. inline uint16_t day() const {
  74. return this->hour() / 24;
  75. }
  76. /**
  77. * @brief Formats the duration as hours
  78. * @return The number of hours
  79. */
  80. inline uint32_t hour() const {
  81. return this->minute() / 60;
  82. }
  83. /**
  84. * @brief Formats the duration as minutes
  85. * @return The number of minutes
  86. */
  87. inline uint32_t minute() const {
  88. return this->second() / 60;
  89. }
  90. /**
  91. * @brief Formats the duration as seconds
  92. * @return The number of seconds
  93. */
  94. inline uint32_t second() const {
  95. return this->value;
  96. }
  97. /**
  98. * @brief Formats the duration as a string
  99. * @details String will be formated using a "full" representation of duration
  100. *
  101. * @param buffer The array pointed to must be able to accommodate 21 bytes
  102. *
  103. * Output examples:
  104. * 123456789012345678901 (strlen)
  105. * 135y 364d 23h 59m 59s
  106. * 364d 23h 59m 59s
  107. * 23h 59m 59s
  108. * 59m 59s
  109. * 59s
  110. */
  111. void toString(char *buffer) const {
  112. int y = this->year(),
  113. d = this->day() % 365,
  114. h = this->hour() % 24,
  115. m = this->minute() % 60,
  116. s = this->second() % 60;
  117. if (y) sprintf_P(buffer, PSTR("%iy %id %ih %im %is"), y, d, h, m, s);
  118. else if (d) sprintf_P(buffer, PSTR("%id %ih %im %is"), d, h, m, s);
  119. else if (h) sprintf_P(buffer, PSTR("%ih %im %is"), h, m, s);
  120. else if (m) sprintf_P(buffer, PSTR("%im %is"), m, s);
  121. else sprintf_P(buffer, PSTR("%is"), s);
  122. }
  123. /**
  124. * @brief Formats the duration as a string
  125. * @details String will be formated using a "digital" representation of duration
  126. *
  127. * @param buffer The array pointed to must be able to accommodate 10 bytes
  128. *
  129. * Output examples:
  130. * 123456789 (strlen)
  131. * 99:59
  132. * 11d 12:33
  133. */
  134. uint8_t toDigital(char *buffer, bool with_days=false) const {
  135. uint16_t h = uint16_t(this->hour()),
  136. m = uint16_t(this->minute() % 60UL);
  137. if (with_days) {
  138. uint16_t d = this->day();
  139. sprintf_P(buffer, PSTR("%ud %02u:%02u"), d, h % 24, m);
  140. return d >= 10 ? 8 : 7;
  141. }
  142. else if (h < 100) {
  143. sprintf_P(buffer, PSTR("%02u:%02u"), h % 24, m);
  144. return 5;
  145. }
  146. else {
  147. sprintf_P(buffer, PSTR("%u:%02u"), h, m);
  148. return 6;
  149. }
  150. }
  151. };
  152. #endif // __DURATION_T__