This commit is contained in:
pikastech 2021-12-28 10:51:03 +08:00
commit 49802461e7

View File

@ -49,22 +49,15 @@ PikaObj *pikaMain;
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
#define RX_Buff_SIZE 256
char rxBuff[RX_Buff_SIZE] = { 0 };
char rx_char = 0;
void clearBuff(char *buff, uint32_t size) {
for (int i = 0; i < size; i++) {
buff[i] = 0;
}
}
static char rx_char = 0;
void USART1_IRQHandler(void){
if (LL_USART_IsActiveFlag_RXNE(USART1)) {
rx_char = LL_USART_ReceiveData8(USART1);
}
}
char pika_getchar(){
/* support pikaScript Shell */
char __platform_getchar(){
char res = 0;
while(rx_char != 0){
res = rx_char;
@ -93,38 +86,8 @@ int main(void){
printf("| [ https://github.com/pikastech/pikascript ] |\r\n");
printf("| [ https://gitee.com/lyon1998/pikascript ] |\r\n");
printf("| |\r\n");
printf("------------------------------------------------------------------\r\n");
pikaMain = pikaScriptInit();
printf(">>> ");
while (1){
char inputChar = pika_getchar();
printf("%c", inputChar);
if ((inputChar == '\b') || (inputChar == 127)){
uint32_t size = strGetSize(rxBuff);
if(size == 0){
printf(" ");
continue;
}
printf(" \b");
rxBuff[size - 1] = 0;
continue;
}
if (inputChar != '\r' && inputChar != '\n') {
strAppendWithSize(rxBuff, &inputChar, 1);
continue;
}
if ( (inputChar == '\r') || (inputChar == '\n') ) {
printf("\r\n");
if(strEqu("exit()", rxBuff)){
/* exit pika shell */
break;
}
obj_run(pikaMain, rxBuff);
printf(">>> ");
clearBuff(rxBuff, RX_Buff_SIZE);
continue;
}
}
printf("------------------------------------------------------------------\r\n");
pikaScriptShell(pikaScriptInit());
/* after exit() from pika shell */
NVIC_SystemReset();
}