Skip to content

Commit 08d9cbb

Browse files
πŸ§‘β€πŸ’» Add SD Card 'hide' method for dev usage (MarlinFirmware#22425)
1 parent 7c0b465 commit 08d9cbb

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

β€ŽMarlin/src/sd/SdBaseFile.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -1668,6 +1668,28 @@ bool SdBaseFile::remove(SdBaseFile *dirFile, const char *path) {
16681668
return file.open(dirFile, path, O_WRITE) ? file.remove() : false;
16691669
}
16701670

1671+
bool SdBaseFile::hide(const bool hidden) {
1672+
if (ENABLED(SDCARD_READONLY)) return false;
1673+
// must be an open file or subdirectory
1674+
if (!(isFile() || isSubDir())) return false;
1675+
// sync() and cache directory entry
1676+
sync();
1677+
dir_t *d = cacheDirEntry(SdVolume::CACHE_FOR_WRITE);
1678+
if (!d) return false;
1679+
uint8_t a = d->attributes;
1680+
if (hidden)
1681+
a |= DIR_ATT_HIDDEN;
1682+
else
1683+
a &= ~DIR_ATT_HIDDEN;
1684+
1685+
if (a != d->attributes) {
1686+
d->attributes = a;
1687+
return vol_->cacheFlush();
1688+
}
1689+
1690+
return true;
1691+
}
1692+
16711693
/**
16721694
* Rename a file or subdirectory.
16731695
*

β€ŽMarlin/src/sd/SdBaseFile.h

+5
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,11 @@ class SdBaseFile {
310310
bool rmdir();
311311
bool rmRfStar();
312312

313+
/**
314+
* Set or clear DIR_ATT_HIDDEN attribute for directory entry
315+
*/
316+
bool hide(const bool hidden);
317+
313318
/**
314319
* Set the files position to current position + \a pos. See seekSet().
315320
* \param[in] offset The new position in bytes from the current position.

0 commit comments

Comments
Β (0)