Esempio n. 1
0
void drawCircleHelper( int16_t x0, int16_t y0,
               int16_t r, uint8_t cornername, uint16_t color) {
  int16_t f     = 1 - r;
  int16_t ddF_x = 1;
  int16_t ddF_y = -2 * r;
  int16_t x     = 0;
  int16_t y     = r;

  while (x<y) {
    if (f >= 0) {
      y--;
      ddF_y += 2;
      f     += ddF_y;
    }
    x++;
    ddF_x += 2;
    f     += ddF_x;
    if (cornername & 0x4) {
      LCD_DrawPixelXY(x0 + x, y0 + y, color);
      LCD_DrawPixelXY(x0 + y, y0 + x, color);
    } 
    if (cornername & 0x2) {
      LCD_DrawPixelXY(x0 + x, y0 - y, color);
      LCD_DrawPixelXY(x0 + y, y0 - x, color);
    }
    if (cornername & 0x8) {
      LCD_DrawPixelXY(x0 - y, y0 + x, color);
      LCD_DrawPixelXY(x0 - x, y0 + y, color);
    }
    if (cornername & 0x1) {
      LCD_DrawPixelXY(x0 - y, y0 - x, color);
      LCD_DrawPixelXY(x0 - x, y0 - y, color);
    }
  }
}
Esempio n. 2
0
void LCD_PrintCharXY(unsigned int x, unsigned int y, u32 c)
{
    u8 row, col, width;
    const u8 *offset = char_offset(c, &width);
    if (! offset || ! width) {
        printf("Could not locate character U-%04x\n", (int)c);
        return;
    }
    // Check if the requested character is available
    LCD_DrawStart(x, y, x + width - 1,  y + HEIGHT(cur_str.font) - 1, DRAW_NWSE);
    for (col = 0; col < width; col++)
    {
        const u8 *data = offset++;
        u8 bit = 0;
        // Data is right aligned,adrawn top to bottom
        for (row = 0; row < HEIGHT(cur_str.font); ++row)
        {
            if (bit == 8) {
                data = offset++;
                bit = 0;
            }
            if (*data & (1 << bit)) {
                LCD_DrawPixelXY(x + col, y + row, cur_str.color);
            }
            bit++;
        }
    }
    LCD_DrawStop();
}
Esempio n. 3
0
void LCD_DrawDashedVLine(int16_t x, int16_t y, 
             int16_t h, int16_t space, uint16_t color) {
    LCD_DrawStart(x, y, x, y + h -1, DRAW_NWSE);
    int16_t y1;
    for (y1 = 0; y1 < h; y1++)
        if ((y1 / space) & 0x01)
            LCD_DrawPixelXY(x, y1 + y, color);
    LCD_DrawStop();
}
Esempio n. 4
0
void LCD_DrawDashedHLine(int16_t x, int16_t y, 
             int16_t w, int16_t space, uint16_t color)
{
    LCD_DrawStart(x, y, x + w -1, y, DRAW_NWSE);
    int16_t x1;
    for (x1 = 0; x1 < w; x1++)
        if ((x1 / space) & 0x01)
            LCD_DrawPixelXY(x1 + x, y, color);
    LCD_DrawStop();
}
Esempio n. 5
0
// bresenham's algorithm - thx wikpedia
void LCD_DrawLine(u16 x0, u16 y0, u16 x1, u16 y1, u16 color)
{
  int16_t steep = abs(y1 - y0) > abs(x1 - x0);
  if (steep) {
    swap(x0, y0);
    swap(x1, y1);
  }

  if (x0 > x1) {
    swap(x0, x1);
    swap(y0, y1);
  }

  int16_t dx, dy;
  dx = x1 - x0;
  dy = abs(y1 - y0);

  int16_t err = dx / 2;
  int16_t ystep;

  if (y0 < y1) {
    ystep = 1;
  } else {
    ystep = -1;
  }

  for (; x0<=x1; x0++) {
    if (steep) {
      LCD_DrawPixelXY(y0, x0, color);
    } else {
      LCD_DrawPixelXY(x0, y0, color);
    }
    err -= dy;
    if (err < 0) {
      y0 += ystep;
      err += dx;
    }
  }
}
Esempio n. 6
0
void LCD_DrawWindowedImageFromFile(u16 x, u16 y, const char *file, s16 w, s16 h, u16 x_off, u16 y_off)
{
    FILE *fh;
    u32 black, white;
    u8 buf[48];
    u16 img_w = 0, img_h = 0;

    fh = fopen(file, "rb");
    if(! fh) {
        printf("DEBUG: LCD_DrawWindowedImageFromFile: Image not found: %s\n", file);
        if (w > 0 && h > 0)
            LCD_FillRect(x, y, w, h, 0);
        return;
    }
    if (! image_read_header(fh, &img_w, &img_h, &black, &white)) {
        fclose(fh);
        return;
    }
    //printf("DEBUG: LCD_DrawWindowedImageFromFile: %s %dx%d %06x %06x\n", file, img_w, img_h, black, white);
    if (img_w > sizeof(buf)*8) {
        printf("DEBUG: LCD_DrawWindowedImageFromFile: Image is too wide: %d > %d\n", img_w, sizeof(buf)*8);
        fclose(fh);
        return;
    }
    if (w < 0)
        w = img_w;
    if (h < 0)
        h = img_h;
    LCD_DrawStart(x, y, x + w - 1, y + h -1, DRAW_NWSE);
    unsigned bytes = (img_w + 7) / 8;
    fseek(fh, bytes * y_off, SEEK_CUR);
    for (int i = 0; i < h; i++) {
        int ret = fread(buf, bytes, 1, fh);
        if (ret != 1) {
            //printf("DEBUG: LCD_DrawWindowedImageFromFile: Buffer read issue? (%s, %d, %d)\n", file, ret, i);
            break;
        }
        for (int j = 0; j < w; j++) {
            unsigned val = buf[(j + x_off) / 8] & (1 << (7 - ((j + x_off) % 8)));
            LCD_DrawPixelXY(x+j, y+i, val ? black : white);
        }
    }
    fclose(fh);
    LCD_DrawStop(); 
}
Esempio n. 7
0
static void move_cb(guiObject_t *obj, const void *data)
{
    //This will draw a little arrow bmp
    (void)data;
    const u8 bmp[] = {
        0x04, //0b00000100,
        0x0e, //0b00001110,
        0x00, //0b00000000,
        0x0a, //0b00001010,
        0x1b, //0b00011011,
        0x0a, //0b00001010,
        0x00, //0b00000000,
        0x0e, //0b00001110,
        0x04, //0b00000100,
    };
    for(unsigned i = 0; i < sizeof(bmp); i++) {
        for(int j = 0; j < 5; j++) {
            if(bmp[i] & (1 << j)) 
                LCD_DrawPixelXY(obj->box.x+i, obj->box.y+j, 0xffff);
        }
    }
}
Esempio n. 8
0
void _draw_channels()
{
    const unsigned offset = HEADER_HEIGHT + LINE_HEIGHT;
    int col, height;

    // draw rssi values
    for (int i = 0; i < Scanner.chan_max - Scanner.chan_min; i++) {
        col = (LCD_WIDTH - (Scanner.chan_max - Scanner.chan_min)) / 2 + i;
        if (sp->mode == PEAK_MODE) {
            height = Scanner.rssi_peak[i] * (LCD_HEIGHT - offset) / 0x1F;
        } else {
            height = Scanner.rssi[i] * (LCD_HEIGHT - offset) / 0x1F;
        }
        LCD_DrawFastVLine(col, offset, LCD_HEIGHT - offset - height, 0);
        LCD_DrawFastVLine(col, LCD_HEIGHT - height, height, 1);

        if (sp->mode == PEAK_HOLD_AVERAGE_MODE) {
            height = Scanner.rssi_peak[i] * (LCD_HEIGHT - offset) / 0x1F;
            LCD_DrawPixelXY(col, LCD_HEIGHT - height, 1);
        }
    }
}
Esempio n. 9
0
void drawCircleHelper( int x0, int y0,
               int r, unsigned cornername, unsigned color) {
  struct circle c = {1 - r, 1, -2 * r, 0, r};

  while (c.x<c.y) {
    _calcCircleHelper(&c);
    if (cornername & 0x4) {
      LCD_DrawPixelXY(x0 + c.x, y0 + c.y, color);
      LCD_DrawPixelXY(x0 + c.y, y0 + c.x, color);
    } 
    if (cornername & 0x2) {
      LCD_DrawPixelXY(x0 + c.x, y0 - c.y, color);
      LCD_DrawPixelXY(x0 + c.y, y0 - c.x, color);
    }
    if (cornername & 0x8) {
      LCD_DrawPixelXY(x0 - c.y, y0 + c.x, color);
      LCD_DrawPixelXY(x0 - c.x, y0 + c.y, color);
    }
    if (cornername & 0x1) {
      LCD_DrawPixelXY(x0 - c.y, y0 - c.x, color);
      LCD_DrawPixelXY(x0 - c.x, y0 - c.y, color);
    }
  }
}
Esempio n. 10
0
void LCD_DrawWindowedImageFromFile(u16 x, u16 y, const char *file, s16 w, s16 h, u16 x_off, u16 y_off)
{
    u16 i, j;
    FILE *fh;
    u8 transparent = 0;
    u8 row_has_transparency = 0;
    (void)row_has_transparency;

    u8 buf[480 * 2];

    if (w == 0 || h == 0)
        return;

    fh = fopen(file, "rb");
    if(! fh) {
        printf("DEBUG: LCD_DrawWindowedImageFromFile: Image not found: %s\n", file);
        if (w > 0 && h > 0)
            LCD_FillRect(x, y, w, h, 0);
        return;
    }
    setbuf(fh, 0);
    u32 img_w, img_h, offset, compression;

    if(fread(buf, 0x46, 1, fh) != 1 || buf[0] != 'B' || buf[1] != 'M')
    {
        fclose(fh);
        printf("DEBUG: LCD_DrawWindowedImageFromFile: Buffer read issue?\n");
        return;
    }
    compression = *((u32 *)(buf + 0x1e));
    if(*((u16 *)(buf + 0x1a)) != 1      /* 1 plane */
       || *((u16 *)(buf + 0x1c)) != 16  /* 16bpp */
       || (compression != 0 && compression != 3)  /* BI_RGB or BI_BITFIELDS */
      )
    {
        fclose(fh);
        printf("DEBUG: LCD_DrawWindowedImageFromFile: BMP Format not correct\n");
        return;
    }
    if(compression == 3)
    {
        if(*((u16 *)(buf + 0x36)) == 0x7c00 
           && *((u16 *)(buf + 0x3a)) == 0x03e0
           && *((u16 *)(buf + 0x3e)) == 0x001f
           && *((u16 *)(buf + 0x42)) == 0x8000)
        {
            transparent = 1;
        } else if(*((u16 *)(buf + 0x36)) != 0xf800 
           || *((u16 *)(buf + 0x3a)) != 0x07e0
           || *((u16 *)(buf + 0x3e)) != 0x001f)
        {
            fclose(fh);
            printf("DEBUG: LCD_DrawWindowedImageFromFile: BMP Format not correct second check\n");
            return;
        }
    }
    offset = *((u32 *)(buf + 0x0a));
    img_w = *((u32 *)(buf + 0x12));
    img_h = *((u32 *)(buf + 0x16));
    if(w < 0)
        w = img_w;
    if(h < 0)
        h = img_h;
    if((u16)w + x_off > img_w || (u16)h + y_off > img_h)
    {
        printf("DEBUG: LCD_DrawWindowedImageFromFile: Dimensions asked for are out of bounds\n");
        printf("size: (%d x %d) bounds(%d x %d)\n", (u16)img_w, (u16)img_h, (u16)(w + x_off), (u16)(h + y_off));
        fclose(fh);
        return;
    }

    offset += (img_w * (img_h - (y_off + h)) + x_off) * 2;
    fseek(fh, offset, SEEK_SET);
    LCD_DrawStart(x, y, x + w - 1, y + h - 1, DRAW_SWNE);
    /* Bitmap start is at lower-left corner */
    for (j = 0; j < h; j++) {
        if (fread(buf, 2 * w, 1, fh) != 1)
            break;
        u16 *color = (u16 *)buf;
        if(transparent) {
#ifdef TRANSPARENT_COLOR
            //Display supports a transparent color
            for (i = 0; i < w; i++ ) {
                u32 c;
                if((*color & 0x8000)) {
                    //convert 1555 -> 565
                    c = ((*color & 0x7fe0) << 1) | (*color & 0x1f);
                } else {
                    c = TRANSPARENT_COLOR;
                }
                LCD_DrawPixel(c);
                color++;
            }
#else
            u8 last_pixel_transparent = row_has_transparency;
            row_has_transparency = 0;
            for (i = 0; i < w; i++ ) {
                if((*color & 0x8000)) {
                    //convert 1555 -> 565
                    u16 c = ((*color & 0x7fe0) << 1) | (*color & 0x1f);
                    if(last_pixel_transparent) {
                        LCD_DrawPixelXY(x + i, y + h - j - 1, c);
                        last_pixel_transparent = 0;
                    } else {
                        LCD_DrawPixel(c);
                    }
                } else {
                    //When we see a transparent pixel, the next real pixel
                    // will need to be drawn with XY coordinates
                    row_has_transparency = 1;
                    last_pixel_transparent = 1;
                }
                color++;
            }
#endif
        } else {
            for (i = 0; i < w; i++ ) {
                if (LCD_DEPTH == 1)
                    *color = (*color & 0x8410) == 0x8410 ?  0 : 0xffff;
                LCD_DrawPixel(*color++);
            }
        }
        if((u16)w < img_w) {
            fseek(fh, 2 * (img_w - w), SEEK_CUR);
        }
    }
    LCD_DrawStop();
    fclose(fh);
}
Esempio n. 11
0
// draw a circle outline
void LCD_DrawCircle(u16 x0, u16 y0, u16 r, u16 color)
{
  int16_t f = 1 - r;
  int16_t ddF_x = 1;
  int16_t ddF_y = -2 * r;
  int16_t x = 0;
  int16_t y = r;

  LCD_DrawPixelXY(x0, y0+r, color);
  LCD_DrawPixelXY(x0, y0-r, color);
  LCD_DrawPixelXY(x0+r, y0, color);
  LCD_DrawPixelXY(x0-r, y0, color);

  while (x<y) {
    if (f >= 0) {
      y--;
      ddF_y += 2;
      f += ddF_y;
    }
    x++;
    ddF_x += 2;
    f += ddF_x;
  
    LCD_DrawPixelXY(x0 + x, y0 + y, color);
    LCD_DrawPixelXY(x0 - x, y0 + y, color);
    LCD_DrawPixelXY(x0 + x, y0 - y, color);
    LCD_DrawPixelXY(x0 - x, y0 - y, color);
    LCD_DrawPixelXY(x0 + y, y0 + x, color);
    LCD_DrawPixelXY(x0 - y, y0 + x, color);
    LCD_DrawPixelXY(x0 + y, y0 - x, color);
    LCD_DrawPixelXY(x0 - y, y0 - x, color);
    
  }
}
Esempio n. 12
0
// draw a circle outline
void LCD_DrawCircle(u16 x0, u16 y0, u16 r, u16 color)
{
  struct circle c = {1 - r, 1, -2 * r, 0, r};

  LCD_DrawPixelXY(x0, y0+r, color);
  LCD_DrawPixelXY(x0, y0-r, color);
  LCD_DrawPixelXY(x0+r, y0, color);
  LCD_DrawPixelXY(x0-r, y0, color);

  while (c.x<c.y) {
    _calcCircleHelper(&c);
    LCD_DrawPixelXY(x0 + c.x, y0 + c.y, color);
    LCD_DrawPixelXY(x0 - c.x, y0 + c.y, color);
    LCD_DrawPixelXY(x0 + c.x, y0 - c.y, color);
    LCD_DrawPixelXY(x0 - c.x, y0 - c.y, color);
    LCD_DrawPixelXY(x0 + c.y, y0 + c.x, color);
    LCD_DrawPixelXY(x0 - c.y, y0 + c.x, color);
    LCD_DrawPixelXY(x0 + c.y, y0 - c.x, color);
    LCD_DrawPixelXY(x0 - c.y, y0 - c.x, color);
    
  }
}