simpletext library  v0.98
Compact variations of put/get write/read and print/scan for smaller program sizes
simpletext.h
Go to the documentation of this file.
1 
28 #ifndef __SimpleTEXT__
29 #define __SimpleTEXT__
30 
31 #include <propeller.h>
32 
33 #ifdef __cplusplus
34 extern "C"
35 {
36 #endif
37 
38 #if !defined(__PROPELLER_32BIT_DOUBLES__)
39 #error "This library requires 32bit doubles"
40 #endif
41 
42 #define TERM_NAME_LEN 20
43 #define TERM_COG_LEN 7
44 
45 typedef struct text_struct
46 {
47  int (*rxChar)(struct text_struct *p); /* required for terminal to work */
48  int (*txChar)(struct text_struct *p, int ch); /* required for terminal to work */
49  int cogid[TERM_COG_LEN]; /* pointer to cog(s) used if any */
50  volatile void *devst; /* pointer to device info struct */
51 } text_t;
52 
53 #define getStopCOGID(id) ((id)-(1))
54 #define setStopCOGID(id) ((id)+(1))
55 
60 #include "serial.h"
61 
62 /* Values for use with SimpleIDE Terminal */
63 #ifndef HOME
64 
67 #define HOME (1)
68 #endif
69 
70 #ifndef CRSRXY
71 
77 #define CRSRXY (2)
78 #endif
79 
80 #ifndef CRSRLF
81 
85 #define CRSRLF (3)
86 #endif
87 
88 #ifndef CRSRRT
89 
93 #define CRSRRT (4)
94 #endif
95 
96 #ifndef CRSRUP
97 
101 #define CRSRUP (5)
102 #endif
103 
104 #ifndef CRSRDN
105 
109 #define CRSRDN (6)
110 #endif
111 
112 #ifndef BEEP
113 
117 #define BEEP (7)
118 #endif
119 
120 #ifndef BKSP
121 
126 #define BKSP (8)
127 #endif
128 
129 #ifndef TAB
130 
134 #define TAB (9)
135 #endif
136 
137 #ifndef NL
138 
142 #define NL (10)
143 #endif
144 
145 #ifndef LF
146 
149 #define LF (10)
150 #endif
151 
152 #ifndef CLREOL
153 
157 #define CLREOL (11)
158 #endif
159 
160 #ifndef CLRDN
161 
165 #define CLRDN (12)
166 #endif
167 
168 #ifndef CR
169 
173 #define CR (13)
174 #endif
175 
176 #ifndef CRSRX
177 
181 #define CRSRX (14)
182 #endif
183 
184 #ifndef CRSRY
185 
189 #define CRSRY (15)
190 #endif
191 
192 #ifndef CLS
193 
197 #define CLS (16)
198 #endif
199 
200 
201 typedef text_t terminal;
202 
203 
212 terminal *simpleterm_open(void);
213 
214 
220 void simpleterm_close(void);
221 
222 
228 terminal *simpleterm_pointer(void);
229 
230 
237 static inline void simpleterm_set(text_t *ptr)
238 {
239  extern text_t *dport_ptr;
240  simpleterm_close();
241  dport_ptr = ptr;
242 }
243 
244 
250 int getBin(void);
251 
252 
258 int getChar(void);
259 
260 
266 int getDec(void);
267 
268 
274 float getFloat(void);
275 
276 
282 int getHex(void);
283 
284 
295 char *getStr(char *buffer, int max);
296 
297 
303 void putBin(int value);
304 
305 
314 void putBinDigits(int value, int digits);
315 
316 
322 void putChar(char c);
323 
324 
330 void putDec(int value);
331 
332 
340 void putDecDigits(int value, int width);
341 
342 
349 void putFloat(float value);
350 
351 
357 void putHex(int value);
358 
359 
368 void putHexDigits(int value, int digits);
369 
370 
381 void putFloatPrecision(float value, int width, int precision);
382 
383 
389 int putln(const char* str);
390 
391 
398 int putLine(const char* str);
399 
400 
406 int putStr(const char* str);
407 
415 int putStrDigits(char* str, int width);
416 
424 int readBin(text_t *device);
425 
426 
434 int readChar(text_t *device);
435 
436 
444 int readDec(text_t *device);
445 
446 
454 float readFloat(text_t *device);
455 
456 
464 int readHex(text_t *device);
465 
466 
478 char *readStr(text_t *device, char *buffer, int max);
479 
480 
488 void writeBin(text_t *device, int value);
489 
490 
501 void writeBinDigits(text_t *device, int value, int digits);
502 
503 
511 void writeChar(text_t *device, char c);
512 
513 
521 void writeDec(text_t *device, int value);
522 
523 
534 void writeDecDigits(text_t *device, int value, int width);
535 
536 
544 void writeFloat(text_t *device, float value);
545 
546 
554 void writeHex(text_t *device, int value);
555 
556 
567 void writeHexDigits(text_t *device, int value, int digits);
568 
569 
582 void writeFloatPrecision(text_t *device, float value, int width, int precision);
583 
584 
592 int writeLine(text_t *device, char* str);
593 
594 
602 int writeStr(text_t *device, char* str);
603 
604 
614 int writeStrDigits(text_t *device, char* str, int width);
615 
616 
657 int print(const char *format, ...) __attribute__((format (printf, 1, 2)));
658 
659 
673 int printi(const char *format, ...) __attribute__((format (printf, 1, 2)));
674 
675 
716 int scan(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
717 
718 
732 int scani(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
733 
734 
749 int dprint(text_t* device, const char *format, ...) __attribute__((format (printf, 2, 3)));
750 
751 
767 int dprinti(text_t* device, const char *format, ...) __attribute__((format (printf, 2, 3)));
768 
769 
784 int dscan(text_t* device, const char *fmt, ...) __attribute__((format (printf, 2, 3)));
785 
786 
802 int dscani(text_t* device, const char *fmt, ...) __attribute__((format (printf, 2, 3)));
803 
804 
819 int sprint(char *buffer, const char *format, ...) __attribute__((format (printf, 2, 3)));
820 
821 
837 int sprinti(char *buffer, const char *format, ...) __attribute__((format (printf, 2, 3)));
838 
839 
853 int sscan(const char *buffer, const char *fmt, ...) __attribute__((format (printf, 2, 3)));
854 
855 
870 int sscani(const char *buffer, const char *fmt, ...) __attribute__((format (printf, 2, 3)));
871 
872 /* API not intended for public use */
873 int printNumber(text_t *p, unsigned long u, int base, int width, int fill_char);
874 char* _safe_gets(text_t *term, char* origBuf, int count);
875 const char* _scanf_getf(const char *str, float* dst);
876 const char* _scanf_getl(const char *str, int* dst, int base, unsigned width, int isSigned);
877 
878 int SPUTC(int c, char *buf);
879 int SPUTS(char *s, char *obuf);
880 int SPUTL(unsigned long u, int base, int width, int fill_char, char *obuf);
881 
882 #include <stdarg.h>
883 int _doscanf(const char* str, const char *fmt, va_list args);
884 int _intscanf(const char* str, const char *fmt, va_list args);
885 int _dosprnt(const char *fmt, va_list args, char *obuf);
886 int _intsprnt(const char *fmt, va_list args, char *obuf);
887 
888 char* float2string(float f, char *s, int width, int precision);
889 float string2float(char *s, char **end);
890 
891 #ifdef __cplusplus
892 }
893 #endif
894 
895 #endif
896 /* __SimpleTEXT__ */
897 
898