SDInterface.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include "SDInterface.h"
  2. bool SDInterface::initSD() {
  3. String display_string = "";
  4. if (!SD.begin(SD_CS)) {
  5. Serial.println("Failed to mount SD Card");
  6. this->supported = false;
  7. return false;
  8. }
  9. else {
  10. this->supported = true;
  11. this->cardType = SD.cardType();
  12. if (cardType == CARD_MMC)
  13. Serial.println("SD: MMC Mounted");
  14. else if(cardType == CARD_SD)
  15. Serial.println("SD: SDSC Mounted");
  16. else if(cardType == CARD_SDHC)
  17. Serial.println("SD: SDHC Mounted");
  18. else
  19. Serial.println("SD: UNKNOWN Card Mounted");
  20. this->cardSizeBT = SD.cardSize();
  21. this->cardSizeKB = SD.cardSize() / 1024;
  22. this->cardSizeMB = SD.cardSize() / (1024 * 1024);
  23. this->cardSizeGB = SD.cardSize() / (1024 * 1024 * 1024);
  24. Serial.printf("SD Card Size: %llu Bytes\n", this->cardSizeBT);
  25. Serial.printf("SD Card Size: %lluKB\n", this->cardSizeKB);
  26. Serial.printf("SD Card Size: %lluMB\n", this->cardSizeMB);
  27. Serial.printf("SD Card Size: %lluGB\n", this->cardSizeGB);
  28. if (this->supported) {
  29. //display_obj.tft.println((byte)(sd_obj.cardSizeMB % 10));
  30. const int NUM_DIGITS = log10(this->cardSizeMB) + 1;
  31. char sz[NUM_DIGITS + 1];
  32. sz[NUM_DIGITS] = 0;
  33. for ( size_t i = NUM_DIGITS; i--; this->cardSizeMB /= 10)
  34. {
  35. sz[i] = '0' + (this->cardSizeMB % 10);
  36. display_string.concat((String)sz[i]);
  37. }
  38. //this->card_sz = display_string;
  39. this->card_sz = sz;
  40. }
  41. return true;
  42. }
  43. }