Hello,
I have a file on an SD card formatted like this:
0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,
0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,
and so on (8000 lines or so).
I'm using a WaveShare 4.2 inch 4 tone greyscale e-paper display. To display images, it required unsigned char arrays in this format:
const unsigned char gImage_cutdown[] = {
0XFE,0XAF,0XEA,0XFE,0XAF,0XEA,0XFE,0XAF,0XEA,0XFE,0XAF,0XEA,0XFE,0XAF,0XEA,0XFE,
0XAF,0XEA,0XFE,0XAF,0XEA,0X00,0X00,0X00,0X00,0X05,0X55,0XAA,0XAA,0X95,0XA9,0X5A,
...........
}
By having const unsigned char arrays compiled into the code, I can show them on the display. I want be able to load files from my SD card, write the contents to unsigned char arrays and then show the result on the e-paper display.
(I'm hoping that "const" isn't going to trip me up here, but I'll cross that bridge later)
I'm using the standard SPI interface for SD. (FS.h, SD,h, SPI,h). Not sure if it matters, but I'm using an ESP32.
I know the SPI interface is working as I'm able to write the file contents to the serial monitor. I've also been able to make Strings with the contents, but not been able to re-create the arrays.
/* Declares */
unsigned char SDarray[30000]; //Declare unsigned char array with max possible size
String SDstr; // for storing each byte while processing
//Modified SD Card read function. The default function just prints to serial monitor.
void readFile(fs::FS &fs, const char * path){
Serial.printf("Reading file: %s\n", path);
File file = fs.open(path);
if(!file){
Serial.println("Failed to open file for reading");
return;
}
int SDparse = 0; // new integer to manage array creation
Serial.print("Read from file: ");
while(file.available()){
//Serial.write(file.read());
char c = file.read(); //This is where the major changes start. I record each character into char c
if (c == ','){ //comma indicates end of a byte has been reached
SDarray[SDparse] = SDstr(); //SDstr was fully assembled on previous loop, already contains something like 0xFF
SDparse++; //this integer incremented so that the next full byte gets written to the next place in the array
SDstr = ""; //empty the SDstr String ready to create the next one
}
else if (c == '\n') {
continue; //if newline character, ignore and continue on.
}
else
{
SDstr.concat(c); //this goes about assembling the individual characters into something like 0xFF or 0xA1
}
}
file.close();
}
Later in the script, the readFile() function is called out:
readFile(SD, "/octopus.c"); //should put the bitmap array into the unsigned char array: SDarray[]
Paint_Clear(WHITE);
Paint_DrawImage(SDarray,16,0,768,300);//This is the Waveshare function that adds the bitmap array to the "paint area" before displaying it
EPD_4IN2_4GrayDisplay(BlackImage);
DEV_Delay_ms(10000);
So of course, assuming the way I'm trying to do this isn't complete off, the line giving me trouble is this one:
SDarray[SDparse] = SDstr();
because you can't just put a String into an unsigned char array and expect that to work. I need it to somehow look at the contents of SDstr (eg/ 0x02) and actually interpret that literally(?).
Does anyone know how to do that? Or have a completely different way of doing what I'm trying to achieve? Thanks in advance.