Esempio n. 1
0
static void update(GDISPLAY_WIDGET* widget) {
    GDISPLAY* display = widget->_owner_;
    NUMBER_WIDGET* numb = (NUMBER_WIDGET*)widget;
    char txt[20];
    char oldtxt[20];

    signed char width = numb->_props_.numDigits;
    if(numb->_props_.setting.min < 0) {
        width++;
    }
    unsigned char prec = numb->_props_.numDecimals;

    signed char dWidth = width;
    if(prec>0) {
        dWidth += prec + 1;
        width += prec;
    }

    // Convert to text
    dtostrf(numb->_props_.setting.value, dWidth, prec, txt );
    dtostrf(numb->_props_.setting.old,   dWidth, prec, oldtxt );

    // Replace the variable content colour with the background colour
//	_displayReplace(display, &widget->content, &numb->dial, widget->x, widget->y, widget->w, widget->h);

    // The display width of the dial
    PIXEL dispHeight = (widget->h - widget->padding - widget->padding);
    PIXEL dispWidth = widget->w - widget->padding - widget->padding;

    // Get the bounding box of each character
    PIXEL fontHeight = dispHeight - (FONT_VPAD*2);
    // Make enough space for bottom bar
    fontHeight -= fontHeight / 8;

    PIXEL fontWidth  = dispWidth / (width+1);		// Leave half a char to the left and right

    PIXEL fontPadLeft = (dispWidth - (fontWidth * width))/2;

    // Move to top left of display area
    _displayMoveTo(display, fontPadLeft + numb->_widget_.x + numb->_widget_.padding , FONT_VPAD + numb->_widget_.y + numb->_widget_.padding);

    // Now lets show each digit
    char* digit = txt;
    char* old = oldtxt;
    while(*digit) {
        if(*digit != '.') {
            if(numb->_props_.first || *digit != *old) {
                putDigit(widget, fontWidth, fontHeight,
                         *digit, (digit[1]=='.') ? TRUE : FALSE,
                         *old, (old[1]=='.') ? TRUE : FALSE
                        );
            }
            // Move to next char along
            _displayMoveBy(display, fontWidth, 0);
        }
        digit++;
        old++;
    }
    numb->_props_.first = FALSE;
}
Esempio n. 2
0
void printInt(int r) {
  int t;
  int found;

  found = 0;

  if (r >= 10000) {
      /* print -1) */
    putchar(45);
    putDigit(1);
    return;
  }
  else {
    if (r >= 1000) {
       t = r / 1000;
       putDigit(t);
       r = r - t * 1000;
       found=1;
    }

    if (r >= 100) {
       t = r / 100;
       putDigit(t);
       r = r - t * 100;
       found=1;
    }
    else if (found == 1) {
       putDigit(0);
    }

    if (r >= 10) {
       t = r / 10;
       putDigit(t);
       r = r - t * 10;
    }
    else if (found == 1) {
       putDigit(0);
    }

    putDigit(r);
  }

}
Esempio n. 3
0
int main (void) {

  int b;
  int c;
  int g;
  int h;
  int i;

  b = c = 5;

  if (b == 5) {
    a = 3;
  }
  else {
    a = 4;
  }

  g = 0;
  i = 1;
  while (i <= 8) {
    g = g + i;
    i = i+1;
  }
  h = g / 3;
  g = h * 4;

  c = addThem(a, b);
  putchar (56);
  putchar (61);
  putchar (c+g);
  putchar (10);

  i = 0;
  while (i < 10) {
    putchar(48+i);
    i = i+1;
  }
  putchar(10);
  putchar(67);
  putchar(83); 
  printInt(3510);
  putchar(10);

  b = 0;
  c = 1;
  g = 1;
  h = 0;
  i = 0;

  if (b == 0) {
    if (c==0) {
      i = 1;
    }
    else if (g == 0) {
      i = 2;
    }
    else if (h == 0) {
      i = 10;
    }
    else {
      i = 3;
    }
  }
  else {
    i = 0;
  }


  if (i == 10) {
    putchar(99);
    putDigit(0);
    putDigit(0); 
    putchar(108);  
  }
  else {
    putchar(98);
    putchar(97);
    putchar(100);
    putchar(61);
    printInt(i);
  }
  putchar(10);

  return 0;
}