util.cpp 19 KB

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