diff --git a/.arduino-ci.yml b/.arduino-ci.yml index 319d7302..1e394c06 100644 --- a/.arduino-ci.yml +++ b/.arduino-ci.yml @@ -1,4 +1,22 @@ - +platforms: + mega2560: + board: arduino:avr:mega:cpu=atmega2560 + package: arduino:avr + gcc: + features: + defines: + - __AVR__ + - __AVR_ATmega2560__ + - ARDUINO_ARCH_AVR + - ARDUINO_AVR_MEGA2560 + # Why aren't these already provided elsewhere? + - SS=1 + - MOSI=2 + - MISO=3 + - SCK=4 + warnings: + flags: + unittest: platforms: - mega2560 @@ -8,6 +26,7 @@ unittest: - "Ethernet" - "LiquidCrystal" - "RTClib" + - "SD" compile: platforms: @@ -18,3 +37,4 @@ compile: - "Ethernet" - "LiquidCrystal" - "RTClib" + - "SD" diff --git a/Gemfile b/Gemfile index 80468b55..fb422d12 100644 --- a/Gemfile +++ b/Gemfile @@ -1,2 +1,2 @@ source 'https://rubygems.org' -gem 'arduino_ci', git: 'https://github.com/Arduino-CI/arduino_ci.git', branch: 'master' +gem 'arduino_ci' diff --git a/src/Devices/SD_TC.cpp b/src/Devices/SD_TC.cpp new file mode 100644 index 00000000..0672efee --- /dev/null +++ b/src/Devices/SD_TC.cpp @@ -0,0 +1,54 @@ +#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 +/** + * Constructor sets pins, dimensions, and shows splash screen + */ +SDClass_TC::SDClass_TC() : SDClass() { + pinMode(10, OUTPUT); + digitalWrite(10, HIGH); + // TODO: Need to re-enable this for the physical device + // begin(4); +} + +void SDClass_TC::printRootDirectory() { + File root = open("/"); + printDirectory(root, 0); +} + +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..453f47f4 --- /dev/null +++ b/src/Devices/SD_TC.h @@ -0,0 +1,26 @@ +#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(); + // bool begin(uint8_t csPin = SD_CHIP_SELECT_PIN); + // bool begin(uint32_t clock, uint8_t csPin); + +private: + // class variables + static SDClass_TC* _instance; + + // instance methods + SDClass_TC(); + void printDirectory(File dir, int numTabs); +}; diff --git a/src/TankControllerLib.cpp b/src/TankControllerLib.cpp index c138ede6..b1cdc519 100644 --- a/src/TankControllerLib.cpp +++ b/src/TankControllerLib.cpp @@ -37,6 +37,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 fecb7098..636f2cf8 100644 --- a/src/TankControllerLib.h +++ b/src/TankControllerLib.h @@ -2,6 +2,7 @@ #include #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()