Prusa3d Marlin fork
util.h
1 #pragma once
2 #include <stdint.h>
3 #include <string.h>
4 
5 extern const uint16_t FW_VERSION_NR[4];
6 const char* FW_VERSION_STR_P();
7 
8 extern const char FW_VERSION_HASH[];
9 const char* FW_VERSION_HASH_P();
10 
11 // Definition of a firmware flavor numerical values.
12 // To keep it short as possible
13 // DEVs/ALPHAs/BETAs limited to max 8 flavor versions
14 // RCs limited to 32 flavor versions
15 // Final Release always 64 as highest
16 enum FirmwareRevisionFlavorType : uint16_t {
17  FIRMWARE_REVISION_RELEASED = 0x0040,
18  FIRMWARE_REVISION_DEV = 0x0000,
19  FIRMWARE_REVISION_ALPHA = 0x008,
20  FIRMWARE_REVISION_BETA = 0x0010,
21  FIRMWARE_REVISION_RC = 0x0020
22 };
23 
24 bool show_upgrade_dialog_if_version_newer(const char *version_string);
25 bool eeprom_fw_version_older_than_p(const uint16_t (&req_ver)[4]);
26 void update_current_firmware_version_to_eeprom();
27 
28 #define EEPROM_NOZZLE_DIAMETER_uM_DEFAULT 400
29 
30 enum class ClPrintChecking:uint_least8_t
31 {
32  _Nozzle=1,
33  _Model=2,
34  _Smodel=3,
35  _Version=4,
36  _Gcode=5,
37  _Features=6,
38  _PrinterState=7
39 };
40 
41 enum class ClNozzleDiameter:uint_least8_t
42 {
43  _Diameter_250=25,
44  _Diameter_400=40,
45  _Diameter_600=60,
46  _Diameter_800=80,
47  _Diameter_Undef=EEPROM_EMPTY_VALUE
48 };
49 
50 enum class ClCheckMode:uint_least8_t
51 {
52  _None,
53  _Warn,
54  _Strict,
55  _Undef=EEPROM_EMPTY_VALUE
56 };
57 
58 enum class ClCheckModel:uint_least8_t
59 {
60  _None,
61  _Warn,
62  _Strict,
63  _Undef=EEPROM_EMPTY_VALUE
64 };
65 
66 enum class ClCheckVersion:uint_least8_t
67 {
68  _None,
69  _Warn,
70  _Strict,
71  _Undef=EEPROM_EMPTY_VALUE
72 };
73 
74 enum class ClCheckGcode:uint_least8_t
75 {
76  _None,
77  _Warn,
78  _Strict,
79  _Undef=EEPROM_EMPTY_VALUE
80 };
81 
82 #define COMPARE_VALUE_EQUAL (((uint8_t)ClCompareValue::_Equal<<6)+((uint8_t)ClCompareValue::_Equal<<4)+((uint8_t)ClCompareValue::_Equal<<2)+((uint8_t)ClCompareValue::_Equal))
83 enum class ClCompareValue:uint_least8_t
84 {
85  _Less=0,
86  _Equal=1,
87  _Greater=2
88 };
89 
91 public:
95  inline __attribute__((always_inline)) unquoted_string(const char * const pStr)
96  : len(0)
97  , found(false)
98  {
99  char * pStrEnd = NULL;
100 
101  // Start of the string
102  this->ptr = strchr(pStr, '"');
103  if (!this->ptr) {
104  // First quote not found
105  return;
106  }
107 
108  // Skip the leading quote
109  this->ptr++;
110 
111  // End of the string
112  pStrEnd = strchr(this->ptr, '"');
113  if(!pStrEnd) {
114  // Second quote not found
115  return;
116  }
117  this->len = pStrEnd - this->ptr;
118  this->found = true;
119  }
120 
121  bool WasFound() { return found; }
122  uint8_t GetLength() { return len; }
123  const char * GetUnquotedString() { return ptr; }
124 private:
125  const char * ptr = NULL;
126  uint8_t len;
127  bool found;
128 };
129 
130 extern ClNozzleDiameter oNozzleDiameter;
131 extern ClCheckMode oCheckMode;
132 extern ClCheckModel oCheckModel;
133 extern ClCheckVersion oCheckVersion;
134 extern ClCheckGcode oCheckGcode;
135 
136 void fCheckModeInit();
137 void nozzle_diameter_check(uint16_t nDiameter);
138 void printer_model_check(uint16_t nPrinterModel, uint16_t actualPrinterModel);
139 void printer_smodel_check(const char *pStrPos, const char *actualPrinterSModel);
140 void fw_version_check(const char *pVersion);
141 void gcode_level_check(uint16_t nGcodeLevel);
142 
143 uint16_t nPrinterType(bool bMMu);
144 const char *sPrinterType(bool bMMu);
145 
146 #define IP4_STR_SIZE 16
147 extern void ip4_to_str(char* dest, uint8_t* IP);
148 
149 // Calibration status of the machine
150 // (unsigned char*)EEPROM_CALIBRATION_STATUS_V2
151 typedef uint8_t CalibrationStatus;
152 const CalibrationStatus CALIBRATION_STATUS_SELFTEST = 0b00000001; // Selftest
153 const CalibrationStatus CALIBRATION_STATUS_XYZ = 0b00000010; // XYZ calibration
154 const CalibrationStatus CALIBRATION_STATUS_Z = 0b00000100; // Z calibration
155 #ifdef THERMAL_MODEL
156 const CalibrationStatus CALIBRATION_STATUS_THERMAL_MODEL = 0b00001000; // Thermal model calibration
157 #endif
158 const CalibrationStatus CALIBRATION_STATUS_LIVE_ADJUST = 0b00010000; // 1st layer calibration
159 const CalibrationStatus CALIBRATION_STATUS_UNKNOWN = 0b10000000; // Freshly assembled or unknown status
160 
161 // Calibration steps performed by the wizard
162 const CalibrationStatus CALIBRATION_WIZARD_STEPS =
163  CALIBRATION_STATUS_SELFTEST |
164  CALIBRATION_STATUS_XYZ |
165  CALIBRATION_STATUS_Z |
166 #ifdef THERMAL_MODEL
167  CALIBRATION_STATUS_THERMAL_MODEL |
168 #endif
169  CALIBRATION_STATUS_LIVE_ADJUST;
170 
171 // Calibration steps enforced after service prep
172 const CalibrationStatus CALIBRATION_FORCE_PREP = CALIBRATION_STATUS_Z;
173 
174 bool calibration_status_get(CalibrationStatus components);
175 void calibration_status_set(CalibrationStatus components);
176 void calibration_status_clear(CalibrationStatus components);
177 
178 // PINDA has an independent calibration flag
179 inline bool calibration_status_pinda() { return eeprom_read_byte((uint8_t*)EEPROM_CALIBRATION_STATUS_PINDA); }
Definition: util.h:90
__attribute__((always_inline)) unquoted_string(const char *const pStr)
Given a pointer to a quoted string, filter out the quotes.
Definition: util.h:95