/// Functions provided that use serial code, but are more independent
#include "libSerial/serialUtils.h"
void sendString(usart_ctl *ctl, char const *string, int length)
{
for (int i = 0; i < length; i++)
PutCharSerial(ctl, string[i]);
}
void initReadLine(editBuffer *context, char *buffer, int limit, char readLines)
{
context->buffer = buffer;
context->limit = limit;
context->counter = 0;
context->complete = 0;
context->readLines = readLines; // if readlines , then we look for \r at the end of a line and skip control chars
context->buffer[0] = 0;
}
editBufferReturn readLine(usart_ctl *ctl, editBuffer *context)
{
int cnt = PollSerial(ctl);
if (!cnt)
return EDIT_NULL;
while (cnt && context->counter != context->limit)
{
char c = GetCharSerial(ctl);
if (!context->readLines || c >= ' ')
{
context->buffer[context->counter++] =c;
if (context->counter != context->limit)
context->buffer[context->counter] = 0;
}
if (context->readLines)
{
if (c == '\r')
{
context->complete = 1;
return EDIT_CR;
}
else if (c < ' ')
{
context->counter = 0;
context->buffer[0] = 0;
}
}
}
return (context->counter == context->limit) ? EDIT_DONE : EDIT_NULL;
}