Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

added wrapper class for SD #27

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 21 additions & 1 deletion .arduino-ci.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -8,6 +26,7 @@ unittest:
- "Ethernet"
- "LiquidCrystal"
- "RTClib"
- "SD"

compile:
platforms:
Expand All @@ -18,3 +37,4 @@ compile:
- "Ethernet"
- "LiquidCrystal"
- "RTClib"
- "SD"
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -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'
54 changes: 54 additions & 0 deletions src/Devices/SD_TC.cpp
Original file line number Diff line number Diff line change
@@ -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();
}
}
26 changes: 26 additions & 0 deletions src/Devices/SD_TC.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

#include <Arduino.h>
#ifdef MOCK_PINS_COUNT
#include <SD_CI.h>
#else
#include <SD.h>
#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);
};
1 change: 1 addition & 0 deletions src/TankControllerLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/TankControllerLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <Arduino.h>

#include "Devices/LiquidCrystal_TC.h"
#include "Devices/SD_TC.h"
#include "Devices/Serial_TC.h"

const char TANK_CONTROLLER_VERSION[] = "0.3.0";
Expand Down
13 changes: 13 additions & 0 deletions test/SD.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <Arduino.h>
#include <ArduinoUnitTests.h>

#include "TankControllerLib.h"

unittest(test) {
TankControllerLib* tank = TankControllerLib::instance();
SDClass_TC* sd = SDClass_TC::instance();
assertTrue(tank != nullptr);
assertTrue(sd != nullptr);
}

unittest_main()