Rev 13 | Rev 15 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 10 | mjames | 1 | /// Functions provided that use serial code, but are more independent |
| 2 | |||
| 3 | #include "libSerial/serialUtils.h" |
||
| 4 | |||
| 5 | void sendString(usart_ctl *ctl, char const *string, int length) |
||
| 6 | { |
||
| 7 | for (int i = 0; i < length; i++) |
||
| 8 | PutCharSerial(ctl, string[i]); |
||
| 9 | } |
||
| 10 | |||
| 11 | void initReadLine(editBuffer *context, char *buffer, int limit, char readLines) |
||
| 12 | { |
||
| 13 | context->buffer = buffer; |
||
| 14 | context->limit = limit; |
||
| 15 | context->counter = 0; |
||
| 16 | context->complete = 0; |
||
| 17 | context->readLines = readLines; // if readlines , then we look for \r at the end of a line and skip control chars |
||
| 18 | context->buffer[0] = 0; |
||
| 19 | } |
||
| 20 | |||
| 21 | editBufferReturn readLine(usart_ctl *ctl, editBuffer *context) |
||
| 22 | { |
||
| 23 | int cnt = PollSerial(ctl); |
||
| 24 | if (!cnt) |
||
| 25 | return EDIT_NULL; |
||
| 26 | |||
| 27 | while (cnt && context->counter != context->limit) |
||
| 28 | { |
||
| 29 | char c = GetCharSerial(ctl); |
||
| 30 | if (!context->readLines || c >= ' ') |
||
| 31 | { |
||
| 32 | context->buffer[context->counter++] =c; |
||
| 33 | if (context->counter != context->limit) |
||
| 34 | context->buffer[context->counter] = 0; |
||
| 35 | } |
||
| 36 | if (context->readLines) |
||
| 37 | { |
||
| 38 | if (c == '\r') |
||
| 39 | { |
||
| 40 | context->complete = 1; |
||
| 41 | return EDIT_CR; |
||
| 42 | } |
||
| 43 | else if (c < ' ') |
||
| 44 | { |
||
| 45 | context->counter = 0; |
||
| 46 | context->buffer[0] = 0; |
||
| 47 | } |
||
| 48 | } |
||
| 49 | } |
||
| 50 | |||
| 51 | return (context->counter == context->limit) ? EDIT_DONE : EDIT_NULL; |
||
| 52 | } |
||
| 14 | mjames | 53 | |
| 54 | |||
| 55 | void resetInput(editBuffer * context) |
||
| 56 | { |
||
| 57 | context->counter = 0; |
||
| 58 | context->complete = 0; |
||
| 59 | } |
||
| 60 | |||
| 61 | int charCount(editBuffer * context) |
||
| 62 | { |
||
| 63 | return context->counter; |
||
| 64 | } |