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 
408 
416 int readBin(text_t *device);
417 
418 
426 int readChar(text_t *device);
427 
428 
436 int readDec(text_t *device);
437 
438 
446 float readFloat(text_t *device);
447 
448 
456 int readHex(text_t *device);
457 
458 
470 char *readStr(text_t *device, char *buffer, int max);
471 
472 
480 void writeBin(text_t *device, int value);
481 
482 
493 void writeBinDigits(text_t *device, int value, int digits);
494 
495 
503 void writeChar(text_t *device, char c);
504 
505 
513 void writeDec(text_t *device, int value);
514 
515 
526 void writeDecDigits(text_t *device, int value, int width);
527 
528 
536 void writeFloat(text_t *device, float value);
537 
538 
546 void writeHex(text_t *device, int value);
547 
548 
559 void writeHexDigits(text_t *device, int value, int digits);
560 
561 
574 void writeFloatPrecision(text_t *device, float value, int width, int precision);
575 
576 
584 int writeLine(text_t *device, char* str);
585 
586 
594 int writeStr(text_t *device, char* str);
595 
596 
606 int writeStrDigits(text_t *device, char* str, int width);
607 
608 
649 int print(const char *format, ...) __attribute__((format (printf, 1, 2)));
650 
651 
665 int printi(const char *format, ...) __attribute__((format (printf, 1, 2)));
666 
667 
708 int scan(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
709 
710 
724 int scani(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
725 
726 
741 int dprint(text_t* device, const char *format, ...) __attribute__((format (printf, 2, 3)));
742 
743 
759 int dprinti(text_t* device, const char *format, ...) __attribute__((format (printf, 2, 3)));
760 
761 
776 int dscan(text_t* device, const char *fmt, ...) __attribute__((format (printf, 2, 3)));
777 
778 
794 int dscani(text_t* device, const char *fmt, ...) __attribute__((format (printf, 2, 3)));
795 
796 
811 int sprint(char *buffer, const char *format, ...) __attribute__((format (printf, 2, 3)));
812 
813 
829 int sprinti(char *buffer, const char *format, ...) __attribute__((format (printf, 2, 3)));
830 
831 
845 int sscan(const char *buffer, const char *fmt, ...) __attribute__((format (printf, 2, 3)));
846 
847 
862 int sscani(const char *buffer, const char *fmt, ...) __attribute__((format (printf, 2, 3)));
863 
864 /* API not intended for public use */
865 int printNumber(text_t *p, unsigned long u, int base, int width, int fill_char);
866 char* _safe_gets(text_t *term, char* origBuf, int count);
867 const char* _scanf_getf(const char *str, float* dst);
868 const char* _scanf_getl(const char *str, int* dst, int base, unsigned width, int isSigned);
869 
870 int SPUTC(int c, char *buf);
871 int SPUTS(char *s, char *obuf);
872 int SPUTL(unsigned long u, int base, int width, int fill_char, char *obuf);
873 
874 #include <stdarg.h>
875 int _doscanf(const char* str, const char *fmt, va_list args);
876 int _intscanf(const char* str, const char *fmt, va_list args);
877 int _dosprnt(const char *fmt, va_list args, char *obuf);
878 int _intsprnt(const char *fmt, va_list args, char *obuf);
879 
880 char* float2string(float f, char *s, int width, int precision);
881 float string2float(char *s, char **end);
882 
883 #ifdef __cplusplus
884 }
885 #endif
886 
887 #endif
888 /* __SimpleTEXT__ */
889 
890