Rev 13 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
10 | mjames | 1 | #pragma once |
2 | #include "libSerial/serial.h" |
||
3 | |||
4 | /// @brief storage for a string reader |
||
5 | typedef struct |
||
6 | { |
||
7 | char *buffer; // pointer to workspace |
||
8 | int limit; // string limit |
||
9 | int counter; // byte counter |
||
10 | char complete; // flag complete |
||
11 | char readLines; // true if reading lines with CR at end |
||
12 | } editBuffer; |
||
13 | |||
14 | mjames | 14 | /// @brief Use this for the readlines parameter if reading up to buffer length or using CR |
15 | static const char READLINES_CR = 1; |
||
16 | /// @brief Use this for the readlines parameter if reading up to buffer length |
||
17 | static const char READLINES_BIN = 0; |
||
18 | |||
10 | mjames | 19 | /// |
20 | typedef enum |
||
21 | { |
||
22 | EDIT_NULL = 0, ///< No result |
||
23 | EDIT_DONE, ///< All characters read |
||
24 | EDIT_CR ///< Characters up to CR read |
||
25 | } editBufferReturn; |
||
26 | |||
11 | mjames | 27 | /// @brief Send a string to the user |
13 | mjames | 28 | /// @param ctl Handle of usart |
29 | /// @param string String to send |
||
30 | /// @param length Length of string |
||
11 | mjames | 31 | extern void sendString(usart_ctl *ctl, char const *string, int length); |
32 | |||
33 | /// @brief Prepare the line buffer reader |
||
34 | /// @param context editBuffer object to initialise |
||
35 | /// @param buffer Pointer to data: externally allocated memory buffer. |
||
36 | /// @param limit Maximum number of bytes in externally allocated memory buffer. |
||
37 | /// @param readLines if 1 then we are reading text with <CR> as line terminator, control codes ignored. |
||
10 | mjames | 38 | extern void initReadLine(editBuffer *context, char *buffer, int limit, char readLines); |
39 | |||
11 | mjames | 40 | /// @brief Poll the line buffer reader |
41 | /// @param ctl pointer to a USART control structure |
||
42 | /// @param context pointer to the editBuffer context |
||
43 | /// @return what kind of state the buffer is now in |
||
10 | mjames | 44 | extern editBufferReturn readLine(usart_ctl *ctl, editBuffer *context); |
14 | mjames | 45 | |
46 | /// @brief Reset the state of the line buffer reader for the next command |
||
47 | /// @param context editBuffer object to reset |
||
48 | extern void resetInput(editBuffer * context); |
||
49 | |||
50 | |||
51 | /// @brief Return number of characters in context |
||
52 | /// @param context |
||
53 | /// @return number of characters in the context |
||
54 | extern int charCount(editBuffer * context); |