takže co to dělá a nedělá:
když použiju funkci listShow() stane se to co se má, vrátí mi seznam souborů, v mém případě 5 souborů
problém nastává při použití fileRead nebo fileWrite, za prvé, někdy mi to ten soubor vezme a někdy ne (záleží na názvu souboru, nwm proč)
a za druhé pokud tyto funkce udělají co mají, přestává pracovat listShow, teda ne že by nepracoval ale vrací méně souborů než na sd kartě obravdu je
takhle vypadá celý program a nahrávám ho na arduino uno s LCD TFT shieldem
Kód: Vybrat vše
#include <SD.h>
#include <EEPROM.h>
#include <Adafruit_GFX.h>
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;
#include <TouchScreen.h>
#define YP A1
#define YM 7
#define XM A2
#define XP 6
#define MINPRESSURE 10
#define MAXPRESSURE 1000
int TP_LEFT=EEPROM.read(0)+(EEPROM.read(1)<<8); //938;
int TP_TOP=EEPROM.read(2)+(EEPROM.read(3)<<8); //915;
int TP_RT=EEPROM.read(4)+(EEPROM.read(5)<<8); //567;
int TP_BOT=EEPROM.read(6)+(EEPROM.read(7)<<8); //245;
TouchScreen touchScreen = TouchScreen(XP, YP, XM, YM, 150);
TSPoint touchPoint;
void reset(void) {tft.fillScreen(0xffff); asm volatile (" jmp 0");}
void TSinit(boolean maping=1) {touchPoint=touchScreen.getPoint();
if (maping) {
int tpy=touchPoint.y;
touchPoint.y=map(touchPoint.x,TP_LEFT,TP_RT,tft.height()-10,10);
touchPoint.x=map(tpy,TP_TOP,TP_BOT,10,tft.width()-10);
} // bug!!! prohozene x a y (nula vlevo dole)
pinMode(YP, OUTPUT); pinMode(XM, OUTPUT); pinMode(XP, OUTPUT); pinMode(YM, OUTPUT);
}
boolean TStouch(void) {return (touchPoint.z > MINPRESSURE && touchPoint.z < MAXPRESSURE);}
boolean TSrect(int x1, int y1, int x2, int y2) {
return (touchPoint.z > MINPRESSURE && touchPoint.z < MAXPRESSURE &&touchPoint.x>x1 && touchPoint.x<x2 && touchPoint.y>y1 && touchPoint.y<y2);}
class CON {
public:
String input="";
String dir="/";
String file="";
File f;
}; CON console;
void listShow(String fn) {
console.f=SD.open(console.dir.c_str(),FILE_READ);
while(true) {
File entry = console.f.openNextFile();
if (!entry) {break;}
String out=entry.name();
if (entry.isDirectory()) {out=out+"/";}
else {out=out+" - "+entry.size()+" byte";}
Serial.println(out);
entry.close();
}
console.f.close();
}
void cd(String dir="") {
if (dir.length()!=0) {
if (dir[0]=="/"[0]) {console.dir=dir;}
else {console.dir=console.dir+dir;}
if (dir[dir.length()-1]!="/"[0]) {console.dir=console.dir+"/";}
}
Serial.println(console.dir);
}
void fileOpen(String fname) {
fname=console.dir+fname;
Serial.println(fname);
console.file=fname;
}
void fileRead() {
console.f=SD.open(console.file.c_str(),FILE_READ);
while (console.f.available()) {
Serial.write(console.f.read());
}
console.f.close();
}
void fileWrite(String txt) {
console.f=SD.open(console.file.c_str(),FILE_WRITE);
console.f.println(txt);
Serial.println(txt);
console.f.close();
}
void setup() {
Serial.begin(9600);
tft.reset();
tft.begin(0x4747);
tft.setRotation(1);
tft.fillScreen(0x0000);
SD.begin(10);
console.dir="/";
Serial.println("Serial initialize");
Serial.setTimeout(10);
}
void loop() {
while(1) {
if (Serial.available()) {
console.input=Serial.readString();
break;
}
delay(30);
}
String command="";
String argument="";
int pos=0;
for(int i;i<console.input.length();i++) {
if (console.input.charAt(i)==32) {break;} else {pos+=1;}
}
command=console.input.substring(0,pos);
argument=console.input.substring(pos+1,console.input.length());
//translate start
if (command=="print") {tft.print(argument);}
else if (command=="println") {tft.println(argument);}
else if (command=="ls") {listShow(argument);}
else if (command=="fopen") {fileOpen(argument);}
else if (command=="fread") {fileRead();}
else if (command=="fwrite") {fileWrite(argument);}
else if (command=="cd") {cd(argument);}
else {Serial.println("prikaz \""+command+"\" nenalezen");}
//translate end
//console.print(command);
//console.print(argument);
console.input="";
delay(500);
}