Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
MarlinKimbra
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
machinery
MarlinKimbra
Commits
dda444c5
Commit
dda444c5
authored
May 16, 2015
by
MagoKimbra
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Same fix
parent
e7efd3aa
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
90 additions
and
69 deletions
+90
-69
Marlin_main.cpp
MarlinKimbra/Marlin_main.cpp
+4
-2
SdBaseFile.cpp
MarlinKimbra/SdBaseFile.cpp
+23
-34
cardreader.cpp
MarlinKimbra/cardreader.cpp
+63
-33
No files found.
MarlinKimbra/Marlin_main.cpp
View file @
dda444c5
...
@@ -3472,10 +3472,12 @@ inline void gcode_G28(boolean home_x = false, boolean home_y = false) {
...
@@ -3472,10 +3472,12 @@ inline void gcode_G28(boolean home_x = false, boolean home_y = false) {
}
}
return
;
return
;
}
}
saved_feedrate
=
feedrate
;
saved_feedrate
=
feedrate
;
saved_feedrate_multiplier
=
feedrate_multiplier
;
saved_feedrate_multiplier
=
feedrate_multiplier
;
feedrate_multiplier
=
100
;
feedrate_multiplier
=
100
;
home_delta_axis
();
deploy_z_probe
();
deploy_z_probe
();
calibrate_print_surface
(
z_probe_offset
[
Z_AXIS
]
+
(
code_seen
(
axis_codes
[
Z_AXIS
])
?
code_value
()
:
0.0
));
calibrate_print_surface
(
z_probe_offset
[
Z_AXIS
]
+
(
code_seen
(
axis_codes
[
Z_AXIS
])
?
code_value
()
:
0.0
));
retract_z_probe
();
retract_z_probe
();
...
...
MarlinKimbra/SdBaseFile.cpp
View file @
dda444c5
...
@@ -1097,8 +1097,9 @@ int16_t SdBaseFile::read(void* buf, uint16_t nbyte) {
...
@@ -1097,8 +1097,9 @@ int16_t SdBaseFile::read(void* buf, uint16_t nbyte) {
fail
:
fail
:
return
-
1
;
return
-
1
;
}
}
//------------------------------------------------------------------------------
/** Read the next directory entry from a directory file.
/**
* Read the next entry in a directory.
*
*
* \param[out] dir The dir_t struct that will receive the data.
* \param[out] dir The dir_t struct that will receive the data.
*
*
...
@@ -1114,50 +1115,38 @@ int8_t SdBaseFile::readDir(dir_t* dir, char* longFilename) {
...
@@ -1114,50 +1115,38 @@ int8_t SdBaseFile::readDir(dir_t* dir, char* longFilename) {
if
(
!
isDir
()
||
(
0X1F
&
curPosition_
))
return
-
1
;
if
(
!
isDir
()
||
(
0X1F
&
curPosition_
))
return
-
1
;
//If we have a longFilename buffer, mark it as invalid. If we find a long filename it will be filled automaticly.
//If we have a longFilename buffer, mark it as invalid. If we find a long filename it will be filled automaticly.
if
(
longFilename
!=
NULL
)
if
(
longFilename
!=
NULL
)
longFilename
[
0
]
=
'\0'
;
{
longFilename
[
0
]
=
'\0'
;
}
while
(
1
)
{
while
(
1
)
{
n
=
read
(
dir
,
sizeof
(
dir_t
));
n
=
read
(
dir
,
sizeof
(
dir_t
));
if
(
n
!=
sizeof
(
dir_t
))
return
n
==
0
?
0
:
-
1
;
if
(
n
!=
sizeof
(
dir_t
))
return
n
==
0
?
0
:
-
1
;
// last entry if DIR_NAME_FREE
// last entry if DIR_NAME_FREE
if
(
dir
->
name
[
0
]
==
DIR_NAME_FREE
)
return
0
;
if
(
dir
->
name
[
0
]
==
DIR_NAME_FREE
)
return
0
;
// skip empty entries and entry for . and ..
// skip empty entries and entry for . and ..
if
(
dir
->
name
[
0
]
==
DIR_NAME_DELETED
||
dir
->
name
[
0
]
==
'.'
)
continue
;
if
(
dir
->
name
[
0
]
==
DIR_NAME_DELETED
||
dir
->
name
[
0
]
==
'.'
)
continue
;
//Fill the long filename if we have a long filename entry,
// long filename entries are stored before the actual filename
.
// Fill the long filename if we have a long filename entry
.
if
(
DIR_IS_LONG_NAME
(
dir
)
&&
longFilename
!=
NULL
)
// Long filename entries are stored before the short filename.
{
if
(
longFilename
!=
NULL
&&
DIR_IS_LONG_NAME
(
dir
))
{
vfat_t
*
VFAT
=
(
vfat_t
*
)
dir
;
vfat_t
*
VFAT
=
(
vfat_t
*
)
dir
;
//Sanity check the VFAT entry. The first cluster is always set to zero. And th esequence number should be higher then 0
// Sanity-check the VFAT entry. The first cluster is always set to zero. And the sequence number should be higher than 0
if
(
VFAT
->
firstClusterLow
==
0
&&
(
VFAT
->
sequenceNumber
&
0x1F
)
>
0
&&
(
VFAT
->
sequenceNumber
&
0x1F
)
<=
MAX_VFAT_ENTRIES
)
if
(
VFAT
->
firstClusterLow
==
0
&&
(
VFAT
->
sequenceNumber
&
0x1F
)
>
0
&&
(
VFAT
->
sequenceNumber
&
0x1F
)
<=
MAX_VFAT_ENTRIES
)
{
{
// TODO: Store the filename checksum to verify if a none-long filename aware system modified the file table.
//TODO: Store the filename checksum to verify if a none-long filename aware system modified the file table.
n
=
((
VFAT
->
sequenceNumber
&
0x1F
)
-
1
)
*
FILENAME_LENGTH
;
n
=
((
VFAT
->
sequenceNumber
&
0x1F
)
-
1
)
*
FILENAME_LENGTH
;
longFilename
[
n
+
0
]
=
VFAT
->
name1
[
0
];
for
(
uint8_t
i
=
0
;
i
<
FILENAME_LENGTH
;
i
++
)
longFilename
[
n
+
1
]
=
VFAT
->
name1
[
1
];
longFilename
[
n
+
i
]
=
(
i
<
5
)
?
VFAT
->
name1
[
i
]
:
(
i
<
11
)
?
VFAT
->
name2
[
i
-
5
]
:
VFAT
->
name3
[
i
-
11
];
longFilename
[
n
+
2
]
=
VFAT
->
name1
[
2
];
// If this VFAT entry is the last one, add a NUL terminator at the end of the string
longFilename
[
n
+
3
]
=
VFAT
->
name1
[
3
];
if
(
VFAT
->
sequenceNumber
&
0x40
)
longFilename
[
n
+
FILENAME_LENGTH
]
=
'\0'
;
longFilename
[
n
+
4
]
=
VFAT
->
name1
[
4
];
}
longFilename
[
n
+
5
]
=
VFAT
->
name2
[
0
];
}
longFilename
[
n
+
6
]
=
VFAT
->
name2
[
1
];
// Return if normal file or subdirectory
longFilename
[
n
+
7
]
=
VFAT
->
name2
[
2
];
longFilename
[
n
+
8
]
=
VFAT
->
name2
[
3
];
longFilename
[
n
+
9
]
=
VFAT
->
name2
[
4
];
longFilename
[
n
+
10
]
=
VFAT
->
name2
[
5
];
longFilename
[
n
+
11
]
=
VFAT
->
name3
[
0
];
longFilename
[
n
+
12
]
=
VFAT
->
name3
[
1
];
//If this VFAT entry is the last one, add a NUL terminator at the end of the string
if
(
VFAT
->
sequenceNumber
&
0x40
)
longFilename
[
n
+
FILENAME_LENGTH
]
=
'\0'
;
}
}
// return if normal file or subdirectory
if
(
DIR_IS_FILE_OR_SUBDIR
(
dir
))
return
n
;
if
(
DIR_IS_FILE_OR_SUBDIR
(
dir
))
return
n
;
}
}
}
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// Read next directory entry into the cache
// Read next directory entry into the cache
// Assumes file is correctly positioned
// Assumes file is correctly positioned
...
...
MarlinKimbra/cardreader.cpp
View file @
dda444c5
...
@@ -39,24 +39,43 @@ char *createFilename(char *buffer, const dir_t &p) { //buffer > 12characters
...
@@ -39,24 +39,43 @@ char *createFilename(char *buffer, const dir_t &p) { //buffer > 12characters
return
buffer
;
return
buffer
;
}
}
/**
* Dive into a folder and recurse depth-first to perform a pre-set operation lsAction:
* LS_Count - Add +1 to nrFiles for every file within the parent
* LS_GetFilename - Get the filename of the file indexed by nrFiles
* LS_SerialPrint - Print the full path of each file to serial output
*/
void
CardReader
::
lsDive
(
const
char
*
prepend
,
SdFile
parent
,
const
char
*
const
match
/*=NULL*/
)
{
void
CardReader
::
lsDive
(
const
char
*
prepend
,
SdFile
parent
,
const
char
*
const
match
/*=NULL*/
)
{
dir_t
p
;
dir_t
p
;
uint8_t
cnt
=
0
;
uint8_t
cnt
=
0
;
// Read the next entry from a directory
while
(
parent
.
readDir
(
p
,
longFilename
)
>
0
)
{
while
(
parent
.
readDir
(
p
,
longFilename
)
>
0
)
{
if
(
DIR_IS_SUBDIR
(
&
p
)
&&
lsAction
!=
LS_Count
&&
lsAction
!=
LS_GetFilename
)
{
// hence LS_SerialPrint
char
path
[
FILENAME_LENGTH
*
2
];
// If the entry is a directory and the action is LS_SerialPrint
if
(
DIR_IS_SUBDIR
(
&
p
)
&&
lsAction
!=
LS_Count
&&
lsAction
!=
LS_GetFilename
)
{
// Allocate enough stack space for the full path to a folder
int
len
=
strlen
(
prepend
)
+
FILENAME_LENGTH
+
1
;
char
path
[
len
];
// Get the short name for the item, which we know is a folder
char
lfilename
[
FILENAME_LENGTH
];
char
lfilename
[
FILENAME_LENGTH
];
createFilename
(
lfilename
,
p
);
createFilename
(
lfilename
,
p
);
path
[
0
]
=
0
;
// Append the FOLDERNAME12/ to the passed string.
if
(
prepend
[
0
]
==
0
)
strcat
(
path
,
"/"
);
//avoid leading / if already in prepend
// It contains the full path to the "parent" argument.
// We now have the full path to the item in this folder.
path
[
0
]
=
'\0'
;
if
(
prepend
[
0
]
==
'\0'
)
strcat
(
path
,
"/"
);
// a root slash if prepend is empty
strcat
(
path
,
prepend
);
strcat
(
path
,
prepend
);
strcat
(
path
,
lfilename
);
strcat
(
path
,
lfilename
);
strcat
(
path
,
"/"
);
strcat
(
path
,
"/"
);
//Serial.print(path);
//
Serial.print(path);
// Get a new directory object using the full path
// and dive recursively into it.
SdFile
dir
;
SdFile
dir
;
if
(
!
dir
.
open
(
parent
,
lfilename
,
O_READ
))
{
if
(
!
dir
.
open
(
parent
,
lfilename
,
O_READ
))
{
if
(
lsAction
==
LS_SerialPrint
)
{
if
(
lsAction
==
LS_SerialPrint
)
{
...
@@ -64,14 +83,13 @@ void CardReader::lsDive(const char *prepend, SdFile parent, const char * const m
...
@@ -64,14 +83,13 @@ void CardReader::lsDive(const char *prepend, SdFile parent, const char * const m
}
}
}
}
lsDive
(
path
,
dir
);
lsDive
(
path
,
dir
);
//
close
done automatically by destructor of SdFile
//
close() is
done automatically by destructor of SdFile
}
}
else
{
else
{
char
pn0
=
p
.
name
[
0
];
char
pn0
=
p
.
name
[
0
];
if
(
pn0
==
DIR_NAME_FREE
)
break
;
if
(
pn0
==
DIR_NAME_FREE
)
break
;
if
(
pn0
==
DIR_NAME_DELETED
||
pn0
==
'.'
)
continue
;
if
(
pn0
==
DIR_NAME_DELETED
||
pn0
==
'.'
)
continue
;
char
lf0
=
longFilename
[
0
];
if
(
longFilename
[
0
]
==
'.'
)
continue
;
if
(
lf0
==
'.'
)
continue
;
if
(
!
DIR_IS_FILE_OR_SUBDIR
(
&
p
))
continue
;
if
(
!
DIR_IS_FILE_OR_SUBDIR
(
&
p
))
continue
;
...
@@ -79,24 +97,26 @@ void CardReader::lsDive(const char *prepend, SdFile parent, const char * const m
...
@@ -79,24 +97,26 @@ void CardReader::lsDive(const char *prepend, SdFile parent, const char * const m
if
(
!
filenameIsDir
&&
(
p
.
name
[
8
]
!=
'G'
||
p
.
name
[
9
]
==
'~'
))
continue
;
if
(
!
filenameIsDir
&&
(
p
.
name
[
8
]
!=
'G'
||
p
.
name
[
9
]
==
'~'
))
continue
;
//if (cnt++ != nr) continue;
switch
(
lsAction
)
{
case
LS_Count
:
nrFiles
++
;
break
;
case
LS_SerialPrint
:
createFilename
(
filename
,
p
);
createFilename
(
filename
,
p
);
if
(
lsAction
==
LS_SerialPrint
)
{
ECHO_V
(
prepend
);
ECHO_V
(
prepend
);
ECHO_EV
(
filename
);
ECHO_EV
(
filename
);
}
break
;
else
if
(
lsAction
==
LS_Count
)
{
case
LS_GetFilename
:
nrFiles
++
;
createFilename
(
filename
,
p
);
}
else
if
(
lsAction
==
LS_GetFilename
)
{
if
(
match
!=
NULL
)
{
if
(
match
!=
NULL
)
{
if
(
strcasecmp
(
match
,
filename
)
==
0
)
return
;
if
(
strcasecmp
(
match
,
filename
)
==
0
)
return
;
}
}
else
if
(
cnt
==
nrFiles
)
return
;
else
if
(
cnt
==
nrFiles
)
return
;
cnt
++
;
cnt
++
;
break
;
}
}
}
}
}
}
// while readDir
}
}
void
CardReader
::
ls
()
{
void
CardReader
::
ls
()
{
...
@@ -130,14 +150,15 @@ void CardReader::initsd() {
...
@@ -130,14 +150,15 @@ void CardReader::initsd() {
}
}
else
{
else
{
cardOK
=
true
;
cardOK
=
true
;
ECHO_LM
(
OK
,
MSG_SD_CARD_OK
);
ECHO_LM
(
DB
,
MSG_SD_CARD_OK
);
}
}
workDir
=
root
;
workDir
=
root
;
curDir
=
&
root
;
curDir
=
&
root
;
/*
/*
if (!workDir.openRoot(&volume)) {
if (!workDir.openRoot(&volume)) {
ECHO_EM(MSG_SD_WORKDIR_FAIL);
ECHO_EM(MSG_SD_WORKDIR_FAIL);
}*/
}
*/
}
}
void
CardReader
::
setroot
()
{
void
CardReader
::
setroot
()
{
...
@@ -210,22 +231,28 @@ void CardReader::openFile(char* name, bool read, bool replace_current/*=true*/,
...
@@ -210,22 +231,28 @@ void CardReader::openFile(char* name, bool read, bool replace_current/*=true*/,
char
*
dirname_start
,
*
dirname_end
;
char
*
dirname_start
,
*
dirname_end
;
if
(
name
[
0
]
==
'/'
)
{
if
(
name
[
0
]
==
'/'
)
{
dirname_start
=
&
name
[
1
];
dirname_start
=
&
name
[
1
];
while
(
dirname_start
>
0
)
{
while
(
dirname_start
>
0
)
{
dirname_end
=
strchr
(
dirname_start
,
'/'
);
dirname_end
=
strchr
(
dirname_start
,
'/'
);
if
(
dirname_end
>
0
&&
dirname_end
>
dirname_start
)
{
if
(
dirname_end
>
0
&&
dirname_end
>
dirname_start
)
{
char
subdirname
[
FILENAME_LENGTH
];
char
subdirname
[
FILENAME_LENGTH
];
strncpy
(
subdirname
,
dirname_start
,
dirname_end
-
dirname_start
);
strncpy
(
subdirname
,
dirname_start
,
dirname_end
-
dirname_start
);
subdirname
[
dirname_end
-
dirname_start
]
=
0
;
subdirname
[
dirname_end
-
dirname_start
]
=
0
;
ECHO_EV
(
subdirname
);
if
(
!
myDir
.
open
(
curDir
,
subdirname
,
O_READ
))
{
if
(
!
myDir
.
open
(
curDir
,
subdirname
,
O_READ
))
{
ECHO_LMV
(
ER
,
MSG_SD_OPEN_FILE_FAIL
,
subdirname
);
ECHO_LMV
(
ER
,
MSG_SD_OPEN_FILE_FAIL
,
subdirname
);
return
;
return
;
}
}
else
{
//ECHO_EM("dive ok");
}
curDir
=
&
myDir
;
curDir
=
&
myDir
;
dirname_start
=
dirname_end
+
1
;
dirname_start
=
dirname_end
+
1
;
}
}
else
{
// the remainder after all /fsa/fdsa/ is the filename
else
{
// the remainder after all /fsa/fdsa/ is the filename
fname
=
dirname_start
;
fname
=
dirname_start
;
//ECHO_EM("remainder");
//ECHO_EV(fname);
break
;
break
;
}
}
}
}
...
@@ -237,14 +264,16 @@ void CardReader::openFile(char* name, bool read, bool replace_current/*=true*/,
...
@@ -237,14 +264,16 @@ void CardReader::openFile(char* name, bool read, bool replace_current/*=true*/,
if
(
read
)
{
if
(
read
)
{
if
(
file
.
open
(
curDir
,
fname
,
O_READ
))
{
if
(
file
.
open
(
curDir
,
fname
,
O_READ
))
{
filesize
=
file
.
fileSize
();
filesize
=
file
.
fileSize
();
ECHO_SMV
(
OK
,
MSG_SD_FILE_OPENED
,
fname
);
ECHO_SMV
(
OK
,
MSG_SD_FILE_OPENED
,
fname
);
ECHO_EMV
(
MSG_SD_SIZE
,
filesize
);
ECHO_EMV
(
MSG_SD_SIZE
,
filesize
);
sdpos
=
0
;
sdpos
=
0
;
ECHO_EM
(
MSG_SD_FILE_SELECTED
);
getfilename
(
0
,
fname
);
getfilename
(
0
,
fname
);
if
(
lcd_status
)
lcd_setstatus
(
longFilename
[
0
]
?
longFilename
:
fname
);
lcd_setstatus
(
longFilename
[
0
]
?
longFilename
:
fname
);
}
}
else
{
else
{
ECHO_LMV
(
ER
,
MSG_SD_OPEN_FILE_FAIL
,
fname
);
ECHO_LMV
(
ER
,
MSG_SD_OPEN_FILE_FAIL
,
fname
);
}
}
}
}
else
{
//write
else
{
//write
...
@@ -278,6 +307,7 @@ void CardReader::removeFile(char* name) {
...
@@ -278,6 +307,7 @@ void CardReader::removeFile(char* name) {
char
subdirname
[
FILENAME_LENGTH
];
char
subdirname
[
FILENAME_LENGTH
];
strncpy
(
subdirname
,
dirname_start
,
dirname_end
-
dirname_start
);
strncpy
(
subdirname
,
dirname_start
,
dirname_end
-
dirname_start
);
subdirname
[
dirname_end
-
dirname_start
]
=
0
;
subdirname
[
dirname_end
-
dirname_start
]
=
0
;
ECHO_EV
(
subdirname
);
if
(
!
myDir
.
open
(
curDir
,
subdirname
,
O_READ
))
{
if
(
!
myDir
.
open
(
curDir
,
subdirname
,
O_READ
))
{
ECHO_LMV
(
ER
,
MSG_SD_OPEN_FILE_FAIL
,
subdirname
);
ECHO_LMV
(
ER
,
MSG_SD_OPEN_FILE_FAIL
,
subdirname
);
return
;
return
;
...
@@ -301,7 +331,7 @@ void CardReader::removeFile(char* name) {
...
@@ -301,7 +331,7 @@ void CardReader::removeFile(char* name) {
sdpos
=
0
;
sdpos
=
0
;
}
}
else
{
else
{
ECHO_LMV
(
ER
,
MSG_SD_FILE_DELETION_ERR
,
fname
);
ECHO_LMV
(
ER
,
MSG_SD_FILE_DELETION_ERR
,
fname
);
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment