Query the serial input buffer for any new characters
| 159 | |
| 160 | // Query the serial input buffer for any new characters |
| 161 | int CLI_process() |
| 162 | { |
| 163 | // Current buffer position |
| 164 | uint8_t prev_buf_pos = CLILineBufferCurrent; |
| 165 | |
| 166 | if (CLILineBufferPrev != 255) { |
| 167 | prev_buf_pos = CLILineBufferPrev; |
| 168 | CLILineBufferPrev = 255; |
| 169 | } else { |
| 170 | // Process each character while available |
| 171 | while ( 1 ) |
| 172 | { |
| 173 | // No more characters to process |
| 174 | if ( Output_availablechar() == 0 ) |
| 175 | break; |
| 176 | |
| 177 | // Retrieve from output module |
| 178 | char cur_char = (char)Output_getchar(); |
| 179 | |
| 180 | // Make sure buffer isn't full |
| 181 | if ( CLILineBufferCurrent >= CLILineBufferMaxSize ) |
| 182 | { |
| 183 | print( NL ); |
| 184 | erro_printNL("Serial line buffer is full, dropping character and resetting..."); |
| 185 | |
| 186 | // Clear buffer |
| 187 | CLILineBufferCurrent = 0; |
| 188 | |
| 189 | // Reset the prompt |
| 190 | prompt(); |
| 191 | |
| 192 | return 0; |
| 193 | } |
| 194 | |
| 195 | // Place into line buffer |
| 196 | CLILineBuffer[CLILineBufferCurrent++] = cur_char; |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | // Display Hex Key Input if enabled |
| 201 | if ( CLIHexDebugMode && CLILineBufferCurrent > prev_buf_pos ) |
| 202 | { |
| 203 | print("\033[s\r\n"); // Save cursor position, and move to the next line |
| 204 | print("\033[2K"); // Erases the current line |
| 205 | |
| 206 | uint8_t pos = prev_buf_pos; |
| 207 | while ( CLILineBufferCurrent > pos ) |
| 208 | { |
| 209 | printHex( CLILineBuffer[pos++] ); |
| 210 | print(" "); |
| 211 | } |
| 212 | |
| 213 | print("\033[u"); // Restore cursor position |
| 214 | } |
| 215 | |
| 216 | // If buffer has changed, output to screen while there are still characters in the buffer not displayed |
| 217 | uint8_t dirty = CLILineBufferCurrent > prev_buf_pos; |
| 218 | while ( CLILineBufferCurrent > prev_buf_pos ) |
no test coverage detected
searching dependent graphs…