/* ** Print an array of words in columns. */ void el_print_columns(int ac, char **av) { char *p; int i; int j; int k; int len; int skip; int longest; int cols; /* Find longest name, determine column count from that. */ for (longest = 0, i = 0; i < ac; i++) if ((j = strlen((char *)av[i])) > longest) longest = j; cols = tty_cols / (longest + 3); tty_puts(NEWLINE); for (skip = ac / cols + 1, i = 0; i < skip; i++) { for (j = i; j < ac; j += skip) { for (p = av[j], len = strlen((char *)p), k = len; --k >= 0; p++) tty_put(*p); if (j + skip < ac) while (++len < longest + 3) tty_put(' '); } tty_puts(NEWLINE); } }
static void clear_line(void) { rl_point = -(int)strlen(rl_prompt); tty_put('\r'); ceol(); rl_point = 0; rl_end = 0; rl_line_buffer[0] = '\0'; }
static void reposition(void) { int i; tty_put('\r'); tty_puts(rl_prompt); for (i = 0; i < rl_point; i++) tty_show(rl_line_buffer[i]); }
void loop_states(void) { char c; for(;;) { for(;robot_state == CONNECTED;) { //wait for commands if(!bt_rx_empty()) { c = bt_get_block(); if (is_endchar(c)) { char buffer[128]; if (bt_get_command(buffer)) { // interpret command if (interpret_command(buffer) && robot_state == CONNECTED) { tty_puts("COMMAND: "); tty_puts(buffer); tty_puts("\r\n"); } } } } } for(;robot_state == DISCONNECTED;) { //loopback BLUETOOTH <--> UART1 interface (ttyUSB) if (!tty_rx_empty()) { c = tty_get_noblock(); bt_put(c); } if(!bt_rx_empty()) { c = bt_get_noblock(); tty_put(c); //still check for commands as connected disconnected if (is_endchar(c)) { char buffer[128]; if (bt_get_command(buffer)) { interpret_command(buffer); } } } } } }
int tty_bufc(char ch) { int rc=OK; if(out_bufpos==OUT_MAXBUF) { rc=tty_put(out_buffer,OUT_MAXBUF); out_bufpos=0; } out_buffer[out_bufpos++]=ch; return rc; }
static el_status_t delete_string(int count) { int i; char *p; if (count <= 0 || rl_end == rl_point) return el_ring_bell(); if (count == 1 && rl_point == rl_end - 1) { /* Optimize common case of delete at end of line. */ rl_end--; p = &rl_line_buffer[rl_point]; i = 1; tty_put(' '); if (ISCTL(*p)) { i = 2; tty_put(' '); } else if (rl_meta_chars && ISMETA(*p)) { i = 3; tty_put(' '); tty_put(' '); } tty_backn(i); *p = '\0'; return CSmove; } if (rl_point + count > rl_end && (count = rl_end - rl_point) <= 0) return CSstay; if (count > 1) save_yank(rl_point, count); for (p = &rl_line_buffer[rl_point], i = rl_end - (rl_point + count) + 1; --i >= 0; p++) p[0] = p[count]; ceol(); rl_end -= count; tty_string(&rl_line_buffer[rl_point]); return CSmove; }
static void ceol(void) { int extras; int i; char *p; for (extras = 0, i = rl_point, p = &rl_line_buffer[i]; i <= rl_end; i++, p++) { tty_put(' '); if (ISMETA(*p)) { if (rl_meta_chars) { tty_put(' '); tty_put(' '); extras += 2; } } if (ISCTL(*p)) { tty_put(' '); extras++; } } for (i += extras; i > rl_point; i--) tty_back(); }
static void tty_show(unsigned char c) { if (c == DEL) { tty_put('^'); tty_put('?'); } else if (ISCTL(c)) { tty_put('^'); tty_put(UNCTL(c)); } else if (rl_meta_chars && ISMETA(c)) { tty_put('M'); tty_put('-'); tty_put(UNMETA(c)); } else { tty_put(c); } }
void tty_puts(const char * string) { #ifdef BUFFERED while(*string) { buffer_put(&u1tx, *string); usart_enable_tx_interrupt(USART1); string++; } #else while(*string) { tty_put(*string); string++; } #endif }
int tty_putc(char ch) { return tty_put((byte*)&ch,1); }
int tty_bufflush() { int rc=tty_put(out_buffer,out_bufpos); out_bufpos=0; return rc; }
el_status_t el_ring_bell(void) { tty_put('\07'); tty_flush(); return CSstay; }
static void tty_puts(const char *p) { while (*p) tty_put(*p++); }