/********************************************************************* * Put one character onto the screen : * CR moves cursor to column zero of current line. * NL moves to next line, scrolling if ncessary, and implies CR. *********************************************************************/ void lcd_putc(char c) { if ( c == '\r' ) { /* CR - move cursor to col 0 */ lcd_setx(lcd_x=0); return; } else if ( c == '\n' ) { /* NL - move to next line */ if ( ++lcd_y >= lcd_lines ) { lcd_scroll(); lcd_y = lcd_lines-1; } lcd_move(lcd_y,lcd_x=0); return; } if ( lcd_x + 1 > lcd_cols ) { /* Past column end? */ if ( ++lcd_y >= lcd_lines ) { lcd_scroll(); /* Scroll if necessary */ lcd_y = lcd_lines-1; } lcd_move(lcd_y,lcd_x=0); } lcd_putraw(c); lcd_buf[lcd_y][lcd_x++] = c; }
void lcd_putc(int c) { // let's process ASCII as fast as possible if(c < 127 && c >= 32) { lcd_fb_write_raw(&(lcd_chars6x8[c - 32][0]), 6); } else { // cyrillic is a bit slower if(c >= 0xC0 && c <= 0xFF) // cyrillic starts in font array at index 95 lcd_fb_write_raw(&(lcd_chars6x8[c - 0xC0 + 95][0]), 6); else // handle control characters switch(c) { case '\n': // new line: new line, then do carriage return if(++lcd_state.current_line >= 8) // scroll or wrap, depending if we have a framebuffer and scrolling state if(lcd_state.framebuffer != NULL && (lcd_state.flags & LCD_FLAG_SCROLL)) { lcd_state.current_line = 7; lcd_scroll(); } case '\r': // carriage return: move cursor to beginning of current line lcd_set_cursor(lcd_state.current_line, 0); return; case '\f': // form feed: clear screen lcd_clear(); return; default: // non-printable character. skip it return; } } // advance cursor/scroll if((lcd_state.current_column += 6) >= 96) { // new line lcd_state.current_column = 0; if(++lcd_state.current_line >= 8) { // scroll or wrap, depending if we have a framebuffer and scrolling state if(lcd_state.framebuffer != NULL && (lcd_state.flags & LCD_FLAG_SCROLL)) { lcd_state.current_line = 7; lcd_scroll(); } else lcd_set_cursor(0, 0); } } }
int main(void) { while(1) { print("Hello"); delay_ms(200); lcd_scroll(LCD_RIGHT, 3, 200); clear(); lcd_goto_xy(3, 1); print("Hello"); delay_ms(200); lcd_scroll(LCD_LEFT, 3, 200); clear(); } return(0); }
static void console_crlf(console_t* const console) { const uint_fast16_t line_height = console->lcd->font->line_height; console->x = 0; console->y += line_height; const int32_t y_excess = console->y + console->lcd->font->line_height - console->lcd->scroll.height; if( y_excess > 0 ) { lcd_scroll(console->lcd, -line_height); console->y -= y_excess; const lcd_color_t prior_background = lcd_set_background(console->lcd, console->background); lcd_clear_rectangle(console->lcd, 0, lcd_scroll_area_y(console->lcd, console->y), console->lcd->size.w, line_height); lcd_set_background(console->lcd, prior_background); } }
int main(void) { //スクロールの初期設定 SCROLL_FACTORY settings; strcpy(settings.string, "Kisarazu-KNCT"); settings.speed = 250; settings.x = 0; settings.y = 1; settings.direction = RIGHT; lcd_init(); lcd_scroll(settings); return 0; }
void lcd_putline(uint8_t row, char *in) { if(row == 0) { // Title drawtext(in, TITLE_LINECHARS, TITLE_FONT, TITLE_FONT_WIDTH, 0, 0, TITLE_FONT_HEIGHT); } else if(row < 9) { // Body, directly adressed row--; drawtext(in, BODY_LINECHARS, BODY_FONT, BODY_FONT_WIDTH, lcd_scroll_y+BODY_FONT_HEIGHT*row, 0, BODY_FONT_HEIGHT); } else if(row == 9 || row == 10) { // Scrolling if(row == 9) { // Up row = BODY_LINES-1; } else { // Down row = 0; } #define CHUNK 1 // 2 lines of offscrean area, // but only usable for up uint8_t dpyoffset = (row? (row+1)*BODY_FONT_HEIGHT : 0); uint8_t fontoffset = (row ? 0 : BODY_FONT_HEIGHT-1); uint8_t counter = 0; // Scroll speed is ca 12-14 lines/sec while(counter != BODY_FONT_HEIGHT) { lcd_scroll(row == 0 ? -CHUNK : CHUNK); drawtext(in, BODY_LINECHARS, BODY_FONT, BODY_FONT_WIDTH, lcd_scroll_y+dpyoffset, fontoffset, CHUNK); fontoffset += (row ? CHUNK : -CHUNK); counter += CHUNK; } } }
/* Scroll a text horizontally. Number of rows depend on font height. */ void scroll(int start_row, int start_col, int width, int offset){ lcd_scroll(start_row, start_col, width, font_height, offset); };