int main() { int err, col, row, i; if ((err = fbopen()) != 0) { fprintf(stderr, "Error: Could not open framebuffer: %d\n", err); exit(1); } // Clear the screen before starting fbclearlines(0, 47); /* init: Draw 12 bands at distinct frequencies as well as *the dials in the middle of the bands */ for (i = 1 ; i < 13 ; i++) { for (row = 470; row > 370; row--){ fbputchar('I', row, COL_NUM(i)); } updatedial(420, COL_NUM(i)); } //Initialize current cursor state for first column // The position of the cursor int keyRow = 420, keyCol = 30; // Display the cursor fbputchar(95, keyRow, keyCol); return 0; } //end main
//function to print a basic view creating separate //space for text from the server and input area. void basicview() { int col; for (col = 0 ; col < 128 ; col++) { fbputchar('*', 0, col); fbputchar('*', 43, col); fbputchar('*', 46, col); } }
void updatedial(int row, int col) { int i; fbputchar('*', row, col-1); fbputchar('*', row, col+1); for(i = 0; i < 12; i++){ if(dials[i].col == col){ dials[i],row = row; } } }
void fbclearlines(int rowStart, int rowEnd) { int i, j; if (rowStart > MAX_SCREEN_Y + 3) return; for (i = rowStart ; i < rowEnd && i < MAX_SCREEN_Y + 4; i++) for (j = 0; j < MAX_SCREEN_X; j++) fbputchar(32, i, j); }
/* * Draw the given string at the given row/column. * String must fit on a single line: wrap-around is not handled. */ void fbputs(const char *s, int row, int col) { char c; while ((c = *s++) != 0){ fbputchar(c, row, col++); if(col == 127){ col = 0; row++; } } }
void fbputpacket(char *msg, int *row) { int len = strlen(msg); int needed_rows = (int)ceil(((double) len) / MAX_SCREEN_X) + 1; if (needed_rows > MAX_SCREEN_Y - 1) { *row = 2; fbclearlines(1, MAX_SCREEN_Y - 1); fbputs("Message too long to display", 1, 0); return; } if (*row + needed_rows > MAX_SCREEN_Y) { // Mark the beginning of the last blank line unsigned char *bottom = framebuffer + (*row * FONT_HEIGHT + fb_vinfo.yoffset) * fb_finfo.line_length; printf("initial position: %p, bottom: %p, byte difference: %d, needed rows: %d\n", framebuffer, (char *)bottom, bottom - framebuffer, needed_rows); // Mark the position from the beginning of the terminal unsigned char *top = framebuffer + (1 * FONT_HEIGHT + fb_vinfo.yoffset) * fb_finfo.line_length; // Mark the new top unsigned char *new_top = framebuffer + ((1 + needed_rows) * FONT_HEIGHT + fb_vinfo.yoffset) * fb_finfo.line_length; // Copy the onscreen stuff up memcpy(top, new_top, bottom - new_top); // Clear everything below fbclearlines(*row - needed_rows, MAX_SCREEN_Y); // Change the value of rows *row = *row - needed_rows; } int col = 0; while (*msg != 0) { if (col == 128) { col = 0; (*row)++; } fbputchar(*msg, *row, col); msg++; col++; } (*row)++; }
// When called prints space on all columns between the rows startRow and endRow // startRow inclusive and endRow exclusive. void clearscreen(int startRow, int endRow) { int x, y; unsigned char pixels, *pixelp = font + FONT_HEIGHT ; unsigned char *pixel, *left = framebuffer + (fb_vinfo.yoffset) * fb_finfo.line_length + (fb_vinfo.xoffset) * BITS_PER_PIXEL / 8; for (y = 0 ; y < 128 ; y++, left += fb_finfo.line_length) { pixels = *pixelp++; pixel = left; for (x = startRow ; x < endRow ; x++, pixels <<= 1, pixel += 4) { //pixel[0] = 0; // pixel[1] = 0; // pixel[2] = 0; // pixel[3] = 0; fbputchar(' ', x, y); } } basicview(); }
/* * Draw the given string at the given row/column. * String must fit on a single line: wrap-around is not handled. */ void fbputs(const char *s, int row, int col) { char c; while ((c = *s++) != 0) fbputchar(c, row, col++); }