Added sd card test program plus minor changes
This commit is contained in:
parent
becaad5584
commit
35b682b13d
@ -1,6 +1,6 @@
|
||||
#include "RtcManager.h"
|
||||
|
||||
RtcManager::RtcManager(const RTC_DS3231 &rtc) : _rtcRef(rtc)
|
||||
RtcManager::RtcManager(RTC_DS3231 &rtc) : _rtcRef(rtc)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -12,9 +12,9 @@ class RtcManager
|
||||
void setDateTime(const DateTime dateTime);
|
||||
boolean hasLostPower() const;
|
||||
protected:
|
||||
RtcManager(const RTC_DS3231 &rtc);
|
||||
RtcManager(RTC_DS3231 &rtc);
|
||||
private:
|
||||
const RTC_DS3231 &_rtcRef;
|
||||
RTC_DS3231 &_rtcRef;
|
||||
};
|
||||
|
||||
#endif //RTCMANAGER_H
|
||||
|
@ -29,7 +29,7 @@ ScreenManager& SAB::getScreenManager()
|
||||
return _screenManager;
|
||||
}
|
||||
|
||||
const RtcManager& SAB::getRtcManager() const
|
||||
RtcManager& SAB::getRtcManager()
|
||||
{
|
||||
return _rtcManager;
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ class SAB
|
||||
SAB(const PinMapping pinConfig, const ScreenConfig screenConfig, const SDCardConfig sdCardConfig);
|
||||
|
||||
ScreenManager& getScreenManager();
|
||||
const RtcManager& getRtcManager() const;
|
||||
RtcManager& getRtcManager();
|
||||
SDCardManager& getSdCardManager();
|
||||
ScreenConfig getScreenConfig() const;
|
||||
PinMapping getPinConfig() const;
|
||||
@ -32,8 +32,8 @@ class SAB
|
||||
Adafruit_SSD1306 _display;
|
||||
ScreenManager _screenManager;
|
||||
|
||||
const RTC_DS3231 _rtc;
|
||||
const RtcManager _rtcManager;
|
||||
RTC_DS3231 _rtc;
|
||||
RtcManager _rtcManager;
|
||||
|
||||
SDClass _sdCard;
|
||||
SDCardManager _sdCardManager;
|
||||
|
@ -4,7 +4,6 @@
|
||||
#include "views.h"
|
||||
|
||||
SAB sab;
|
||||
long *memoryEater = NULL;
|
||||
|
||||
unsigned long currentMs = 0;
|
||||
int mySize = 0;
|
||||
@ -13,15 +12,15 @@ DateTimePacket dtp = {sab.getRtcManager().getDateTime(), sab.getSdCardManager().
|
||||
void setup() {
|
||||
// put your setup code here, to run once:
|
||||
Serial.println("Starting setup");
|
||||
|
||||
pinMode(GPIO_0, INPUT);
|
||||
sab.getScreenManager().addView(&(view_1), &dtp, 1);
|
||||
|
||||
Serial.print("SD size : ");Serial.println(sab.getSdCardManager().getSize(GBYTE));
|
||||
/*Serial.print("SD size : ");Serial.println(sab.getSdCardManager().getSize(GBYTE));
|
||||
Serial.print("SD size : ");Serial.println(sab.getSdCardManager().getSize(GBIT));
|
||||
Serial.print("SD size : ");Serial.println(sab.getSdCardManager().getSize(MBYTE));
|
||||
Serial.print("SD size : ");Serial.println(sab.getSdCardManager().getSize(MBIT));
|
||||
Serial.print("SD size : ");Serial.println(sab.getSdCardManager().getSize(KBYTE));
|
||||
Serial.print("SD size : ");Serial.println(sab.getSdCardManager().getSize(KBIT));
|
||||
Serial.print("SD size : ");Serial.println(sab.getSdCardManager().getSize(KBIT));*/
|
||||
|
||||
Serial.println("End setup");
|
||||
}
|
||||
@ -32,14 +31,8 @@ void loop() {
|
||||
currentMs = millis();
|
||||
dtp.dateTime = sab.getRtcManager().getDateTime();
|
||||
sab.getScreenManager().displayView(1);
|
||||
|
||||
long *temp = (long *) realloc(memoryEater,sizeof(long) * ++mySize);
|
||||
|
||||
if(temp != NULL)
|
||||
memoryEater = temp;
|
||||
else
|
||||
{
|
||||
free(memoryEater);memoryEater = NULL;mySize = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*if(digitalRead(GPIO_0)==0)
|
||||
sab.getRtcManager().setDateTime(DateTime(2019,3,9,19,34,0));*/
|
||||
}
|
||||
|
75
src/sdCard_test/sdCard_test.ino
Normal file
75
src/sdCard_test/sdCard_test.ino
Normal file
@ -0,0 +1,75 @@
|
||||
#include "definition.h"
|
||||
#include "PinMapping.h"
|
||||
#include "SAB.h"
|
||||
|
||||
SAB sab;
|
||||
|
||||
File f,g;
|
||||
|
||||
void setup() {
|
||||
// put your setup code here, to run once:
|
||||
Serial.println("Starting setup");
|
||||
//Testing if directory exists :
|
||||
if(!sab.getSdCardManager().getSdCardHandler().exists("test/doesnotexist"))
|
||||
Serial.println("The directory does not exist");
|
||||
else
|
||||
Serial.println("The directory does exist");
|
||||
|
||||
if(!sab.getSdCardManager().getSdCardHandler().mkdir("test"))
|
||||
Serial.println("Failed to create test dir");
|
||||
|
||||
if(!sab.getSdCardManager().getSdCardHandler().exists("test"))
|
||||
Serial.println("The directory does not exist");
|
||||
else
|
||||
Serial.println("The directory does exist");
|
||||
|
||||
f = sab.getSdCardManager().getSdCardHandler().open("test/doesnotexist.txt");
|
||||
if(f == NULL) Serial.println("Unable to open file doesnotexist.txt");
|
||||
|
||||
f = sab.getSdCardManager().getSdCardHandler().open("test/exist.txt", FILE_WRITE);
|
||||
if(f == NULL) Serial.println("Unable to open file exist.txt");
|
||||
else
|
||||
{
|
||||
char text[] = "I am the file's content.\nHere is a new Line";
|
||||
f.write(text, strlen(text));
|
||||
f.close();
|
||||
}
|
||||
|
||||
f = sab.getSdCardManager().getSdCardHandler().open("test/exist.txt");
|
||||
if(f == NULL) Serial.println("Unable to open file exist.txt");
|
||||
else
|
||||
{
|
||||
Serial.println("File content :");
|
||||
while(f.available())
|
||||
{
|
||||
char c = f.read();
|
||||
Serial.print(c);
|
||||
}
|
||||
Serial.println();
|
||||
f.close();
|
||||
}
|
||||
|
||||
if(!sab.getSdCardManager().getSdCardHandler().remove("test/exist.txt"))
|
||||
Serial.println("Failed to remove file");
|
||||
else
|
||||
Serial.println("Deleted successfully");
|
||||
|
||||
f = sab.getSdCardManager().getSdCardHandler().open("several");
|
||||
if(f == NULL) Serial.println("Unable to open file several");
|
||||
else
|
||||
{
|
||||
Serial.println("dir content :");
|
||||
while((g = f.openNextFile()) != 0)
|
||||
{
|
||||
Serial.println(g.name());
|
||||
}
|
||||
Serial.println();
|
||||
f.close();
|
||||
}
|
||||
|
||||
Serial.println("End setup");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user