static char * number(char * str, int size, int type, u64 num) { char fill,sign,tmp[24]; const char *digits="0123456789abcdef"; int i; if (type & LARGE) digits = "0123456789ABCDEF"; fill = (type & ZEROPAD) ? '0' : ' '; sign = 0; if (type & SIGN) { if ((s64)num <0) { sign = '-'; num = -num; size--; } } i = 0; do { unsigned rem; if (type&HEX) { rem = num & 0x0f; num >>=4; } else { div10(num, rem); } tmp[i++] = digits[rem]; } while (num != 0);
void seg_led::Calc_digit (float n) { unsigned char res; dec = div10(n); res = static_cast<unsigned char>(n); ones = res%10; res =(unsigned char) n*10; decimal = res%10; }
static int unsimal(unsigned x, char *ptr, int n) { if (10<=x) { unsigned const q = div10(x); x -= 10 * q; n = unsimal(q, ptr, n); } ptr[n] = '0' + x; return 1+ n; }
/* Convert the double-width integer hi:lo to an ASCII decimal integer in str[]. str[] is assumed to have enough space for the decimal digits and a terminating nul. Return str. */ static char *dbl2dec(word_t lo, word_t hi, char *str) { char *p = str; do { *p++ = '0' + div10(&lo, &hi); } while (lo | hi); *p-- = 0; char *q = str; while (q < p) { char tmp = *q; *q++ = *p; *p-- = tmp; } return str; }
int divide(char * a,int al ,char * b ,int bl){ //written division a/b - whitout result : only testing the divisibility int i; for(i=0;i<al;i++) todiv[i+1]=a[i]; todiv[0]=al; for(i=0;i<bl;i++) divby[i+al-bl+1]=b[i]; for(i=1;i<=al-bl;i++) divby[i]=0; divby[0]=al; while(1){ while(cmp(divby,todiv)>0) if(divby[0]>bl)div10(divby); else return 0; while(cmp(todiv,divby)>=0) substract(todiv,divby); if(todiv[0]==0)return 1; } }
static display_t ticker() { static byte yPos; static byte yPos_secs; static bool moving = false; static bool moving2[5]; #if COMPILE_ANIMATIONS static byte hour2; static byte mins; static byte secs; if(appConfig.animations) { if(timeDate.time.secs != secs) { yPos = 0; yPos_secs = 0; moving = true; moving2[0] = div10(timeDate.time.hour) != div10(hour2); moving2[1] = mod10(timeDate.time.hour) != mod10(hour2); moving2[2] = div10(timeDate.time.mins) != div10(mins); moving2[3] = mod10(timeDate.time.mins) != mod10(mins); moving2[4] = div10(timeDate.time.secs) != div10(secs); //memcpy(&timeDateLast, &timeDate, sizeof(timeDate_s)); hour2 = timeDate.time.hour; mins = timeDate.time.mins; secs = timeDate.time.secs; } if(moving) { if(yPos <= 3) yPos++; else if(yPos <= 6) yPos += 3; else if(yPos <= 16) yPos += 5; else if(yPos <= 22) yPos += 3; else if(yPos <= 24 + TICKER_GAP) yPos++; if(yPos >= MIDFONT_HEIGHT + TICKER_GAP) yPos = 255; if(yPos_secs <= 1) yPos_secs++; else if(yPos_secs <= 13) yPos_secs += 3; else if(yPos_secs <= 16 + TICKER_GAP) yPos_secs++; if(yPos_secs >= FONT_SMALL2_HEIGHT + TICKER_GAP) yPos_secs = 255; if(yPos_secs > FONT_SMALL2_HEIGHT + TICKER_GAP && yPos > MIDFONT_HEIGHT + TICKER_GAP) { yPos = 0; yPos_secs = 0; moving = false; memset(moving2, false, sizeof(moving2)); } } } else #endif { yPos = 0; yPos_secs = 0; moving = false; memset(moving2, false, sizeof(moving2)); } // Set up image image_s img = newImage(104, 28, (const byte*)&small2Font, FONT_SMALL2_WIDTH, FONT_SMALL2_HEIGHT, WHITE, false, yPos_secs); draw_bitmap_set(&img); // Seconds drawTickerNum2(&img, div10(timeDate.time.secs), 5, moving2[4]); img.x = 116; drawTickerNum2(&img, mod10(timeDate.time.secs), 9, moving); // Set new font data for hours and minutes img.y = TIME_POS_Y; img.width = MIDFONT_WIDTH; img.height = MIDFONT_HEIGHT; img.bitmap = (const byte*)&midFont; img.offsetY = yPos; // Minutes img.x = 60; drawTickerNum2(&img, div10(timeDate.time.mins), 5, moving2[2]); img.x = 83; drawTickerNum2(&img, mod10(timeDate.time.mins), 9, moving2[3]); // Hours img.x = 1; drawTickerNum2(&img, div10(timeDate.time.hour), 5, moving2[0]); img.x = 24; drawTickerNum2(&img, mod10(timeDate.time.hour), 9, moving2[1]); // Draw colon for half a second if(RTC_HALFSEC()) { img.x = TIME_POS_X + 46 + 2; img.bitmap = colon; img.width = FONT_COLON_WIDTH; img.height = FONT_COLON_HEIGHT; img.offsetY = 0; draw_bitmap_s2(NULL); } // Draw AM/PM character char tmp[2]; tmp[0] = timeDate.time.ampm; tmp[1] = 0x00; draw_string(tmp, false, 104, 20); // char buff[12]; // sprintf_P(buff, PSTR("%lu"), time_getTimestamp()); // draw_string(buff, false, 30, 50); return (moving ? DISPLAY_BUSY : DISPLAY_DONE); }