util.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. #include "Configuration.h"
  2. #include "ultralcd.h"
  3. #include "sound.h"
  4. #include "language.h"
  5. #include "util.h"
  6. // Allocate the version string in the program memory. Otherwise the string lands either on the stack or in the global RAM.
  7. const char FW_VERSION_STR[] PROGMEM = FW_VERSION;
  8. const char* FW_VERSION_STR_P()
  9. {
  10. return FW_VERSION_STR;
  11. }
  12. const char FW_PRUSA3D_MAGIC_STR[] PROGMEM = FW_PRUSA3D_MAGIC;
  13. const char* FW_PRUSA3D_MAGIC_STR_P()
  14. {
  15. return FW_PRUSA3D_MAGIC_STR;
  16. }
  17. const char STR_REVISION_DEV [] PROGMEM = "dev";
  18. const char STR_REVISION_ALPHA[] PROGMEM = "alpha";
  19. const char STR_REVISION_BETA [] PROGMEM = "beta";
  20. const char STR_REVISION_RC [] PROGMEM = "rc";
  21. inline bool is_whitespace_or_nl(char c)
  22. {
  23. return c == ' ' || c == '\t' || c == '\n' || c == '\r';
  24. }
  25. inline bool is_whitespace_or_nl_or_eol(char c)
  26. {
  27. return c == 0 || c == ' ' || c == '\t' || c == '\n' || c == '\r';
  28. }
  29. inline bool is_digit(char c)
  30. {
  31. return c >= '0' && c <= '9';
  32. }
  33. // Parse a major.minor.revision version number.
  34. // Return true if valid.
  35. inline bool parse_version(const char *str, uint16_t version[4])
  36. {
  37. #if 0
  38. SERIAL_ECHOPGM("Parsing version string ");
  39. SERIAL_ECHO(str);
  40. SERIAL_ECHOLNPGM("");
  41. #endif
  42. const char *major = str;
  43. const char *p = str;
  44. while (is_digit(*p)) ++ p;
  45. if (*p != '.')
  46. return false;
  47. const char *minor = ++ p;
  48. while (is_digit(*p)) ++ p;
  49. if (*p != '.')
  50. return false;
  51. const char *rev = ++ p;
  52. while (is_digit(*p)) ++ p;
  53. if (! is_whitespace_or_nl_or_eol(*p) && *p != '-')
  54. return false;
  55. char *endptr = NULL;
  56. version[0] = strtol(major, &endptr, 10);
  57. if (endptr != minor - 1)
  58. return false;
  59. version[1] = strtol(minor, &endptr, 10);
  60. if (endptr != rev - 1)
  61. return false;
  62. version[2] = strtol(rev, &endptr, 10);
  63. if (endptr != p)
  64. return false;
  65. version[3] = FIRMWARE_REVISION_RELEASED;
  66. if (*p ++ == '-') {
  67. const char *q = p;
  68. while (! is_whitespace_or_nl_or_eol(*q))
  69. ++ q;
  70. uint8_t n = q - p;
  71. if (n == strlen_P(STR_REVISION_DEV) && strncmp_P(p, STR_REVISION_DEV, n) == 0)
  72. version[3] = FIRMWARE_REVISION_DEV;
  73. else if (n == strlen_P(STR_REVISION_ALPHA) && strncmp_P(p, STR_REVISION_ALPHA, n) == 0)
  74. version[3] = FIRMWARE_REVISION_ALPHA;
  75. else if (n == strlen_P(STR_REVISION_BETA) && strncmp_P(p, STR_REVISION_BETA, n) == 0)
  76. version[3] = FIRMWARE_REVISION_BETA;
  77. else if ((n == 2 || n == 3) && (p[0] == 'r' || p[0] == 'R') && (p[1] == 'c' || p[1] == 'C')) {
  78. if (n == 2)
  79. version[3] = FIRMWARE_REVISION_RC;
  80. else {
  81. if (is_digit(p[2]))
  82. version[3] = FIRMWARE_REVISION_RC + p[2] - '1';
  83. else
  84. return false;
  85. }
  86. } else
  87. return false;
  88. }
  89. #if 0
  90. SERIAL_ECHOPGM("Version parsed, major: ");
  91. SERIAL_ECHO(version[0]);
  92. SERIAL_ECHOPGM(", minor: ");
  93. SERIAL_ECHO(version[1]);
  94. SERIAL_ECHOPGM(", revision: ");
  95. SERIAL_ECHO(version[2]);
  96. SERIAL_ECHOPGM(", flavor: ");
  97. SERIAL_ECHO(version[3]);
  98. SERIAL_ECHOLNPGM("");
  99. #endif
  100. return true;
  101. }
  102. inline bool strncmp_PP(const char *p1, const char *p2, uint8_t n)
  103. {
  104. for (; n > 0; -- n, ++ p1, ++ p2) {
  105. if (pgm_read_byte(p1) >= 65 && pgm_read_byte(p1) <= 92) //p1 is upper case (p2 is always lowercase)
  106. {
  107. if ((pgm_read_byte(p1)+32) < pgm_read_byte(p2))
  108. return -1;
  109. if ((pgm_read_byte(p1)+32) > pgm_read_byte(p2))
  110. return 1;
  111. }
  112. else if (pgm_read_byte(p1) == 0) {
  113. return 0;
  114. }
  115. else { //p1 is lowercase
  116. if (pgm_read_byte(p1) < pgm_read_byte(p2))
  117. return -1;
  118. if (pgm_read_byte(p1) > pgm_read_byte(p2))
  119. return 1;
  120. }
  121. }
  122. return 0;
  123. }
  124. // Parse a major.minor.revision version number.
  125. // Return true if valid.
  126. inline bool parse_version_P(const char *str, uint16_t version[4])
  127. {
  128. #if 0
  129. SERIAL_ECHOPGM("Parsing version string ");
  130. SERIAL_ECHORPGM(str);
  131. SERIAL_ECHOLNPGM("");
  132. #endif
  133. const char *major = str;
  134. const char *p = str;
  135. while (is_digit(char(pgm_read_byte(p)))) ++ p;
  136. if (pgm_read_byte(p) != '.')
  137. return false;
  138. const char *minor = ++ p;
  139. while (is_digit(char(pgm_read_byte(p)))) ++ p;
  140. if (pgm_read_byte(p) != '.')
  141. return false;
  142. const char *rev = ++ p;
  143. while (is_digit(char(pgm_read_byte(p)))) ++ p;
  144. if (! is_whitespace_or_nl_or_eol(char(pgm_read_byte(p))) && pgm_read_byte(p) != '-')
  145. return false;
  146. char buf[5];
  147. uint8_t n = minor - major - 1;
  148. if (n > 4)
  149. return false;
  150. memcpy_P(buf, major, n); buf[n] = 0;
  151. char *endptr = NULL;
  152. version[0] = strtol(buf, &endptr, 10);
  153. if (*endptr != 0)
  154. return false;
  155. n = rev - minor - 1;
  156. if (n > 4)
  157. return false;
  158. memcpy_P(buf, minor, n); buf[n] = 0;
  159. version[1] = strtol(buf, &endptr, 10);
  160. if (*endptr != 0)
  161. return false;
  162. n = p - rev;
  163. if (n > 4)
  164. return false;
  165. memcpy_P(buf, rev, n);
  166. buf[n] = 0;
  167. version[2] = strtol(buf, &endptr, 10);
  168. if (*endptr != 0)
  169. return false;
  170. version[3] = FIRMWARE_REVISION_RELEASED;
  171. if (pgm_read_byte(p ++) == '-') {
  172. const char *q = p;
  173. while (! is_whitespace_or_nl_or_eol(char(pgm_read_byte(q))))
  174. ++ q;
  175. n = q - p;
  176. if (n == strlen_P(STR_REVISION_DEV) && strncmp_PP(p, STR_REVISION_DEV, n) == 0)
  177. version[3] = FIRMWARE_REVISION_DEV;
  178. else if (n == strlen_P(STR_REVISION_ALPHA) && strncmp_PP(p, STR_REVISION_ALPHA, n) == 0)
  179. version[3] = FIRMWARE_REVISION_ALPHA;
  180. else if (n == strlen_P(STR_REVISION_BETA) && strncmp_PP(p, STR_REVISION_BETA, n) == 0)
  181. version[3] = FIRMWARE_REVISION_BETA;
  182. else if ((n == 2 || n == 3) && strncmp_PP(p, STR_REVISION_RC, 2) == 0) {
  183. if (n == 2)
  184. version[3] = FIRMWARE_REVISION_RC;
  185. else {
  186. p += 2;
  187. if (is_digit(pgm_read_byte(p)))
  188. version[3] = FIRMWARE_REVISION_RC + pgm_read_byte(p) - '1';
  189. else
  190. return false;
  191. }
  192. } else
  193. return false;
  194. }
  195. #if 0
  196. SERIAL_ECHOPGM("Version parsed, major: ");
  197. SERIAL_ECHO(version[0]);
  198. SERIAL_ECHOPGM(", minor: ");
  199. SERIAL_ECHO(version[1]);
  200. SERIAL_ECHOPGM(", revision: ");
  201. SERIAL_ECHO(version[2]);
  202. SERIAL_ECHOPGM(", flavor: ");
  203. SERIAL_ECHO(version[3]);
  204. SERIAL_ECHOLNPGM("");
  205. #endif
  206. return true;
  207. }
  208. // 1 - yes, 0 - false, -1 - error;
  209. inline int8_t is_provided_version_newer(const char *version_string)
  210. {
  211. uint16_t ver_gcode[4], ver_current[4];
  212. if (! parse_version(version_string, ver_gcode))
  213. return -1;
  214. if (! parse_version_P(FW_VERSION_STR, ver_current))
  215. return 0; // this shall not happen
  216. for (uint8_t i = 0; i < 3; ++ i)
  217. if (ver_gcode[i] > ver_current[i])
  218. return 1;
  219. return 0;
  220. }
  221. bool force_selftest_if_fw_version()
  222. {
  223. //if fw version used before flashing new firmware (fw version currently stored in eeprom) is lower then 3.1.2-RC2, function returns true to force selftest
  224. uint16_t ver_eeprom[4];
  225. uint16_t ver_with_calibration[4] = {3, 1, 2, 4}; //hardcoded 3.1.2-RC2 version
  226. bool force_selftest = false;
  227. ver_eeprom[0] = eeprom_read_word((uint16_t*)EEPROM_FIRMWARE_VERSION_MAJOR);
  228. ver_eeprom[1] = eeprom_read_word((uint16_t*)EEPROM_FIRMWARE_VERSION_MINOR);
  229. ver_eeprom[2] = eeprom_read_word((uint16_t*)EEPROM_FIRMWARE_VERSION_REVISION);
  230. ver_eeprom[3] = eeprom_read_word((uint16_t*)EEPROM_FIRMWARE_VERSION_FLAVOR);
  231. for (uint8_t i = 0; i < 4; ++i) {
  232. if (ver_with_calibration[i] > ver_eeprom[i]) {
  233. force_selftest = true;
  234. break;
  235. }
  236. else if (ver_with_calibration[i] < ver_eeprom[i])
  237. break;
  238. }
  239. //force selftest also in case that version used before flashing new firmware was 3.2.0-RC1
  240. if ((ver_eeprom[0] == 3) && (ver_eeprom[1] == 2) && (ver_eeprom[2] == 0) && (ver_eeprom[3] == 3)) force_selftest = true;
  241. return force_selftest;
  242. }
  243. bool show_upgrade_dialog_if_version_newer(const char *version_string)
  244. {
  245. uint16_t ver_gcode[4], ver_current[4];
  246. if (! parse_version(version_string, ver_gcode)) {
  247. // SERIAL_PROTOCOLLNPGM("parse_version failed");
  248. return false;
  249. }
  250. if (! parse_version_P(FW_VERSION_STR, ver_current)) {
  251. // SERIAL_PROTOCOLLNPGM("parse_version_P failed");
  252. return false; // this shall not happen
  253. }
  254. // SERIAL_PROTOCOLLNPGM("versions parsed");
  255. bool upgrade = false;
  256. for (uint8_t i = 0; i < 4; ++ i) {
  257. if (ver_gcode[i] > ver_current[i]) {
  258. upgrade = true;
  259. break;
  260. } else if (ver_gcode[i] < ver_current[i])
  261. break;
  262. }
  263. if (upgrade) {
  264. lcd_display_message_fullscreen_P(_i("New firmware version available:"));////MSG_NEW_FIRMWARE_AVAILABLE c=20 r=2
  265. lcd_puts_at_P(0, 2, PSTR(""));
  266. for (const char *c = version_string; ! is_whitespace_or_nl_or_eol(*c); ++ c)
  267. lcd_putc(*c);
  268. lcd_puts_at_P(0, 3, _i("Please upgrade."));////MSG_NEW_FIRMWARE_PLEASE_UPGRADE c=20
  269. Sound_MakeCustom(50,1000,false);
  270. delay_keep_alive(500);
  271. Sound_MakeCustom(50,1000,false);
  272. lcd_wait_for_click_delay(30);
  273. lcd_update_enable(true);
  274. lcd_clear();
  275. lcd_update(0);
  276. }
  277. // Succeeded.
  278. return true;
  279. }
  280. void update_current_firmware_version_to_eeprom()
  281. {
  282. for (int8_t i = 0; i < FW_PRUSA3D_MAGIC_LEN; ++ i)
  283. eeprom_update_byte((uint8_t*)(EEPROM_FIRMWARE_PRUSA_MAGIC+i), pgm_read_byte(FW_PRUSA3D_MAGIC_STR+i));
  284. uint16_t ver_current[4];
  285. if (parse_version_P(FW_VERSION_STR, ver_current)) {
  286. eeprom_update_word((uint16_t*)EEPROM_FIRMWARE_VERSION_MAJOR, ver_current[0]);
  287. eeprom_update_word((uint16_t*)EEPROM_FIRMWARE_VERSION_MINOR, ver_current[1]);
  288. eeprom_update_word((uint16_t*)EEPROM_FIRMWARE_VERSION_REVISION, ver_current[2]);
  289. // See FirmwareRevisionFlavorType for the definition of firmware flavors.
  290. eeprom_update_word((uint16_t*)EEPROM_FIRMWARE_VERSION_FLAVOR, ver_current[3]);
  291. }
  292. }
  293. //-//
  294. #define MSG_PRINT_CHECKING_FAILED_TIMEOUT 30
  295. ClNozzleDiameter oNozzleDiameter=ClNozzleDiameter::_Diameter_400;
  296. ClCheckMode oCheckMode=ClCheckMode::_None;
  297. ClCheckModel oCheckModel=ClCheckModel::_None;
  298. ClCheckVersion oCheckVersion=ClCheckVersion::_None;
  299. ClCheckGcode oCheckGcode=ClCheckGcode::_None;
  300. void fCheckModeInit()
  301. {
  302. oCheckMode=(ClCheckMode)eeprom_read_byte((uint8_t*)EEPROM_CHECK_MODE);
  303. if(oCheckMode==ClCheckMode::_Undef)
  304. {
  305. oCheckMode=ClCheckMode::_Warn;
  306. eeprom_update_byte((uint8_t*)EEPROM_CHECK_MODE,(uint8_t)oCheckMode);
  307. }
  308. if(farm_mode)
  309. {
  310. oCheckMode=ClCheckMode::_Strict;
  311. if(eeprom_read_word((uint16_t*)EEPROM_NOZZLE_DIAMETER_uM)==EEPROM_EMPTY_VALUE16)
  312. eeprom_update_word((uint16_t*)EEPROM_NOZZLE_DIAMETER_uM,EEPROM_NOZZLE_DIAMETER_uM_DEFAULT);
  313. }
  314. oNozzleDiameter=(ClNozzleDiameter)eeprom_read_byte((uint8_t*)EEPROM_NOZZLE_DIAMETER);
  315. if((oNozzleDiameter==ClNozzleDiameter::_Diameter_Undef)&& !farm_mode)
  316. {
  317. oNozzleDiameter=ClNozzleDiameter::_Diameter_400;
  318. eeprom_update_byte((uint8_t*)EEPROM_NOZZLE_DIAMETER,(uint8_t)oNozzleDiameter);
  319. eeprom_update_word((uint16_t*)EEPROM_NOZZLE_DIAMETER_uM,EEPROM_NOZZLE_DIAMETER_uM_DEFAULT);
  320. }
  321. oCheckModel=(ClCheckModel)eeprom_read_byte((uint8_t*)EEPROM_CHECK_MODEL);
  322. if(oCheckModel==ClCheckModel::_Undef)
  323. {
  324. oCheckModel=ClCheckModel::_Warn;
  325. eeprom_update_byte((uint8_t*)EEPROM_CHECK_MODEL,(uint8_t)oCheckModel);
  326. }
  327. oCheckVersion=(ClCheckVersion)eeprom_read_byte((uint8_t*)EEPROM_CHECK_VERSION);
  328. if(oCheckVersion==ClCheckVersion::_Undef)
  329. {
  330. oCheckVersion=ClCheckVersion::_Warn;
  331. eeprom_update_byte((uint8_t*)EEPROM_CHECK_VERSION,(uint8_t)oCheckVersion);
  332. }
  333. oCheckGcode=(ClCheckGcode)eeprom_read_byte((uint8_t*)EEPROM_CHECK_GCODE);
  334. if(oCheckGcode==ClCheckGcode::_Undef)
  335. {
  336. oCheckGcode=ClCheckGcode::_Warn;
  337. eeprom_update_byte((uint8_t*)EEPROM_CHECK_GCODE,(uint8_t)oCheckGcode);
  338. }
  339. }
  340. void nozzle_diameter_check(uint16_t nDiameter)
  341. {
  342. uint16_t nDiameter_um;
  343. if(oCheckMode==ClCheckMode::_None)
  344. return;
  345. nDiameter_um=eeprom_read_word((uint16_t*)EEPROM_NOZZLE_DIAMETER_uM);
  346. if(nDiameter==nDiameter_um)
  347. return;
  348. //SERIAL_ECHO_START;
  349. //SERIAL_ECHOLNPGM("Printer nozzle diameter differs from the G-code ...");
  350. //SERIAL_ECHOPGM("actual : ");
  351. //SERIAL_ECHOLN((float)(nDiameter_um/1000.0));
  352. //SERIAL_ECHOPGM("expected: ");
  353. //SERIAL_ECHOLN((float)(nDiameter/1000.0));
  354. switch(oCheckMode)
  355. {
  356. case ClCheckMode::_Warn:
  357. // lcd_show_fullscreen_message_and_wait_P(_i("Printer nozzle diameter differs from the G-code. Continue?"));
  358. lcd_display_message_fullscreen_P(_i("Printer nozzle diameter differs from the G-code. Continue?"));
  359. lcd_wait_for_click_delay(MSG_PRINT_CHECKING_FAILED_TIMEOUT);
  360. //???custom_message_type=CUSTOM_MSG_TYPE_STATUS; // display / status-line recovery
  361. lcd_update_enable(true); // display / status-line recovery
  362. break;
  363. case ClCheckMode::_Strict:
  364. lcd_show_fullscreen_message_and_wait_P(_i("Printer nozzle diameter differs from the G-code. Please check the value in settings. Print cancelled."));
  365. lcd_print_stop();
  366. break;
  367. case ClCheckMode::_None:
  368. case ClCheckMode::_Undef:
  369. break;
  370. }
  371. if(!farm_mode)
  372. {
  373. bSettings=false; // flag ('fake parameter') for 'lcd_hw_setup_menu()' function
  374. menu_submenu(lcd_hw_setup_menu);
  375. }
  376. }
  377. void printer_model_check(uint16_t nPrinterModel)
  378. {
  379. if(oCheckModel==ClCheckModel::_None)
  380. return;
  381. if(nPrinterModel==nPrinterType)
  382. return;
  383. //SERIAL_ECHO_START;
  384. //SERIAL_ECHOLNPGM("Printer model differs from the G-code ...");
  385. //SERIAL_ECHOPGM("actual : ");
  386. //SERIAL_ECHOLN(nPrinterType);
  387. //SERIAL_ECHOPGM("expected: ");
  388. //SERIAL_ECHOLN(nPrinterModel);
  389. switch(oCheckModel)
  390. {
  391. case ClCheckModel::_Warn:
  392. // lcd_show_fullscreen_message_and_wait_P(_i("Printer model differs from the G-code. Continue?"));
  393. lcd_display_message_fullscreen_P(_T(MSG_GCODE_DIFF_PRINTER_CONTINUE));
  394. lcd_wait_for_click_delay(MSG_PRINT_CHECKING_FAILED_TIMEOUT);
  395. //???custom_message_type=CUSTOM_MSG_TYPE_STATUS; // display / status-line recovery
  396. lcd_update_enable(true); // display / status-line recovery
  397. break;
  398. case ClCheckModel::_Strict:
  399. lcd_show_fullscreen_message_and_wait_P(_T(MSG_GCODE_DIFF_PRINTER_CANCELLED));
  400. lcd_print_stop();
  401. break;
  402. case ClCheckModel::_None:
  403. case ClCheckModel::_Undef:
  404. break;
  405. }
  406. }
  407. uint8_t mCompareValue(uint16_t nX,uint16_t nY)
  408. {
  409. if(nX>nY)
  410. return((uint8_t)ClCompareValue::_Greater);
  411. if(nX<nY)
  412. return((uint8_t)ClCompareValue::_Less);
  413. return((uint8_t)ClCompareValue::_Equal);
  414. }
  415. void fw_version_check(const char *pVersion)
  416. {
  417. uint16_t aVersion[4];
  418. uint8_t nCompareValueResult;
  419. if(oCheckVersion==ClCheckVersion::_None)
  420. return;
  421. parse_version(pVersion,aVersion);
  422. nCompareValueResult=mCompareValue(aVersion[0],eeprom_read_word((uint16_t*)EEPROM_FIRMWARE_VERSION_MAJOR))<<6;
  423. nCompareValueResult+=mCompareValue(aVersion[1],eeprom_read_word((uint16_t*)EEPROM_FIRMWARE_VERSION_MINOR))<<4;
  424. nCompareValueResult+=mCompareValue(aVersion[2],eeprom_read_word((uint16_t*)EEPROM_FIRMWARE_VERSION_REVISION))<<2;
  425. nCompareValueResult+=mCompareValue(aVersion[3],eeprom_read_word((uint16_t*)EEPROM_FIRMWARE_VERSION_FLAVOR));
  426. if(nCompareValueResult==COMPARE_VALUE_EQUAL)
  427. return;
  428. if((nCompareValueResult<COMPARE_VALUE_EQUAL)&&oCheckVersion==ClCheckVersion::_Warn)
  429. return;
  430. //SERIAL_ECHO_START;
  431. //SERIAL_ECHOLNPGM("Printer FW version differs from the G-code ...");
  432. //SERIAL_ECHOPGM("actual : ");
  433. //SERIAL_ECHOLN(FW_VERSION);
  434. //SERIAL_ECHOPGM("expected: ");
  435. //SERIAL_ECHOLN(pVersion);
  436. switch(oCheckVersion)
  437. {
  438. case ClCheckVersion::_Warn:
  439. // lcd_show_fullscreen_message_and_wait_P(_i("Printer FW version differs from the G-code. Continue?"));
  440. lcd_display_message_fullscreen_P(_i("G-code sliced for a newer firmware. Continue?"));
  441. lcd_wait_for_click_delay(MSG_PRINT_CHECKING_FAILED_TIMEOUT);
  442. //???custom_message_type=CUSTOM_MSG_TYPE_STATUS; // display / status-line recovery
  443. lcd_update_enable(true); // display / status-line recovery
  444. break;
  445. case ClCheckVersion::_Strict:
  446. lcd_show_fullscreen_message_and_wait_P(_i("G-code sliced for a newer firmware. Please update the firmware. Print cancelled."));
  447. lcd_print_stop();
  448. break;
  449. case ClCheckVersion::_None:
  450. case ClCheckVersion::_Undef:
  451. break;
  452. }
  453. }
  454. void gcode_level_check(uint16_t nGcodeLevel)
  455. {
  456. if(oCheckGcode==ClCheckGcode::_None)
  457. return;
  458. if(nGcodeLevel==(uint16_t)GCODE_LEVEL)
  459. return;
  460. if((nGcodeLevel<(uint16_t)GCODE_LEVEL)&&(oCheckGcode==ClCheckGcode::_Warn))
  461. return;
  462. //SERIAL_ECHO_START;
  463. //SERIAL_ECHOLNPGM("Printer G-code level differs from the G-code ...");
  464. //SERIAL_ECHOPGM("actual : ");
  465. //SERIAL_ECHOLN(GCODE_LEVEL);
  466. //SERIAL_ECHOPGM("expected: ");
  467. //SERIAL_ECHOLN(nGcodeLevel);
  468. switch(oCheckGcode)
  469. {
  470. case ClCheckGcode::_Warn:
  471. // lcd_show_fullscreen_message_and_wait_P(_i("Printer G-code level differs from the G-code. Continue?"));
  472. lcd_display_message_fullscreen_P(_i("G-code sliced for a different level. Continue?"));
  473. lcd_wait_for_click_delay(MSG_PRINT_CHECKING_FAILED_TIMEOUT);
  474. //???custom_message_type=CUSTOM_MSG_TYPE_STATUS; // display / status-line recovery
  475. lcd_update_enable(true); // display / status-line recovery
  476. break;
  477. case ClCheckGcode::_Strict:
  478. lcd_show_fullscreen_message_and_wait_P(_i("G-code sliced for a different level. Please re-slice the model again. Print cancelled."));
  479. lcd_print_stop();
  480. break;
  481. case ClCheckGcode::_None:
  482. case ClCheckGcode::_Undef:
  483. break;
  484. }
  485. }
  486. //-// -> cmdqueue ???
  487. #define PRINTER_NAME_LENGTH ((sizeof(PRINTER_MMU_NAME)>sizeof(PRINTER_NAME))?(sizeof(PRINTER_MMU_NAME)-1):(sizeof(PRINTER_NAME)-1))
  488. #define GCODE_DELIMITER '"'
  489. #define ELLIPSIS "..."
  490. char* code_string(char* pStr,size_t* nLength)
  491. {
  492. char* pStrBegin;
  493. char* pStrEnd;
  494. pStrBegin=strchr(pStr,GCODE_DELIMITER);
  495. if(!pStrBegin)
  496. return(NULL);
  497. pStrBegin++;
  498. pStrEnd=strchr(pStrBegin,GCODE_DELIMITER);
  499. if(!pStrEnd)
  500. return(NULL);
  501. *nLength=pStrEnd-pStrBegin;
  502. return(pStrBegin);
  503. }
  504. void printer_smodel_check(char* pStrPos)
  505. {
  506. char* pResult;
  507. size_t nLength,nPrinterNameLength;
  508. bool bCheckOK;
  509. char sPrinterName[PRINTER_NAME_LENGTH+sizeof(ELLIPSIS)-1+1]="";
  510. nPrinterNameLength=strlen_P(::sPrinterName);
  511. pResult=code_string(pStrPos,&nLength);
  512. if(pResult!=NULL)
  513. {
  514. strlcpy(sPrinterName,pResult,min(nPrinterNameLength,nLength)+1);
  515. if(nLength>nPrinterNameLength)
  516. strcat(sPrinterName,ELLIPSIS);
  517. bCheckOK=(nLength==nPrinterNameLength);
  518. if(bCheckOK&&(!strncasecmp_P(pResult,::sPrinterName,nLength))) // i.e. string compare execute only if lengths are same
  519. return;
  520. }
  521. //SERIAL_ECHO_START;
  522. //SERIAL_ECHOLNPGM("Printer model differs from the G-code ...");
  523. //SERIAL_ECHOPGM("actual : \"");
  524. //serialprintPGM(::sPrinterName);
  525. //SERIAL_ECHOLNPGM("\"");
  526. //SERIAL_ECHOPGM("expected: \"");
  527. ////SERIAL_ECHO(sPrinterName);
  528. //SERIAL_ECHOLNPGM("\"");
  529. switch(oCheckModel)
  530. {
  531. case ClCheckModel::_Warn:
  532. // lcd_show_fullscreen_message_and_wait_P(_i("Printer model differs from the G-code. Continue?"));
  533. lcd_display_message_fullscreen_P(_T(MSG_GCODE_DIFF_PRINTER_CONTINUE));
  534. lcd_wait_for_click_delay(MSG_PRINT_CHECKING_FAILED_TIMEOUT);
  535. //???custom_message_type=CUSTOM_MSG_TYPE_STATUS; // display / status-line recovery
  536. lcd_update_enable(true); // display / status-line recovery
  537. break;
  538. case ClCheckModel::_Strict:
  539. lcd_show_fullscreen_message_and_wait_P(_T(MSG_GCODE_DIFF_PRINTER_CANCELLED));
  540. lcd_print_stop();
  541. break;
  542. case ClCheckModel::_None:
  543. case ClCheckModel::_Undef:
  544. break;
  545. }
  546. }
  547. void fSetMmuMode(bool bMMu)
  548. {
  549. if(bMMu)
  550. {
  551. nPrinterType=pgm_read_word(&_nPrinterMmuType);
  552. sPrinterName=_sPrinterMmuName;
  553. }
  554. else {
  555. nPrinterType=pgm_read_word(&_nPrinterType);
  556. sPrinterName=_sPrinterName;
  557. }
  558. }