void screen_write_char(char c) { if (c == '\n') { kdata.screen_x = 0; kdata.screen_y ++; } else if (c == '\t') { kdata.screen_x += 4 - (kdata.screen_x % 4); } else if (c == '\r') { kdata.screen_x = 0; } else { _screen_write_char(kdata.screen_y, kdata.screen_x, c, kdata.screen_fg, kdata.screen_bg); kdata.screen_x ++; if (kdata.screen_x == SCREEN_WIDTH) { kdata.screen_x = 0; kdata.screen_y ++; } } if (kdata.screen_y == SCREEN_HEIGHT) { _screen_scroll_up(); kdata.screen_y --; } screen_move_cursor(kdata.screen_y, kdata.screen_x); serial_write_char(c); }
int getDistance(serial * s){ char buffer[128]; int distance = 0; //Request sensor data serial_write_char(s, 'p'); usleep(500); //Read the data serial_read(s, buffer, '\n', 128); //Data received if(strlen(buffer) > 0){ //printf("Buffer length: %d\n", strlen(buffer)); //printf("Distance: %d \n", (int)buffer[0]); distance = (int)buffer[0]; } //Clear the buffer buffer_clear(s); return(distance); }