Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Touchscreen Prerelease V1.9 #3

Open
wants to merge 239 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
239 commits
Select commit Hold shift + click to select a range
a57aa97
Added servoWrite, REVERSE_SERVO, corrected servo.
tgolla Feb 5, 2021
26a21ac
Moved Ruby version of utility code.
tgolla Feb 5, 2021
b9fa4b3
Added back Python code updated to V3.
tgolla Feb 5, 2021
c365b0e
Opened and configured Python code with VSCode.
tgolla Feb 5, 2021
5951ca8
Added g-code files for testing utility code.
tgolla Feb 5, 2021
60af5fc
Opened Arduino code with VSCode and configured.
tgolla Feb 5, 2021
11aa850
Reformated code. Naming conventions are next.
tgolla Feb 6, 2021
3145f77
Added Utils readme and updated settings.
tgolla Feb 6, 2021
f76c3da
Merge pull request #1 from tgolla/Python
tgolla Feb 7, 2021
272dbd5
Corrected naming conventions, structure, comments.
tgolla Feb 11, 2021
3c967d5
Updated configuration documentation.
tgolla Feb 12, 2021
c38b24e
Merge pull request #2 from tgolla/camelCase
tgolla Feb 13, 2021
99a4450
Initial class design. More items to finish coding and test.
tgolla Feb 15, 2021
b4a3130
Added unit test and corrections.
tgolla Feb 15, 2021
638ca29
Added and improved tests.
tgolla Feb 15, 2021
827fe49
Added FindWord and corrected testing.
tgolla Feb 15, 2021
19d1e69
Removed spaces and tabs from line, added blockDelete and updated test…
tgolla Feb 15, 2021
24d8b8c
Code optimized to single buffer.
tgolla Feb 17, 2021
e5c744e
Updated code documentation (comments).
tgolla Feb 17, 2021
0c7b113
Moved GCodeParser files.
tgolla Feb 17, 2021
e937a9b
Integration of GCodeParser.
tgolla Feb 18, 2021
9f012ff
Added start of G-Code documentation.
tgolla Feb 19, 2021
7d9ad52
Additional documentation corrections.
tgolla Feb 19, 2021
1846542
Minor documentation updates.
tgolla Feb 19, 2021
bcb3293
Added lastComment to GCodeParser.
tgolla Feb 20, 2021
9b7ab53
Separated testing methods to be more concise.
tgolla Feb 21, 2021
678cd4d
Added remove comment separators unit test.
tgolla Feb 21, 2021
51446fd
Added RemoveCommentSeparators().
tgolla Feb 21, 2021
2796a48
Updated project readme.
tgolla Feb 21, 2021
986c21f
Merge pull request #3 from tgolla/GCodeParser
tgolla Feb 21, 2021
ddde568
Breaking point. Need Mega board.
tgolla Mar 14, 2021
5374f23
Added SPLASH_SCREEN_DELAY.
tgolla Mar 16, 2021
038129d
Added PEN_DOWN_POSITION and M304 code.
tgolla Mar 16, 2021
053a07d
Added ADAFRUIT_TFT_TOUCH_SHIELD conditional.
tgolla Mar 16, 2021
6f3b2f0
Modified EEPROM locations to allow for other types
tgolla Mar 17, 2021
78ac1d4
Added new M code constants and corrected naming.
tgolla Mar 17, 2021
2bc3f5c
Added default mode values.
tgolla Mar 17, 2021
33289c0
Added decode for M305, M306, M307, M308, M309
tgolla Mar 17, 2021
f57c548
Added code to set/use pen feedrate.
tgolla Mar 17, 2021
bbbd6fc
Added mAdjust code to M300.
tgolla Mar 18, 2021
81fbc42
Added validation for M305, M306 & M307.
tgolla Mar 18, 2021
a75fd90
Finished adding code for mzMode.
tgolla Mar 18, 2021
01a83f9
Shortened comment line for clean print.
tgolla Mar 19, 2021
a2d08c7
Added debug code.
tgolla Mar 19, 2021
3a955cb
Correct reversed pen up/down speed code w/ deg/sec
tgolla Mar 19, 2021
a3694e8
Corrected int8_t to short.
tgolla Mar 19, 2021
b939053
Moved setting of M & Z Adjust Calculated.
tgolla Mar 19, 2021
a9155b3
Always recalculation adjustment for M306 & M307.
tgolla Mar 19, 2021
a830149
Beefed up M999 - DEBUG.
tgolla Mar 19, 2021
520e715
Added command info to DEBUG.
tgolla Mar 19, 2021
140983b
Added preset feedrates.
tgolla Mar 20, 2021
766366c
Corrected EEPROM memory type storage issue.
tgolla Mar 20, 2021
29d44b6
Added M312 - Pen up feedrate multiplier.
tgolla Mar 20, 2021
8c0dfbb
C/C++ Properties update.
tgolla Mar 24, 2021
eab2752
Prepping code for v1 release.
tgolla Apr 5, 2021
1c27227
Completed documentation for V1 release.
tgolla Apr 5, 2021
8e973d4
Merge pull request #4 from tgolla/Touchscreen
tgolla Apr 5, 2021
75190e5
Turned debug info into commands.
tgolla Apr 21, 2021
07b2ebc
Default debugging (M999) command.
tgolla Apr 21, 2021
8176780
Typo correction.
tgolla Apr 21, 2021
fc1d034
Added splash screen.
tgolla Sep 14, 2021
8e00b4e
Updated Splash Screen.
tgolla Sep 14, 2021
724e436
Start of touchscreen button class.
tgolla Jan 23, 2022
e7a9b2a
Moved images.
tgolla Jan 25, 2022
499ad0f
Corrected images to 24-bit and added prompt code.
tgolla Jan 25, 2022
839288a
Added AlphabeticSDFileList with test.
tgolla Apr 18, 2022
159807f
Adding menu button images.
tgolla Apr 18, 2022
f8bfa94
Added next and previous buttons.
tgolla May 1, 2022
9347efc
Modified alphabetic list with Begin().
tgolla May 2, 2022
cf8221d
Added code to display design image.
tgolla May 15, 2022
bb1338e
Added information and print buttons.
tgolla May 20, 2022
e9efe40
Added initial print code.
tgolla May 21, 2022
fc80244
Updated G-Code documentation.
tgolla May 21, 2022
57f7351
Added text constents for display messages.
tgolla May 22, 2022
bc23693
Start of print modifications.
tgolla May 22, 2022
5400f5b
Print modifications completed.
tgolla May 23, 2022
bffa394
Added M01 pause and display comments with no gcode
tgolla May 24, 2022
40acbd8
Added processing for block delete.
tgolla May 24, 2022
29cb307
File corrections
tgolla May 24, 2022
42c4c5e
Pause after file printed.
tgolla May 24, 2022
1a1711e
Enum correction (mzActiveMode == M)
tgolla May 24, 2022
7cacb51
Configuration.md completed through DEFAULT_MZ_MODE
tgolla May 24, 2022
bb85af3
Added initializePenConfiguration().
tgolla May 24, 2022
a9792cf
More configuration documentation.
tgolla May 25, 2022
0d5b3c6
Eliminated jitter caused by I2C!!!
tgolla May 25, 2022
71ab1b7
Added file info.
tgolla May 26, 2022
939f04f
Using new method GCode.NoWords()
tgolla May 26, 2022
de27590
Added TFT_TEXT_COLOR and TFT_TEXT_BACKGROUND_COLOR
tgolla May 26, 2022
3040d0b
Correct end of file processing.
tgolla May 26, 2022
f23126b
Anded createFilenamePath() and fileLineCount()
tgolla May 27, 2022
5a1af7c
Added DisplayAlternate()
tgolla May 27, 2022
b530910
Worked on displayed menu icons.
tgolla May 27, 2022
fe2fb33
Added percentage calculation.
tgolla May 27, 2022
efb2bdc
Added setTextSize()
tgolla May 27, 2022
47d9aad
V1.9 prerelease gcode files.
tgolla May 27, 2022
e394caa
Completed Configuration.md documentation.
tgolla May 27, 2022
07ec275
Completed Configuration.md documentation.
tgolla May 27, 2022
86c6128
Corrected typo.
tgolla May 28, 2022
ca4464c
Updating documentation for release.
tgolla May 28, 2022
c1f80d7
M300 presetPenFeedrate bug, document corrections
tgolla May 28, 2022
82177cd
Finished correcting documantation for release.
tgolla May 28, 2022
bb3b19a
New FIle movement images.
tgolla May 28, 2022
34bcfad
Added forward and rewind.
tgolla May 28, 2022
b0b0b1b
FIxed text size bug in displayFileInfo()
tgolla May 29, 2022
618b6bb
Alphabetic file list corrected to case insensitive
tgolla May 29, 2022
0e75db0
Reload pen configuration for each new file prinetd
tgolla May 29, 2022
8dd54cd
Added Process(silent)
tgolla May 29, 2022
9c41dbb
Documantation correction.
tgolla May 29, 2022
9a542b4
Added DebugTouchscreenButton to remove Serial print.
tgolla May 29, 2022
e6025fe
Added SerialDisplayPrint class.
tgolla May 30, 2022
108734c
Implemented M17
tgolla May 30, 2022
4b07c3f
Added M17, M18 command gcode.
tgolla May 30, 2022
1731eb4
Increased file size buffer.
tgolla May 30, 2022
ee3afa6
Corrected M17 with scope {}, added to M999 and reviewed all case stat…
tgolla May 30, 2022
f4c125b
Added SAVED_EEPROM_BASE_MEMORY_LOCATION
tgolla May 30, 2022
229afcd
Adding Eggbot Peano-Gosper Curve
tgolla May 30, 2022
4ab86f8
Added Stars Vine by SnoBahr.
tgolla May 30, 2022
827a85b
Corrected variable naming silent to noSerialResponse.
tgolla May 30, 2022
3d58334
Added Pi Egg.
tgolla May 31, 2022
cc1f529
Added Zipper.
tgolla May 31, 2022
53a047b
MAJOR BUG FIX in G01 implementation discovered with Hilbert curve g-c…
tgolla Jun 1, 2022
f461a55
Added Egg Definition.
tgolla Jun 7, 2022
a9847f7
Adding more designs.
tgolla Jun 8, 2022
03cce58
Added estimated time remaining.
tgolla Jun 20, 2022
340787b
Moved documentation.
tgolla Jul 1, 2022
b3fb984
Electronics documentation started.
tgolla Jul 5, 2022
d7783d2
Photo Corrections
tgolla Jul 5, 2022
8a08641
Corrected zipper files.
tgolla Jul 5, 2022
4eaded2
PI egg typo correction.
tgolla Jul 5, 2022
3314672
Updated electronics overview. Need to add assembly instructions.
tgolla Jul 5, 2022
e7b710e
Added pause with alert (beep).
tgolla Jul 6, 2022
b668caa
Completed electronics parts list.
tgolla Jul 6, 2022
abe045b
Merge branch 'TouchscreenV2' of https://github.com/tgolla/SphereBot i…
tgolla Jul 6, 2022
a171410
Added cubes.
tgolla Jul 6, 2022
15a8c0d
Added omelet.
tgolla Jul 6, 2022
a268bfc
Added more designs.
tgolla Jul 7, 2022
4bda029
Adjusted change pen location.
tgolla Jul 7, 2022
cc6bb73
Refactored touchScreenToContinue.
tgolla Jul 7, 2022
153886f
Modified touchScreenToContinue to progressive alerts.
tgolla Jul 7, 2022
9faa2a1
Updated documentation.
tgolla Jul 7, 2022
d4d8ba3
Prerelease v1.9.1 documentation changes.
tgolla Jul 7, 2022
0ad715b
Added document history.
tgolla Jul 10, 2022
f8430f4
Added future feature note.
tgolla Jul 10, 2022
d61d151
Added steps to create g-code.
tgolla Jul 10, 2022
e63cfe1
Changed M999 code directive from DEBUG as the directive was deceptive.
tgolla Jul 13, 2022
6d5c962
MAJOR CORRECTION to arcDraw!
tgolla Jul 14, 2022
2a6642f
Adding Rose and Spiral Vines.
tgolla Jul 14, 2022
3d75057
Updated readme concerning MAJOR bug fix.
tgolla Jul 14, 2022
c62b059
Corrected line calculation and time passed to unsigned long.
tgolla Jul 14, 2022
249a4af
Updated InkScape documentation with images.
tgolla Jul 14, 2022
8476704
Added leaf vine.
tgolla Jul 15, 2022
73ccc63
Corrected leaf vine images.
tgolla Jul 16, 2022
9870be6
Added rocket design.
tgolla Jul 16, 2022
3bc71c3
Reorganized images.
tgolla Jul 16, 2022
734553a
Add butterfly and snowflake band.
tgolla Jul 16, 2022
186b149
Added documentation for motor control modifications.
tgolla Jul 17, 2022
aefc5c6
Added documentation image.
tgolla Jul 19, 2022
4414038
Added bee vine design.
tgolla Jul 19, 2022
e01fbc6
Folders renamed for clarity.
tgolla Jul 20, 2022
17d6430
Updated electronics documentation.
tgolla Jul 20, 2022
ba9d20c
Completed electronics documentation. Release 1.9.2
tgolla Jul 21, 2022
b01585f
Implemented percentageTimeCalculationEnabled.
tgolla Jul 23, 2022
c04d4e1
Update documentation for M990 & M991
tgolla Aug 2, 2022
df966f4
File name correction.
tgolla Aug 3, 2022
0546404
Added M990 command code.
tgolla Aug 3, 2022
d621683
Typo correction in Leaf Vine 5 color.
tgolla Aug 18, 2022
b4b95be
Adding Olaf pattern.
tgolla Aug 20, 2022
fd7242e
Adding geometric plot 16 & 20
tgolla Aug 21, 2022
d7e013b
Typo correction.
tgolla Aug 21, 2022
65a3e2d
Adding Christmas icons and globe.
tgolla Aug 21, 2022
325fc32
Documented potential feature FlipXYAxis.
tgolla Aug 23, 2022
f8df788
Updated processer utilization information for M991 & M992.
tgolla Aug 23, 2022
ee59b67
Added scales diamoind.
tgolla Aug 23, 2022
ea2ebeb
Adding scales rainbow diagonal.
tgolla Aug 24, 2022
c39f5cd
Added scales rainbow horizontal.
tgolla Aug 25, 2022
e3117c9
Added scales random.
tgolla Aug 29, 2022
c631c9e
Increased XY feedrate to max. Need to do more research on XY max feed…
tgolla Aug 29, 2022
6412cad
Added ether egg.
tgolla Aug 29, 2022
416c6fb
Added sleeping cat and pattern.
tgolla Aug 30, 2022
4603141
Added Pioneer Spacecraft Plaque.
tgolla Aug 30, 2022
e66643a
Added Assembly documentation with 3D Prints information along with ot…
tgolla Sep 3, 2022
df307fa
Documented importants of layers in Inkscape.
tgolla Sep 3, 2022
9571546
Updated parts list.
tgolla Sep 4, 2022
62b4414
Updated asembly documentation.
tgolla Sep 4, 2022
2a0d538
Added Arduino LCD mount STL file.
tgolla Sep 24, 2022
1683ce7
Add OSU logo.
tgolla Sep 24, 2022
917f9ca
Adding consistent M01 start with pen color message.
tgolla Sep 26, 2022
7720f25
Added Pistol Pete.
tgolla Sep 26, 2022
357110a
Added OSU small.
tgolla Sep 27, 2022
b22a14a
Added ABC button.
tgolla Oct 25, 2022
95bdb32
Ruff in alphabetic file selection.
tgolla Nov 1, 2022
501ba4c
Added basic ABC...
tgolla Nov 1, 2022
4b29994
New approach to ABC.
tgolla Nov 1, 2022
3100f2c
New A-Z image.
tgolla Nov 9, 2022
acdd353
Documentation typo correction.
tgolla Nov 9, 2022
8f1ecfd
Added touchscreen grid detection.
tgolla Nov 10, 2022
361bad6
Added grid to character calculation.
tgolla Nov 10, 2022
dc85959
Corrected gcode file names.
tgolla Nov 11, 2022
03b6fd7
Added AlphabeticSDFileList Find() and completed ABC button.
tgolla Nov 11, 2022
fe7393e
Adding ABC file list option. Needs file title/subtitle.
tgolla Nov 11, 2022
47cad91
Completed ABC graphic/text.
tgolla Nov 11, 2022
a60e349
Pre-release v1.9.4 updates.
tgolla Nov 11, 2022
b57b80e
Working on bill of materials.
tgolla Dec 13, 2022
7a9215d
Completed bill of materials. Updating assembly instructions.
tgolla Dec 13, 2022
99b8c27
Added missing o-ring.
tgolla Dec 14, 2022
ac4a737
Up to step 25, end cap nuts in assembly.
tgolla Dec 17, 2022
b893d46
#8 Barrel Spring
tgolla Dec 19, 2022
cb397dc
Updated assembly instructions with images.
tgolla Feb 5, 2023
b303937
Exported PDF files on documentation using Markdown PDF v1.4.4 yzane h…
tgolla Feb 5, 2023
3f30c28
Added Honeycomb Swirl.
tgolla Feb 15, 2023
be3ab70
Added diagonals simple and efficient, rosettes and honeycomb.
tgolla Feb 21, 2023
d33d0ef
Project build updated to ARDUINO=10607
tgolla Feb 21, 2023
ff9fc21
Add United States gcode.
tgolla Feb 25, 2023
f70b4e3
Add checkerboard.
tgolla Feb 25, 2023
7a65af6
Added Zigzap Dissolved and Mirrored.
tgolla Mar 4, 2023
f36d86e
M3 modification (optional).
tgolla Mar 4, 2023
f3fb67e
Adding Kistka loop and traditional designs.
tgolla Mar 9, 2023
c1b78dd
Adding other kistka loops.
tgolla Mar 10, 2023
db40a82
Adding traditional 2.
tgolla Mar 10, 2023
b038fbb
Adding traditional 1B.
tgolla Mar 11, 2023
e6b1f7c
Added stainglass.
tgolla Mar 21, 2023
4474a80
Changes print order of Olaf from lightest to darkest.
tgolla Apr 2, 2023
65c3634
Added COORDINATE_ROTATION.
tgolla Apr 2, 2023
60ed8c8
Added G68.G69 configuration G-Code files.
tgolla Apr 2, 2023
ae971de
Added G68/G69 and missing M990 and M991 documantation.
tgolla Apr 2, 2023
2d6dd95
Add coordinateRotation, but not implementation in XY calculations.
tgolla Apr 2, 2023
606a8cb
Additional changes for coordinateRotation. Calculations not yet imple…
tgolla Apr 2, 2023
0655e46
180-degree coordinate rotation implemented.
tgolla Apr 3, 2023
e383a98
Corrected documentation in configuration.h.
tgolla Apr 3, 2023
54daeb8
Updated read me for v1.9.5
tgolla Apr 5, 2023
c69ce1f
Adding pattern 800.
tgolla Apr 8, 2023
d762991
Merge branch 'TouchscreenV2' of https://github.com/tgolla/SphereBot i…
tgolla Apr 8, 2023
61c5ea2
Updated documentation concerning M999 directive when compiling for an…
tgolla Apr 10, 2023
43a53e5
Updated readme.
Jan 8, 2024
6309150
Readme update for minor release 1.9.51
Jan 8, 2024
b2a6d48
Had to update Inkscape (Universal) after recalibration.
Apr 2, 2024
d6252ed
Did not completely correct Inkscape (Universal).
Apr 2, 2024
65039be
Bug fix with SD card alphabetic list find.
Apr 3, 2024
a2bb3ae
Updated documentation on Servo and potentian failure.
Apr 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .vscode/arduino.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"sketch": "SphereBot.ino",
"board": "arduino:avr:mega",
"port": "COM4",
"configuration": "cpu=atmega2560"
}
577 changes: 577 additions & 0 deletions .vscode/c_cpp_properties.json

Large diffs are not rendered by default.

276 changes: 276 additions & 0 deletions AlphabeticSDFileList.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,276 @@
/*
AlphabeticSDFileList.cpp - Library for listing SD files in a directory on alphabetic order.
Created by Terence F. Golla, April 17, 2022
Released into the public domain.
*/

#include "AlphabeticSDFileList.h"

/// <summary>
/// Class constructor.
/// </summary>
AlphabeticSDFileList::AlphabeticSDFileList() { }

/// <summary>
/// Class initializer.
/// </summary>
/// <param name="SdFat">The SD Fat object created to read the card.</param>
/// <param name="directory">The directory on the SD to list.</param>
/// <param name="contiguous">Boolean indicating Previous and Next are
/// to loop through the directory start to end and end to start.</param>
/// <remarks>If you add files to the directory you will need to re-execute Begin.</remarks>
void AlphabeticSDFileList::Begin(SdFat &SdFat, char *directory, bool contiguous)
{
AlphabeticSDFileList::SD = &SdFat;
AlphabeticSDFileList::contiguous = contiguous;
AlphabeticSDFileList::directory = directory;

strcpy(first, "");
strcpy(last, "");
strcpy(current, "");

char filename[DEFAULT_FILE_NAME_SIZE];

File directoryFile = SD->open(directory);

// Loop through entire directory (file list). Note the file list is not ordered.
while (true) {
File file = directoryFile.openNextFile();

if (!file) {
// no more files
break;
}

file.getName(filename, DEFAULT_FILE_NAME_SIZE);

// If we are looking at a filename (not a directory)
if (!file.isDirectory()) {
// If the first filename is empty, fill first and last.
if (stricmp(first, "") == 0) {
strcpy(first, filename);
strcpy(last, filename);
}
else {
// If the filename is less than the first filename, place it in first.
if (stricmp(filename, first) < 0) {
strcpy(first, filename);
}
else {
// If the filename is greater than the last filename, place it in last.
if (stricmp(filename, last) > 0) {
strcpy(last, filename);
}
}
}
}

file.close();
}
}

/// <summary>
/// String compare without case sensitivity.
/// </summary>
/// <param name="s1">The first string (string1).</param>
/// <param name="s2">The second string (string2).</param>
/// <returns>Less than 0 if string1 is less than string2. 0 if string1 equivalent to string2. Greater than 0 if string1 is greater than string2.</returns>
int AlphabeticSDFileList::stricmp(const char *s1, const char *s2)
{
while (tolower((unsigned char) *s1) == tolower((unsigned char) *s2)) {
if (*s1 == '\0')
return 0;
s1++; s2++;
}

return (int) tolower((unsigned char) *s1) - (int) tolower((unsigned char) *s2);
}

/// <summary>
/// The first file in the directory.
/// </summary>
char* AlphabeticSDFileList::First()
{
return first;
}

/// <summary>
/// The last file in the directory.
/// </summary>
char* AlphabeticSDFileList::Last()
{
return last;
}

/// <summary>
/// The current file as you progress through the list.
/// </summary>
char* AlphabeticSDFileList::Current()
{
return current;
}

/// <summary>
/// Moves to the previous file in the list.
/// </summary>
/// <returns>The previous filename.</returns>
/// <remarks>
/// If contiguous was set to true and the current file is the fisrt file in the list
/// Previous will return the last file in the list.
/// If contiguous was set to false and the current file is the fisrt file in the list
/// Previous will return a blank filename.
/// </remarks>
char* AlphabeticSDFileList::Previous()
{
char filename[DEFAULT_FILE_NAME_SIZE];
char previous[DEFAULT_FILE_NAME_SIZE];

strcpy(previous, "");

if (stricmp(current, "") == 0)
strcpy(current, "\x7F");

File directoryFile = SD->open(directory);

// Loop through entire directory (file list). Note the file list is not ordered.
while (true) {
File file = directoryFile.openNextFile();

if (!file) {
// no more files
break;
}

file.getName(filename, DEFAULT_FILE_NAME_SIZE);

// If we are looking at a filename (not a directory).
if (!file.isDirectory()) {
// If the filename is less than the current filename, it might be the previous file.
if (stricmp(filename, current) < 0) {
// If the previous filename is empty, fill it with the filename.
if (stricmp(previous, "") == 0) {
strcpy(previous, filename);
}
else {
// If the filename is greater than the previous filename, make it the previous filename.
if (stricmp(filename, previous) > 0) {
strcpy(previous, filename);
}
}
}
}

file.close();
}

if (contiguous && stricmp(previous, "") == 0)
strcpy(previous, last);

strcpy(current, previous);
return current;
}

/// <summary>
/// Moves to the next file in the list.
/// </summary>
/// <returns>The next filename.</returns>
/// <remarks>
/// If contiguous was set to true and the current file is the last file in the list
/// Next will return the first file in the list.
/// If contiguous was set to false and the current file is the last file in the list
/// Previous will return a blank filename.
/// </remarks>
char* AlphabeticSDFileList::Next()
{
char filename[DEFAULT_FILE_NAME_SIZE];
char next[DEFAULT_FILE_NAME_SIZE];

strcpy(next, "");

File directoryFile = SD->open(directory);

// Loop through entire directory (file list). Note the file list is not ordered.
while (true) {
File file = directoryFile.openNextFile();

if (!file) {
// no more files
break;
}

file.getName(filename, DEFAULT_FILE_NAME_SIZE);

// If we are looking at a filename (not a directory).
if (!file.isDirectory()) {
// If the filename is greater than the current filename, it might be the next file.
if (stricmp(filename, current) > 0) {
// If the next filename is empty, fill it with the filename.
if (stricmp(next, "") == 0) {
strcpy(next, filename);
}
else {
// If the filename is less than the next filename, make it the next filename.
if (stricmp(filename, next) < 0) {
strcpy(next, filename);
}
}
}
}

file.close();
}

if (contiguous && stricmp(next, "") == 0)
strcpy(next, first);

strcpy(current, next);
return current;
}

/// <summary>
/// Finds the closest match to the provided filename.
/// </summary>
/// <param name="filename">The filename to match.</param>
/// <returns>The closest match to the provided filename.</returns>
char* AlphabeticSDFileList::Find(char *findFilename)
{
char filename[DEFAULT_FILE_NAME_SIZE];
char next[DEFAULT_FILE_NAME_SIZE];

strcpy(current, last);

File directoryFile = SD->open(directory);

// Loop through entire directory (file list). Note the file list is not ordered.
while (true) {
File file = directoryFile.openNextFile();

if (!file) {
// no more files
break;
}

file.getName(filename, DEFAULT_FILE_NAME_SIZE);

// If we are looking at a filename (not a directory).
if (!file.isDirectory()) {
// If the current filename is empty, fill it.
if (stricmp(current, "") == 0) {
strcpy(current, filename);
}
else {
// If the filename is greater than or equal the find filename.
if (stricmp(filename, findFilename) >= 0) {
// If the filename is less than the current filename, fill the current filename.
if (stricmp(filename, current) < 0) {
strcpy(current, filename);
}
}
}
}

file.close();
}

return current;
}
36 changes: 36 additions & 0 deletions AlphabeticSDFileList.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
AlphabeticSDFileList.h - Library for listing SD files in a directory on alphabetic order.
Created by Terence F. Golla, April 17, 2022
Released into the public domain.
*/

#ifndef AlphabeticSDFileList_h
#define AlphabeticSDFileList_h

#include <Arduino.h>
#include <SdFat.h> // SD card & FAT filesystem library.

#define DEFAULT_FILE_NAME_SIZE 64

class AlphabeticSDFileList
{
public:
AlphabeticSDFileList();
void Begin(SdFat &SD, char *directory, bool contiguous);
char* First();
char* Last();
char* Current();
char* Previous();
char* Next();
char* Find(char *findFilename);
private:
SdFat *SD;
stricmp(const char *s1, const char *s2);
char first[DEFAULT_FILE_NAME_SIZE];
char last[DEFAULT_FILE_NAME_SIZE];
char current[DEFAULT_FILE_NAME_SIZE];
bool contiguous;
char* directory;
};

#endif
Loading