Prusa MINI Firmware overview
utility.h
Go to the documentation of this file.
1 /**
2  * Marlin 3D Printer Firmware
3  * Copyright (c) 2019 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 #pragma once
23 
24 #include "../inc/MarlinConfigPre.h"
25 #include "../core/types.h"
26 
27 // Delay that ensures heaters and watchdog are kept alive
28 void safe_delay(millis_t ms);
29 
30 // A delay to provide brittle hosts time to receive bytes
31 inline void serial_delay(const millis_t ms) {
32  #if ENABLED(SERIAL_OVERRUN_PROTECTION)
33  safe_delay(ms);
34  #else
35  UNUSED(ms);
36  #endif
37 }
38 
39 #if GRID_MAX_POINTS_X && GRID_MAX_POINTS_Y
40 
41  // 16x16 bit arrays
42  template <int W, int H>
43  struct FlagBits {
44  typename IF<(W>8), uint16_t, uint8_t>::type bits[H];
45  void fill() { memset(bits, 0xFF, sizeof(bits)); }
46  void reset() { memset(bits, 0x00, sizeof(bits)); }
47  void unmark(const uint8_t x, const uint8_t y) { CBI(bits[y], x); }
48  void mark(const uint8_t x, const uint8_t y) { SBI(bits[y], x); }
49  bool marked(const uint8_t x, const uint8_t y) { return TEST(bits[y], x); }
50  inline void unmark(const xy_int8_t &xy) { unmark(xy.y, xy.x); }
51  inline void mark(const xy_int8_t &xy) { mark(xy.y, xy.x); }
52  inline bool marked(const xy_int8_t &xy) { return marked(xy.y, xy.x); }
53  };
54 
55  typedef FlagBits<GRID_MAX_POINTS_X, GRID_MAX_POINTS_Y> MeshFlags;
56 
57 #endif
58 
59 #if ENABLED(DEBUG_LEVELING_FEATURE)
60  void log_machine_info();
61 #else
62  #define log_machine_info() NOOP
63 #endif
64 
65 template<typename T>
66 class restorer {
67  T& ref_;
68  T val_;
69 public:
70  restorer(T& perm) : ref_(perm), val_(perm) {}
71  restorer(T& perm, T temp_val) : ref_(perm), val_(perm) { perm = temp_val; }
72  ~restorer() { restore(); }
73  inline void restore() { ref_ = val_; }
74 };
75 
76 #define REMEMBER(N,X,V...) const restorer<typeof(X)> restorer_##N(X, ##V)
77 #define RESTORE(N) restorer_##N.restore()
78 
79 // Converts from an uint8_t in the range of 0-255 to an uint8_t
80 // in the range 0-100 while avoiding rounding artifacts
81 constexpr uint8_t ui8_to_percent(const uint8_t i) { return (int(i) * 100 + 127) / 255; }
XYZval::z
T z
Definition: types.h:286
SERIAL_CHAR
#define SERIAL_CHAR(x)
Definition: serial.h:69
XYZEval::z
T z
Definition: types.h:383
mbl
mesh_bed_leveling mbl
SERIAL_ECHO
#define SERIAL_ECHO(x)
Definition: serial.h:70
safe_delay
void safe_delay(millis_t ms)
Definition: utility.cpp:28
XYZval::x
T x
Definition: types.h:286
mesh_bed_leveling::get_z
static float get_z(const xy_pos_t &pos)
Definition: mesh_bed_leveling.h:107
HAS_Z_SERVO_PROBE
#define HAS_Z_SERVO_PROBE
Definition: Conditionals_LCD.h:495
probe_offset
constexpr xyz_pos_t probe_offset
Definition: probe.h:58
ftostr43sign
const char * ftostr43sign(const float &f, char plus)
Definition: numtostr.cpp:231
Planner::get_axis_position_mm
static float get_axis_position_mm(const AxisEnum axis)
Definition: planner.cpp:1526
Planner::leveling_active
static bool leveling_active
Definition: planner.h:276
SERIAL_ECHOPAIR
#define SERIAL_ECHOPAIR(V...)
Definition: serial.h:114
type
uint8_t type
Definition: UsbCore.h:184
i
uint8_t i
Definition: screen_test_graph.c:72
utility.h
AxisEnum
AxisEnum
Definition: types.h:36
Temperature::manage_heater
static void manage_heater() _O2
Definition: temperature.cpp:975
IS_CORE
#define IS_CORE
Definition: Conditionals_post.h:104
AUTO_BED_LEVELING_BILINEAR
#define AUTO_BED_LEVELING_BILINEAR
Definition: Configuration_A3ides_2209_MINI.h:1092
restorer::restorer
restorer(T &perm)
Definition: utility.h:70
current_position
xyze_pos_t current_position
Definition: motion.cpp:102
restorer
Definition: utility.h:66
LOOP_XYZ
#define LOOP_XYZ(VAR)
Definition: types.h:60
SERIAL_ECHOPGM
#define SERIAL_ECHOPGM(S)
Definition: serial.h:173
restorer::restore
void restore()
Definition: utility.h:73
SERIAL_ECHOLNPAIR
#define SERIAL_ECHOLNPAIR(V...)
Definition: serial.h:144
XYval
Definition: types.h:99
createSpeedLookupTable.a
list a
Definition: createSpeedLookupTable.py:29
unified_bed_leveling::get_z_correction
static float get_z_correction(const float &rx0, const float &ry0)
Definition: ubl.h:238
XYval::x
T x
Definition: types.h:185
restorer::restorer
restorer(T &perm, T temp_val)
Definition: utility.h:71
FIX_MOUNTED_PROBE
#define FIX_MOUNTED_PROBE
Definition: Configuration_A3ides_2209_MINI.h:798
restorer::~restorer
~restorer()
Definition: utility.h:72
uint8_t
const uint8_t[]
Definition: 404_html.c:3
bilinear_z_offset
float bilinear_z_offset(const xy_pos_t &raw)
XYZval::y
T y
Definition: types.h:286
delay
void delay(uint32_t ms)
Definition: wiring_time.c:42
IS_SCARA
#define IS_SCARA
Definition: Conditionals_LCD.h:544
CBI
#define CBI(A, B)
Definition: macros.h:89
ubl
unified_bed_leveling ubl
ui8_to_percent
constexpr uint8_t ui8_to_percent(const uint8_t i)
Definition: utility.h:81
Planner::fade_scaling_factor_for_z
static FORCE_INLINE float fade_scaling_factor_for_z(const float &)
Definition: planner.h:445
SERIAL_EOL
#define SERIAL_EOL()
Definition: serial.h:181
IF
Definition: types.h:73
TEST
#define TEST(n, b)
Definition: macros.h:81
XYval::y
T y
Definition: types.h:185
log_machine_info
#define log_machine_info()
Definition: utility.h:62
safe_delay
void safe_delay(millis_t ms)
Definition: utility.cpp:28
serial_delay
void serial_delay(const millis_t ms)
Definition: utility.h:31
SBI
#define SBI(A, B)
Definition: macros.h:85
SERIAL_ECHOLNPGM
#define SERIAL_ECHOLNPGM(S)
Definition: serial.h:174
thermalManager
Temperature thermalManager
Definition: temperature.cpp:89
UNUSED
#define UNUSED(X)
Definition: stm32f4xx_hal_def.h:74
millis_t
uint32_t millis_t
Definition: millis_t.h:26
ENABLED
#define ENABLED(V...)
Definition: macros.h:177
planner
Planner planner
Definition: planner.cpp:111