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 
46 #ifndef __SimpleTEXT__
47 #define __SimpleTEXT__
48 
49 #include <propeller.h>
50 
51 #ifdef __cplusplus
52 extern "C"
53 {
54 #endif
55 
56 #if !defined(__PROPELLER_32BIT_DOUBLES__)
57 #error "This library requires 32bit doubles"
58 #endif
59 
60 #define TERM_NAME_LEN 20
61 #define TERM_COG_LEN 7
62 
63 typedef struct text_struct
64 {
65  int (*rxChar)(struct text_struct *p); // Required for terminal
66  int (*txChar)(struct text_struct *p, int ch); // required for terminal
67  int cogid[TERM_COG_LEN]; // Pointer to cog(s)
68  volatile void *devst; // Device info struct pointer
69 } text_t;
70 
71 #define getStopCOGID(id) ((id)-(1))
72 #define setStopCOGID(id) ((id)+(1))
73 
78 #include "serial.h"
79 
80 /* Values for use with SimpleIDE Terminal */
81 #ifndef HOME
82 
86 #define HOME (1)
87 #endif
88 
89 #ifndef CRSRXY
90 
96 #define CRSRXY (2)
97 #endif
98 
99 #ifndef CRSRLF
100 
104 #define CRSRLF (3)
105 #endif
106 
107 #ifndef CRSRRT
108 
112 #define CRSRRT (4)
113 #endif
114 
115 #ifndef CRSRUP
116 
120 #define CRSRUP (5)
121 #endif
122 
123 #ifndef CRSRDN
124 
128 #define CRSRDN (6)
129 #endif
130 
131 #ifndef BEEP
132 
136 #define BEEP (7)
137 #endif
138 
139 #ifndef BKSP
140 
145 #define BKSP (8)
146 #endif
147 
148 #ifndef TAB
149 
153 #define TAB (9)
154 #endif
155 
156 #ifndef NL
157 
161 #define NL (10)
162 #endif
163 
164 #ifndef LF
165 
168 #define LF (10)
169 #endif
170 
171 #ifndef CLREOL
172 
176 #define CLREOL (11)
177 #endif
178 
179 #ifndef CLRDN
180 
184 #define CLRDN (12)
185 #endif
186 
187 #ifndef CR
188 
192 #define CR (13)
193 #endif
194 
195 #ifndef CRSRX
196 
200 #define CRSRX (14)
201 #endif
202 
203 #ifndef CRSRY
204 
208 #define CRSRY (15)
209 #endif
210 
211 #ifndef CLS
212 
216 #define CLS (16)
217 #endif
218 
219 
220 typedef text_t terminal;
221 
222 
263 int print(const char *format, ...) __attribute__((format (printf, 1, 2)));
264 
265 
306 int scan(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
307 
308 
323 int sprint(char *buffer, const char *format, ...) __attribute__((format (printf, 2, 3)));
324 
325 
339 int sscan(const char *buffer, const char *fmt, ...) __attribute__((format (printf, 2, 3)));
340 
341 
363 int dprint(text_t* device, const char *format, ...) __attribute__((format (printf, 2, 3)));
364 
365 
381 int dscan(text_t* device, const char *fmt, ...) __attribute__((format (printf, 2, 3)));
382 
383 
404 int printi(const char *format, ...) __attribute__((format (printf, 1, 2)));
405 
406 
420 int scani(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
421 
422 
440 int dprinti(text_t* device, const char *format, ...) __attribute__((format (printf, 2, 3)));
441 
442 
459 int dscani(text_t* device, const char *fmt, ...) __attribute__((format (printf, 2, 3)));
460 
461 
477 int sprinti(char *buffer, const char *format, ...) __attribute__((format (printf, 2, 3)));
478 
479 
494 int sscani(const char *buffer, const char *fmt, ...) __attribute__((format (printf, 2, 3)));
495 
496 
508 void putChar(char c);
509 
510 
516 int putStr(const char* str);
517 
518 
524 void putDec(int value);
525 
526 
533 void putFloat(float value);
534 
535 
541 void putBin(int value);
542 
543 
550 void putHex(int value);
551 
552 
560 int putStrLen(char* str, int width);
561 
562 
570 void putDecLen(int value, int width);
571 
572 
583 void putFloatPrecision(float value, int width, int precision);
584 
585 
594 void putBinLen(int value, int digits);
595 
596 
605 void putHexLen(int value, int digits);
606 
607 
613 int putln(const char* str);
614 
615 
622 int putLine(const char* str);
623 
624 
638 int getBin(void);
639 
640 
646 int getChar(void);
647 
648 
654 int getDec(void);
655 
656 
662 float getFloat(void);
663 
664 
670 int getHex(void);
671 
672 
683 char *getStr(char *buffer, int max);
684 
685 
702 void writeChar(text_t *device, char c);
703 
704 
713 int writeStr(text_t *device, char* str);
714 
715 
724 void writeDec(text_t *device, int value);
725 
726 
736 void writeFloat(text_t *device, float value);
737 
738 
748 void writeBin(text_t *device, int value);
749 
750 
760 void writeHex(text_t *device, int value);
761 
762 
773 int writeStrLen(text_t *device, char* str, int width);
774 
775 
787 void writeDecLen(text_t *device, int value, int width);
788 
789 
803 void writeFloatPrecision(text_t *device, float value, int width, int precision);
804 
805 
817 void writeBinLen(text_t *device, int value, int digits);
818 
819 
831 void writeHexLen(text_t *device, int value, int digits);
832 
833 
842 int writeLine(text_t *device, char* str);
843 
844 
861 int readChar(text_t *device);
862 
863 
876 char *readStr(text_t *device, char *buffer, int max);
877 
878 
887 int readDec(text_t *device);
888 
889 
898 float readFloat(text_t *device);
899 
900 
909 int readBin(text_t *device);
910 
911 
920 int readHex(text_t *device);
921 
922 
939 terminal *simpleterm_open(void);
940 
941 
947 void simpleterm_close(void);
948 
949 
955 terminal *simpleterm_pointer(void);
956 
957 
964 static inline void simpleterm_set(text_t *ptr)
965 {
966  extern text_t *dport_ptr;
967  simpleterm_close();
968  dport_ptr = ptr;
969 }
970 
971 
977  /*
978  * @cond
979  * API not intended for public use
980  */
981 int printNumber(text_t *p, unsigned long u, int base, int width, int fill_char);
982 char* _safe_gets(text_t *term, char* origBuf, int count);
983 const char* _scanf_getf(const char *str, float* dst);
984 const char* _scanf_getl(const char *str, int* dst, int base, unsigned width, int isSigned);
985 
986 int SPUTC(int c, char *buf);
987 int SPUTS(char *s, char *obuf);
988 int SPUTL(unsigned long u, int base, int width, int fill_char, char *obuf);
989 
990 #include <stdarg.h>
991 int _doscanf(const char* str, const char *fmt, va_list args);
992 int _intscanf(const char* str, const char *fmt, va_list args);
993 int _dosprnt(const char *fmt, va_list args, char *obuf);
994 int _intsprnt(const char *fmt, va_list args, char *obuf);
995 
996 char* float2string(float f, char *s, int width, int precision);
997 float string2float(char *s, char **end);
998 
999  /*
1000  * @endcond
1001  * API not intended for public use
1002  */
1003 
1004 #ifdef __cplusplus
1005 }
1006 #endif
1007 
1008 #endif
1009 /* __SimpleTEXT__ */
1010 
1011