My Marlin configs for Fabrikator Mini and CTC i3 Pro B
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

timestamp_t.h 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 Timestamp blank constructor
  31. */
  32. timestamp_t()
  33. : timestamp_t(0) {};
  34. /**
  35. * @briefTimestamp 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 timestamp in 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 timestamp in 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 timestamp in 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 timestamp in 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 timestamp in seconds
  73. * @return The number of seconds
  74. */
  75. inline uint32_t second() const {
  76. return this->timestamp;
  77. }
  78. /**
  79. * @brief Formats the timestamp 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 when
  83. * on standard mode or 10 bytes otherwise.
  84. * @param shorty If true a short representation will be returned.
  85. *
  86. * Standard toString() output examples:
  87. * 123456789012345678901 (strlen)
  88. * 135y 364d 23h 59m 59s
  89. * 364d 23h 59m 59s
  90. * 23h 59m 59s
  91. * 59m 59s
  92. * 59s
  93. *
  94. * Short toString() output examples:
  95. * 1234567890 (strlen)
  96. * 1193046:59
  97. *
  98. */
  99. void toString(char *buffer, bool const &shorty = false) const {
  100. int h = this->hour() % 24,
  101. m = this->minute() % 60;
  102. if (shorty) sprintf_P(buffer, PSTR("%02i:%02i"), h, m);
  103. else {
  104. int y = this->year(),
  105. d = this->day() % 365,
  106. s = this->second() % 60;
  107. if (y) sprintf_P(buffer, PSTR("%iy %id %ih %im %is"), y, d, h, m, s);
  108. else if (d) sprintf_P(buffer, PSTR("%id %ih %im %is"), d, h, m, s);
  109. else if (h) sprintf_P(buffer, PSTR("%ih %im %is"), h, m, s);
  110. else if (m) sprintf_P(buffer, PSTR("%im %is"), m, s);
  111. else sprintf_P(buffer, PSTR("%is"), s);
  112. }
  113. }
  114. };
  115. #endif // __TIMESTAMP_T__