-
Notifications
You must be signed in to change notification settings - Fork 0
/
kserial.h
52 lines (40 loc) · 1.57 KB
/
kserial.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#ifndef _kserial_h_
#define _kserial_h_
#include <pololu/orangutan.h>
// This will not return until the serial send buffer is empty.
//
void empty_sendbuf();
// This will not return until all characters have been written.
//
void s_write(const char* buf, int len);
// This function will read up to want bytes of data
// into buf and return the actual count read. If data
// is available, or if msecTimeout==0, this function
// will return immediately. Otherwise, it will block
// until either msecTimeout milliseconds elapses or
// until data is available, whichever occurs first.
//
int s_read(char* buf, int want, int msecTimeout);
// This function works just like printf. If you want a new line
// at the end, you may append s_eol[] chars or use s_println().
//
int s_printf(const char* fmt, ...);
// The character sequence that produces a carriage return plus linefeed.
//
extern const char s_eol[];
// Just like s_printf(), but puts s_eol at the end.
//
int s_println(const char* fmt, ...);
#ifndef USE_FLOATS
#define USE_FLOATS 0
#endif
#if USE_FLOATS
// Because %f does not seem to work, here are alternatives for printing floats.
// The will print as though you had specified %.*f, places.
//
char* s_ftosbp(char** buf, double f, int places); // e.g. char buf[16]; char* bp = buf; s_println("x=%s", s_ftosbp(&bp, x));
char* s_ftosb(char* buf, double f, int places); // e.g. char buf[16]; s_println("x=%s", s_ftosb(buf, x));
char* s_ftos(double f, int places); // a non-reentrant version that uses a static buffer
int s_printflt(double f, int places);
#endif
#endif // #ifndef _kserial_h_