sdcard.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #include "sdcard.h"
  2. extern SdFs SD;
  3. extern FsFile LOG_FILE;
  4. extern uint16_t imageSelect;
  5. // read SD information and print to logfile
  6. void readSDCardInfo()
  7. {
  8. cid_t sd_cid;
  9. if(SD.card()->readCID(&sd_cid))
  10. {
  11. Serial.print("Sd MID:");
  12. Serial.print(sd_cid.mid, 16);
  13. Serial.print(" OID:");
  14. Serial.print(sd_cid.oid[0]);
  15. Serial.println(sd_cid.oid[1]);
  16. Serial.print("Sd Name:");
  17. Serial.print(sd_cid.pnm[0]);
  18. Serial.print(sd_cid.pnm[1]);
  19. Serial.print(sd_cid.pnm[2]);
  20. Serial.print(sd_cid.pnm[3]);
  21. Serial.println(sd_cid.pnm[4]);
  22. Serial.print("Sd Date:");
  23. Serial.print(sd_cid.mdt_month);
  24. Serial.print("/20"); // CID year is 2000 + high/low
  25. Serial.print(sd_cid.mdt_year_high);
  26. Serial.println(sd_cid.mdt_year_low);
  27. Serial.print("Sd Serial:");
  28. Serial.println(sd_cid.psn);
  29. }
  30. }
  31. void readSDCardInfo2()
  32. {
  33. cid_t sd_cid;
  34. if(SD.card()->readCID(&sd_cid))
  35. {
  36. LOG_FILE.print("Sd MID:");
  37. LOG_FILE.print(sd_cid.mid, 16);
  38. LOG_FILE.print(" OID:");
  39. LOG_FILE.print(sd_cid.oid[0]);
  40. LOG_FILE.println(sd_cid.oid[1]);
  41. LOG_FILE.print("Sd Name:");
  42. LOG_FILE.print(sd_cid.pnm[0]);
  43. LOG_FILE.print(sd_cid.pnm[1]);
  44. LOG_FILE.print(sd_cid.pnm[2]);
  45. LOG_FILE.print(sd_cid.pnm[3]);
  46. LOG_FILE.println(sd_cid.pnm[4]);
  47. LOG_FILE.print("Sd Date:");
  48. LOG_FILE.print(sd_cid.mdt_month);
  49. LOG_FILE.print("/20"); // CID year is 2000 + high/low
  50. LOG_FILE.print(sd_cid.mdt_year_high);
  51. LOG_FILE.println(sd_cid.mdt_year_low);
  52. LOG_FILE.print("Sd Serial:");
  53. LOG_FILE.println(sd_cid.psn);
  54. LOG_FILE.sync();
  55. }
  56. }
  57. /*
  58. * No SC Card found, blink 5x fast
  59. */
  60. void noSDCardFound(void)
  61. {
  62. while(!SD.begin(SdSpiConfig(SS, DEDICATED_SPI))) {
  63. for(int i = 0; i < 5; i++) {
  64. LED3_ON();
  65. delay(500);
  66. LED3_OFF();
  67. delay(500);
  68. }
  69. delay(1000);
  70. }
  71. }
  72. void sdCardInsert(void){
  73. if (digitalRead(BOARD_SDCARD_INSERT)){
  74. LED1_OFF();
  75. }else{
  76. LED1_ON();
  77. }
  78. }
  79. void switchImage(void){
  80. uint16_t oldimageSelect = imageSelect;
  81. imageSelect = digitalRead(BOARD_SWITCH1_PIN) |
  82. digitalRead(BOARD_SWITCH2_PIN) << 1 |
  83. digitalRead(BOARD_SWITCH3_PIN) << 2 |
  84. digitalRead(BOARD_SWITCH4_PIN) << 3;
  85. if ( oldimageSelect!=imageSelect){
  86. Serial.print("Image: ");
  87. Serial.println(15-imageSelect);
  88. Serial.flush();
  89. }
  90. }