Exemplo n.º 1
0
void Textbox::draw() {
    if (_fillBackground) {
        tft.fillRect(_pos.x, _pos.y, _size.w, _size.h, bgColor);
        _fillBackground = false;
    }
    if (fontSize == 1) {
        tft.setFont(&Inconsolata_g5pt7b);
    } else {
        tft.setFont(&Inconsolata_g8pt7b);
    }

    const char *valStr = _value;
    size_t valLength = strlen(valStr);
    if (_lastValLength > 0) {
        if (strcmp(_lastVal, valStr) == 0) {
            return;
        }

        tft.setCursor(_pos.x, _pos.y +_size.h-2);
        tft.setTextColor(bgColor);
        tft.print(_lastVal);
    }

    tft.setCursor(_pos.x, _pos.y +_size.h-2);
    tft.setTextColor(fontColor);
    tft.print(valStr);
    tft.setFont(&Inconsolata_g5pt7b);
    strcpy(_lastVal, valStr);
    _lastValLength = valLength;
}
Exemplo n.º 2
0
unsigned long testFillScreen() {
    unsigned long start = micros();
    tft.fillScreen(ILI9341_BLACK);
    tft.fillScreen(ILI9341_RED);
    tft.fillScreen(ILI9341_GREEN);
    tft.fillScreen(ILI9341_BLUE);
    tft.fillScreen(ILI9341_BLACK);
    return micros() - start;
}
Exemplo n.º 3
0
unsigned long testFastLines(uint16_t color1, uint16_t color2) {
    unsigned long start;
    int x, y, w = tft.width(), h = tft.height();

    tft.fillScreen(ILI9341_BLACK);
    start = micros();
    for (y = 0; y < h; y += 5) tft.drawFastHLine(0, y, w, color1);
    for (x = 0; x < w; x += 5) tft.drawFastVLine(x, 0, h, color2);

    return micros() - start;
}
Exemplo n.º 4
0
void Button::draw() {
    if (_touching) {
        tft.fillRect(_pos.x, _pos.y, _size.w, _size.h, touchColor);
    } else {
        tft.fillRect(_pos.x-1, _pos.y-1, _size.w, _size.h, bgColor);
        // TODO: Better drop shadow
        tft.drawFastVLine(_pos.x-1+_size.w, _pos.y-1, _size.h, ILI9341_BLACK);
        tft.drawFastHLine(_pos.x-1, _pos.y-1+_size.h, _size.w, ILI9341_BLACK);
    }

    Label::draw();
}
Exemplo n.º 5
0
void Label::draw() {
    int ox = _pos.x;
    int oy = _pos.y;
    if (_touching) {
        ox++;
        oy++;
    }
    tft.setTextColor(fontColor);
    int offset = CURSOR_Y_SMALL;
    if (fontSize == 1) {
        tft.setFont(&Inconsolata_g5pt7b);
    } else {
        tft.setFont(&Inconsolata_g8pt7b);
        offset = CURSOR_Y_LARGE;
    }
    if (centerLabel) {
        uint16_t w, h;
        int16_t x1, y1;
        tft.getTextBounds(_label, 10, 10, &x1, &y1, &w, &h);
        int x = ox + (_size.w / 2) - ((int) w / 2) - 1;
        int y = oy + (_size.h / 2) - ((int) h / 2);
        tft.setCursor(x, y + offset);
        tft.print(_label);
    } else {
        tft.setCursor(ox, oy+_size.h-2);
        tft.print(_label);
    }
}
Exemplo n.º 6
0
unsigned long testFilledCircles(uint8_t radius, uint16_t color) {
    unsigned long start;
    int x, y, w = tft.width(), h = tft.height(), r2 = radius * 2;

    tft.fillScreen(ILI9341_BLACK);
    start = micros();
    for (x = radius; x < w; x += r2) {
        for (y = radius; y < h; y += r2) {
            tft.fillCircle(x, y, radius, color);
        }
    }

    return micros() - start;
}
Exemplo n.º 7
0
void setup(void) {
  Serial.println(F("Touch Paint!"));
  
  tft.begin();

  if (!ts.begin()) {
    Serial.println("Couldn't start touchscreen controller");
    while (1);
  }
  Serial.println("Touchscreen started");
  
  tft.fillScreen(ILI9341_BLACK);
  
  // make the color selection boxes
  tft.fillRect(0, 0, BOXSIZE, BOXSIZE, ILI9341_RED);
  tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, ILI9341_YELLOW);
  tft.fillRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, ILI9341_GREEN);
  tft.fillRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, ILI9341_CYAN);
  tft.fillRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, ILI9341_BLUE);
  tft.fillRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, ILI9341_MAGENTA);
 
  // select the current color 'red'
  tft.drawRect(0, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);
  currentcolor = ILI9341_RED;
}
Exemplo n.º 8
0
void setup() {
    Serial.begin(38400);
    Serial.println("handset");

    tft.begin();
    tft.fillScreen(ILI9341_BLACK);

    setupLog();

    radio = new CC1101Radio();
    radio->listen(onMessageReceived);

    pipe = new Pipeline();
    pipe->segueTo(new DashboardViewController());
}
Exemplo n.º 9
0
unsigned long testCircles(uint8_t radius, uint16_t color) {
    unsigned long start;
    int x, y, r2 = radius * 2,
            w = tft.width() + radius,
            h = tft.height() + radius;

    // Screen is not cleared for this one -- this is
    // intentional and does not affect the reported time.
    start = micros();
    for (x = 0; x < w; x += r2) {
        for (y = 0; y < h; y += r2) {
            tft.drawCircle(x, y, radius, color);
        }
    }

    return micros() - start;
}
Exemplo n.º 10
0
//--------------------------------------------------------------------------
// SignalHandler - Try to free up things like servos if we abort.
//--------------------------------------------------------------------------
void SignalHandler(int sig){
    printf("Caught signal %d\n", sig);

    tft.end();  // try to cleanup.
    
   exit(1); 

}
Exemplo n.º 11
0
unsigned long testTriangles() {
    unsigned long start;
    int n, i, cx = tft.width() / 2 - 1,
            cy = tft.height() / 2 - 1;

    tft.fillScreen(ILI9341_BLACK);
    n = min(cx, cy);
    start = micros();
    for (i = 0; i < n; i += 5) {
        tft.drawTriangle(
                cx, cy - i, // peak
                cx - i, cy + i, // bottom left
                cx + i, cy + i, // bottom right
                tft.Color565(0, 0, i));
    }

    return micros() - start;
}
Exemplo n.º 12
0
unsigned long testRandomRects() {
    unsigned long start;
    int r, g, b, t, x, y, size = 16;
    float i = 0.0f;
    float pi = 3.1459; // 180 degrees

    start = micros();
    for (i = 0.0f; i < 2 * pi; i += (pi / 360.0)) {
        r = (sin(i) * 127) + 128;
        g = (sin(i + ((2 * pi) / 3.0)) * 127) + 128;
        b = (sin(i + ((4 * pi) / 3.0)) * 127) + 128;

        y = random(320 / size);
        x = random(240 / size);
        tft.fillRect(x * size, y*size, size, size, tft.Color565(r, g, b));
    }

    return micros() - start;
}
Exemplo n.º 13
0
/************************************ 
 * Name    : print_item
 * Purpuse : 
 * Inputs  : None
 * Outputs : None
 * Returns : None
 ************************************/
int  print_item(int line, char *iname, float value, char *unit)
{
  int stPos;
  if (line <= 0) return -1;
  stPos = (line-1)*PERIOD;
  tft.fillRect(0, stPos, 240, TEXTSIZE, ILI9341_BLACK);
  tft.setCursor(2, stPos);
  tft.setTextColor(ILI9341_WHITE);  
  tft.setTextSize(FONTSIZE);
  tft.print(iname);
  tft.print(value, 2);  
  tft.print(" ");
  tft.print(unit);  
}
Exemplo n.º 14
0
void Stat::drawLabel() {
    if (!_hideLabel) {
        tft.setFont(&Inconsolata_g8pt7b);
        tft.setCursor(_pos.x, _pos.y+1+CURSOR_Y_LARGE);
        tft.setTextColor(ILI9341_WHITE);
        tft.print(_labelText);
    }
    tft.fillRect(_value.x, _value.y, _controlWidth, 17, tft.color565(10, 10, 10));
}
Exemplo n.º 15
0
unsigned long testFilledRoundRects() {
    unsigned long start;
    int i, i2,
            cx = tft.width() / 2 - 1,
            cy = tft.height() / 2 - 1;

    tft.fillScreen(ILI9341_BLACK);
    start = micros();
    for (i = min(tft.width(), tft.height()); i > 20; i -= 6) {
        i2 = i / 2;
        tft.fillRoundRect(cx - i2, cy - i2, i, i, i / 8, tft.Color565(0, i, 0));
    }

    return micros() - start;
}
Exemplo n.º 16
0
unsigned long testRoundRects() {
    unsigned long start;
    int w, i, i2,
            cx = tft.width() / 2 - 1,
            cy = tft.height() / 2 - 1;

    tft.fillScreen(ILI9341_BLACK);
    w = min(tft.width(), tft.height());
    start = micros();
    for (i = 0; i < w; i += 6) {
        i2 = i / 2;
        tft.drawRoundRect(cx - i2, cy - i2, i, i, i / 8, tft.Color565(i, 0, 0));
    }

    return micros() - start;
}
Exemplo n.º 17
0
unsigned long testFilledTriangles() {
    unsigned long start, t = 0;
    int i, cx = tft.width() / 2 - 1,
            cy = tft.height() / 2 - 1;

    tft.fillScreen(ILI9341_BLACK);
    start = micros();
    for (i = min(cx, cy); i > 10; i -= 5) {
        start = micros();
        tft.fillTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
                tft.Color565(0, i, i));
        t += micros() - start;
        tft.drawTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
                tft.Color565(i, i, 0));
    }

    return t;
}
Exemplo n.º 18
0
unsigned long testFilledRects(uint16_t color1, uint16_t color2) {
    unsigned long start, t = 0;
    int n, i, i2,
            cx = tft.width() / 2 - 1,
            cy = tft.height() / 2 - 1;

    tft.fillScreen(ILI9341_BLACK);
    n = min(tft.width(), tft.height());
    for (i = n; i > 0; i -= 6) {
        i2 = i / 2;
        start = micros();
        tft.fillRect(cx - i2, cy - i2, i, i, color1);
        t += micros() - start;
        // Outlines are not included in timing results
        tft.drawRect(cx - i2, cy - i2, i, i, color2);
    }

    return t;
}
Exemplo n.º 19
0
unsigned long testRects(uint16_t color) {
    unsigned long start;
    int n, i, i2,
            cx = tft.width() / 2,
            cy = tft.height() / 2;

    tft.fillScreen(ILI9341_BLACK);
    n = min(tft.width(), tft.height());
    start = micros();
    for (i = 2; i < n; i += 6) {
        i2 = i / 2;
        tft.drawRect(cx - i2, cy - i2, i, i, color);
    }

    return micros() - start;
}
Exemplo n.º 20
0
/************************************ 
 * Name    : init_TFT
 * Purpuse : Init TFT module
 * Inputs  : None
 * Outputs : None
 * Returns : None
 ************************************/
void init_TFT()
{
  tft.begin();

  Serial.println("ILI9341 Begin"); 

  // read diagnostics (optional but can help debug problems)
  uint8_t x = tft.readcommand8(ILI9341_RDMODE);
  Serial.print("Display Power Mode: 0x"); Serial.println(x, HEX);
  x = tft.readcommand8(ILI9341_RDMADCTL);
  Serial.print("MADCTL Mode: 0x"); Serial.println(x, HEX);
  x = tft.readcommand8(ILI9341_RDPIXFMT);
  Serial.print("Pixel Format: 0x"); Serial.println(x, HEX);
  x = tft.readcommand8(ILI9341_RDIMGFMT);
  Serial.print("Image Format: 0x"); Serial.println(x, HEX);
  x = tft.readcommand8(ILI9341_RDSELFDIAG);
  Serial.print("Self Diagnostic: 0x"); Serial.println(x, HEX); 
    
} //init_TFTcreen
Exemplo n.º 21
0
/************************************ 
 * Name    : clear_screen
 * Purpuse : Clear screen (fill black)
 * Inputs  : None
 * Outputs : None
 * Returns : None
 ************************************/
void clear_screen()
{
  tft.fillScreen(ILI9341_BLACK);
} //clear_screen
Exemplo n.º 22
0
void busy()
{
  tft.print(".");  
}
Exemplo n.º 23
0
static void drawLine( int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t color)
{
    tft.drawLine(x0 + 120, y0 + 160, x1 + 120, y1 + 160, color);
}
Exemplo n.º 24
0
unsigned long testText() {
    tft.fillScreen(ILI9341_BLACK);
    unsigned long start = micros();
    tft.setCursor(0, 0);
    tft.setTextColor(ILI9341_WHITE);
    tft.setTextSize(1);
    tft.println("Hello World!");
    tft.setTextColor(ILI9341_YELLOW);
    tft.setTextSize(2);
    tft.println(1234.56);
    tft.setTextColor(ILI9341_RED);
    tft.setTextSize(3);
    tft.println(0xDEADBEEF, HEX);
    tft.println();
    tft.setTextColor(ILI9341_GREEN);
    tft.setTextSize(5);
    tft.println("Groop");
    tft.setTextSize(2);
    tft.println("I implore thee,");
    tft.setTextSize(1);
    tft.println("my foonting turlingdromes.");
    tft.println("And hooptiously drangle me");
    tft.println("with crinkly bindlewurdles,");
    tft.println("Or I will rend thee");
    tft.println("in the gobberwarts");
    tft.println("with my blurglecruncheon,");
    tft.println("see if I don't!");
    return micros() - start;
}
Exemplo n.º 25
0
unsigned long testLines(uint16_t color) {
    unsigned long start, t;
    int x1, y1, x2, y2,
            w = tft.width(),
            h = tft.height();

    tft.fillScreen(ILI9341_BLACK);

    x1 = y1 = 0;
    y2 = h - 1;
    start = micros();
    for (x2 = 0; x2 < w; x2 += 6) tft.drawLine(x1, y1, x2, y2, color);
    x2 = w - 1;
    for (y2 = 0; y2 < h; y2 += 6) tft.drawLine(x1, y1, x2, y2, color);
    t = micros() - start; // fillScreen doesn't count against timing

    tft.fillScreen(ILI9341_BLACK);

    x1 = w - 1;
    y1 = 0;
    y2 = h - 1;
    start = micros();
    for (x2 = 0; x2 < w; x2 += 6) tft.drawLine(x1, y1, x2, y2, color);
    x2 = 0;
    for (y2 = 0; y2 < h; y2 += 6) tft.drawLine(x1, y1, x2, y2, color);
    t += micros() - start;

    tft.fillScreen(ILI9341_BLACK);

    x1 = 0;
    y1 = h - 1;
    y2 = 0;
    start = micros();
    for (x2 = 0; x2 < w; x2 += 6) tft.drawLine(x1, y1, x2, y2, color);
    x2 = w - 1;
    for (y2 = 0; y2 < h; y2 += 6) tft.drawLine(x1, y1, x2, y2, color);
    t += micros() - start;

    tft.fillScreen(ILI9341_BLACK);

    x1 = w - 1;
    y1 = h - 1;
    y2 = 0;
    start = micros();
    for (x2 = 0; x2 < w; x2 += 6) tft.drawLine(x1, y1, x2, y2, color);
    x2 = 0;
    for (y2 = 0; y2 < h; y2 += 6) tft.drawLine(x1, y1, x2, y2, color);

    return micros() - start;
}
Exemplo n.º 26
0
void Stat::drawValue() {
    char valStr[8];
    size_t valLength;
    if (validReadingi(_stat)) {
        valLength = (size_t) sprintf(valStr, "%d", _stat);
    } else {
        valLength = (size_t) sprintf(valStr, "-- ");
    }
    if (_lastValLength > 0) {
        if (_lastValDrawn == _stat) {
            return;
        }

        tft.setCursor(_value.x, _value.y + 1 + CURSOR_Y_LARGE);
        tft.setFont(&Inconsolata_g8pt7b);
        tft.setTextColor(tft.color565(10, 10, 10));
        tft.print(_lastVal);

        if (valLength != _lastValLength) {
            tft.setFont(&Inconsolata_g5pt7b);
            tft.print(_unitText);
        }
    }

    tft.setCursor(_value.x, _value.y+1+CURSOR_Y_LARGE);
    tft.setFont(&Inconsolata_g8pt7b);
    tft.setTextColor(ILI9341_WHITE, tft.color565(10, 10, 10));
    tft.print(valStr);
    tft.setFont(&Inconsolata_g5pt7b);
    if (valLength != _lastValLength) {
        tft.setFont(&Inconsolata_g5pt7b);
        tft.print(_unitText);
    }
    memcpy(_lastVal, valStr, valLength+1);
    _lastValDrawn = _stat;
    _lastValLength = valLength;
}
Exemplo n.º 27
0
void loop()
{
  // See if there's any  touch data for us
  if (ts.bufferEmpty()) {
    return;
  }
  /*
  // You can also wait for a touch
  if (! ts.touched()) {
    return;
  }
  */

  // Retrieve a point  
  TS_Point p = ts.getPoint();
  
 /*
  Serial.print("X = "); Serial.print(p.x);
  Serial.print("\tY = "); Serial.print(p.y);
  Serial.print("\tPressure = "); Serial.println(p.z);  
 */
 
  // Scale from ~0->4000 to tft.width using the calibration #'s
  p.x = map(p.x, TS_MINX, TS_MAXX, 0, tft.width());
  p.y = map(p.y, TS_MINY, TS_MAXY, 0, tft.height());

  /*
  Serial.print("("); Serial.print(p.x);
  Serial.print(", "); Serial.print(p.y);
  Serial.println(")");
  */

  if (p.y < BOXSIZE) {
     oldcolor = currentcolor;

     if (p.x < BOXSIZE) { 
       currentcolor = ILI9341_RED; 
       tft.drawRect(0, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);
     } else if (p.x < BOXSIZE*2) {
       currentcolor = ILI9341_YELLOW;
       tft.drawRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);
     } else if (p.x < BOXSIZE*3) {
       currentcolor = ILI9341_GREEN;
       tft.drawRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);
     } else if (p.x < BOXSIZE*4) {
       currentcolor = ILI9341_CYAN;
       tft.drawRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);
     } else if (p.x < BOXSIZE*5) {
       currentcolor = ILI9341_BLUE;
       tft.drawRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);
     } else if (p.x < BOXSIZE*6) {
       currentcolor = ILI9341_MAGENTA;
       tft.drawRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);
     }

     if (oldcolor != currentcolor) {
        if (oldcolor == ILI9341_RED) 
          tft.fillRect(0, 0, BOXSIZE, BOXSIZE, ILI9341_RED);
        if (oldcolor == ILI9341_YELLOW) 
          tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, ILI9341_YELLOW);
        if (oldcolor == ILI9341_GREEN) 
          tft.fillRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, ILI9341_GREEN);
        if (oldcolor == ILI9341_CYAN) 
          tft.fillRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, ILI9341_CYAN);
        if (oldcolor == ILI9341_BLUE) 
          tft.fillRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, ILI9341_BLUE);
        if (oldcolor == ILI9341_MAGENTA) 
          tft.fillRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, ILI9341_MAGENTA);
     }
  }
  if (((p.y-PENRADIUS) > BOXSIZE) && ((p.y+PENRADIUS) < tft.height())) {
    tft.fillCircle(p.x, p.y, PENRADIUS, currentcolor);
  }
}
Exemplo n.º 28
0
void Stat::drawChart() {
    if (_redrawChart) {
        _cur = 0;
        tft.fillRect(_chart.x, _chart.y - 1 /* catch the top of the unit of the axis */,
                     _chartWidth, 32 /* to catch the bottom of the unit on the axis */,
                     ILI9341_BLACK);
        tft.setCursor(_chart.x + 27 - ((int16_t) strlen(_labelText) * 6), _chart.y + 12+CURSOR_Y_SMALL);
        tft.setTextColor(ILI9341_WHITE);
        tft.setFont(&Inconsolata_g5pt7b);
        tft.print(_labelText);
        tft.setCursor(_chart.x + _chartWidth - 45, _chart.y+CURSOR_Y_SMALL);
        tft.print(_max == INT_MIN ? 0 : _max);

        if (_unitText) {
            tft.setTextColor(_chartColor);
            tft.setCursor(_chart.x + _chartWidth - 45, _chart.y + 12+CURSOR_Y_SMALL);
            tft.print(_unitText);
            tft.setTextColor(ILI9341_WHITE);
        }
        tft.setCursor(_chart.x + _chartWidth - 45, _chart.y + 24+CURSOR_Y_SMALL);
        tft.print(_min == INT_MAX ? 0 : _min);
        tft.setFont(&Inconsolata_g8pt7b);
        _redrawChart = false;
        tft.fillRect(_chart.x + 30, _chart.y, _chartWidth - 80, 30, tft.color565(10, 10, 10));
    }

    for ( ; _cur < _end; _cur++) {
        if (invalidReadingi(_historical[_cur])) {
            tft.drawFastVLine(_chart.x+30+_cur, _chart.y, 30, ILI9341_MAROON);
            continue;
        }
        int norm = (int) map(_historical[_cur], _min, _max, 0, 29);
        int x = _chart.x+30+_cur;
        int y = _chart.y+29-norm;
        tft.fillRect(x, y, 1, 1, _chartColor);
    }
}
Exemplo n.º 29
0
void setup() {
    Serial.begin(9600);
    Serial.println("ILI9341 Test!");
    tft.begin();
    tft.fillScreen(ILI9341_BLACK);
}