Skip to content

Commit 3274d57

Browse files
author
KalbeAbbas
committed
added function to read file
1 parent 5b9ef4d commit 3274d57

File tree

9 files changed

+33076
-33395
lines changed

9 files changed

+33076
-33395
lines changed

built/binary.hex

Lines changed: 16060 additions & 16005 deletions
Large diffs are not rendered by default.

built/mbcodal-binary.asm

Lines changed: 78 additions & 308 deletions
Large diffs are not rendered by default.

built/mbcodal-binary.hex

Lines changed: 9828 additions & 9830 deletions
Large diffs are not rendered by default.

built/mbdal-binary.asm

Lines changed: 79 additions & 309 deletions
Large diffs are not rendered by default.

built/mbdal-binary.hex

Lines changed: 6999 additions & 6938 deletions
Large diffs are not rendered by default.

cs11.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,6 @@ namespace IM01 {
6363
//%u.defl="log.txt"
6464
export function readFile(u: string): string {
6565
u = truncateStringLength(u)
66-
if (sdFlag == false) {
67-
createFolder("CS11")
68-
sdFlag = true
69-
}
7066
return file_read(u)
7167
}
7268

im01.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,32 @@ bool _exists(String s)
7373
//%
7474
String _read(String s)
7575
{
76+
FATFS FatFs;
77+
String cpy_string;
78+
char* error_no_file = "ERROR! NO FILE";
79+
UINT* br;
80+
char* buff;
81+
uint32_t lSize = 0;
82+
FIL Fil;
83+
FRESULT fr;
84+
85+
86+
f_mount(&FatFs, "", 0);
87+
88+
fr = f_open(&Fil, (const char *)s->getUTF8Data(), FA_READ);
89+
if(fr == FR_OK)
90+
{
91+
lSize = f_size(&Fil);
92+
buff = (char*) malloc (sizeof(char)*lSize);
93+
94+
f_read(&Fil, buff, lSize, br);
95+
}else{
96+
cpy_string = mkString(error_no_file, strlen(error_no_file));
97+
}
98+
99+
cpy_string = mkString(buff, lSize);
100+
free(buff);
101+
f_close(&Fil);
102+
return cpy_string;
76103
}
77104
} // namespace cs11

main.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
basic.forever(function()
2+
{
3+
basic.showString(IM01.readFile("hello.txt"))
4+
})

sdmm.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ DSTATUS disk_initialize(
287287
if(!enabled)
288288
{
289289
p = allocSPI();
290-
p->frequency(10000);
290+
p->frequency(1000000);
291291
p->format(8, 0);
292292
enabled = true;
293293
uBit.serial.send("Called!\n");

0 commit comments

Comments
 (0)