simpletext library  v0.8
Compact variations of put/get write/read and print/scan for smaller program sizes
simpletext.h
Go to the documentation of this file.
1 
18 #ifndef __SimpleTEXT__
19 #define __SimpleTEXT__
20 
21 #include <propeller.h>
22 
23 #if !defined(__PROPELLER_32BIT_DOUBLES__)
24 #error "This library requires 32bit doubles"
25 #endif
26 
27 #define TERM_NAME_LEN 20
28 #define TERM_COG_LEN 7
29 
30 typedef struct text_struct
31 {
32  int (*rxChar)(struct text_struct *p); /* required for terminal to work */
33  int (*txChar)(struct text_struct *p, int ch); /* required for terminal to work */
34  int cogid[TERM_COG_LEN]; /* pointer to cog(s) used if any */
35  volatile void *devst; /* pointer to device info struct */
36 } text_t;
37 
38 #define getStopCOGID(id) ((id)-(1))
39 #define setStopCOGID(id) ((id)+(1))
40 
45 #include "serial.h"
46 
47 /* Values for use with SimpleIDE Terminal */
48 #ifndef HOME
49 #define HOME (1)
50 #endif
51 #ifndef CRSRXY
52 #define CRSRXY (2)
53 #endif
54 #ifndef CRSRLF
55 #define CRSRLF (3)
56 #endif
57 #ifndef CRSRRT
58 #define CRSRRT (4)
59 #endif
60 #ifndef CRSRUP
61 #define CRSRUP (5)
62 #endif
63 #ifndef CRSRDN
64 #define CRSRDN (6)
65 #endif
66 #ifndef BEEP
67 #define BEEP (7)
68 #endif
69 #ifndef BKSP
70 #define BKSP (8)
71 #endif
72 #ifndef TAB
73 #define TAB (9)
74 #endif
75 #ifndef NL
76 #define NL (10)
77 #endif
78 #ifndef LF
79 #define LF (10)
80 #endif
81 #ifndef CLREOL
82 #define CLREOL (11)
83 #endif
84 #ifndef CLRDN
85 #define CLRDN (12)
86 #endif
87 #ifndef CR
88 #define CR (13)
89 #endif
90 #ifndef CRSRX
91 #define CRSRX (14)
92 #endif
93 #ifndef CRSRY
94 #define CRSRY (15)
95 #endif
96 #ifndef CLS
97 #define CLS (16)
98 #endif
99 
100 typedef text_t terminal;
101 
111 
116 void simpleterm_close(void);
117 
122 
123 
128 int getBin(void);
129 
134 int getChar(void);
135 
140 int getDec(void);
141 
146 float getFloat(void);
147 
152 int getHex(void);
153 
160 char *getStr(char *buffer, int max);
161 
167 void putBin(int value);
172 void putChar(char c);
177 void putDec(int value);
182 void putFloat(float value);
188 void putHex(int value);
193 int putln(char* str);
198 int putStr(char* str);
199 
205 int readBin(text_t *device);
206 
212 int readChar(text_t *device);
213 
219 int readDec(text_t *device);
220 
226 float readFloat(text_t *device);
227 
233 int readHex(text_t *device);
234 
242 char *readStr(text_t *device, char *buffer, int max);
243 
249 void writeBin(text_t *device, int value);
256 void writeBinDigits(text_t *device, int value, int digits);
262 void writeChar(text_t *device, char c);
268 void writeDec(text_t *device, int value);
275 void writeDecDigits(text_t *device, int value, int width);
281 void writeFloat(text_t *device, float value);
287 void writeHex(text_t *device, int value);
294 void writeHexDigits(text_t *device, int value, int digits);
302 void writeFloatPrecision(text_t *device, float value, int width, int precision);
308 int writeLine(text_t *device, char* str);
314 int writeStr(text_t *device, char* str);
321 int writeStrDigits(text_t *device, char* str, int width);
322 
331 int print(const char *format, ...);
332 
341 int scan(const char *fmt, ...);
342 
352 int dprint(text_t* device, const char *format, ...);
353 
363 int dscan(text_t* device, const char *fmt, ...);
364 
374 int sprint(char *buffer, const char *format, ...);
375 
384 int sscan(const char *buffer, const char *fmt, ...);
385 
386 
387 /* API not intended for public use */
388 int printNumber(text_t *p, unsigned long u, int base, int width, int fill_char);
389 char* _safe_gets(text_t *term, char* origBuf, int count);
390 const char* _scanf_getf(const char *str, float* dst);
391 const char* _scanf_getl(const char *str, int* dst, int base, unsigned width, int isSigned);
392 
393 #include <stdarg.h>
394 int _doscanf(const char* str, const char *fmt, va_list args);
395 int _dosprnt(const char *fmt, va_list args, char *obuf);
396 
397 char* float2string(float f, char *s, int width, int precision);
398 float string2float(char *s, char **end);
399 
400 #endif
401 
402 /*
403 +--------------------------------------------------------------------
404 | TERMS OF USE: MIT License
405 +--------------------------------------------------------------------
406 Permission is hereby granted, free of charge, to any person obtaining
407 a copy of this software and associated documentation files
408 (the "Software"), to deal in the Software without restriction,
409 including without limitation the rights to use, copy, modify, merge,
410 publish, distribute, sublicense, and/or sell copies of the Software,
411 and to permit persons to whom the Software is furnished to do so,
412 subject to the following conditions:
413 
414 The above copyright notice and this permission notice shall be
415 included in all copies or substantial portions of the Software.
416 
417 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
418 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
419 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
420 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
421 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
422 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
423 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
424 +--------------------------------------------------------------------
425 */