2017-10-14 51 views
1

這是Compilation error due to table in C++C++ UART Infite循環與TI-Nspire

延續所以這是我的計劃:

#include <os.h> 
#include <nspireio/uart.hpp> 
#include <nspireio/console.hpp> 

int key_already_pressed = 0; 
char oldinput[100] = {0}; 
char voidlist[100] = {0}; 
/* 
void messagel(void) { 
    if(messagemode){ 
    if(isKeyPressed(KEY_NSPIRE_A) && !key_already_pressed) { 
     nio_printf("A"); 
     uart_printf("A"); 
     //strcat(message,"A"); 
     key_already_pressed = 1; 
    } 
    if(isKeyPressed(KEY_NSPIRE_B) && !key_already_pressed) { 
     nio_printf("B"); 
     uart_printf("B"); 
     //strcat(message,"B"); 
     key_already_pressed = 1; 
    } 
     if(isKeyPressed(KEY_NSPIRE_ENTER) && messagemode && !key_already_pressed) { 
      messagemode = 0; 
     key_already_pressed = 1; 
     } 
    if(!any_key_pressed()) 
     key_already_pressed = 0; 
    } 
}*/ 


int main(void) 
{ 
    assert_ndless_rev(874); 
    //clrscr(); 
    nio_console csl; 
    nio_init(&csl,NIO_MAX_COLS,NIO_MAX_ROWS,0,0,NIO_COLOR_WHITE,NIO_COLOR_BLACK,TRUE); 
    nio_set_default(&csl); 
    nio_color(&csl,NIO_COLOR_BLACK,NIO_COLOR_WHITE); 
    nio_printf("Nspire UART Chat by Samy. Compiled the %s At %s\n",__DATE__,__TIME__); 
    nio_color(&csl,NIO_COLOR_WHITE,NIO_COLOR_BLACK); 
    nio_puts("Press any ESC to exit and CTRL to send msg...\n"); 
    while(!isKeyPressed(KEY_NSPIRE_ESC)){ 
    if(isKeyPressed(KEY_NSPIRE_CTRL) && !key_already_pressed){ 
    nio_printf(">"); 
    char input[100] = {0}; 
     nio_getsn(input,100); 
    uart_printf(input); 
    key_already_pressed = 1; 
    } 
    if(!any_key_pressed()) 
     key_already_pressed = 0; 
    if(uart_ready()) { 
    char input[100] = {0}; 
    getline(input,100); 
    if(oldinput != input) { 
     if(input != voidlist) { 
      nio_puts(input); 
      strcpy(oldinput,input); 
      strcpy(input,voidlist); 
     } 
    } 
    } 
    } 
    nio_puts("Closing the programm."); 
    nio_free(&csl); 

    return 0; 
} 

的PROGRAME不停地發送一個字母continualy TI的屏幕上和串行輸出。例如,如果我在串口監視器上寫入lol,它將發送l,如果我發送一個新字符串,字母不會改變。

我真的希望這個程序在週末結束時全面工作,所以告訴我我做錯了什麼?

PS:我是法國人

+0

你可能還沒有完全理解弦背後的概念在C/C++中可能會有所幫助瞭解更多關於它們的信息,如果你編寫的程序如此接近實際的硬件,只是說;) – ExOfDe

+0

我沒有選擇它是唯一的方法來與calc進行通信 – TurtleForGaming

+0

不要擔心,但對於這種情況下,它可以幫助你,我給了我的答案ght幫助你進一步。 – ExOfDe

回答

0

讓我們看看你的代碼

if(uart_ready()) { 
    char input[100] = {0}; 
    getline(input,100); 
    if(oldinput != input) { 
     if(input != voidlist) { 
      nio_puts(input); 
      strcpy(oldinput,input); 
      strcpy(input,voidlist); 
     } 
    } 
} 

要檢查的這部分,如果UART已準備好,如果這樣你用100元聲明一個字符ARRY。到這裏罰款。但你在做什麼:

if(oldinput != input) { 

你比較數組'oldinput'的地址與前面聲明的'input'數組的地址。我假定你真正想要的是比較這兩個char數組的內容,因爲'oldinput'和'input'總是不相等。

你其實想是這樣的:

if(strcmp(oldinput,input) != 0){ 

這這些領域的實際內容進行比較。但請注意,這個函數假設在字符串末尾有一個空終止符。下一個'如果'也是如此。

試着解決這個問題,它可能會幫助你解決你的問題。

Strings in C

PS:我是德國人,但誰在乎XP

+0

你能給我答案我學到了很多東西,工作 – TurtleForGaming

+0

如果我可以我會,但我沒有測試代碼的手段,對不起。我在家裏使用stdperiph庫,沒有使用您的庫的經驗。我只能指出可能是問題的最明顯的錯誤。 但是,如果你仔細閱讀我的答案,我相信它會解決重複編寫相同內容的問題。只是想一想。在你現在的版本中,你的條件將永遠是真實的。那是你不想要的東西。你只需要他們有時候是真的! – ExOfDe