My Marlin configs for Fabrikator Mini and CTC i3 Pro B
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

timestamp_t.h 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 __TIMESTAMP_T__
  23. #define __TIMESTAMP_T__
  24. struct timestamp_t {
  25. /**
  26. * @brief Number of seconds
  27. */
  28. uint32_t timestamp;
  29. /**
  30. * @brief Date time blank constructor
  31. */
  32. timestamp_t()
  33. : timestamp_t(0) {};
  34. /**
  35. * @brief Date time constructor
  36. * @details Initializes the timestamp_t structure based on a number of seconds
  37. *
  38. * @param seconds The number of seconds
  39. */
  40. timestamp_t(uint32_t const &seconds) {
  41. this->timestamp = seconds;
  42. }
  43. /**
  44. * @brief Formats the date as number of years
  45. * @return The number of years
  46. */
  47. inline uint8_t year() const {
  48. return this->day() / 365;
  49. }
  50. /**
  51. * @brief Formats the date as number of days
  52. * @return The number of days
  53. */
  54. inline uint16_t day() const {
  55. return this->hour() / 24;
  56. }
  57. /**
  58. * @brief Formats the date as number of hours
  59. * @return The number of hours
  60. */
  61. inline uint32_t hour() const {
  62. return this->minute() / 60;
  63. }
  64. /**
  65. * @brief Formats the date as number of minutes
  66. * @return The number of minutes
  67. */
  68. inline uint32_t minute() const {
  69. return this->second() / 60;
  70. }
  71. /**
  72. * @brief Formats the date as number of seconds
  73. * @return The number of seconds
  74. */
  75. inline uint32_t second() const {
  76. return this->timestamp;
  77. }
  78. /**
  79. * @brief Formats the date as a string
  80. * @details Returns the timestamp formated as a string
  81. *
  82. * @param buffer The array pointed to must be able to accommodate 21 bytes
  83. *
  84. * String output examples:
  85. * 123456789012345678901 (strlen)
  86. * 135y 364d 23h 59m 59s
  87. * 364d 23h 59m 59s
  88. * 23h 59m 59s
  89. * 59m 59s
  90. * 59s
  91. *
  92. */
  93. void toString(char *buffer) const {
  94. int y = this->year(),
  95. d = this->day() % 365,
  96. h = this->hour() % 24,
  97. m = this->minute() % 60,
  98. s = this->second() % 60;
  99. if (y) sprintf_P(buffer, PSTR("%iy %id %ih %im %is"), y, d, h, m, s);
  100. else if (d) sprintf_P(buffer, PSTR("%id %ih %im %is"), d, h, m, s);
  101. else if (h) sprintf_P(buffer, PSTR("%ih %im %is"), h, m, s);
  102. else if (m) sprintf_P(buffer, PSTR("%im %is"), m, s);
  103. else sprintf_P(buffer, PSTR("%is"), s);
  104. }
  105. };
  106. #endif // __TIMESTAMP_T__