diff --git a/.arduino-ci.yml b/.arduino-ci.yml index 67bb624b..5430a367 100644 --- a/.arduino-ci.yml +++ b/.arduino-ci.yml @@ -1,4 +1,3 @@ - unittest: platforms: - mega2560 @@ -9,6 +8,7 @@ unittest: - "LiquidCrystal" - "RTClib" - "Keypad" + - "SD" compile: platforms: @@ -20,3 +20,4 @@ compile: - "LiquidCrystal" - "RTClib" - "Keypad" + - "SD" diff --git a/src/Devices/SD_TC.cpp b/src/Devices/SD_TC.cpp new file mode 100644 index 00000000..17eadf46 --- /dev/null +++ b/src/Devices/SD_TC.cpp @@ -0,0 +1,50 @@ +#include "Devices/SD_TC.h" + +// class variables +SDClass_TC* SDClass_TC::_instance = nullptr; + +// class methods +/** + * accessor for singleton + */ +SDClass_TC* SDClass_TC::instance() { + if (!_instance) { + _instance = new SDClass_TC(); + } + return _instance; +} + +// instance methods +/** + * print the root directory and all subdirectories + */ +void SDClass_TC::printRootDirectory() { + File root = open("/"); + printDirectory(root, 0); +} + +/** + * print a specified directory with an indent + */ +void SDClass_TC::printDirectory(File dir, int numTabs) { + while (true) { + File entry = dir.openNextFile(); + if (!entry) { + // no more files + break; + } + for (uint8_t i = 0; i < numTabs; i++) { + Serial.print('\t'); + } + Serial.print(entry.name()); + if (entry.isDirectory()) { + Serial.println(F("/")); + printDirectory(entry, numTabs + 1); + } else { + // files have sizes, directories do not + Serial.print(F("\t\t")); + Serial.println(entry.size(), DEC); + } + entry.close(); + } +} diff --git a/src/Devices/SD_TC.h b/src/Devices/SD_TC.h new file mode 100644 index 00000000..585cd4d3 --- /dev/null +++ b/src/Devices/SD_TC.h @@ -0,0 +1,24 @@ +#pragma once + +#include +#ifdef MOCK_PINS_COUNT +#include +#else +#include +#endif + +class SDClass_TC : public SDClass { +public: + // class methods + static SDClass_TC* instance(); + + // instance methods + void printRootDirectory(); + +private: + // class variables + static SDClass_TC* _instance; + + // instance methods + void printDirectory(File dir, int numTabs); +}; diff --git a/src/TankControllerLib.cpp b/src/TankControllerLib.cpp index a393e1f0..acc5cf7b 100644 --- a/src/TankControllerLib.cpp +++ b/src/TankControllerLib.cpp @@ -36,6 +36,7 @@ TankControllerLib::TankControllerLib() { lcd = LiquidCrystal_TC::instance(); log = Serial_TC::instance(); log->print(F("TankControllerLib::TankControllerLib() - version "), TANK_CONTROLLER_VERSION); + SDClass_TC::instance()->printRootDirectory(); } /** diff --git a/src/TankControllerLib.h b/src/TankControllerLib.h index a8f0105b..a2bcfbd5 100644 --- a/src/TankControllerLib.h +++ b/src/TankControllerLib.h @@ -5,6 +5,7 @@ #include "Devices/EthernetServer_TC.h" #include "Devices/Keypad_TC.h" #include "Devices/LiquidCrystal_TC.h" +#include "Devices/SD_TC.h" #include "Devices/Serial_TC.h" const char TANK_CONTROLLER_VERSION[] = "0.3.0"; diff --git a/test/SD.cpp b/test/SD.cpp new file mode 100644 index 00000000..8efa8971 --- /dev/null +++ b/test/SD.cpp @@ -0,0 +1,13 @@ +#include +#include + +#include "TankControllerLib.h" + +unittest(test) { + TankControllerLib* tank = TankControllerLib::instance(); + SDClass_TC* sd = SDClass_TC::instance(); + assertTrue(tank != nullptr); + assertTrue(sd != nullptr); +} + +unittest_main()