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
355d2b4d
Commit
355d2b4d
authored
Dec 16, 2014
by
MagoKimbra
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add alpha sort files in SD card
parent
aad22c23
Changes
9
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
407 additions
and
227 deletions
+407
-227
Configuration.h
MarlinKimbra/Configuration.h
+2
-2
Configuration_Cartesian.h
MarlinKimbra/Configuration_Cartesian.h
+27
-27
Configuration_adv.h
MarlinKimbra/Configuration_adv.h
+133
-139
Marlin_main.cpp
MarlinKimbra/Marlin_main.cpp
+1
-1
SdFatConfig.h
MarlinKimbra/SdFatConfig.h
+4
-2
cardreader.cpp
MarlinKimbra/cardreader.cpp
+188
-33
cardreader.h
MarlinKimbra/cardreader.h
+29
-7
pins.h
MarlinKimbra/pins.h
+1
-1
ultralcd.cpp
MarlinKimbra/ultralcd.cpp
+22
-15
No files found.
MarlinKimbra/Configuration.h
View file @
355d2b4d
...
...
@@ -163,7 +163,7 @@
* 10 is 100k RS thermistor 198-961 (4.7k pullup)
* 11 is 100k beta 3950 1% thermistor (4.7k pullup)
* 12 is 100k 0603 SMD Vishay NTCS0603E3104FXT (4.7k pullup) (calibrated for Makibox hot bed)
* 13 is 100k Hisens 3950 1% up to 300
Â
°C for hotend "Simple ONE " & "Hotend "All In ONE"
* 13 is 100k Hisens 3950 1% up to 300°C for hotend "Simple ONE " & "Hotend "All In ONE"
* 20 is the PT100 circuit found in the Ultimainboard V2.x
* 60 is 100k Maker's Tool Works Kapton Bed Thermistor beta=3950
*
...
...
MarlinKimbra/Configuration_Cartesian.h
View file @
355d2b4d
...
...
@@ -192,7 +192,7 @@ const bool Z_MAX_ENDSTOP_INVERTING = false; // set to true to invert the logic o
//// MOVEMENT SETTINGS
#define NUM_AXIS 4 // The axis order in all axis related arrays is X, Y, Z, E
#define HOMING_FEEDRATE {100*60,100*60,
4*60,0}
// set the homing speeds (mm/min)
#define HOMING_FEEDRATE {100*60,100*60,
2*60,0}
// set the homing speeds (mm/min)
// default settings
...
...
@@ -244,5 +244,5 @@ const bool Z_MAX_ENDSTOP_INVERTING = false; // set to true to invert the logic o
// This allows for servo actuated endstops, primary usage is for the Z Axis to eliminate calibration or bed height changes.
// Use M206 command to correct for switch height offset to actual nozzle height. Store that setting with M500.
//
#define SERVO_ENDSTOPS {-1,
-1,
0} // Servo index for X, Y, Z. Disable with -1
#define SERVO_ENDSTOP_ANGLES {0,0,
0,0,
90,0} // X,Y,Z Axis Extend and Retract angles
#define SERVO_ENDSTOPS {-1,
-1,
0} // Servo index for X, Y, Z. Disable with -1
#define SERVO_ENDSTOP_ANGLES {0,0,
0,0,
90,0} // X,Y,Z Axis Extend and Retract angles
\ No newline at end of file
MarlinKimbra/Configuration_adv.h
View file @
355d2b4d
This diff is collapsed.
Click to expand it.
MarlinKimbra/Marlin_main.cpp
View file @
355d2b4d
MarlinKimbra/SdFatConfig.h
View file @
355d2b4d
...
...
@@ -111,10 +111,12 @@ uint8_t const SOFT_SPI_SCK_PIN = 13;
/**
* Defines for long (vfat) filenames
*/
/** Number of UTF-16 characters per entry */
#define FILENAME_LENGTH 13
/** Number of VFAT entries used. Every entry has 13 UTF-16 characters */
#define MAX_VFAT_ENTRIES (2)
/** Total size of the buffer used to store the long filenames */
#define LONG_FILENAME_LENGTH (
13
*MAX_VFAT_ENTRIES+1)
#define LONG_FILENAME_LENGTH (
FILENAME_LENGTH
*MAX_VFAT_ENTRIES+1)
#endif // SdFatConfig_h
...
...
MarlinKimbra/cardreader.cpp
View file @
355d2b4d
...
...
@@ -11,6 +11,9 @@
CardReader
::
CardReader
()
{
#ifdef SDCARD_SORT_ALPHA
sort_count
=
0
;
#endif
filesize
=
0
;
sdpos
=
0
;
sdprinting
=
false
;
...
...
@@ -33,19 +36,15 @@ CardReader::CardReader()
autostart_atmillis
=
millis
()
+
5000
;
}
char
*
createFilename
(
char
*
buffer
,
const
dir_t
&
p
)
//buffer>12characters
char
*
createFilename
(
char
*
buffer
,
const
dir_t
&
p
)
//buffer>12characters
{
char
*
pos
=
buffer
;
for
(
uint8_t
i
=
0
;
i
<
11
;
i
++
)
{
if
(
p
.
name
[
i
]
==
' '
)
continue
;
if
(
i
==
8
)
{
*
pos
++=
'.'
;
for
(
uint8_t
i
=
0
;
i
<
11
;
i
++
)
{
if
(
p
.
name
[
i
]
==
' '
)
continue
;
if
(
i
==
8
)
*
pos
++
=
'.'
;
*
pos
++
=
p
.
name
[
i
];
}
*
pos
++=
p
.
name
[
i
];
}
*
pos
++=
0
;
*
pos
++
=
0
;
return
buffer
;
}
...
...
@@ -60,8 +59,8 @@ void CardReader::lsDive(const char *prepend,SdFile parent)
if
(
DIR_IS_SUBDIR
(
&
p
)
&&
lsAction
!=
LS_Count
&&
lsAction
!=
LS_GetFilename
)
// hence LS_SerialPrint
{
char
path
[
13
*
2
];
char
lfilename
[
13
];
char
path
[
FILENAME_LENGTH
*
2
];
char
lfilename
[
FILENAME_LENGTH
];
createFilename
(
lfilename
,
p
);
path
[
0
]
=
0
;
...
...
@@ -87,8 +86,6 @@ void CardReader::lsDive(const char *prepend,SdFile parent)
}
lsDive
(
path
,
dir
);
//close done automatically by destructor of SdFile
}
else
{
...
...
@@ -105,7 +102,6 @@ void CardReader::lsDive(const char *prepend,SdFile parent)
if
(
!
DIR_IS_FILE_OR_SUBDIR
(
&
p
))
continue
;
filenameIsDir
=
DIR_IS_SUBDIR
(
&
p
);
if
(
!
filenameIsDir
)
{
if
(
p
.
name
[
8
]
!=
'G'
)
continue
;
...
...
@@ -124,10 +120,8 @@ void CardReader::lsDive(const char *prepend,SdFile parent)
}
else
if
(
lsAction
==
LS_GetFilename
)
{
if
(
cnt
==
nrFiles
)
return
;
if
(
cnt
==
nrFiles
)
return
;
cnt
++
;
}
}
}
...
...
@@ -136,9 +130,6 @@ void CardReader::lsDive(const char *prepend,SdFile parent)
void
CardReader
::
ls
()
{
lsAction
=
LS_SerialPrint
;
if
(
lsAction
==
LS_Count
)
nrFiles
=
0
;
root
.
rewind
();
lsDive
(
""
,
root
);
}
...
...
@@ -177,6 +168,9 @@ void CardReader::initsd()
}
workDir
=
root
;
curDir
=&
root
;
#ifdef SDCARD_SORT_ALPHA
presort
();
#endif
/*
if(!workDir.openRoot(&volume))
{
...
...
@@ -193,8 +187,10 @@ void CardReader::setroot()
SERIAL_ECHOLNPGM(MSG_SD_WORKDIR_FAIL);
}*/
workDir
=
root
;
curDir
=&
workDir
;
#ifdef SDCARD_SORT_ALPHA
presort
();
#endif
}
void
CardReader
::
release
()
{
...
...
@@ -207,6 +203,9 @@ void CardReader::startFileprint()
if
(
cardOK
)
{
sdprinting
=
true
;
#ifdef SDCARD_SORT_ALPHA
flush_presort
();
#endif
}
}
...
...
@@ -235,7 +234,7 @@ void CardReader::getAbsFilename(char *t)
while
(
*
t
!=
0
&&
cnt
<
MAXPATHNAMELENGTH
)
{
t
++
;
cnt
++
;}
//crawl counter forward.
}
if
(
cnt
<
MAXPATHNAMELENGTH
-
13
)
if
(
cnt
<
MAXPATHNAMELENGTH
-
FILENAME_LENGTH
)
file
.
getFilename
(
t
);
else
t
[
0
]
=
0
;
...
...
@@ -305,7 +304,7 @@ void CardReader::openFile(char* name,bool read, bool replace_current/*=true*/)
//SERIAL_ECHO("end :");SERIAL_ECHOLN((int)(dirname_end-name));
if
(
dirname_end
>
0
&&
dirname_end
>
dirname_start
)
{
char
subdirname
[
13
];
char
subdirname
[
FILENAME_LENGTH
];
strncpy
(
subdirname
,
dirname_start
,
dirname_end
-
dirname_start
);
subdirname
[
dirname_end
-
dirname_start
]
=
0
;
SERIAL_ECHOLN
(
subdirname
);
...
...
@@ -401,7 +400,7 @@ void CardReader::removeFile(char* name)
//SERIAL_ECHO("end :");SERIAL_ECHOLN((int)(dirname_end-name));
if
(
dirname_end
>
0
&&
dirname_end
>
dirname_start
)
{
char
subdirname
[
13
];
char
subdirname
[
FILENAME_LENGTH
];
strncpy
(
subdirname
,
dirname_start
,
dirname_end
-
dirname_start
);
subdirname
[
dirname_end
-
dirname_start
]
=
0
;
SERIAL_ECHOLN
(
subdirname
);
...
...
@@ -439,6 +438,9 @@ void CardReader::removeFile(char* name)
SERIAL_PROTOCOLPGM
(
"File deleted:"
);
SERIAL_PROTOCOLLN
(
fname
);
sdpos
=
0
;
#ifdef SDCARD_SORT_ALPHA
presort
();
#endif
}
else
{
...
...
@@ -552,14 +554,21 @@ void CardReader::closefile(bool store_location)
}
void
CardReader
::
getfilename
(
const
uint
8
_t
nr
)
void
CardReader
::
getfilename
(
const
uint
16
_t
nr
)
{
#if defined(SDCARD_SORT_ALPHA) && SORT_USES_RAM && SORT_USES_MORE_RAM
if
(
nr
<
sort_count
)
{
strcpy
(
filename
,
sortshort
[
nr
]);
strcpy
(
longFilename
,
sortnames
[
nr
]);
filenameIsDir
=
isDir
[
nr
];
return
;
}
#endif
curDir
=&
workDir
;
lsAction
=
LS_GetFilename
;
nrFiles
=
nr
;
curDir
->
rewind
();
lsDive
(
""
,
*
curDir
);
}
uint16_t
CardReader
::
getnrfilenames
()
...
...
@@ -595,21 +604,164 @@ void CardReader::chdir(const char * relpath)
workDirParents
[
0
]
=*
parent
;
}
workDir
=
newfile
;
#ifdef SDCARD_SORT_ALPHA
presort
();
#endif
}
}
void
CardReader
::
updir
()
{
if
(
workDirDepth
>
0
)
if
(
workDirDepth
>
0
)
{
--
workDirDepth
;
workDir
=
workDirParents
[
0
];
int
d
;
for
(
int
d
=
0
;
d
<
workDirDepth
;
d
++
)
workDirParents
[
d
]
=
workDirParents
[
d
+
1
];
#ifdef SDCARD_SORT_ALPHA
presort
();
#endif
}
}
#ifdef SDCARD_SORT_ALPHA
/**
* Get the name of a file in the current directory by sort-index
*/
void
CardReader
::
getfilename_sorted
(
const
uint16_t
nr
)
{
getfilename
(
nr
<
sort_count
?
sort_order
[
nr
]
:
nr
);
}
/**
* Read all the files and produce a sort key
*
* We can do this in 3 ways...
* - Minimal RAM: Read two filenames at a time sorting along...
* - Some RAM: Buffer the directory and return filenames from RAM
* - Some RAM: Buffer the directory just for this sort
*/
void
CardReader
::
presort
()
{
flush_presort
();
uint16_t
fileCnt
=
getnrfilenames
();
if
(
fileCnt
>
0
)
{
if
(
fileCnt
>
SORT_LIMIT
)
fileCnt
=
SORT_LIMIT
;
#if SORT_USES_RAM
#if SORT_USES_MORE_RAM
sortshort
=
(
char
**
)
calloc
(
fileCnt
,
sizeof
(
char
*
));
sortnames
=
(
char
**
)
calloc
(
fileCnt
,
sizeof
(
char
*
));
#else
char
*
sortnames
[
fileCnt
];
#endif
#else
char
name1
[
LONG_FILENAME_LENGTH
+
1
];
#endif
#if FOLDER_SORTING != 0
#if SORT_USES_RAM && SORT_USES_MORE_RAM
isDir
=
(
uint8_t
*
)
calloc
(
fileCnt
,
sizeof
(
uint8_t
));
#else
uint8_t
isDir
[
fileCnt
];
#endif
#endif
sort_order
=
new
uint8_t
[
fileCnt
];
if
(
fileCnt
>
1
)
{
// Init sort order. If using RAM then read all filenames now.
for
(
uint16_t
i
=
0
;
i
<
fileCnt
;
i
++
)
{
sort_order
[
i
]
=
i
;
#if SORT_USES_RAM
getfilename
(
i
);
sortnames
[
i
]
=
strdup
(
longFilename
[
0
]
?
longFilename
:
filename
);
#if SORT_USES_MORE_RAM
sortshort
[
i
]
=
strdup
(
filename
);
#endif
// char out[30];
// sprintf_P(out, PSTR("---- %i %s %s"), i, filenameIsDir ? "D" : " ", sortnames[i]);
// SERIAL_ECHOLN(out);
#if FOLDER_SORTING != 0
isDir
[
i
]
=
filenameIsDir
;
#endif
#endif
}
// Bubble Sort
for
(
uint16_t
i
=
fileCnt
;
--
i
;)
{
bool
cmp
,
didSwap
=
false
;
for
(
uint16_t
j
=
0
;
j
<
i
;
++
j
)
{
uint16_t
s1
=
j
,
s2
=
j
+
1
,
o1
=
sort_order
[
s1
],
o2
=
sort_order
[
s2
];
#if SORT_USES_RAM
#if FOLDER_SORTING != 0
cmp
=
(
isDir
[
o1
]
==
isDir
[
o2
])
?
(
strcasecmp
(
sortnames
[
o1
],
sortnames
[
o2
])
>
0
)
:
isDir
[
FOLDER_SORTING
>
0
?
o1
:
o2
];
#else
cmp
=
strcasecmp
(
sortnames
[
o1
],
sortnames
[
o2
])
>
0
;
#endif
#else
getfilename
(
o1
);
strcpy
(
name1
,
longFilename
[
0
]
?
longFilename
:
filename
);
#if FOLDER_SORTING != 0
bool
dir1
=
filenameIsDir
;
#endif
getfilename
(
o2
);
char
*
name2
=
longFilename
[
0
]
?
longFilename
:
filename
;
#if FOLDER_SORTING != 0
cmp
=
(
dir1
==
filenameIsDir
)
?
(
strcasecmp
(
name1
,
name2
)
>
0
)
:
(
FOLDER_SORTING
>
0
?
dir1
:
!
dir1
);
#else
cmp
=
strcasecmp
(
name1
,
name2
)
>
0
;
#endif
#endif
if
(
cmp
)
{
sort_order
[
s1
]
=
o2
;
sort_order
[
s2
]
=
o1
;
didSwap
=
true
;
}
}
if
(
!
didSwap
)
break
;
}
#if SORT_USES_RAM && !SORT_USES_MORE_RAM
for
(
uint16_t
i
=
0
;
i
<
fileCnt
;
++
i
)
free
(
sortnames
[
i
]);
#endif
}
else
{
sort_order
[
0
]
=
0
;
#if SORT_USES_RAM && SORT_USES_MORE_RAM
sortnames
=
(
char
**
)
malloc
(
sizeof
(
char
*
));
sortshort
=
(
char
**
)
malloc
(
sizeof
(
char
*
));
isDir
=
(
uint8_t
*
)
malloc
(
sizeof
(
uint8_t
));
getfilename
(
0
);
sortnames
[
0
]
=
strdup
(
longFilename
[
0
]
?
longFilename
:
filename
);
sortshort
[
0
]
=
strdup
(
filename
);
isDir
[
0
]
=
filenameIsDir
;
#endif
}
sort_count
=
fileCnt
;
}
}
void
CardReader
::
flush_presort
()
{
if
(
sort_count
>
0
)
{
#if SORT_USES_RAM && SORT_USES_MORE_RAM
for
(
uint8_t
i
=
0
;
i
<
sort_count
;
++
i
)
{
free
(
sortshort
[
i
]);
free
(
sortnames
[
i
]);
}
free
(
sortshort
);
free
(
sortnames
);
#endif
delete
sort_order
;
sort_count
=
0
;
}
}
#endif // SDCARD_SORT_ALPHA
void
CardReader
::
printingHasFinished
()
{
...
...
@@ -633,6 +785,9 @@ void CardReader::printingHasFinished()
enquecommand_P
(
PSTR
(
SD_FINISHED_RELEASECOMMAND
));
}
autotempShutdown
();
#ifdef SDCARD_SORT_ALPHA
presort
();
#endif
}
}
#endif //SDSUPPORT
MarlinKimbra/cardreader.h
View file @
355d2b4d
...
...
@@ -3,7 +3,14 @@
#ifdef SDSUPPORT
#define MAX_DIR_DEPTH 10
#define MAX_DIR_DEPTH 10 // Maximum folder depth
#ifdef SDCARD_SORT_ALPHA
#define SORT_USES_RAM false // Buffer while sorting, else re-read from SD
#define SORT_USES_MORE_RAM false // Always keep the directory in RAM
#define SORT_LIMIT 256 // Maximum number of sorted items
#define FOLDER_SORTING -1 // -1=above 0=none 1=below
#endif
#include "SdFile.h"
enum
LsAction
{
LS_SerialPrint
,
LS_Count
,
LS_GetFilename
};
...
...
@@ -28,7 +35,7 @@ public:
void
getStatus
();
void
printingHasFinished
();
void
getfilename
(
const
uint
8
_t
nr
);
void
getfilename
(
const
uint
16
_t
nr
);
uint16_t
getnrfilenames
();
void
getAbsFilename
(
char
*
t
);
...
...
@@ -39,6 +46,12 @@ public:
void
updir
();
void
setroot
();
#ifdef SDCARD_SORT_ALPHA
void
presort
();
void
flush_presort
();
void
getfilename_sorted
(
const
uint16_t
nr
);
#endif
FORCE_INLINE
bool
isFileOpen
()
{
return
file
.
isOpen
();
}
FORCE_INLINE
bool
eof
()
{
return
sdpos
>=
filesize
;};
...
...
@@ -50,20 +63,29 @@ public:
public
:
bool
saving
;
bool
logging
;
bool
sdprinting
;
bool
cardOK
;
char
filename
[
13
];
bool
sdprinting
;
bool
cardOK
;
char
filename
[
FILENAME_LENGTH
];
char
longFilename
[
LONG_FILENAME_LENGTH
];
bool
filenameIsDir
;
int
lastnr
;
//last number of the autostart;
private
:
SdFile
root
,
*
curDir
,
workDir
,
workDirParents
[
MAX_DIR_DEPTH
];
uint16_t
workDirDepth
;
#ifdef SDCARD_SORT_ALPHA
uint16_t
sort_count
;
uint8_t
*
sort_order
;
#if SORT_USES_MORE_RAM
char
**
sortshort
;
char
**
sortnames
;
uint8_t
*
isDir
;
#endif
#endif
Sd2Card
card
;
SdVolume
volume
;
SdFile
file
;
#define SD_PROCEDURE_DEPTH 1
#define MAXPATHNAMELENGTH (
13
*MAX_DIR_DEPTH+MAX_DIR_DEPTH+1)
#define MAXPATHNAMELENGTH (
FILENAME_LENGTH
*MAX_DIR_DEPTH+MAX_DIR_DEPTH+1)
uint8_t
file_subcall_ctr
;
uint32_t
filespos
[
SD_PROCEDURE_DEPTH
];
char
filenames
[
SD_PROCEDURE_DEPTH
][
MAXPATHNAMELENGTH
];
...
...
@@ -75,7 +97,7 @@ private:
bool
autostart_stilltocheck
;
//the sd start is delayed, because otherwise the serial cannot answer fast enought to make contact with the hostsoftware.
LsAction
lsAction
;
//stored for recursion.
int16_t
nrFiles
;
//counter for the files in the current directory and recycled as position counter for getting the nrFiles'th name in the directory.
u
int16_t
nrFiles
;
//counter for the files in the current directory and recycled as position counter for getting the nrFiles'th name in the directory.
char
*
diveDirName
;
void
lsDive
(
const
char
*
prepend
,
SdFile
parent
);
};
...
...
MarlinKimbra/pins.h
View file @
355d2b4d
MarlinKimbra/ultralcd.cpp
View file @
355d2b4d
...
...
@@ -1207,9 +1207,9 @@ void lcd_sdcard_menu()
card
.
getWorkDirName
();
if
(
card
.
filename
[
0
]
==
'/'
)
{
#if SDCARDDETECT == -1
#if SDCARDDETECT == -1
MENU_ITEM
(
function
,
LCD_STR_REFRESH
MSG_REFRESH
,
lcd_sd_refresh
);
#endif
#endif
}
else
{
MENU_ITEM
(
function
,
LCD_STR_FOLDER
".."
,
lcd_sd_updir
);
}
...
...
@@ -1218,15 +1218,22 @@ void lcd_sdcard_menu()
{
if
(
_menuItemNr
==
_lineNr
)
{
#if
ndef SDCARD_RATHERRECENTFIRST
card
.
getfilename
(
i
)
;
#if
defined(SDCARD_RATHERRECENTFIRST) && !defined(SDCARD_SORT_ALPHA)
int
nr
=
fileCnt
-
1
-
i
;
#else
card
.
getfilename
(
fileCnt
-
1
-
i
)
;
int
nr
=
i
;
#endif
if
(
card
.
filenameIsDir
)
{
#ifdef SDCARD_SORT_ALPHA
card
.
getfilename_sorted
(
nr
);
#else
card
.
getfilename
(
nr
);
#endif
if
(
card
.
filenameIsDir
)
{
MENU_ITEM
(
sddirectory
,
MSG_CARD_MENU
,
card
.
filename
,
card
.
longFilename
);
}
else
{
}
else
{
MENU_ITEM
(
sdfile
,
MSG_CARD_MENU
,
card
.
filename
,
card
.
longFilename
);
}
}
else
{
...
...
@@ -1433,7 +1440,7 @@ void lcd_init()
#endif // SR_LCD_2W_NL
#endif//!NEWPANEL
#if defined
(SDSUPPORT) && defined(SDCARDDETECT) && (SDCARDDETECT > 0)
#if defined(SDSUPPORT) && defined(SDCARDDETECT) && (SDCARDDETECT > 0)
pinMode
(
SDCARDDETECT
,
INPUT
);
WRITE
(
SDCARDDETECT
,
HIGH
);
lcd_oldcardstatus
=
IS_SD_INSERTED
;
...
...
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