123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 |
- #include "Marlin.h"
- #include "utility.h"
- #include "temperature.h"
- void safe_delay(millis_t ms) {
- while (ms > 50) {
- ms -= 50;
- delay(50);
- thermalManager.manage_heater();
- }
- delay(ms);
- thermalManager.manage_heater();
- }
- #if ENABLED(EEPROM_SETTINGS)
- void crc16(uint16_t *crc, const void * const data, uint16_t cnt) {
- uint8_t *ptr = (uint8_t *)data;
- while (cnt--) {
- *crc = (uint16_t)(*crc ^ (uint16_t)(((uint16_t)*ptr++) << 8));
- for (uint8_t i = 0; i < 8; i++)
- *crc = (uint16_t)((*crc & 0x8000) ? ((uint16_t)(*crc << 1) ^ 0x1021) : (*crc << 1));
- }
- }
- #endif
- #if ENABLED(ULTRA_LCD) || (ENABLED(DEBUG_LEVELING_FEATURE) && (ENABLED(MESH_BED_LEVELING) || (HAS_ABL && !ABL_PLANAR)))
- char conv[8] = { 0 };
- #define DIGIT(n) ('0' + (n))
- #define DIGIMOD(n, f) DIGIT((n)/(f) % 10)
- #define RJDIGIT(n, f) ((n) >= (f) ? DIGIMOD(n, f) : ' ')
- #define MINUSOR(n, alt) (n >= 0 ? (alt) : (n = -n, '-'))
-
- char* i8tostr3(const uint8_t i) {
- conv[4] = RJDIGIT(i, 100);
- conv[5] = RJDIGIT(i, 10);
- conv[6] = DIGIMOD(i, 1);
- return &conv[4];
- }
-
- char* itostr3(int i) {
- conv[4] = MINUSOR(i, RJDIGIT(i, 100));
- conv[5] = RJDIGIT(i, 10);
- conv[6] = DIGIMOD(i, 1);
- return &conv[4];
- }
-
- char* itostr3left(const int i) {
- char *str = &conv[6];
- *str = DIGIMOD(i, 1);
- if (i >= 10) {
- *(--str) = DIGIMOD(i, 10);
- if (i >= 100)
- *(--str) = DIGIMOD(i, 100);
- }
- return str;
- }
-
- char* itostr4sign(const int i) {
- const bool neg = i < 0;
- const int ii = neg ? -i : i;
- if (i >= 1000) {
- conv[3] = DIGIMOD(ii, 1000);
- conv[4] = DIGIMOD(ii, 100);
- conv[5] = DIGIMOD(ii, 10);
- }
- else if (ii >= 100) {
- conv[3] = neg ? '-' : ' ';
- conv[4] = DIGIMOD(ii, 100);
- conv[5] = DIGIMOD(ii, 10);
- }
- else {
- conv[3] = ' ';
- conv[4] = ' ';
- if (ii >= 10) {
- conv[4] = neg ? '-' : ' ';
- conv[5] = DIGIMOD(ii, 10);
- }
- else {
- conv[5] = neg ? '-' : ' ';
- }
- }
- conv[6] = DIGIMOD(ii, 1);
- return &conv[3];
- }
-
- char* ftostr12ns(const float &f) {
- const long i = ((f < 0 ? -f : f) * 1000 + 5) / 10;
- conv[3] = DIGIMOD(i, 100);
- conv[4] = '.';
- conv[5] = DIGIMOD(i, 10);
- conv[6] = DIGIMOD(i, 1);
- return &conv[3];
- }
-
- char* ftostr52(const float &f) {
- long i = (f * 1000 + (f < 0 ? -5: 5)) / 10;
- conv[1] = MINUSOR(i, DIGIMOD(i, 10000));
- conv[2] = DIGIMOD(i, 1000);
- conv[3] = DIGIMOD(i, 100);
- conv[4] = '.';
- conv[5] = DIGIMOD(i, 10);
- conv[6] = DIGIMOD(i, 1);
- return &conv[1];
- }
- #if ENABLED(LCD_DECIMAL_SMALL_XY)
-
- char* ftostr4sign(const float &f) {
- const int i = (f * 100 + (f < 0 ? -5: 5)) / 10;
- if (!WITHIN(i, -99, 999)) return itostr4sign((int)f);
- const bool neg = i < 0;
- const int ii = neg ? -i : i;
- conv[3] = neg ? '-' : (ii >= 100 ? DIGIMOD(ii, 100) : ' ');
- conv[4] = DIGIMOD(ii, 10);
- conv[5] = '.';
- conv[6] = DIGIMOD(ii, 1);
- return &conv[3];
- }
- #endif
-
- char* ftostr41sign(const float &f) {
- int i = (f * 100 + (f < 0 ? -5: 5)) / 10;
- conv[1] = MINUSOR(i, '+');
- conv[2] = DIGIMOD(i, 1000);
- conv[3] = DIGIMOD(i, 100);
- conv[4] = DIGIMOD(i, 10);
- conv[5] = '.';
- conv[6] = DIGIMOD(i, 1);
- return &conv[1];
- }
-
- char* ftostr43sign(const float &f, char plus) {
- long i = (f * 10000 + (f < 0 ? -5: 5)) / 10;
- conv[1] = i ? MINUSOR(i, plus) : ' ';
- conv[2] = DIGIMOD(i, 1000);
- conv[3] = '.';
- conv[4] = DIGIMOD(i, 100);
- conv[5] = DIGIMOD(i, 10);
- conv[6] = DIGIMOD(i, 1);
- return &conv[1];
- }
-
- char* ftostr5rj(const float &f) {
- const long i = ((f < 0 ? -f : f) * 10 + 5) / 10;
- conv[2] = RJDIGIT(i, 10000);
- conv[3] = RJDIGIT(i, 1000);
- conv[4] = RJDIGIT(i, 100);
- conv[5] = RJDIGIT(i, 10);
- conv[6] = DIGIMOD(i, 1);
- return &conv[2];
- }
-
- char* ftostr51sign(const float &f) {
- long i = (f * 100 + (f < 0 ? -5: 5)) / 10;
- conv[0] = MINUSOR(i, '+');
- conv[1] = DIGIMOD(i, 10000);
- conv[2] = DIGIMOD(i, 1000);
- conv[3] = DIGIMOD(i, 100);
- conv[4] = DIGIMOD(i, 10);
- conv[5] = '.';
- conv[6] = DIGIMOD(i, 1);
- return conv;
- }
-
- char* ftostr52sign(const float &f) {
- long i = (f * 1000 + (f < 0 ? -5: 5)) / 10;
- conv[0] = MINUSOR(i, '+');
- conv[1] = DIGIMOD(i, 10000);
- conv[2] = DIGIMOD(i, 1000);
- conv[3] = DIGIMOD(i, 100);
- conv[4] = '.';
- conv[5] = DIGIMOD(i, 10);
- conv[6] = DIGIMOD(i, 1);
- return conv;
- }
-
- char* ftostr62rj(const float &f) {
- const long i = ((f < 0 ? -f : f) * 1000 + 5) / 10;
- conv[0] = RJDIGIT(i, 100000);
- conv[1] = RJDIGIT(i, 10000);
- conv[2] = RJDIGIT(i, 1000);
- conv[3] = DIGIMOD(i, 100);
- conv[4] = '.';
- conv[5] = DIGIMOD(i, 10);
- conv[6] = DIGIMOD(i, 1);
- return conv;
- }
-
- char* ftostr52sp(const float &f) {
- long i = (f * 1000 + (f < 0 ? -5: 5)) / 10;
- uint8_t dig;
- conv[1] = MINUSOR(i, RJDIGIT(i, 10000));
- conv[2] = RJDIGIT(i, 1000);
- conv[3] = DIGIMOD(i, 100);
- if ((dig = i % 10)) {
- conv[4] = '.';
- conv[5] = DIGIMOD(i, 10);
- conv[6] = DIGIT(dig);
- }
- else {
- if ((dig = (i / 10) % 10)) {
- conv[4] = '.';
- conv[5] = DIGIT(dig);
- }
- else
- conv[4] = conv[5] = ' ';
- conv[6] = ' ';
- }
- return &conv[1];
- }
- #endif
|