Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 27:dbf79d116497, committed 2016-09-29
- Comitter:
- CaptainR
- Date:
- Thu Sep 29 19:40:53 2016 +0000
- Parent:
- 26:c6a803706a42
- Commit message:
- get word and get string
Changed in this revision
--- a/Picaso_4DGL-32PTU.h Wed Sep 28 12:41:32 2016 +0000
+++ b/Picaso_4DGL-32PTU.h Thu Sep 29 19:40:53 2016 +0000
@@ -119,12 +119,12 @@
#define FILE_SIZE 0x000E
#define FILE_IMAGE 0xFF11
#define FILE_S_CAPTURE 0xFF10
-#define FILE_CHAR_TO 0x
-#define FILE_CHAR_FROM 0x
-#define FILE_WORD_TO 0x
-#define FILE_WORD_FROM 0x
-#define FILE_STRING_TO 0x
-#define FILE_STRING_FROM 0x
+#define FILE_PUT_C 0x
+#define FILE_GET_C 0x
+#define FILE_PUT_W 0x
+#define FILE_GET_W 0xFF0C
+#define FILE_PUT_S 0x
+#define FILE_GET_S 0x0007
#define FILE_ERASE 0x
#define FILE_REWIND 0x
#define FILE_LOAD_F 0x
@@ -271,6 +271,9 @@
bool file_Image(short, short, short); // display an image
bool file_ScreenCapture(short, short, short, short, short); // make a screenshot
+ short file_GetW(short); // read 2 bytes from a file
+ short file_GetS(short, short, char*); // read specified set of bytes from a file (size, handle, stringTo)
+
protected :
Serial _cmd; // serial variable, to comunicate with screen
--- a/Picaso_4DGL-32PTU_CONSTANTS.h Wed Sep 28 12:41:32 2016 +0000 +++ b/Picaso_4DGL-32PTU_CONSTANTS.h Thu Sep 29 19:40:53 2016 +0000 @@ -3,11 +3,11 @@ #define PICASO_CONST_H #ifndef DEBUGMODE -#define DEBUGMODE 1 +#define DEBUGMODE 0 #endif #ifndef DEMO -#define DEMO 1 +#define DEMO 0 #endif // Common WAIT value in millisecond
--- a/Picaso_4DGL-32PTU_File.cpp Wed Sep 28 12:41:32 2016 +0000
+++ b/Picaso_4DGL-32PTU_File.cpp Thu Sep 29 19:40:53 2016 +0000
@@ -82,7 +82,7 @@
writeCOMMAND(command, 2);
short error = fileErrorResponse();
#ifdef DEBUGMODE
- pc.printf("\n\r DEBUG: FAT16 Error: %i\n\r", error);
+ //pc.printf("\n\r DEBUG: FAT16 Error: %i\n\r", error);
#endif
return error;
}
@@ -507,8 +507,8 @@
char command[4] = "";
- command[0] = (FILE_TELL >> (8*1)) & 0xff;
- command[1] = (FILE_TELL >> (8*0)) & 0xff;
+ command[0] = (FILE_SIZE >> (8*1)) & 0xff;
+ command[1] = (FILE_SIZE >> (8*0)) & 0xff;
command[2] = (handle >> (8*1)) & 0xff;
command[3] = (handle >> (8*0)) & 0xff;
writeCOMMAND(command, 4);
@@ -579,6 +579,55 @@
return success;
}
+//**************************************************************************
+// This function reads a word (2 bytes) from the file, at the position indicated
+// by the associated file-position pointer (set by the “File Seek” or “File Index” commands)
+// and advances the pointer appropriately (incremented by 2). The file must be
+// previously opened with 'r' (read) mode.
+//**************************************************************************
+short PICASO_4DGL :: file_GetW(short handle) {
+
+ char command[4] = "";
+
+ command[0] = (FILE_GET_W >> (8*1)) & 0xff;
+ command[1] = (FILE_GET_W >> (8*0)) & 0xff;
+ command[2] = (handle >> (8*1)) & 0xff;
+ command[3] = (handle >> (8*0)) & 0xff;
+ writeCOMMAND(command, 4);
+
+ short word = fileErrorResponse(); // get 2 bytes from file
+#ifdef DEBUGMODE
+ pc.printf("\n\r DEBUG: Read word = %i\n\r", word);
+#endif
+ return word;
+}
+
+//**************************************************************************
+// This function reads a line of text from a file at the current file position
+// indicated by the associated file-position pointer (set by the “File Seek”
+// or “File Index” commands) and advances the pointer appropriately.
+// Characters are read until either a newline or an EOF is received or until
+// the specified maximum "size" is reached. In all cases, the string is null
+// terminated. The file must be previously opened with 'r' (read) mode.
+//**************************************************************************
+short PICASO_4DGL :: file_GetS(short size, short handle, char *str) {
+
+ char command[6] = "";
+
+ command[0] = (FILE_GET_S >> (8*1)) & 0xff;
+ command[1] = (FILE_GET_S >> (8*0)) & 0xff;
+ command[2] = (size >> (8*1)) & 0xff;
+ command[3] = (size >> (8*0)) & 0xff;
+ command[4] = (handle >> (8*1)) & 0xff;
+ command[5] = (handle >> (8*0)) & 0xff;
+ writeCOMMAND(command, 6);
+
+ short count = getFilenameResponse(str); // get specified count of bytes from file
+#ifdef DEBUGMODE
+ //pc.printf("\n\r DEBUG: Read %i bytes from %i\n\r", count, handle);
+#endif
+ return count;
+}
@@ -587,3 +636,4 @@
+
--- a/Picaso_4DGL-32PTU_Response.cpp Wed Sep 28 12:41:32 2016 +0000
+++ b/Picaso_4DGL-32PTU_Response.cpp Thu Sep 29 19:40:53 2016 +0000
@@ -285,10 +285,8 @@
#endif
while (index < 3) wait_ms(100); // wait for screen answer
short len = rxBuf[1] << 8 | rxBuf[2];
- //char *filename;
- //filename = (char *)malloc(sizeof(char) * len);
- //for(i = 0; i < size; i++) filename[i] = 0;
while (index < 3 + len) wait_ms(100); // wait for whole answer
+
for (i = 0; i < len; i++)
out[i] = rxBuf[j++]; // build filename string
--- a/demo.cpp Wed Sep 28 12:41:32 2016 +0000
+++ b/demo.cpp Thu Sep 29 19:40:53 2016 +0000
@@ -110,7 +110,26 @@
sprintf(buf, "\r\nFile %i Close = %s", h1, file_Close(h1) ? "true" : "false");
puts(buf);
+ wait_ms(LONG_WAIT);
+ cls();
+ h1 = file_Open("1.txt", OPEN_READ);
+ err = file_Error();
+ if (err == 0) sprintf(buf, "\r\nnewfile.txt handle = %i", h1);
+ else sprintf(buf, "\rFile Open error = %i", err);
+ puts(buf);
+
+ for (i = 0; i < 3; i++) {
+ clearBuf(fileReadBuf, BUFFER_SIZE);
+ count = file_GetS(30, h1, fileReadBuf);
+ sprintf(buf, "\r\nRead %i bytes", count);
+ puts(buf);
+ sprintf(buf, "\r\nData: %s", fileReadBuf);
+ puts(buf);
+ }
+
+
+ /*
short h2 = file_Open("scr.png", OPEN_APPEND);
file_ScreenCapture(10, 10, 200, 100, h2);
file_Close(h2);
@@ -120,7 +139,7 @@
h2 = file_Open("pic.bmp", OPEN_READ);
file_Image(5, 5, h2);
-
+ */
/*
h1 = file_Open("newfile.txt", OPEN_APPEND); // try appending to file
err = file_Error();