瀏覽代碼

first compile with the cardreader class

Bernhard Kubicek 13 年之前
父節點
當前提交
01df04e02c
共有 5 個文件被更改,包括 288 次插入249 次删除
  1. 46
    183
      Marlin/Marlin.pde
  2. 47
    0
      Marlin/cardreader.h
  3. 177
    0
      Marlin/cardreader.pde
  4. 1
    2
      Marlin/ultralcd.h
  5. 17
    64
      Marlin/ultralcd.pde

+ 46
- 183
Marlin/Marlin.pde 查看文件

@@ -37,13 +37,11 @@
37 37
 #include "stepper.h"
38 38
 #include "temperature.h"
39 39
 #include "motion_control.h"
40
+#include "cardreader.h"
40 41
 
41 42
 
42 43
 char version_string[] = "1.0.0 Alpha 1";
43 44
 
44
-#ifdef SDSUPPORT
45
-  #include "SdFat.h"
46
-#endif //SDSUPPORT
47 45
 
48 46
 
49 47
 // look here for descriptions of gcodes: http://linuxcnc.org/handbook/gcode/g-code.html
@@ -112,7 +110,11 @@ char version_string[] = "1.0.0 Alpha 1";
112 110
 //===========================================================================
113 111
 extern float HeaterPower;
114 112
 
115
-//public variables
113
+
114
+//===========================================================================
115
+//=============================public variables=============================
116
+//===========================================================================
117
+CardReader card;
116 118
 float homing_feedrate[] = HOMING_FEEDRATE;
117 119
 bool axis_relative_modes[] = AXIS_RELATIVE_MODES;
118 120
 volatile int feedmultiply=100; //100->1 200->2
@@ -138,7 +140,6 @@ static bool relative_mode_e = false;  //Determines Absolute or Relative E Codes
138 140
 static uint8_t fanpwm=0;
139 141
 
140 142
 
141
-// comm variables
142 143
 
143 144
 static char cmdbuffer[BUFSIZE][MAX_CMD_SIZE];
144 145
 static bool fromsd[BUFSIZE];
@@ -163,140 +164,12 @@ static unsigned long stepper_inactive_time = 0;
163 164
 static unsigned long starttime=0;
164 165
 static unsigned long stoptime=0;
165 166
 
166
-#ifdef SDSUPPORT
167
-  static Sd2Card card;
168
-  static SdVolume volume;
169
-  static SdFile root;
170
-  static SdFile file;
171
-  static uint32_t filesize = 0;
172
-  static uint32_t sdpos = 0;
173
-  static bool sdmode = false;
174
-  static bool sdactive = false;
175
-  static bool savetosd = false;
176
-  static int16_t n;
177
-  static unsigned long autostart_atmillis=0;
178
-  
179
-  static bool autostart_stilltocheck=true; //the sd start is delayed, because otherwise the serial cannot answer fast enought to make contact with the hostsoftware.
180
-#endif //SDSUPPORT
167
+
181 168
 
182 169
 //===========================================================================
183 170
 //=============================ROUTINES=============================
184 171
 //===========================================================================
185
-#ifdef SDSUPPORT
186
-  void initsd()
187
-  {
188
-    sdactive = false;
189
-    #if SDSS >- 1
190
-      if(root.isOpen())
191
-	root.close();
192
-      if (!card.init(SPI_FULL_SPEED,SDSS))
193
-      {
194
-	//if (!card.init(SPI_HALF_SPEED,SDSS))
195
-	SERIAL_ECHOLN("SD init fail");
196
-      }
197
-      else if (!volume.init(&card))
198
-      {
199
-	SERIAL_ERRORLN("volume.init failed");
200
-      }
201
-      else if (!root.openRoot(&volume)) 
202
-      {
203
-	SERIAL_ERRORLN("openRoot failed");
204
-      }
205
-      else 
206
-      {
207
-	sdactive = true;
208
-	SERIAL_ECHOLN("SD card ok");
209
-      }
210
-    #endif //SDSS
211
-  }
212 172
 
213
-  void quickinitsd()
214
-  {
215
-    sdactive=false;
216
-    autostart_atmillis=millis()+5000;
217
-  }
218
-
219
-  inline void write_command(char *buf)
220
-  {
221
-    char* begin = buf;
222
-    char* npos = 0;
223
-    char* end = buf + strlen(buf) - 1;
224
-
225
-    file.writeError = false;
226
-    if((npos = strchr(buf, 'N')) != NULL)
227
-    {
228
-      begin = strchr(npos, ' ') + 1;
229
-      end = strchr(npos, '*') - 1;
230
-    }
231
-    end[1] = '\r';
232
-    end[2] = '\n';
233
-    end[3] = '\0';
234
-    file.write(begin);
235
-    if (file.writeError)
236
-    {
237
-      SERIAL_ERRORLN("error writing to file");
238
-    }
239
-  }
240
-  
241
-
242
-  void checkautostart(bool force)
243
-  {
244
-  //this is to delay autostart and hence the initialisaiton of the sd card to some seconds after the normal init, so the device is available quick after a reset
245
-    if(!force)
246
-    {
247
-      if(!autostart_stilltocheck)
248
-        return;
249
-      if(autostart_atmillis<millis())
250
-        return;
251
-    }
252
-    autostart_stilltocheck=false;
253
-    if(!sdactive)
254
-    {
255
-      initsd();
256
-      if(!sdactive) //fail
257
-        return;
258
-    }
259
-    static int lastnr=0;
260
-    char autoname[30];
261
-    sprintf(autoname,"auto%i.g",lastnr);
262
-    for(int i=0;i<(int)strlen(autoname);i++)
263
-      autoname[i]=tolower(autoname[i]);
264
-    dir_t p;
265
-
266
-    root.rewind();
267
-    
268
-    bool found=false;
269
-    while (root.readDir(p) > 0) 
270
-    {
271
-      for(int i=0;i<(int)strlen((char*)p.name);i++)
272
-      p.name[i]=tolower(p.name[i]);
273
-      //Serial.print((char*)p.name);
274
-      //Serial.print(" ");
275
-      //Serial.println(autoname);
276
-      if(p.name[9]!='~') //skip safety copies
277
-      if(strncmp((char*)p.name,autoname,5)==0)
278
-      {
279
-        char cmd[30];
280
-
281
-        sprintf(cmd,"M23 %s",autoname);
282
-        //sprintf(cmd,"M115");
283
-        //enquecommand("G92 Z0");
284
-        //enquecommand("G1 Z10 F2000");
285
-        //enquecommand("G28 X-105 Y-105");
286
-        enquecommand(cmd);
287
-        enquecommand("M24");
288
-        found=true;
289
-      }
290
-    }
291
-    if(!found)
292
-      lastnr=-1;
293
-    else
294
-      lastnr++;
295
-  }
296
-#else  //NO SD SUPORT
297
-  inline void checkautostart(bool x){};
298
-  
299
-#endif //SDSUPPORT
300 173
 
301 174
 
302 175
 //adds an command to the main command buffer
@@ -331,14 +204,6 @@ void setup()
331 204
     axis_steps_per_sqr_second[i] = max_acceleration_units_per_sq_second[i] * axis_steps_per_unit[i];
332 205
   }
333 206
 
334
-  #ifdef SDSUPPORT
335
-    //power to SD reader
336
-    #if SDPOWER > -1
337
-      SET_OUTPUT(SDPOWER); 
338
-      WRITE(SDPOWER,HIGH);
339
-    #endif //SDPOWER
340
-    quickinitsd();
341
-  #endif //SDSUPPORT
342 207
   
343 208
   plan_init();  // Initialize planner;
344 209
   st_init();    // Initialize stepper;
@@ -350,22 +215,20 @@ void loop()
350 215
 {
351 216
   if(buflen<3)
352 217
     get_command();
353
-  checkautostart(false);
218
+  card.checkautostart(false);
354 219
   if(buflen)
355 220
   {
356 221
     #ifdef SDSUPPORT
357
-      if(savetosd)
222
+      if(card.savetosd)
358 223
       {
359 224
 	if(strstr(cmdbuffer[bufindr],"M29") == NULL)
360 225
 	{
361
-	  write_command(cmdbuffer[bufindr]);
226
+	  card.write_command(cmdbuffer[bufindr]);
362 227
 	  Serial.println("ok");
363 228
 	}
364 229
 	else
365 230
 	{
366
-	  file.sync();
367
-	  file.close();
368
-	  savetosd = false;
231
+	  card.closefile();
369 232
 	  Serial.println("Done saving file.");
370 233
 	}
371 234
       }
@@ -455,7 +318,7 @@ inline void get_command()
455 318
           case 2:
456 319
           case 3:
457 320
 	    #ifdef SDSUPPORT
458
-            if(savetosd)
321
+            if(card.savetosd)
459 322
               break;
460 323
 	    #endif //SDSUPPORT
461 324
             Serial.println("ok"); 
@@ -479,17 +342,17 @@ inline void get_command()
479 342
     }
480 343
   }
481 344
   #ifdef SDSUPPORT
482
-  if(!sdmode || serial_count!=0){
345
+  if(!card.sdmode || serial_count!=0){
483 346
     return;
484 347
   }
485
-  while( filesize > sdpos  && buflen < BUFSIZE) {
486
-    n = file.read();
348
+  while( card.filesize > card.sdpos  && buflen < BUFSIZE) {
349
+    short n = card.file.read();
487 350
     serial_char = (char)n;
488 351
     if(serial_char == '\n' || serial_char == '\r' || serial_char == ':' || serial_count >= (MAX_CMD_SIZE - 1) || n == -1) 
489 352
     {
490
-      sdpos = file.curPosition();
491
-      if(sdpos >= filesize){
492
-        sdmode = false;
353
+      card.sdpos = card.file.curPosition();
354
+      if(card.sdpos >= card.filesize){
355
+        card.sdmode = false;
493 356
         Serial.println("echo: Done printing file");
494 357
         stoptime=millis();
495 358
         char time[30];
@@ -500,7 +363,7 @@ inline void get_command()
500 363
         sprintf(time,"echo: %i min, %i sec",min,sec);
501 364
         Serial.println(time);
502 365
         LCD_MESSAGE(time);
503
-        checkautostart(true);
366
+        card.checkautostart(true);
504 367
       }
505 368
       if(!serial_count) 
506 369
 	return; //if empty line
@@ -702,31 +565,31 @@ inline void process_commands()
702 565
 
703 566
     case 20: // M20 - list SD card
704 567
       Serial.println("Begin file list");
705
-      root.ls();
568
+      card.root.ls();
706 569
       Serial.println("End file list");
707 570
       break;
708 571
     case 21: // M21 - init SD card
709
-      sdmode = false;
710
-      initsd();
572
+      card.sdmode = false;
573
+      card.initsd();
711 574
       break;
712 575
     case 22: //M22 - release SD card
713
-      sdmode = false;
714
-      sdactive = false;
576
+      card.sdmode = false;
577
+      card.sdactive = false;
715 578
       break;
716 579
     case 23: //M23 - Select file
717
-      if(sdactive){
718
-        sdmode = false;
719
-        file.close();
580
+      if(card.sdactive){
581
+        card.sdmode = false;
582
+        card.file.close();
720 583
         starpos = (strchr(strchr_pointer + 4,'*'));
721 584
         if(starpos!=NULL)
722 585
           *(starpos-1)='\0';
723
-        if (file.open(&root, strchr_pointer + 4, O_READ)) {
586
+        if (card.file.open(&card.root, strchr_pointer + 4, O_READ)) {
724 587
           Serial.print("File opened:");
725 588
           Serial.print(strchr_pointer + 4);
726 589
           Serial.print(" Size:");
727
-          Serial.println(file.fileSize());
728
-          sdpos = 0;
729
-          filesize = file.fileSize();
590
+          Serial.println(card.file.fileSize());
591
+          card.sdpos = 0;
592
+          card.filesize = card.file.fileSize();
730 593
           Serial.println("File selected");
731 594
         }
732 595
         else{
@@ -735,52 +598,52 @@ inline void process_commands()
735 598
       }
736 599
       break;
737 600
     case 24: //M24 - Start SD print
738
-      if(sdactive){
739
-        sdmode = true;
601
+      if(card.sdactive){
602
+        card.sdmode = true;
740 603
 	starttime=millis();
741 604
       }
742 605
       break;
743 606
     case 25: //M25 - Pause SD print
744
-      if(sdmode){
745
-        sdmode = false;
607
+      if(card.sdmode){
608
+        card.sdmode = false;
746 609
       }
747 610
       break;
748 611
     case 26: //M26 - Set SD index
749
-      if(sdactive && code_seen('S')){
750
-        sdpos = code_value_long();
751
-        file.seekSet(sdpos);
612
+      if(card.sdactive && code_seen('S')){
613
+        card.sdpos = code_value_long();
614
+        card.file.seekSet(card.sdpos);
752 615
       }
753 616
       break;
754 617
     case 27: //M27 - Get SD status
755
-      if(sdactive){
618
+      if(card.sdactive){
756 619
         Serial.print("SD printing byte ");
757
-        Serial.print(sdpos);
620
+        Serial.print(card.sdpos);
758 621
         Serial.print("/");
759
-        Serial.println(filesize);
622
+        Serial.println(card.filesize);
760 623
       }
761 624
       else{
762 625
         Serial.println("Not SD printing");
763 626
       }
764 627
       break;
765 628
     case 28: //M28 - Start SD write
766
-      if(sdactive){
629
+      if(card.sdactive){
767 630
         char* npos = 0;
768
-        file.close();
769
-        sdmode = false;
631
+        card.file.close();
632
+        card.sdmode = false;
770 633
         starpos = (strchr(strchr_pointer + 4,'*'));
771 634
         if(starpos != NULL){
772 635
           npos = strchr(cmdbuffer[bufindr], 'N');
773 636
           strchr_pointer = strchr(npos,' ') + 1;
774 637
           *(starpos-1) = '\0';
775 638
         }
776
-        if (!file.open(&root, strchr_pointer+4, O_CREAT | O_APPEND | O_WRITE | O_TRUNC))
639
+        if (!card.file.open(&card.root, strchr_pointer+4, O_CREAT | O_APPEND | O_WRITE | O_TRUNC))
777 640
         {
778 641
           Serial.print("open failed, File: ");
779 642
           Serial.print(strchr_pointer + 4);
780 643
           Serial.print(".");
781 644
         }
782 645
         else{
783
-          savetosd = true;
646
+          card.savetosd = true;
784 647
           Serial.print("Writing to file: ");
785 648
           Serial.println(strchr_pointer + 4);
786 649
         }

+ 47
- 0
Marlin/cardreader.h 查看文件

@@ -0,0 +1,47 @@
1
+#ifndef __CARDREADERH
2
+#define __CARDREADERH
3
+
4
+#ifdef SDSUPPORT
5
+ 
6
+#include "SdFat.h"
7
+
8
+class CardReader
9
+{
10
+public:
11
+  CardReader();
12
+  
13
+  void initsd();
14
+  void write_command(char *buf);
15
+  //files auto[0-9].g on the sd card are performed in a row
16
+  //this is to delay autostart and hence the initialisaiton of the sd card to some seconds after the normal init, so the device is available quick after a reset
17
+
18
+  void checkautostart(bool x); 
19
+  
20
+  void closefile();
21
+  void getfilename(const uint8_t nr);
22
+  uint8_t getnrfilenames();
23
+
24
+public:
25
+  bool savetosd;
26
+  SdFile file;
27
+  uint32_t filesize;
28
+  uint32_t sdpos ;
29
+  bool sdmode ;
30
+  SdFile root;
31
+  bool sdactive ;
32
+  char filename[11];
33
+private:
34
+   Sd2Card card;
35
+   SdVolume volume;
36
+
37
+   //int16_t n;
38
+   unsigned long autostart_atmillis;
39
+
40
+   bool autostart_stilltocheck; //the sd start is delayed, because otherwise the serial cannot answer fast enought to make contact with the hostsoftware.
41
+};
42
+  
43
+#endif //SDSUPPORT
44
+  
45
+  
46
+  
47
+#endif

+ 177
- 0
Marlin/cardreader.pde 查看文件

@@ -0,0 +1,177 @@
1
+#ifdef SDSUPPORT
2
+#include "cardreader.h"
3
+
4
+CardReader::CardReader()
5
+{
6
+   filesize = 0;
7
+   sdpos = 0;
8
+   sdmode = false;
9
+   sdactive = false;
10
+   savetosd = false;
11
+   autostart_atmillis=0;
12
+
13
+   autostart_stilltocheck=true; //the sd start is delayed, because otherwise the serial cannot answer fast enought to make contact with the hostsoftware.
14
+  //power to SD reader
15
+  #if SDPOWER > -1
16
+    SET_OUTPUT(SDPOWER); 
17
+    WRITE(SDPOWER,HIGH);
18
+  #endif //SDPOWER
19
+  
20
+  autostart_atmillis=millis()+5000;
21
+}
22
+
23
+void CardReader::initsd()
24
+{
25
+  sdactive = false;
26
+  #if SDSS >- 1
27
+    if(root.isOpen())
28
+      root.close();
29
+    if (!card.init(SPI_FULL_SPEED,SDSS))
30
+    {
31
+      //if (!card.init(SPI_HALF_SPEED,SDSS))
32
+      SERIAL_ECHOLN("SD init fail");
33
+    }
34
+    else if (!volume.init(&card))
35
+    {
36
+      SERIAL_ERRORLN("volume.init failed");
37
+    }
38
+    else if (!root.openRoot(&volume)) 
39
+    {
40
+      SERIAL_ERRORLN("openRoot failed");
41
+    }
42
+    else 
43
+    {
44
+      sdactive = true;
45
+      SERIAL_ECHOLN("SD card ok");
46
+    }
47
+  #endif //SDSS
48
+}
49
+
50
+void CardReader::write_command(char *buf)
51
+{
52
+  char* begin = buf;
53
+  char* npos = 0;
54
+  char* end = buf + strlen(buf) - 1;
55
+
56
+  file.writeError = false;
57
+  if((npos = strchr(buf, 'N')) != NULL)
58
+  {
59
+    begin = strchr(npos, ' ') + 1;
60
+    end = strchr(npos, '*') - 1;
61
+  }
62
+  end[1] = '\r';
63
+  end[2] = '\n';
64
+  end[3] = '\0';
65
+  file.write(begin);
66
+  if (file.writeError)
67
+  {
68
+    SERIAL_ERRORLN("error writing to file");
69
+  }
70
+}
71
+
72
+
73
+void CardReader::checkautostart(bool force)
74
+{
75
+  if(!force)
76
+  {
77
+    if(!autostart_stilltocheck)
78
+      return;
79
+    if(autostart_atmillis<millis())
80
+      return;
81
+  }
82
+  autostart_stilltocheck=false;
83
+  if(!sdactive)
84
+  {
85
+    initsd();
86
+    if(!sdactive) //fail
87
+      return;
88
+  }
89
+  static int lastnr=0;
90
+  char autoname[30];
91
+  sprintf(autoname,"auto%i.g",lastnr);
92
+  for(int i=0;i<(int)strlen(autoname);i++)
93
+    autoname[i]=tolower(autoname[i]);
94
+  dir_t p;
95
+
96
+  root.rewind();
97
+  
98
+  bool found=false;
99
+  while (root.readDir(p) > 0) 
100
+  {
101
+    for(int i=0;i<(int)strlen((char*)p.name);i++)
102
+    p.name[i]=tolower(p.name[i]);
103
+    //Serial.print((char*)p.name);
104
+    //Serial.print(" ");
105
+    //Serial.println(autoname);
106
+    if(p.name[9]!='~') //skip safety copies
107
+    if(strncmp((char*)p.name,autoname,5)==0)
108
+    {
109
+      char cmd[30];
110
+
111
+      sprintf(cmd,"M23 %s",autoname);
112
+      enquecommand(cmd);
113
+      enquecommand("M24");
114
+      found=true;
115
+    }
116
+  }
117
+  if(!found)
118
+    lastnr=-1;
119
+  else
120
+    lastnr++;
121
+}
122
+
123
+void CardReader::closefile()
124
+{
125
+ file.sync();
126
+  file.close();
127
+  savetosd = false; 
128
+}
129
+
130
+void CardReader::getfilename(const uint8_t nr)
131
+{
132
+
133
+  dir_t p;
134
+  root.rewind();
135
+  uint8_t cnt=0;
136
+  filename[0]='\0';
137
+  while (root.readDir(p) > 0)
138
+  {
139
+    if (p.name[0] == DIR_NAME_FREE) break;
140
+    if (p.name[0] == DIR_NAME_DELETED || p.name[0] == '.'|| p.name[0] == '_') continue;
141
+    if (!DIR_IS_FILE_OR_SUBDIR(&p)) continue;
142
+    if(p.name[8]!='G') continue;
143
+    if(p.name[9]=='~') continue;
144
+    if(cnt++!=nr) continue;
145
+    //Serial.println((char*)p.name);
146
+    uint8_t writepos=0;
147
+    for (uint8_t i = 0; i < 11; i++) 
148
+    {
149
+      if (p.name[i] == ' ') continue;
150
+      if (i == 8) {
151
+        filename[writepos++]='.';
152
+      }
153
+      filename[writepos++]=p.name[i];
154
+    }
155
+    filename[writepos++]=0;
156
+  }
157
+}
158
+
159
+uint8_t CardReader::getnrfilenames()
160
+{
161
+  dir_t p;
162
+  root.rewind();
163
+  uint8_t cnt=0;
164
+  while (root.readDir(p) > 0)
165
+  {
166
+    if (p.name[0] == DIR_NAME_FREE) break;
167
+    if (p.name[0] == DIR_NAME_DELETED || p.name[0] == '.'|| p.name[0] == '_') continue;
168
+    if (!DIR_IS_FILE_OR_SUBDIR(&p)) continue;
169
+    if(p.name[8]!='G') continue;
170
+    if(p.name[9]=='~') continue;
171
+    cnt++;
172
+  }
173
+  return cnt;
174
+}
175
+
176
+
177
+#endif //SDSUPPORT

+ 1
- 2
Marlin/ultralcd.h 查看文件

@@ -57,7 +57,6 @@
57 57
   public:
58 58
     MainMenu();
59 59
     void update();
60
-    void getfilename(const uint8_t nr);
61 60
     uint8_t activeline;
62 61
     MainStatus status;
63 62
     uint8_t displayStartingRow;
@@ -71,7 +70,7 @@
71 70
     int lastencoderpos;
72 71
     int8_t lineoffset;
73 72
     int8_t lastlineoffset;
74
-    char filename[11];
73
+    
75 74
     bool linechanging;
76 75
   };
77 76
 

+ 17
- 64
Marlin/ultralcd.pde 查看文件

@@ -6,6 +6,7 @@ extern volatile int feedmultiply;
6 6
 extern volatile bool feedmultiplychanged;
7 7
 
8 8
 extern long position[4];   
9
+extern CardReader card;
9 10
 
10 11
 static char messagetext[LCD_WIDTH]="";
11 12
 
@@ -1107,56 +1108,8 @@ void MainMenu::showControl()
1107 1108
 
1108 1109
 #include "SdFat.h"
1109 1110
 
1110
-void MainMenu::getfilename(const uint8_t nr)
1111
-{
1112
-#ifdef SDSUPPORT  
1113
-  dir_t p;
1114
-  root.rewind();
1115
-  uint8_t cnt=0;
1116
-  filename[0]='\0';
1117
-  while (root.readDir(p) > 0)
1118
-  {
1119
-    if (p.name[0] == DIR_NAME_FREE) break;
1120
-    if (p.name[0] == DIR_NAME_DELETED || p.name[0] == '.'|| p.name[0] == '_') continue;
1121
-    if (!DIR_IS_FILE_OR_SUBDIR(&p)) continue;
1122
-    if(p.name[8]!='G') continue;
1123
-    if(p.name[9]=='~') continue;
1124
-    if(cnt++!=nr) continue;
1125
-    //Serial.println((char*)p.name);
1126
-    uint8_t writepos=0;
1127
-    for (uint8_t i = 0; i < 11; i++) 
1128
-    {
1129
-      if (p.name[i] == ' ') continue;
1130
-      if (i == 8) {
1131
-        filename[writepos++]='.';
1132
-      }
1133
-      filename[writepos++]=p.name[i];
1134
-    }
1135
-    filename[writepos++]=0;
1136
-  }
1137
-#endif  
1138
-}
1139 1111
 
1140
-uint8_t getnrfilenames()
1141
-{
1142
-#ifdef SDSUPPORT
1143
-  dir_t p;
1144
-  root.rewind();
1145
-  uint8_t cnt=0;
1146
-  while (root.readDir(p) > 0)
1147
-  {
1148
-    if (p.name[0] == DIR_NAME_FREE) break;
1149
-    if (p.name[0] == DIR_NAME_DELETED || p.name[0] == '.'|| p.name[0] == '_') continue;
1150
-    if (!DIR_IS_FILE_OR_SUBDIR(&p)) continue;
1151
-    if(p.name[8]!='G') continue;
1152
-    if(p.name[9]=='~') continue;
1153
-    cnt++;
1154
-  }
1155
-  return cnt;
1156
-#else
1157
-  return 0;
1158
-#endif
1159
-}
1112
+
1160 1113
 
1161 1114
 void MainMenu::showSD()
1162 1115
 {
@@ -1171,9 +1124,9 @@ void MainMenu::showSD()
1171 1124
  if(force_lcd_update)
1172 1125
  {
1173 1126
    clear();
1174
-  if(sdactive)
1127
+  if(card.sdactive)
1175 1128
   {
1176
-    nrfiles=getnrfilenames();
1129
+    nrfiles=card.getnrfilenames();
1177 1130
   }
1178 1131
   else
1179 1132
   {
@@ -1223,9 +1176,9 @@ void MainMenu::showSD()
1223 1176
         {
1224 1177
           BLOCK;
1225 1178
           beepshort();
1226
-          initsd();
1179
+          card.initsd();
1227 1180
           force_lcd_update=true;
1228
-           nrfiles=getnrfilenames();
1181
+           nrfiles=card.getnrfilenames();
1229 1182
         }
1230 1183
       }break;
1231 1184
     default:
@@ -1234,24 +1187,24 @@ void MainMenu::showSD()
1234 1187
       {
1235 1188
         if(force_lcd_update)
1236 1189
         {
1237
-          getfilename(i-2);
1190
+          card.getfilename(i-2);
1238 1191
           //Serial.print("Filenr:");Serial.println(i-2);
1239
-          lcd.setCursor(0,line);lcd.print(" ");lcd.print(filename);
1192
+          lcd.setCursor(0,line);lcd.print(" ");lcd.print(card.filename);
1240 1193
         }
1241 1194
         if((activeline==line) && CLICKED)
1242 1195
         {
1243 1196
           BLOCK
1244
-          getfilename(i-2);
1197
+          card.getfilename(i-2);
1245 1198
           char cmd[30];
1246
-          for(int i=0;i<strlen(filename);i++)
1247
-            filename[i]=tolower(filename[i]);
1248
-          sprintf(cmd,"M23 %s",filename);
1199
+          for(int i=0;i<strlen(card.filename);i++)
1200
+            card.filename[i]=tolower(card.filename[i]);
1201
+          sprintf(cmd,"M23 %s",card.filename);
1249 1202
           //sprintf(cmd,"M115");
1250 1203
           enquecommand(cmd);
1251 1204
           enquecommand("M24");
1252 1205
           beep(); 
1253 1206
           status=Main_Status;
1254
-          lcd_status(filename);
1207
+          lcd_status(card.filename);
1255 1208
         }
1256 1209
       }
1257 1210
       
@@ -1359,7 +1312,7 @@ void MainMenu::showMainMenu()
1359 1312
             if(true)
1360 1313
           #endif
1361 1314
           {
1362
-            if(sdmode)
1315
+            if(card.sdmode)
1363 1316
               lcd.print(" Stop Print   \x7E");
1364 1317
             else
1365 1318
               lcd.print(" Card Menu    \x7E");
@@ -1374,7 +1327,7 @@ void MainMenu::showMainMenu()
1374 1327
         #endif
1375 1328
         if((activeline==line)&&CLICKED)
1376 1329
         {
1377
-          sdmode = false;
1330
+          card.sdmode = false;
1378 1331
           BLOCK;
1379 1332
           status=Main_SD;
1380 1333
           beepshort();
@@ -1419,12 +1372,12 @@ void MainMenu::update()
1419 1372
       //Serial.println("echo: SD CHANGE");
1420 1373
       if(CARDINSERTED)
1421 1374
       {
1422
-        initsd();
1375
+        card.initsd();
1423 1376
         lcd_status("Card inserted");
1424 1377
       }
1425 1378
       else
1426 1379
       {
1427
-        sdactive=false;
1380
+        card.sdactive=false;
1428 1381
         lcd_status("Card removed");
1429 1382
       }
1430 1383
     }

Loading…
取消
儲存