Last active
August 29, 2015 14:05
-
-
Save clicube/32504945d94669dfc0c6 to your computer and use it in GitHub Desktop.
RasPi-ExtBoard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <avr/io.h> | |
#include <avr/interrupt.h> | |
#include <avr/pgmspace.h> | |
#include <string.h> | |
#include "uart.h" | |
#define UART_BAUD_RATE 9600 | |
#define CMD_BUFFER_LEN 32 | |
#define PROMPT "Raspi-ExtBoard> " | |
void main_loop(void); | |
void wait_for_cmd(char*); | |
void exec_cmd(char*); | |
int main(void) | |
{ | |
uart_init(UART_BAUD_SELECT(UART_BAUD_RATE, F_CPU)); | |
sei(); | |
main_loop(); | |
return 0; | |
} | |
inline void main_loop() | |
{ | |
char buf[CMD_BUFFER_LEN]; | |
for(;;) | |
{ | |
wait_for_cmd(buf); | |
exec_cmd(buf); | |
} | |
} | |
inline void wait_for_cmd(char* buf) | |
{ | |
uint16_t c; | |
uint8_t buf_idx; | |
buf[0] = '\0'; | |
buf_idx = 0; | |
uart_puts_P(PROMPT); | |
for(;;) | |
{ | |
c = uart_getc(); | |
if(c & UART_NO_DATA){ continue; } | |
if( c == '\n' || c == '\r' ) | |
{ | |
uart_puts_P("\r\n"); | |
if( buf_idx > 0 ) | |
{ | |
buf[buf_idx] = '\0'; | |
return; | |
} | |
else | |
{ | |
uart_puts_P(PROMPT); | |
} | |
} | |
else if( c == '\b' || c == '\x7f') | |
{ | |
if(buf_idx > 0) | |
{ | |
buf[buf_idx] = '\0'; | |
buf_idx--; | |
uart_puts_P("\b \b"); | |
} | |
else | |
{ | |
uart_putc('\a'); | |
} | |
} | |
else if( 32 <= c && c <=126 ) | |
{ | |
if(buf_idx < CMD_BUFFER_LEN-1) | |
{ | |
uart_putc((char)c); | |
buf[buf_idx] = (char)c; | |
buf_idx++; | |
} | |
else | |
{ | |
uart_putc('\a'); | |
} | |
} | |
} | |
} | |
inline void exec_cmd(char* str) | |
{ | |
/* いまからここ書く!!!! */ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment