util.cpp 17 KB

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