PropWare  3.0.0.229
C++ objects and CMake build system for Parallax Propeller
simpletext.h
Go to the documentation of this file.
1 
48 #ifndef __SimpleTEXT__
49 #define __SimpleTEXT__
50 
51 #include <propeller.h>
52 
53 #ifdef __cplusplus
54 extern "C"
55 {
56 #endif
57 
58 //#define ST_SLASH_ ReturN
59 #define SIMPLETEXT_ECS
60 //#define ST_NO_CHAR_ SUBS
64 #define ECHO_RX_TO_TX 32
65 
66 //extern volatile int simpleterm_echo;
67 
68 
69 #if !defined(__PROPELLER_32BIT_DOUBLES__)
70 #error "This library requires 32bit doubles"
71 #endif
72 
74 #define TERM_NAME_LEN 20
75 #define TERM_COG_LEN 7
76 
81 typedef struct text_struct
82 {
84  int (*rxChar)(struct text_struct *p);
86  int (*txChar)(struct text_struct *p, int ch);
88  int cogid[TERM_COG_LEN];
90  volatile void *devst;
92  volatile int terminalEcho;
94  //char ec[3];
96  //char ecs[3];
97  volatile char ecA;
98  volatile char ecB;
99  volatile char ecsA;
100  volatile char ecsB;
101 } text_t;
102 
103 
104 
105 //void set_endChars(text_t *text, char *endCharArray);
106 //void set_endCharSequence(text_t *text, char *endCharSeqArray);
107 void set_endChars(text_t *text, char cA, char cB);
108 void set_endCharSequence(text_t *text, char cA, char cB);
109 void putByte(char c);
110 int getByte(void);
111 int readByte(text_t *text);
112 void writeByte(text_t *p, char c);
113 void terminal_setEcho(text_t *text, int state);
114 int terminal_checkEcho(text_t *text);
115 
116 
118 #define getStopCOGID(id) ((id)-(1))
119 #define setStopCOGID(id) ((id)+(1))
120 
125 #include "serial.h"
126 
127 /* Values for use with SimpleIDE Terminal */
128 #ifndef HOME
129 
133 #define HOME (1)
134 #endif
135 
136 #ifndef CRSRXY
137 
143 #define CRSRXY (2)
144 #endif
145 
146 #ifndef CRSRLF
147 
151 #define CRSRLF (3)
152 #endif
153 
154 #ifndef CRSRRT
155 
159 #define CRSRRT (4)
160 #endif
161 
162 #ifndef CRSRUP
163 
167 #define CRSRUP (5)
168 #endif
169 
170 #ifndef CRSRDN
171 
175 #define CRSRDN (6)
176 #endif
177 
178 #ifndef BEEP
179 
183 #define BEEP (7)
184 #endif
185 
186 #ifndef BKSP
187 
192 #define BKSP (8)
193 #endif
194 
195 #ifndef TAB
196 
200 #define TAB (9)
201 #endif
202 
203 #ifndef NL
204 
208 #define NL (10)
209 #endif
210 
211 #ifndef LF
212 
215 #define LF (10)
216 #endif
217 
218 #ifndef CLREOL
219 
223 #define CLREOL (11)
224 #endif
225 
226 #ifndef CLRDN
227 
231 #define CLRDN (12)
232 #endif
233 
234 #ifndef CR
235 
239 #define CR (13)
240 #endif
241 
242 #ifndef CRSRX
243 
247 #define CRSRX (14)
248 #endif
249 
250 #ifndef CRSRY
251 
255 #define CRSRY (15)
256 #endif
257 
258 #ifndef CLS
259 
263 #define CLS (16)
264 #endif
265 
266 typedef text_t terminal;
267 
268 
309 int print(const char *format, ...) __attribute__((format (printf, 1, 2)));
310 
311 
352 int scan(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
353 
354 
369 int sprint(char *buffer, const char *format, ...) __attribute__((format (printf, 2, 3)));
370 
371 
385 int sscan(const char *buffer, const char *fmt, ...) __attribute__((format (printf, 2, 3)));
386 
387 
405 int sscanAfterStr(char *buffer, char *str, char *fmt, ...) __attribute__((format (printf, 3, 4)));
406 
407 
408 
430 int dprint(text_t* device, const char *format, ...) __attribute__((format (printf, 2, 3)));
431 
432 
448 int dscan(text_t* device, const char *fmt, ...) __attribute__((format (printf, 2, 3)));
449 
450 
471 int printi(const char *format, ...) __attribute__((format (printf, 1, 2)));
472 
473 
487 int scani(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
488 
489 
507 int dprinti(text_t* device, const char *format, ...) __attribute__((format (printf, 2, 3)));
508 
509 
526 int dscani(text_t* device, const char *fmt, ...) __attribute__((format (printf, 2, 3)));
527 
528 
544 int sprinti(char *buffer, const char *format, ...) __attribute__((format (printf, 2, 3)));
545 
546 
561 int sscani(const char *buffer, const char *fmt, ...) __attribute__((format (printf, 2, 3)));
562 
563 
575 void putChar(char c);
576 
577 
583 int putStr(const char* str);
584 
585 
591 void putDec(int value);
592 
593 
600 void putFloat(float value);
601 
602 
608 void putBin(int value);
609 
610 
617 void putHex(int value);
618 
619 
627 int putStrLen(char* str, int width);
628 
629 
637 void putDecLen(int value, int width);
638 
639 
650 void putFloatPrecision(float value, int width, int precision);
651 
652 
661 void putBinLen(int value, int digits);
662 
663 
672 void putHexLen(int value, int digits);
673 
674 
680 int putln(const char* str);
681 
682 
689 int putLine(const char* str);
690 
691 
699 int putStrWithNpcVals(const char *s);
700 
701 
702 
703 
717 int getBin(void);
718 
719 
725 int getChar(void);
726 
727 
733 int getDec(void);
734 
735 
741 float getFloat(void);
742 
743 
749 int getHex(void);
750 
751 
762 char *getStr(char *buffer, int max);
763 
764 
781 void writeChar(text_t *device, char c);
782 
783 
792 int writeStr(text_t *device, char* str);
793 
794 
803 void writeDec(text_t *device, int value);
804 
805 
815 void writeFloat(text_t *device, float value);
816 
817 
827 void writeBin(text_t *device, int value);
828 
829 
839 void writeHex(text_t *device, int value);
840 
841 
852 int writeStrLen(text_t *device, char* str, int width);
853 
854 
866 void writeDecLen(text_t *device, int value, int width);
867 
868 
882 void writeFloatPrecision(text_t *device, float value, int width, int precision);
883 
884 
896 void writeBinLen(text_t *device, int value, int digits);
897 
898 
910 void writeHexLen(text_t *device, int value, int digits);
911 
912 
921 int writeLine(text_t *device, char* str);
922 
923 
940 int readChar(text_t *device);
941 
942 
955 char *readStr(text_t *device, char *buffer, int max);
956 
957 
966 int readDec(text_t *device);
967 
968 
977 float readFloat(text_t *device);
978 
979 
988 int readBin(text_t *device);
989 
990 
999 int readHex(text_t *device);
1000 
1001 
1002 
1019 terminal *simpleterm_open(void);
1020 
1026 void simpleterm_close(void);
1027 
1048 terminal *simpleterm_reopen(int rxpin, int txpin, int mode, int baud);
1049 
1058 static inline void simpleterm_set(text_t *ptr)
1059 {
1060  extern text_t *dport_ptr;
1061  simpleterm_close();
1062  dport_ptr = ptr;
1063 }
1064 
1071 
1072 
1073 
1086 //void terminal_setEcho(text_t *text, int state);
1087 
1088 
1094 //int terminal_checkEcho(text_t *text);
1095 
1102  /*
1103  * @cond
1104  * API not intended for public use
1105  */
1106 int printNumber(text_t *p, unsigned long u, int base, int width, int fill_char);
1107 char* _safe_gets(text_t *term, char* origBuf, int count);
1108 const char* _scanf_getf(const char *str, float* dst);
1109 const char* _scanf_getl(const char *str, int* dst, int base, unsigned width, int isSigned);
1110 
1111 int SPUTC(int c, char *buf);
1112 int SPUTS(char *s, char *obuf);
1113 int SPUTL(unsigned long u, int base, int width, int fill_char, char *obuf);
1114 
1115 #include <stdarg.h>
1116 int _doscanf(const char* str, const char *fmt, va_list args);
1117 int _intscanf(const char* str, const char *fmt, va_list args);
1118 int _dosprnt(const char *fmt, va_list args, char *obuf);
1119 int _intsprnt(const char *fmt, va_list args, char *obuf);
1120 
1121 char* float2string(float f, char *s, int width, int precision);
1122 float string2float(char *s, char **end);
1123 
1124  /*
1125  * @endcond
1126  * API not intended for public use
1127  */
1128 
1129 #ifdef __cplusplus
1130 }
1131 #endif
1132 
1133 #endif
1134 /* __SimpleTEXT__ */
1135 
1136 
scani
int int scani(const char *fmt,...) __attribute__((format(printf
Convert formatted simple terminal input to the "..." args. This version does not provide floating poi...
writeDecLen
void writeDecLen(text_t *device, int value, int width)
Print string representation of a decimal number to output device with a fixed number of digits.
Definition: writeDecDigits.c:10
putBinLen
void putBinLen(int value, int digits)
Print string representation of a binary number to debug port with a fixed number of digits.
Definition: putBinDigits.c:10
writeHexLen
void writeHexLen(text_t *device, int value, int digits)
Print string representation of a hexadecimal number to output device with a fixed number of digits.
Definition: writeHexDigits.c:10
text_struct::rxChar
int(* rxChar)(struct text_struct *p)
Definition: simpletext.h:84
text_struct::cogid
int cogid[TERM_COG_LEN]
Definition: simpletext.h:88
putln
int putln(const char *str)
Print string + new line on the transmit debug port.
Definition: putln.c:13
putHexLen
void putHexLen(int value, int digits)
Print string representation of a hexadecimal number to the debug port with a fixed number of digits.
Definition: putHexDigits.c:10
simpleterm_reopen
terminal * simpleterm_reopen(int rxpin, int txpin, int mode, int baud)
Closes and the simple terminal connection, and reopens it in the calling cog. Depending on the parame...
Definition: simpleterm_close.c:35
text_struct::txChar
int(* txChar)(struct text_struct *p, int ch)
Definition: simpletext.h:86
terminal
text_t terminal
Definition: simpletext.h:266
writeBinLen
void writeBinLen(text_t *device, int value, int digits)
Print string representation of a binary number to output with a fixed number of digits.
Definition: writeBinDigits.c:10
simpleterm_pointer
terminal * simpleterm_pointer(void)
Get default device pointer to SimpleIDE Terminal.
Definition: simpleterm.c:51
text_struct::devst
volatile void * devst
Definition: simpletext.h:90
putStrLen
int putStrLen(char *str, int width)
Send a string with a certain number of characters.
Definition: putStrDigits.c:11
getHex
int getHex(void)
Get hexadecimal number from the debug port.
Definition: getHex.c:10
writeLine
int writeLine(text_t *device, char *str)
Send a string + new line to the device.
Definition: writeLine.c:10
serial.h
This library supports creating and managing one or more half duplex serial connections with periphera...
dscan
int int dscan(text_t *device, const char *fmt,...) __attribute__((format(printf
Convert formatted device input to the "..." args. The input is limited to 256 bytes.
putFloat
void putFloat(float value)
Print string representation of a 32 bit floating point number to the debug port.
Definition: putFloat.c:10
getDec
int getDec(void)
Get decimal number from the debug port.
Definition: getDec.c:11
dprint
int dprint(text_t *device, const char *format,...) __attribute__((format(printf
Print format "..." args to the device The output is limited to 256 bytes.
putLine
int putLine(const char *str)
Print string + new line on the transmit debug port. This is an alias of putln.
Definition: putLine.c:14
putDec
void putDec(int value)
Print string representation of a decimal number to the debug port.
Definition: putDec.c:10
getBin
int getBin(void)
Get binary number from the debug port.
Definition: getBin.c:10
dprinti
int int int dprinti(text_t *device, const char *format,...) __attribute__((format(printf
Print integer and char only format "..." args to the default simple terminal device....
getStr
char * getStr(char *buffer, int max)
Get string of chars from the debug port.
Definition: getStr.c:19
writeDec
void writeDec(text_t *device, int value)
Print string representation of a decimal number to output.
Definition: writeDec.c:10
readStr
char * readStr(text_t *device, char *buffer, int max)
Get string of chars from the device.
Definition: getStr.c:25
print
int print(const char *format,...) __attribute__((format(printf
Print format "..." args to the default simple terminal device. The output is limited to 256 bytes.
writeFloatPrecision
void writeFloatPrecision(text_t *device, float value, int width, int precision)
Print string representation of a 32 bit floating point number to device with a certain number of deci...
Definition: writeFloatPrecision.c:10
readDec
int readDec(text_t *device)
Get decimal number from the device.
Definition: getDec.c:17
dscani
int int int int dscani(text_t *device, const char *fmt,...) __attribute__((format(printf
Convert formatted device input to the "..." args. This version does not provide floating point conver...
putStrWithNpcVals
int putStrWithNpcVals(const char *s)
Print string to the debug port, and display all non printable characters (NPCs) as decimal ASCII valu...
Definition: putStrWithNpcVals.c:12
putDecLen
void putDecLen(int value, int width)
Print string representation of a decimal number to the debug port.
Definition: putDecDigits.c:10
simpleterm_close
void simpleterm_close(void)
Closes the SimpleIDE Terminal connection in one cog so that it can be opened in another cog with simp...
Definition: simpleterm_close.c:19
getFloat
float getFloat(void)
Get floating point number from the debug port.
Definition: getFloat.c:10
sscani
int int int int int int sscani(const char *buffer, const char *fmt,...) __attribute__((format(printf
Convert formatted buffer to the "..." args. This version does not provide floating point conversions.
sscanAfterStr
int int int int int sscanAfterStr(char *buffer, char *str, char *fmt,...) __attribute__((format(printf
Store values represented by characters in a buffer in variable list using "..." args.
writeFloat
void writeFloat(text_t *device, float value)
Print string representation of a 32 bit floating point number to device.
Definition: writeFloat.c:10
readChar
int readChar(text_t *device)
Get char from the device.
Definition: getChar.c:17
count
long count(int pin, long duration)
Count number of low to high transitions an external input applies to an I/O pin over a certain period...
Definition: count.c:19
text_t
struct text_struct text_t
Structure that contains data used by simple text device libraries.
writeHex
void writeHex(text_t *device, int value)
Print string representation of a hexadecimal number to output device.
Definition: writeHex.c:10
writeChar
void writeChar(text_t *device, char c)
Send a character to the device.
Definition: writeChar.c:11
getChar
int getChar(void)
Get char from the debug port.
Definition: getChar.c:11
putChar
void putChar(char c)
Print a char to the debug port.
Definition: putChar.c:30
scan
int int scan(const char *fmt,...) __attribute__((format(printf
Convert formatted simple terminal input to the "..." args. The input is limited to 256 bytes.
text_struct
Structure that contains data used by simple text device libraries.
Definition: simpletext.h:81
simpleterm_set
static void simpleterm_set(text_t *ptr)
Sets default debug port device. Make sure to open a connection to the device before calling the funct...
Definition: simpletext.h:1058
putHex
void putHex(int value)
Print string representation of a hexadecimal number to the debug port.
Definition: putHex.c:10
readFloat
float readFloat(text_t *device)
Get floating point number from the device.
Definition: getFloat.c:16
putFloatPrecision
void putFloatPrecision(float value, int width, int precision)
Print string representation of a 32 bit floating point number to the debug port with a fixed number o...
Definition: putFloatPrecision.c:10
simpleterm_open
terminal * simpleterm_open(void)
Reopens the SimpleIDE Terminal connection if it was closed previously. The SimpleIDE Terminal connect...
text_struct::terminalEcho
volatile int terminalEcho
Definition: simpletext.h:92
sprint
int int int sprint(char *buffer, const char *format,...) __attribute__((format(printf
Print format "..." args to the output buffer. The output buffer must be big enough for the output.
writeStr
int writeStr(text_t *device, char *str)
Send a string to the device.
Definition: writeStr.c:10
putBin
void putBin(int value)
Print string representation of a binary number to the debug port.
Definition: putBin.c:10
writeBin
void writeBin(text_t *device, int value)
Print string representation of a binary number to the receive device.
Definition: writeBin.c:10
sprinti
int int int int int sprinti(char *buffer, const char *format,...) __attribute__((format(printf
Print integer and char only format "..." args to the default simple terminal device....
text_struct::ecA
volatile char ecA
Definition: simpletext.h:97
putStr
int putStr(const char *str)
Print string to the debug port.
Definition: putStr.c:10
readHex
int readHex(text_t *device)
Get hexadecimal number from the device.
Definition: getHex.c:15
writeStrLen
int writeStrLen(text_t *device, char *str, int width)
Send a string to the device.
Definition: writeStrDigits.c:11
printi
int printi(const char *format,...) __attribute__((format(printf
Print integer and char only format "..." args to the default simple terminal device....
sscan
int int int int sscan(const char *buffer, const char *fmt,...) __attribute__((format(printf
Convert formatted buffer to the "..." args.
readBin
int readBin(text_t *device)
Get binary number from the device.
Definition: getBin.c:16