AnsweredAssumed Answered

Can someone update the console_get_command() function?

Question asked by kivircik_ali on Jan 4, 2017
Latest reply on Jan 4, 2017 by DragosB

Can someone update the console_get_command() function in No-OS drivers as follows? It;

1. sends back the characters that are received from the serial port

2. perceives backspace key and takes necessary precautions.

I have tested and verified the function with different serial port programs.

 

void console_get_command(char* command)

{

   char received_char = 0;

   unsigned char char_number = 0;

   while(1)

   {

      if (char_number == 0) {

         console_print("-> ");

      }

      

      received_char = XUartPs_RecvByte(STDIN_BASEADDRESS);

      if ((received_char == 127) || (received_char == 8)) { //check if backspace key pressed, the received value depends on the serial port program you used

         command[char_number--] = ';

      } else {

         command[char_number++] = received_char;

      }

      XUartPs_SendByte(STDIN_BASEADDRESS, received_char); //send back what is written

      if ((received_char == '\n') || (received_char == '\r')) {

         if (char_number > 1) {

            break;

         } else {

            char_number = 0;

         }

      }

   }

Outcomes