Skip to content

Commit

Permalink
added test parts of the code for various errors
Browse files Browse the repository at this point in the history
  • Loading branch information
johnyHV committed May 13, 2024
1 parent 41f32f7 commit 49f89e9
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 13 deletions.
4 changes: 3 additions & 1 deletion ESP32_PrusaConnectCam/camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ void Camera::CapturePhoto() {
log->AddEvent(LogLevel_Info, F("Taking photo..."));

/* capture final photo */
delay(5); // delay for camera stabilization. test it
FrameBuffer = esp_camera_fb_get();
if (!FrameBuffer) {
log->AddEvent(LogLevel_Error, F("Camera capture failed! photo"));
Expand Down Expand Up @@ -476,7 +477,8 @@ void Camera::CopyPhoto(String* i_data, int i_from, int i_to) {
* @return int - photo size
*/
int Camera::GetPhotoSize() {
return FrameBuffer->len;
log->AddEvent(LogLevel_Verbose, "Photo size: " + String(FrameBuffer->len));
return (int) FrameBuffer->len;
}

/**
Expand Down
48 changes: 41 additions & 7 deletions ESP32_PrusaConnectCam/cfg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,13 @@ void Configuration::GetFingerprint() {
*/
void Configuration::SaveUint8(uint16_t address, uint8_t data) {
EEPROM.write(address, data);
EEPROM.commit();

if (EEPROM.commit()) {
Log->AddEvent(LogLevel_Verbose, F("Write uint8_t done"));
} else {
Log->AddEvent(LogLevel_Error, F("Failed to write uint8_t"));
EEPROM.commit(); // try again
}
}
/**
@info Function for save int8_t to EEPROM
Expand All @@ -268,7 +274,13 @@ void Configuration::SaveUint8(uint16_t address, uint8_t data) {
*/
void Configuration::SaveInt8(uint16_t address, int8_t data) {
EEPROM.write(address, data);
EEPROM.commit();

if (EEPROM.commit()) {
Log->AddEvent(LogLevel_Verbose, F("Write int8_t done"));
} else {
Log->AddEvent(LogLevel_Error, F("Failed to write int8_t"));
EEPROM.commit(); // try again
}
}
/**
@info Function for save bool to EEPROM
Expand All @@ -278,7 +290,13 @@ void Configuration::SaveInt8(uint16_t address, int8_t data) {
*/
void Configuration::SaveBool(uint16_t address, bool data) {
EEPROM.write(address, data);
EEPROM.commit();

if (EEPROM.commit()) {
Log->AddEvent(LogLevel_Verbose, F("Write bool done"));
} else {
Log->AddEvent(LogLevel_Error, F("Failed to write bool"));
EEPROM.commit(); // try again
}
}
/**
@info Function for save uint16_t to EEPROM
Expand All @@ -292,7 +310,13 @@ void Configuration::SaveUint16(uint16_t address, uint16_t data) {

EEPROM.write(address, highByte);
EEPROM.write(address + 1, lowByte);
EEPROM.commit();

if (EEPROM.commit()) {
Log->AddEvent(LogLevel_Verbose, F("Write uint16_t done"));
} else {
Log->AddEvent(LogLevel_Error, F("Failed to write uint16_t"));
EEPROM.commit(); // try again
}
}

/**
Expand All @@ -311,8 +335,13 @@ void Configuration::SaveString(uint16_t address, uint16_t max_length, String dat
for (uint16_t i = address + 1, j = 0; j < data.length(); i++, j++) {
EEPROM.write(i, data.charAt(j));
}
EEPROM.commit();
Log->AddEvent(LogLevel_Verbose, F("Write string done"));

if (EEPROM.commit()) {
Log->AddEvent(LogLevel_Verbose, F("Write string done"));
} else {
Log->AddEvent(LogLevel_Error, F("Failed to write string"));
EEPROM.commit(); // try again
}
} else {
Log->AddEvent(LogLevel_Verbose, F("Skip write string"));
}
Expand All @@ -331,7 +360,12 @@ void Configuration::SaveIpAddress(uint16_t address, String data) {
EEPROM.write(address + 1, ip[1]);
EEPROM.write(address + 2, ip[2]);
EEPROM.write(address + 3, ip[3]);
EEPROM.commit();

if (EEPROM.commit()) {
Log->AddEvent(LogLevel_Verbose, F("Write IP address done"));
} else {
Log->AddEvent(LogLevel_Error, F("Failed to write IP address"));
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions ESP32_PrusaConnectCam/connect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ bool PrusaConnect::SendDataToBackend(String *i_data, int i_data_length, String i
WiFiClientSecure client;
BackendReceivedStatus = "";
bool ret = false;
log->AddEvent(LogLevel_Info, "Sending " + i_type + " to PrusaConnect");
log->AddEvent(LogLevel_Info, "Sending " + i_type + " to PrusaConnect, " + String(i_data_length) + " bytes");

/* check fingerprint and token length */
if ((Fingerprint.length() > 0) && (Token.length() > 0)) {
Expand Down Expand Up @@ -119,7 +119,7 @@ bool PrusaConnect::SendDataToBackend(String *i_data, int i_data_length, String i
log->AddEvent(LogLevel_Verbose, F("Send data photo"));
int index = 0;
/* send data in fragments */
for (index = 0; index < i_data_length; index = index + PHOTO_FRAGMENT_SIZE) {
for (index = 0; index < i_data_length; index += PHOTO_FRAGMENT_SIZE) {
camera->CopyPhoto(i_data, index, index + PHOTO_FRAGMENT_SIZE);
client.print(*i_data);
log->AddEvent(LogLevel_Verbose, String(i_data_length) + "/" + String(index));
Expand Down
2 changes: 1 addition & 1 deletion ESP32_PrusaConnectCam/connect.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class PrusaConnect {
Logs *log; ///< pointer to logs object
Camera *camera; ///< pointer to camera object

bool SendDataToBackend(String *,int, String, String, String, SendDataToBackendType);
bool SendDataToBackend(String *, int, String, String, String, SendDataToBackendType);

public:
PrusaConnect(Configuration*, Logs*, Camera*);
Expand Down
2 changes: 1 addition & 1 deletion ESP32_PrusaConnectCam/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ String Logs::GetSystemTime() {
struct tm timeinfo;
if (!getLocalTime(&timeinfo)) {
#if (true == CONSOLE_VERBOSE_DEBUG)
Serial.println("Failed to obtain time");
Serial.println(F("Failed to obtain time"));
#endif
return ret;
}
Expand Down
2 changes: 1 addition & 1 deletion ESP32_PrusaConnectCam/serial_cfg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ String lastTwoChars = command.substring(command.length() - 2);
ESP.restart();

} else if (command.startsWith("commandslist") && command.endsWith(";")) {
log->AddEvent(LogLevel_Warning, "--> Available commands");
log->AddEvent(LogLevel_Warning, F("--> Available commands"));
PrintAvailableCommands();

} else {
Expand Down

0 comments on commit 49f89e9

Please sign in to comment.