fix uart_RX & node.input() input conflict

This commit is contained in:
cs8425 2015-06-25 21:24:05 +08:00
parent 5c84ea1b74
commit 079fe08962
3 changed files with 220 additions and 101 deletions

View File

@ -5,7 +5,7 @@
#include "eagle_soc.h"
#include "c_types.h"
#define RX_BUFF_SIZE 0x100
#define RX_BUFF_SIZE 0x800 // 2048
#define TX_BUFF_SIZE 100
typedef enum {
@ -107,4 +107,3 @@ void uart0_tx_buffer(uint8 *buf, uint16 len);
void uart_setup(uint8 uart_no);
STATUS uart_tx_one_char(uint8 uart, uint8 TxChar);
#endif

View File

@ -16,6 +16,8 @@
#define USE_OPTIMIZE_PRINTF
#define UART_BUFF_SIZE 1024
#ifdef DEVELOP_VERSION
#define NODE_DEBUG
#define COAP_DEBUG

View File

@ -491,7 +491,7 @@ void dojob(lua_Load *load){
const char *oldprogname = progname;
progname = NULL;
do{
// do{
if(load->done == 1){
l = c_strlen(b);
if (l > 0 && b[l-1] == '\n') /* line ends with newline? */
@ -531,7 +531,7 @@ void dojob(lua_Load *load){
load->prmt = get_prompt(L, 0);
}
}
}while(0);
// }while(0);
progname = oldprogname;
@ -594,107 +594,225 @@ extern bool uart0_echo;
extern bool run_input;
extern uint16_t need_len;
extern int16_t end_char;
// void readline(lua_Load *load){
// // NODE_DBG("readline() is called.\n");
// #ifdef DEVKIT_VERSION_0_9
// update_key_led();
// #endif
// char ch;
// while (uart_getc(&ch))
// {
// if(run_input)
// {
// /* handle CR key */
// if (ch == '\r')
// {
// char next;
// if (uart_getc(&next))
// ch = next;
// }
// /* backspace key */
// else if (ch == 0x7f || ch == 0x08)
// {
// if (load->line_position > 0)
// {
// if(uart0_echo) uart_putc(0x08);
// if(uart0_echo) uart_putc(' ');
// if(uart0_echo) uart_putc(0x08);
// load->line_position--;
// }
// load->line[load->line_position] = 0;
// continue;
// }
// /* EOT(ctrl+d) */
// // else if (ch == 0x04)
// // {
// // if (load->line_position == 0)
// // // No input which makes lua interpreter close
// // donejob(load);
// // else
// // continue;
// // }
//
// /* end of line */
// if (ch == '\r' || ch == '\n')
// {
// load->line[load->line_position] = 0;
// if(uart0_echo) uart_putc('\n');
// uart_on_data_cb(load->line, load->line_position);
// if (load->line_position == 0)
// {
// /* Get a empty line, then go to get a new line */
// c_puts(load->prmt);
// os_timer_disarm(&readline_timer);
// os_timer_setfn(&readline_timer, (os_timer_func_t *)readline, load);
// os_timer_arm(&readline_timer, READLINE_INTERVAL, 0); // no repeat
// } else {
// load->done = 1;
// os_timer_disarm(&lua_timer);
// os_timer_setfn(&lua_timer, (os_timer_func_t *)dojob, load);
// os_timer_arm(&lua_timer, READLINE_INTERVAL, 0); // no repeat
// }
// continue;
// }
//
// /* other control character or not an acsii character */
// // if (ch < 0x20 || ch >= 0x80)
// // {
// // continue;
// // }
//
// /* echo */
// if(uart0_echo) uart_putc(ch);
//
// /* it's a large line, discard it */
// if ( load->line_position + 1 >= load->len ){
// load->line_position = 0;
// }
// }
//
// load->line[load->line_position] = ch;
// load->line_position++;
//
// if(!run_input)
// {
// if( ((need_len!=0) && (load->line_position >= need_len)) || \
// (load->line_position >= load->len) || \
// ((end_char>=0) && ((unsigned char)ch==(unsigned char)end_char)) )
// {
// uart_on_data_cb(load->line, load->line_position);
// load->line_position = 0;
// }
// }
//
// ch = 0;
// }
//
// if( (load->line_position > 0) && (!run_input) && (need_len==0) && (end_char<0) )
// {
// uart_on_data_cb(load->line, load->line_position);
// load->line_position = 0;
// }
// // if there is no input from user, repeat readline()
// os_timer_disarm(&readline_timer);
// os_timer_setfn(&readline_timer, (os_timer_func_t *)readline, load);
// os_timer_arm(&readline_timer, READLINE_INTERVAL, 0); // no repeat
// }
char UART_buf[UART_BUFF_SIZE];
int UART_pos = 0;
void readline(lua_Load *load){
// NODE_DBG("readline() is called.\n");
// NODE_DBG("readline() is called.\n");
#ifdef DEVKIT_VERSION_0_9
update_key_led();
update_key_led();
#endif
char ch;
while (uart_getc(&ch))
{
if(run_input)
char ch;
while (uart_getc(&ch))
{
/* handle CR key */
if (ch == '\r')
{
char next;
if (uart_getc(&next))
ch = next;
}
/* backspace key */
else if (ch == 0x7f || ch == 0x08)
{
if (load->line_position > 0)
if(run_input)
{
if(uart0_echo) uart_putc(0x08);
if(uart0_echo) uart_putc(' ');
if(uart0_echo) uart_putc(0x08);
load->line_position--;
/* handle CR key */
if (ch == '\r')
{
char next;
if (uart_getc(&next))
ch = next;
}
/* backspace key */
else if (ch == 0x7f || ch == 0x08)
{
if (load->line_position > 0)
{
if(uart0_echo)
{
uart_putc(0x08);
uart_putc(' ');
uart_putc(0x08);
}
load->line_position--;
}
load->line[load->line_position] = 0;
continue;
}
/* EOT(ctrl+d) */
// else if (ch == 0x04)
// {
// if (load->line_position == 0)
// // No input which makes lua interpreter close
// donejob(load);
// else
// continue;
// }
/* end of line */
if (ch == '\r' || ch == '\n')
{
load->line[load->line_position] = 0;
if(uart0_echo) uart_putc('\n');
uart_on_data_cb(load->line, load->line_position);
if (load->line_position == 0)
{
/* Get a empty line, then go to get a new line */
c_puts(load->prmt);
os_timer_disarm(&readline_timer);
os_timer_setfn(&readline_timer, (os_timer_func_t *)readline, load);
os_timer_arm(&readline_timer, READLINE_INTERVAL, 0); // no repeat
} else {
load->done = 1;
os_timer_disarm(&lua_timer);
os_timer_setfn(&lua_timer, (os_timer_func_t *)dojob, load);
os_timer_arm(&lua_timer, READLINE_INTERVAL, 0); // no repeat
}
continue;
}
/* other control character or not an acsii character */
// if (ch < 0x20 || ch >= 0x80)
// {
// continue;
// }
/* echo */
if(uart0_echo) uart_putc(ch);
/* it's a large line, discard it */
if ( load->line_position + 1 >= load->len ){
load->line_position = 0;
}
load->line[load->line_position] = ch;
load->line_position++;
}else{
UART_buf[UART_pos] = ch;
UART_pos++;
// if ( UART_pos + 1 >= RX_BUFF_SIZE ){
// uart_on_data_cb(UART_buf, UART_pos);
// UART_pos = 0;
// break;
// }
if( ((need_len!=0) && (UART_pos >= need_len)) || \
( UART_pos + 1 >= UART_BUFF_SIZE ) || \
((end_char>=0) && ((unsigned char)ch==(unsigned char)end_char)) )
{
uart_on_data_cb(UART_buf, UART_pos);
// uart_on_data_cb(load->line, load->line_position);
UART_pos = 0;
}
}
load->line[load->line_position] = 0;
continue;
}
/* EOT(ctrl+d) */
// else if (ch == 0x04)
// {
// if (load->line_position == 0)
// // No input which makes lua interpreter close
// donejob(load);
// else
// continue;
// }
/* end of line */
if (ch == '\r' || ch == '\n')
{
load->line[load->line_position] = 0;
if(uart0_echo) uart_putc('\n');
uart_on_data_cb(load->line, load->line_position);
if (load->line_position == 0)
{
/* Get a empty line, then go to get a new line */
c_puts(load->prmt);
os_timer_disarm(&readline_timer);
os_timer_setfn(&readline_timer, (os_timer_func_t *)readline, load);
os_timer_arm(&readline_timer, READLINE_INTERVAL, 0); // no repeat
} else {
load->done = 1;
os_timer_disarm(&lua_timer);
os_timer_setfn(&lua_timer, (os_timer_func_t *)dojob, load);
os_timer_arm(&lua_timer, READLINE_INTERVAL, 0); // no repeat
}
continue;
}
/* other control character or not an acsii character */
// if (ch < 0x20 || ch >= 0x80)
// {
// continue;
// }
/* echo */
if(uart0_echo) uart_putc(ch);
/* it's a large line, discard it */
if ( load->line_position + 1 >= load->len ){
load->line_position = 0;
}
ch = 0;
}
load->line[load->line_position] = ch;
load->line_position++;
if(!run_input)
if( (UART_pos > 0) && (!run_input) && (need_len==0) && (end_char<0) )
{
if( ((need_len!=0) && (load->line_position >= need_len)) || \
(load->line_position >= load->len) || \
((end_char>=0) && ((unsigned char)ch==(unsigned char)end_char)) )
{
uart_on_data_cb(load->line, load->line_position);
load->line_position = 0;
}
uart_on_data_cb(UART_buf, UART_pos);
UART_pos = 0;
}
ch = 0;
}
if( (load->line_position > 0) && (!run_input) && (need_len==0) && (end_char<0) )
{
uart_on_data_cb(load->line, load->line_position);
load->line_position = 0;
}
// if there is no input from user, repeat readline()
os_timer_disarm(&readline_timer);
os_timer_setfn(&readline_timer, (os_timer_func_t *)readline, load);
os_timer_arm(&readline_timer, READLINE_INTERVAL, 0); // no repeat
// if there is no input from user, repeat readline()
os_timer_disarm(&readline_timer);
os_timer_setfn(&readline_timer, (os_timer_func_t *)readline, load);
os_timer_arm(&readline_timer, READLINE_INTERVAL, 0); // no repeat
}