simpletext library  v0.85
Compact variations of put/get write/read and print/scan for smaller program sizes
simpletext.h
Go to the documentation of this file.
1 
23 #ifndef __SimpleTEXT__
24 #define __SimpleTEXT__
25 
26 #include <propeller.h>
27 
28 #ifdef __cplusplus
29 extern "C"
30 {
31 #endif
32 
33 #if !defined(__PROPELLER_32BIT_DOUBLES__)
34 #error "This library requires 32bit doubles"
35 #endif
36 
37 #define TERM_NAME_LEN 20
38 #define TERM_COG_LEN 7
39 
40 typedef struct text_struct
41 {
42  int (*rxChar)(struct text_struct *p); /* required for terminal to work */
43  int (*txChar)(struct text_struct *p, int ch); /* required for terminal to work */
44  int cogid[TERM_COG_LEN]; /* pointer to cog(s) used if any */
45  volatile void *devst; /* pointer to device info struct */
46 } text_t;
47 
48 #define getStopCOGID(id) ((id)-(1))
49 #define setStopCOGID(id) ((id)+(1))
50 
55 #include "serial.h"
56 
57 /* Values for use with SimpleIDE Terminal */
58 #ifndef HOME
59 #define HOME (1)
60 #endif
61 #ifndef CRSRXY
62 #define CRSRXY (2)
63 #endif
64 #ifndef CRSRLF
65 #define CRSRLF (3)
66 #endif
67 #ifndef CRSRRT
68 #define CRSRRT (4)
69 #endif
70 #ifndef CRSRUP
71 #define CRSRUP (5)
72 #endif
73 #ifndef CRSRDN
74 #define CRSRDN (6)
75 #endif
76 #ifndef BEEP
77 #define BEEP (7)
78 #endif
79 #ifndef BKSP
80 #define BKSP (8)
81 #endif
82 #ifndef TAB
83 #define TAB (9)
84 #endif
85 #ifndef NL
86 #define NL (10)
87 #endif
88 #ifndef LF
89 #define LF (10)
90 #endif
91 #ifndef CLREOL
92 #define CLREOL (11)
93 #endif
94 #ifndef CLRDN
95 #define CLRDN (12)
96 #endif
97 #ifndef CR
98 #define CR (13)
99 #endif
100 #ifndef CRSRX
101 #define CRSRX (14)
102 #endif
103 #ifndef CRSRY
104 #define CRSRY (15)
105 #endif
106 #ifndef CLS
107 #define CLS (16)
108 #endif
109 
110 typedef text_t terminal;
111 
120 terminal *simpleterm_open(void);
121 
126 void simpleterm_close(void);
127 
131 terminal *simpleterm_pointer(void);
132 
133 
138 int getBin(void);
139 
144 int getChar(void);
145 
150 int getDec(void);
151 
156 float getFloat(void);
157 
162 int getHex(void);
163 
170 char *getStr(char *buffer, int max);
171 
177 void putBin(int value);
182 void putChar(char c);
187 void putDec(int value);
192 void putFloat(float value);
198 void putHex(int value);
203 int putln(const char* str);
208 int putLine(const char* str);
213 int putStr(const char* str);
214 
220 int readBin(text_t *device);
221 
227 int readChar(text_t *device);
228 
234 int readDec(text_t *device);
235 
241 float readFloat(text_t *device);
242 
248 int readHex(text_t *device);
249 
257 char *readStr(text_t *device, char *buffer, int max);
258 
264 void writeBin(text_t *device, int value);
271 void writeBinDigits(text_t *device, int value, int digits);
277 void writeChar(text_t *device, char c);
283 void writeDec(text_t *device, int value);
290 void writeDecDigits(text_t *device, int value, int width);
296 void writeFloat(text_t *device, float value);
302 void writeHex(text_t *device, int value);
309 void writeHexDigits(text_t *device, int value, int digits);
317 void writeFloatPrecision(text_t *device, float value, int width, int precision);
323 int writeLine(text_t *device, char* str);
329 int writeStr(text_t *device, char* str);
336 int writeStrDigits(text_t *device, char* str, int width);
337 
346 int print(const char *format, ...);
347 
356 int scan(const char *fmt, ...);
357 
367 int dprint(text_t* device, const char *format, ...);
368 
378 int dscan(text_t* device, const char *fmt, ...);
379 
389 int sprint(char *buffer, const char *format, ...);
390 
399 int sscan(const char *buffer, const char *fmt, ...);
400 
401 
402 /* API not intended for public use */
403 int printNumber(text_t *p, unsigned long u, int base, int width, int fill_char);
404 char* _safe_gets(text_t *term, char* origBuf, int count);
405 const char* _scanf_getf(const char *str, float* dst);
406 const char* _scanf_getl(const char *str, int* dst, int base, unsigned width, int isSigned);
407 
408 #include <stdarg.h>
409 int _doscanf(const char* str, const char *fmt, va_list args);
410 int _dosprnt(const char *fmt, va_list args, char *obuf);
411 
412 char* float2string(float f, char *s, int width, int precision);
413 float string2float(char *s, char **end);
414 
415 #ifdef __cplusplus
416 }
417 #endif
418 
419 #endif
420 /* __SimpleTEXT__ */
421 
422 /*
423 +--------------------------------------------------------------------
424 | TERMS OF USE: MIT License
425 +--------------------------------------------------------------------
426 Permission is hereby granted, free of charge, to any person obtaining
427 a copy of this software and associated documentation files
428 (the "Software"), to deal in the Software without restriction,
429 including without limitation the rights to use, copy, modify, merge,
430 publish, distribute, sublicense, and/or sell copies of the Software,
431 and to permit persons to whom the Software is furnished to do so,
432 subject to the following conditions:
433 
434 The above copyright notice and this permission notice shall be
435 included in all copies or substantial portions of the Software.
436 
437 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
438 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
439 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
440 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
441 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
442 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
443 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
444 +--------------------------------------------------------------------
445 */