lcd-recorder.c

来自「编译后直接运行的MP3播放器全部C语言源代码 一个包含FAT文件系统、系统」· C语言 代码 · 共 957 行 · 第 1/2 页

C
957 行
字号
    ny += shift;    /* Calculate bit masks */    mask4 = ~(0xfe << ((ny-1) & 7));    if (clear)    {        mask = ~(0xff << shift);        mask2 = 0;        mask3 = ~mask4;        if (ny <= 8)            mask3 |= mask;    }    else        mask = mask2 = mask3 = 0xff;    /* Loop for each column */    for (x = 0; x < nx; x++)    {        dst = dst2;        dst2++;        data = 0;        y = 0;        if (ny > 8)        {            /* First partial row */            data = *src++ << shift;            *dst = (*dst & mask) | data;            data >>= 8;            dst += LCD_WIDTH;            /* Intermediate rows */            for (y = 8; y < ny-8; y += 8)            {                data |= *src++ << shift;                *dst = (*dst & mask2) | data;                data >>= 8;                dst += LCD_WIDTH;            }        }        /* Last partial row */        if (y + shift < ny)            data |= *src++ << shift;        *dst = (*dst & mask3) | (data & mask4);    }}/*  * Draw a rectangle with upper left corner at (x, y) * and size (nx, ny) */void lcd_drawrect (int x, int y, int nx, int ny){    int i;    if (x > LCD_WIDTH)        return;    if (y > LCD_HEIGHT)        return;    if (x + nx > LCD_WIDTH)        nx = LCD_WIDTH - x;    if (y + ny > LCD_HEIGHT)        ny = LCD_HEIGHT - y;    /* vertical lines */    for (i = 0; i < ny; i++) {        DRAW_PIXEL(x, (y + i));        DRAW_PIXEL((x + nx - 1), (y + i));    }    /* horizontal lines */    for (i = 0; i < nx; i++) {        DRAW_PIXEL((x + i),y);        DRAW_PIXEL((x + i),(y + ny - 1));    }}/* * Clear a rectangular area at (x, y), size (nx, ny) */void lcd_clearrect (int x, int y, int nx, int ny){    int i;    for (i = 0; i < nx; i++)        lcd_bitmap (zeros, x+i, y, 1, ny, true);}/* * Fill a rectangular area at (x, y), size (nx, ny) */void lcd_fillrect (int x, int y, int nx, int ny){    int i;    for (i = 0; i < nx; i++)        lcd_bitmap (ones, x+i, y, 1, ny, true);}/* Invert a rectangular area at (x, y), size (nx, ny) */void lcd_invertrect (int x, int y, int nx, int ny){    int i, j;    if (x > LCD_WIDTH)        return;    if (y > LCD_HEIGHT)        return;    if (x + nx > LCD_WIDTH)        nx = LCD_WIDTH - x;    if (y + ny > LCD_HEIGHT)        ny = LCD_HEIGHT - y;    for (i = 0; i < nx; i++)        for (j = 0; j < ny; j++)            INVERT_PIXEL((x + i), (y + j));}/* Reverse the invert setting of the scrolling line (if any) at given char   position.  Setting will go into affect next time line scrolls. */void lcd_invertscroll(int x, int y){    struct scrollinfo* s;    int index;    for ( index = 0; index < SCROLLABLE_LINES; index++ ) {        /* is this a scrolling line? */        if ( !(scrolling_lines&(1<<index)) )            continue;                s = &scroll[index];        if (s->startx == x && s->starty == y)        {            /* Found the line */            s->invert = !s->invert;            break;        }    }}void lcd_drawline( int x1, int y1, int x2, int y2 ){    int numpixels;    int i;    int deltax, deltay;    int d, dinc1, dinc2;    int x, xinc1, xinc2;    int y, yinc1, yinc2;    deltax = abs(x2 - x1);    deltay = abs(y2 - y1);    if(deltax >= deltay)    {        numpixels = deltax;        d = 2 * deltay - deltax;        dinc1 = deltay * 2;        dinc2 = (deltay - deltax) * 2;        xinc1 = 1;        xinc2 = 1;        yinc1 = 0;        yinc2 = 1;    }    else    {        numpixels = deltay;        d = 2 * deltax - deltay;        dinc1 = deltax * 2;        dinc2 = (deltax - deltay) * 2;        xinc1 = 0;        xinc2 = 1;        yinc1 = 1;        yinc2 = 1;    }    numpixels++; /* include endpoints */    if(x1 > x2)    {        xinc1 = -xinc1;        xinc2 = -xinc2;    }    if(y1 > y2)    {        yinc1 = -yinc1;        yinc2 = -yinc2;    }    x = x1;    y = y1;    for(i=0; i<numpixels; i++)    {        DRAW_PIXEL(x,y);        if(d < 0)        {            d += dinc1;            x += xinc1;            y += yinc1;        }        else        {            d += dinc2;            x += xinc2;            y += yinc2;        }    }}void lcd_clearline( int x1, int y1, int x2, int y2 ){    int numpixels;    int i;    int deltax, deltay;    int d, dinc1, dinc2;    int x, xinc1, xinc2;    int y, yinc1, yinc2;    deltax = abs(x2 - x1);    deltay = abs(y2 - y1);    if(deltax >= deltay)    {        numpixels = deltax;        d = 2 * deltay - deltax;        dinc1 = deltay * 2;        dinc2 = (deltay - deltax) * 2;        xinc1 = 1;        xinc2 = 1;        yinc1 = 0;        yinc2 = 1;    }    else    {        numpixels = deltay;        d = 2 * deltax - deltay;        dinc1 = deltax * 2;        dinc2 = (deltax - deltay) * 2;        xinc1 = 0;        xinc2 = 1;        yinc1 = 1;        yinc2 = 1;    }    numpixels++; /* include endpoints */    if(x1 > x2)    {        xinc1 = -xinc1;        xinc2 = -xinc2;    }    if(y1 > y2)    {        yinc1 = -yinc1;        yinc2 = -yinc2;    }    x = x1;    y = y1;    for(i=0; i<numpixels; i++)    {        CLEAR_PIXEL(x,y);        if(d < 0)        {            d += dinc1;            x += xinc1;            y += yinc1;        }        else        {            d += dinc2;            x += xinc2;            y += yinc2;        }    }}/* * Set a single pixel */void lcd_drawpixel(int x, int y){    DRAW_PIXEL(x,y);}/* * Clear a single pixel */void lcd_clearpixel(int x, int y){    CLEAR_PIXEL(x,y);}/* * Invert a single pixel */void lcd_invertpixel(int x, int y){    INVERT_PIXEL(x,y);}void lcd_puts_scroll(int x, int y, unsigned char *string){    lcd_puts_scroll_style(x, y, string, STYLE_DEFAULT);}void lcd_puts_scroll_style(int x, int y, unsigned char *string, int style){    struct scrollinfo* s;    int w, h;    int index;    int free_index=0;    DEBUGF("puts_scroll_style: %s\n", string);        for (index = 0; index < SCROLLABLE_LINES; index++) {        s = &scroll[index];        if (scrolling_lines&(1<<index)) {            if (s->starty == y) {                /* we prefer to re-use an existing index with the                   same y-position */                free_index=index;                break;            }        }        else {            /* remember the last unused one */            free_index=index;        }    }    index=free_index;    s = &scroll[index]; /* get the proper 's' */    s->start_tick = current_tick + scroll_delay;    s->invert = false;    if (style & STYLE_INVERT) {        s->invert = true;        lcd_puts_style(x,y,string,STYLE_INVERT);    }    else        lcd_puts(x,y,string);    lcd_getstringsize(string, &w, &h);    if (LCD_WIDTH - x * 8 - xmargin < w) {        /* prepare scroll line */        char *end;        memset(s->line, 0, sizeof s->line);        strcpy(s->line, string);        /* get width */        s->width = lcd_getstringsize(s->line, &w, &h);        /* scroll bidirectional or forward only depending on the string           width */        if ( bidir_limit ) {            s->bidir = s->width < (LCD_WIDTH - xmargin) *                (100 + bidir_limit) / 100;        }        else            s->bidir = false;        if (!s->bidir) { /* add spaces if scrolling in the round */            strcat(s->line, "   ");            /* get new width incl. spaces */            s->width = lcd_getstringsize(s->line, &w, &h);        }        end = strchr(s->line, '\0');        strncpy(end, string, LCD_WIDTH/2);        s->len = strlen(string);        s->offset = 0;        s->startx = x;        s->starty = y;        s->backward = false;        scrolling_lines |= (1<<index);    }    else        /* force a bit switch-off since it doesn't scroll */        scrolling_lines &= ~(1<<index);}void lcd_stop_scroll(void){    scrolling_lines=0;}void lcd_scroll_speed(int speed){    scroll_speed = speed;}void lcd_scroll_step(int step){    scroll_step = step;}void lcd_scroll_delay(int ms){    scroll_delay = ms / (HZ / 10);}void lcd_bidir_scroll(int percent){    bidir_limit = percent;}static void scroll_thread(void){    struct font* pf;    struct scrollinfo* s;    int index;    int xpos, ypos;    /* initialize scroll struct array */    scrolling_lines = 0;    while ( 1 ) {        for ( index = 0; index < SCROLLABLE_LINES; index++ ) {            /* really scroll? */            if ( !(scrolling_lines&(1<<index)) )                continue;            s = &scroll[index];            /* check pause */            if (TIME_BEFORE(current_tick, s->start_tick))                continue;            if (s->backward)                s->offset -= scroll_step;            else                s->offset += scroll_step;            pf = font_get(curfont);            xpos = xmargin + s->startx * s->width / s->len;            ypos = ymargin + s->starty * pf->height;            if (s->bidir) { /* scroll bidirectional */                if (s->offset <= 0) {                    /* at beginning of line */                    s->offset = 0;                    s->backward = false;                    s->start_tick = current_tick + scroll_delay * 2;                }                if (s->offset >= s->width - (LCD_WIDTH - xpos)) {                    /* at end of line */                    s->offset = s->width - (LCD_WIDTH - xpos);                    s->backward = true;                    s->start_tick = current_tick + scroll_delay * 2;                }            }            else {                /* scroll forward the whole time */                if (s->offset >= s->width)                    s->offset %= s->width;            }            lcd_clearrect(xpos, ypos, LCD_WIDTH - xpos, pf->height);            lcd_putsxyofs(xpos, ypos, s->offset, s->line);            if (s->invert)                lcd_invertrect(xpos, ypos, LCD_WIDTH - xpos, pf->height);            lcd_update_rect(xpos, ypos, LCD_WIDTH - xpos, pf->height);        }        sleep(HZ/scroll_speed);    }}#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?