You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
3.5KB

  1. /* Arduino SdFat Library
  2. * Copyright (C) 2012 by William Greiman
  3. *
  4. * This file is part of the Arduino SdFat Library
  5. *
  6. * This Library is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This Library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with the Arduino SdFat Library. If not, see
  18. * <http://www.gnu.org/licenses/>.
  19. */
  20. #include "SdFat.h"
  21. //------------------------------------------------------------------------------
  22. void SdFatBase::errorHalt(Print* pr) {
  23. errorPrint(pr);
  24. while (1) {}
  25. }
  26. //------------------------------------------------------------------------------
  27. void SdFatBase::errorHalt(Print* pr, char const* msg) {
  28. errorPrint(pr, msg);
  29. while (1) {}
  30. }
  31. //------------------------------------------------------------------------------
  32. void SdFatBase::errorHalt(Print* pr, const __FlashStringHelper* msg) {
  33. errorPrint(pr, msg);
  34. while (1) {}
  35. }
  36. //------------------------------------------------------------------------------
  37. void SdFatBase::errorPrint(Print* pr) {
  38. if (!cardErrorCode()) {
  39. return;
  40. }
  41. pr->print(F("SD errorCode: 0X"));
  42. pr->print(cardErrorCode(), HEX);
  43. pr->print(F(",0X"));
  44. pr->println(cardErrorData(), HEX);
  45. }
  46. //------------------------------------------------------------------------------
  47. void SdFatBase::errorPrint(Print* pr, char const* msg) {
  48. pr->print(F("error: "));
  49. pr->println(msg);
  50. errorPrint(pr);
  51. }
  52. //------------------------------------------------------------------------------
  53. void SdFatBase::errorPrint(Print* pr, const __FlashStringHelper* msg) {
  54. pr->print(F("error: "));
  55. pr->println(msg);
  56. errorPrint(pr);
  57. }
  58. //------------------------------------------------------------------------------
  59. void SdFatBase::initErrorHalt(Print* pr) {
  60. initErrorPrint(pr);
  61. while (1) {}
  62. }
  63. //------------------------------------------------------------------------------
  64. void SdFatBase::initErrorHalt(Print* pr, char const *msg) {
  65. pr->println(msg);
  66. initErrorHalt(pr);
  67. }
  68. //------------------------------------------------------------------------------
  69. void SdFatBase::initErrorHalt(Print* pr, const __FlashStringHelper* msg) {
  70. pr->println(msg);
  71. initErrorHalt(pr);
  72. }
  73. //------------------------------------------------------------------------------
  74. void SdFatBase::initErrorPrint(Print* pr) {
  75. if (cardErrorCode()) {
  76. pr->println(F("Can't access SD card. Do not reformat."));
  77. if (cardErrorCode() == SD_CARD_ERROR_CMD0) {
  78. pr->println(F("No card, wrong chip select pin, or SPI problem?"));
  79. }
  80. errorPrint(pr);
  81. } else if (vol()->fatType() == 0) {
  82. pr->println(F("Invalid format, reformat SD."));
  83. } else if (!vwd()->isOpen()) {
  84. pr->println(F("Can't open root directory."));
  85. } else {
  86. pr->println(F("No error found."));
  87. }
  88. }
  89. //------------------------------------------------------------------------------
  90. void SdFatBase::initErrorPrint(Print* pr, char const *msg) {
  91. pr->println(msg);
  92. initErrorPrint(pr);
  93. }
  94. //------------------------------------------------------------------------------
  95. void SdFatBase::initErrorPrint(Print* pr, const __FlashStringHelper* msg) {
  96. pr->println(msg);
  97. initErrorPrint(pr);
  98. }