util.cpp 20 KB

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