Skip to content

Commit e171a27

Browse files
committed
SD lib is not pilite across platforms
fitting all into .h file to be used if included
1 parent 7a3bce0 commit e171a27

File tree

3 files changed

+124
-126
lines changed

3 files changed

+124
-126
lines changed

Diff for: .travis.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ install:
6262
- wget https://github.com/adafruit/Adafruit-ST7735-Library/archive/master.zip -O /tmp/Adafruit-ST7735-Library-master.zip
6363
- unzip /tmp/Adafruit-ST7735-Library-master.zip -d /tmp/
6464

65-
- wget https://github.com/PaulStoffregen/SD/archive/master.zip -O /tmp/SD-master.zip
66-
- unzip /tmp/SD-master.zip -d /tmp/
65+
# - wget https://github.com/PaulStoffregen/SD/archive/master.zip -O /tmp/SD-master.zip
66+
# - unzip /tmp/SD-master.zip -d /tmp/
6767

6868
script:
69-
# - platformio ci --lib="." --board=nanoatmega328 --board=teensy31
70-
- platformio ci --lib="." --lib="/tmp/Streaming-master" --lib="/tmp/Adafruit-GFX-Library-master" --lib="/tmp/PCINT-master" --lib="/tmp/U8glib_Arduino-master" --lib="/tmp/AnsiStream-master" --lib="/tmp/NewliquidCrystal" --lib="/tmp/Adafruit-PCD8544-Nokia-5110-LCD-library-master" --lib="/tmp/Adafruit-ST7735-Library-master" --lib="/tmp/SD-master" --board=nanoatmega328 --board=teensy31 --board=due
69+
# - platformio ci --lib="." --lib="/tmp/SD-master" --board=nanoatmega328 --board=teensy31
70+
- platformio ci --lib="." --lib="/tmp/Streaming-master" --lib="/tmp/Adafruit-GFX-Library-master" --lib="/tmp/PCINT-master" --lib="/tmp/U8glib_Arduino-master" --lib="/tmp/AnsiStream-master" --lib="/tmp/NewliquidCrystal" --lib="/tmp/Adafruit-PCD8544-Nokia-5110-LCD-library-master" --lib="/tmp/Adafruit-ST7735-Library-master" --board=nanoatmega328 --board=teensy31 --board=due

Diff for: src/plugin/SDMenu.cpp

-121
This file was deleted.

Diff for: src/plugin/SDMenu.h

+120-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/* -*- C++ -*- */
2+
#pragma once
23
// a full automated SDCard file select
34
// plugin for arduino menu library
45
// IO: Serial
56
// Feb 2019 - Rui Azevedo [[email protected]]
6-
77
#include <menu.h>
88

99
using namespace Menu;
@@ -45,4 +45,123 @@ using namespace Menu;
4545
//print menu and items as this is a virtual data menu
4646
Used printTo(navRoot &root,bool sel,menuOut& out, idx_t idx,idx_t len,idx_t pn);
4747
};
48+
49+
result SDMenu::sysHandler(SYS_FUNC_PARAMS) {
50+
switch(event) {
51+
case enterEvent:
52+
if (nav.root->navFocus!=nav.target) {//on sd card entry
53+
nav.sel=((SDMenu*)(&item))->selIdx;//restore context
54+
}
55+
}
56+
return proceed;
57+
}
58+
59+
void SDMenu::doNav(navNode& nav,navCmd cmd) {
60+
switch(cmd.cmd) {
61+
case enterCmd: {
62+
String selFile=entry(nav.sel);
63+
if (selFile.endsWith("/")) {
64+
// Serial.print("\nOpen folder...");
65+
//open folder (reusing the menu)
66+
folderName+=selFile;
67+
dirty=true;//redraw menu
68+
nav.sel=0;
69+
} else {
70+
selIdx=nav.sel;
71+
//Serial.print("\nFile selected:");
72+
//select a file and return
73+
selectedFile=selFile;
74+
nav.root->node().event(enterEvent);
75+
menuNode::doNav(nav,escCmd);
76+
}
77+
return;
78+
}
79+
case escCmd:
80+
if(folderName=="/")//at root?
81+
menuNode::doNav(nav,escCmd);//then exit
82+
else {//previous folder
83+
idx_t at=folderName.lastIndexOf("/",folderName.length()-2)+1;
84+
String fn=folderName.substring(at,folderName.length()-1);
85+
folderName.remove(folderName.lastIndexOf("/",folderName.length()-2)+1);
86+
// Serial.println(folderName);
87+
dirty=true;//redraw menu
88+
nav.sel=entryIdx(fn);
89+
}
90+
selIdx=nav.sel;
91+
return;
92+
}
93+
menuNode::doNav(nav,cmd);
94+
selIdx=nav.sel;
95+
}
96+
97+
idx_t SDMenu::count() {
98+
File dir=SD.open(folderName.c_str());
99+
int cnt=0;
100+
while(true) {
101+
File file=dir.openNextFile();
102+
if (!file) {
103+
file.close();
104+
dir.close();
105+
break;
106+
}
107+
file.close();
108+
cnt++;
109+
}
110+
dir.close();
111+
return cnt;
112+
}
113+
114+
idx_t SDMenu::entryIdx(String name) {
115+
File dir=SD.open(folderName.c_str());
116+
int cnt=0;
117+
while(true) {
118+
File file=dir.openNextFile();
119+
if (!file) {
120+
file.close();
121+
break;
122+
}
123+
if(name==file.name()) {
124+
file.close();
125+
dir.close();
126+
return cnt;
127+
}
128+
file.close();
129+
cnt++;
130+
}
131+
dir.close();
132+
return 0;//stay at menu start if not found
133+
}
134+
135+
String SDMenu::entry(idx_t idx) {
136+
File dir=SD.open(folderName.c_str());
137+
idx_t cnt=0;
138+
while(true) {
139+
File file=dir.openNextFile();
140+
if (!file) {
141+
file.close();
142+
break;
143+
}
144+
if(idx==cnt++) {
145+
String n=String(file.name())+(file.isDirectory()?"/":"");
146+
file.close();
147+
dir.close();
148+
return n;
149+
}
150+
file.close();
151+
}
152+
dir.close();
153+
return "";
154+
}
155+
156+
Used SDMenu::printTo(navRoot &root,bool sel,menuOut& out, idx_t idx,idx_t len,idx_t pn) {
157+
((menuNodeShadow*)shadow)->sz=count();
158+
if(root.navFocus!=this) //show given title
159+
return menuNode::printTo(root,sel,out,idx,len,pn);
160+
else if(idx==-1)//when menu open (show folder name)
161+
return out.printRaw(folderName.c_str(),len);
162+
//drawing options
163+
len-=out.printRaw(entry(idx).c_str(),len);
164+
return len;
165+
}
166+
48167
#endif

0 commit comments

Comments
 (0)