My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

utility.h 3.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 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 <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #pragma once
  23. #include "../inc/MarlinConfigPre.h"
  24. #include "../core/types.h"
  25. #include "../core/millis_t.h"
  26. void safe_delay(millis_t ms); // Delay ensuring that temperatures are updated and the watchdog is kept alive.
  27. #if ENABLED(SERIAL_OVERRUN_PROTECTION)
  28. void serial_delay(const millis_t ms);
  29. #else
  30. inline void serial_delay(const millis_t) {}
  31. #endif
  32. #if (GRID_MAX_POINTS_X) && (GRID_MAX_POINTS_Y)
  33. // 16x16 bit arrays
  34. template <int W, int H>
  35. struct FlagBits {
  36. typename IF<(W>8), uint16_t, uint8_t>::type bits[H];
  37. void fill() { memset(bits, 0xFF, sizeof(bits)); }
  38. void reset() { memset(bits, 0x00, sizeof(bits)); }
  39. void unmark(const uint8_t x, const uint8_t y) { CBI(bits[y], x); }
  40. void mark(const uint8_t x, const uint8_t y) { SBI(bits[y], x); }
  41. bool marked(const uint8_t x, const uint8_t y) { return TEST(bits[y], x); }
  42. inline void unmark(const xy_int8_t &xy) { unmark(xy.x, xy.y); }
  43. inline void mark(const xy_int8_t &xy) { mark(xy.x, xy.y); }
  44. inline bool marked(const xy_int8_t &xy) { return marked(xy.x, xy.y); }
  45. };
  46. typedef FlagBits<GRID_MAX_POINTS_X, GRID_MAX_POINTS_Y> MeshFlags;
  47. #endif
  48. #if ENABLED(DEBUG_LEVELING_FEATURE)
  49. void log_machine_info();
  50. #else
  51. #define log_machine_info() NOOP
  52. #endif
  53. /**
  54. * A restorer instance remembers a variable's value before setting a
  55. * new value, then restores the old value when it goes out of scope.
  56. * Put operator= on your type to get extended behavior on value change.
  57. */
  58. template<typename T>
  59. class restorer {
  60. T& ref_;
  61. T val_;
  62. public:
  63. restorer(T& perm) : ref_(perm), val_(perm) {}
  64. restorer(T& perm, T temp_val) : ref_(perm), val_(perm) { perm = temp_val; }
  65. ~restorer() { restore(); }
  66. inline void restore() { ref_ = val_; }
  67. };
  68. #define REMEMBER(N,X,V...) restorer<__typeof__(X)> restorer_##N(X, ##V)
  69. #define RESTORE(N) restorer_##N.restore()
  70. // Converts from an uint8_t in the range of 0-255 to an uint8_t
  71. // in the range 0-100 while avoiding rounding artifacts
  72. constexpr uint8_t ui8_to_percent(const uint8_t i) { return (int(i) * 100 + 127) / 255; }
  73. // Axis names for G-code parsing, reports, etc.
  74. const xyze_char_t axis_codes LOGICAL_AXIS_ARRAY('E', 'X', 'Y', 'Z', AXIS4_NAME, AXIS5_NAME, AXIS6_NAME, AXIS7_NAME, AXIS8_NAME, AXIS9_NAME);
  75. #if NUM_AXES <= XYZ && !HAS_EXTRUDERS
  76. #define AXIS_CHAR(A) ((char)('X' + A))
  77. #define IAXIS_CHAR AXIS_CHAR
  78. #else
  79. const xyze_char_t iaxis_codes LOGICAL_AXIS_ARRAY('E', 'X', 'Y', 'Z', 'I', 'J', 'K', 'U', 'V', 'W');
  80. #define AXIS_CHAR(A) axis_codes[A]
  81. #define IAXIS_CHAR(A) iaxis_codes[A]
  82. #endif