#pragma once
#include "libSerial/serial.h"
/// @brief storage for a string reader
typedef struct
{
char *buffer; // pointer to workspace
int limit; // string limit
int counter; // byte counter
char complete; // flag complete
char readLines; // true if reading lines with CR at end
} editBuffer;
///
typedef enum
{
EDIT_NULL = 0, ///< No result
EDIT_DONE, ///< All characters read
EDIT_CR ///< Characters up to CR read
} editBufferReturn;
/// @brief Send a string to the user
/// @param ctl Handle of usart
/// @param string String to send
/// @param length Length of string
extern void sendString(usart_ctl *ctl, char const *string, int length);
/// @brief Prepare the line buffer reader
/// @param context editBuffer object to initialise
/// @param buffer Pointer to data: externally allocated memory buffer.
/// @param limit Maximum number of bytes in externally allocated memory buffer.
/// @param readLines if 1 then we are reading text with <CR> as line terminator, control codes ignored.
extern void initReadLine(editBuffer *context, char *buffer, int limit, char readLines);
/// @brief Poll the line buffer reader
/// @param ctl pointer to a USART control structure
/// @param context pointer to the editBuffer context
/// @return what kind of state the buffer is now in
extern editBufferReturn readLine(usart_ctl *ctl, editBuffer *context);