Skip to content

Commit

Permalink
remove duplicate code to open file for verfication
Browse files Browse the repository at this point in the history
  • Loading branch information
smesgr9000 committed May 20, 2024
1 parent d7e795f commit f82be2d
Showing 1 changed file with 22 additions and 49 deletions.
71 changes: 22 additions & 49 deletions Cart_Reader/FLASH.ino
Original file line number Diff line number Diff line change
Expand Up @@ -1055,14 +1055,7 @@ word readWord_Flash(unsigned long myAddress) {
/******************************************
write helper functions
*****************************************/
bool openFlashFile() {
// Create filepath
sprintf(filePath, "%s/%s", filePath, fileName);
print_STR(flashing_file_STR, 0);
print_Msg(filePath);
println_Msg(F("..."));
display_Update();

bool openFileOnSD() {
// Open file on sd card
if (myFile.open(filePath, O_READ)) {
// Get rom size from file
Expand All @@ -1076,6 +1069,24 @@ bool openFlashFile() {
return false;
}

bool openFlashFile() {
// Create filepath
sprintf(filePath, "%s/%s", filePath, fileName);
print_STR(flashing_file_STR, 0);
print_Msg(filePath);
println_Msg(F("..."));
display_Update();

return openFileOnSD();
}

bool openVerifyFlashFile() {
print_STR(verifying_STR, 1);
display_Update();

return openFileOnSD();
}

/******************************************
29F032 flashrom functions
*****************************************/
Expand Down Expand Up @@ -1710,16 +1721,7 @@ void blankcheck_Flash() {
}

void verifyFlash() {
print_STR(verifying_STR, 1);
display_Update();

// Open file on sd card
if (myFile.open(filePath, O_READ)) {
// Get rom size from file
fileSize = myFile.fileSize();
if (fileSize > flashSize)
print_FatalError(file_too_big_STR);

if (openVerifyFlashFile()) {
blank = 0;
for (unsigned long currByte = 0; currByte < fileSize; currByte += 512) {
//fill sdBuffer
Expand All @@ -1741,9 +1743,6 @@ void verifyFlash() {
}
// Close the file:
myFile.close();
} else {
print_STR(open_file_STR, 1);
display_Update();
}
}

Expand Down Expand Up @@ -1994,17 +1993,7 @@ void blankcheck16() {
}

void verifyFlash16() {
print_STR(verifying_STR, 1);
display_Update();

// Open file on sd card
if (myFile.open(filePath, O_READ)) {
// Get rom size from file
fileSize = myFile.fileSize();
if (fileSize > flashSize) {
print_FatalError(file_too_big_STR);
}

if (openVerifyFlashFile()) {
blank = 0;
word d = 0;
for (unsigned long currByte = 0; currByte < fileSize / 2; currByte += 256) {
Expand All @@ -2031,9 +2020,6 @@ void verifyFlash16() {
}
// Close the file:
myFile.close();
} else {
println_Msg(F("Can't open file on SD."));
display_Update();
}
}

Expand Down Expand Up @@ -2417,17 +2403,7 @@ void write_Eprom() {
}

void verify_Eprom() {
print_STR(verifying_STR, 1);
display_Update();

// Open file on sd card
if (myFile.open(filePath, O_READ)) {
// Get rom size from file
fileSize = myFile.fileSize();
if (fileSize > flashSize) {
print_FatalError(file_too_big_STR);
}

if (openVerifyFlashFile()) {
blank = 0;
word d = 0;
for (unsigned long currWord = 0; currWord < (fileSize / 2); currWord += 256) {
Expand All @@ -2454,9 +2430,6 @@ void verify_Eprom() {
}
// Close the file:
myFile.close();
} else {
println_Msg(F("Can't open file on SD."));
display_Update();
}
}

Expand Down

0 comments on commit f82be2d

Please sign in to comment.