Skip to content

Commit

Permalink
Sync with ESP3D latest code (227)
Browse files Browse the repository at this point in the history
  • Loading branch information
luc-github committed Feb 2, 2024
1 parent b86670a commit 7bee09b
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 44 deletions.
58 changes: 31 additions & 27 deletions src/core/commands/ESP170.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
// /awb/agc/aec/hmirror/vflip/awb_gain/agc_gain/aec_value/aec2/cw/bpc/wpc
// /raw_gma/lenc/special_effect/wb_mode/ae_level
void ESP3DCommands::ESP170(int cmd_params_pos, ESP3DMessage* msg) {
const char* camcmd = [] = {
const char* camcmd[] = {
"framesize",
"quality",
"contrast",
Expand Down Expand Up @@ -63,13 +63,17 @@ void ESP3DCommands::ESP170(int cmd_params_pos, ESP3DMessage* msg) {
"light",
#endif // CAM_LED_PIN
};
bool hasError = false;
String ok_msg;
String error_msg;
ESP3DClientType target = msg->origin;
ESP3DRequest requestId = msg->request_id;
msg->target = target;
msg->origin = ESP3DClientType::command;
bool json = hasTag(msg, cmd_params_pos, "json");
String tmpstr;
#if AUTHENTICATION_FEATURE

#ifdef AUTHENTICATION_FEATURE
if (msg->authentication_level == ESP3DAuthenticationLevel::guest) {
dispatchAuthenticationError(msg, COMMAND_ID, json);
return;
Expand Down Expand Up @@ -102,146 +106,146 @@ void ESP3DCommands::ESP170(int cmd_params_pos, ESP3DMessage* msg) {
// now send all settings one by one
// framesize
if (!dispatchIdValue(json, "framesize",
String(status.framesize).c_str(), target,
String(s->status.framesize).c_str(), target,
requestId, true)) {
return;
}

// quality
if (!dispatchIdValue(json, "quality", String(status.quality).c_str(),
if (!dispatchIdValue(json, "quality", String(s->status.quality).c_str(),
target, requestId)) {
return;
}

// brightness
if (!dispatchIdValue(json, "brightness",
String(status.brightness).c_str(), target,
String(s->status.brightness).c_str(), target,
requestId)) {
return;
}

// contrast
if (!dispatchIdValue(json, "contrast", String(status.contrast).c_str(),
if (!dispatchIdValue(json, "contrast", String(s->status.contrast).c_str(),
target, requestId)) {
return;
}

// saturation
if (!dispatchIdValue(json, "saturation",
String(status.saturation).c_str(), target,
String(s->status.saturation).c_str(), target,
requestId)) {
return;

// sharpness
if (!dispatchIdValue(json, "sharpness",
String(status.sharpness).c_str(), target,
String(s->status.sharpness).c_str(), target,
requestId)) {
return;
}

// special_effect
if (!dispatchIdValue(json, "special_effect",
String(status.special_effect).c_str(), target,
String(s->status.special_effect).c_str(), target,
requestId)) {
return;
}

// wb_mode
if (!dispatchIdValue(json, "wb_mode", String(status.wb_mode).c_str(),
if (!dispatchIdValue(json, "wb_mode", String(s->status.wb_mode).c_str(),
target, requestId)) {
return;
}

// awb
if (!dispatchIdValue(json, "awb", String(status.awb).c_str(), target,
if (!dispatchIdValue(json, "awb", String(s->status.awb).c_str(), target,
requestId)) {
return;
}

// awb_gain
if (!dispatchIdValue(json, "awb_gain",
String(status.awb_gain).c_str(), target,
String(s->status.awb_gain).c_str(), target,
requestId)) {
return;
}

// aec
if (!dispatchIdValue(json, "aec", String(status.aec).c_str(), target,
if (!dispatchIdValue(json, "aec", String(s->status.aec).c_str(), target,
requestId)) {
return;
}
// aec2
if (!dispatchIdValue(json, "aec2", String(status.aec2).c_str(),
if (!dispatchIdValue(json, "aec2", String(s->status.aec2).c_str(),
target, requestId)) {
return;
}
// ae_level
if (!dispatchIdValue(json, "ae_level",
String(status.ae_level).c_str(), target,
String(s->status.ae_level).c_str(), target,
requestId)) {
return;
}
// aec_value
if (!dispatchIdValue(json, "aec_value",
String(status.aec_value).c_str(), target,
String(s->status.aec_value).c_str(), target,
requestId)) {
return;
}
// agc
if (!dispatchIdValue(json, "agc", String(status.agc).c_str(), target,
if (!dispatchIdValue(json, "agc", String(s->status.agc).c_str(), target,
requestId)) {
return;
}
// agc_gain
if (!dispatchIdValue(json, "agc_gain",
String(status.agc_gain).c_str(), target,
String(s->status.agc_gain).c_str(), target,
requestId)) {
return;
}
// gainceiling
if (!dispatchIdValue(json, "gainceiling",
String(status.gainceiling).c_str(), target,
String(s->status.gainceiling).c_str(), target,
requestId)) {
return;
}
// bpc
if (!dispatchIdValue(json, "bpc", String(status.bpc).c_str(), target,
if (!dispatchIdValue(json, "bpc", String(s->status.bpc).c_str(), target,
requestId)) {
return;
}
// wpc
if (!dispatchIdValue(json, "wpc", String(status.wpc).c_str(), target,
if (!dispatchIdValue(json, "wpc", String(s->status.wpc).c_str(), target,
requestId)) {
return;
}
// raw_gma
if (!dispatchIdValue(json, "raw_gma", String(status.raw_gma).c_str(),
if (!dispatchIdValue(json, "raw_gma", String(s->status.raw_gma).c_str(),
target, requestId)) {
return;
}
// lenc
if (!dispatchIdValue(json, "lenc", String(status.lenc).c_str(),
if (!dispatchIdValue(json, "lenc", String(s->status.lenc).c_str(),
target, requestId)) {
return;
}
// vflip
if (!dispatchIdValue(json, "vflip", String(status.vflip).c_str(),
if (!dispatchIdValue(json, "vflip", String(s->status.vflip).c_str(),
target, requestId)) {
return;
}
// hmirror
if (!dispatchIdValue(json, "hmirror", String(status.hmirror).c_str(),
if (!dispatchIdValue(json, "hmirror", String(s->status.hmirror).c_str(),
target, requestId)) {
return;
}
// dcw
if (!dispatchIdValue(json, "dcw", String(status.dcw).c_str(), target,
if (!dispatchIdValue(json, "dcw", String(s->status.dcw).c_str(), target,
requestId)) {
return;
}
// colorbar
if (!dispatchIdValue(json, "colorbar",
String(status.colorbar).c_str(), target,
String(s->status.colorbar).c_str(), target,
requestId)) {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/commands/ESP999.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void ESP3DCommands::ESP999(int cmd_params_pos, ESP3DMessage* msg) {
tmpstr = get_clean_param(msg, cmd_params_pos);
if (tmpstr.length() == 0) {
hasError = true;
error_msg = "Missing parameter"
error_msg = "Missing parameter";
} else {
if (quietboot) {
if (esp_efuse_set_rom_log_scheme(ESP_EFUSE_ROM_LOG_ON_GPIO_HIGH) !=
Expand All @@ -70,4 +70,4 @@ void ESP3DCommands::ESP999(int cmd_params_pos, ESP3DMessage* msg) {
}

#endif // defined(ARDUINO_ARCH_ESP32) && (CONFIG_IDF_TARGET_ESP32S3 ||
// CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32C3)
// CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32C3)
4 changes: 2 additions & 2 deletions src/core/esp3d_commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -609,14 +609,14 @@ void ESP3DCommands::execute_internal_command(int cmd, int cmd_params_pos,
ESP215(cmd_params_pos, msg);
break;
#endif // DISPLAY_TOUCH_DRIVER
#endif // DISPLAY_DEVICE
#ifdef BUZZER_DEVICE
// Play sound
//[ESP250]F=<frequency> D=<duration> [pwd=<user password>]
case 250:
ESP250(cmd_params_pos, msg);
break;
#endif // BUZZER_DEVICE
#endif // DISPLAY_DEVICE
// Show pins
//[ESP220][pwd=<user password>]
case 220:
Expand Down Expand Up @@ -880,7 +880,7 @@ bool ESP3DCommands::dispatchSetting(bool json, const char *filter,
break;
default: // String
if (index == ESP_STA_PASSWORD || index == ESP_AP_PASSWORD ||
#if ESP3D_NOTIFICATIONS_FEATURE
#if defined (ESP3D_NOTIFICATIONS_FEATURE)
index == ESP_NOTIFICATION_TOKEN1 ||
index == ESP_NOTIFICATION_TOKEN2 ||
#endif // ESP3D_NOTIFICATIONS_FEATURE
Expand Down
7 changes: 4 additions & 3 deletions src/core/esp3d_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#if defined(ESP_SAVE_SETTINGS)
#include "esp3d_message.h"
#include "esp3d_settings.h"
#include "esp3d_string.h"

#if ESP_SAVE_SETTINGS == SETTINGS_IN_EEPROM
#include <EEPROM.h>
Expand Down Expand Up @@ -386,7 +387,7 @@ bool ESP3DSettings::writeByte(int pos, const uint8_t value) {

bool ESP3DSettings::is_string(const char *s, uint len) {
for (uint p = 0; p < len; p++) {
if (!isPrintable(char(s[p]))) {
if (!esp3d_string::isPrintableChar(char(s[p]))) {
return false;
}
}
Expand Down Expand Up @@ -431,7 +432,7 @@ const char *ESP3DSettings::readString(int pos, bool *haserror) {
// read until max size is reached or \0 is found
while (i < size_max && b != 0) {
b = EEPROM.read(pos + i);
byte_buffer[i] = isPrintable(char(b)) ? b : 0;
byte_buffer[i] = esp3d_string::isPrintableChar(char(b)) ? b : 0;
i++;
}

Expand Down Expand Up @@ -778,7 +779,7 @@ bool ESP3DSettings::isValidStringSetting(const char *value,
}
// only printable char allowed
for (size_t i = 0; i < strlen(value); i++) {
if (!isPrintable(value[i])) {
if (!esp3d_string::isPrintableChar(value[i])) {
return false;
}
}
Expand Down
10 changes: 9 additions & 1 deletion src/core/esp3d_string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,12 @@ const char* esp3d_string::formatBytes(uint64_t bytes) {
res = String((float)(bytes / 1024.0 / 1024.0 / 1024.0), 2) + " GB";
}
return res.c_str();
}
}

bool esp3d_string::isPrintableChar(char ch){
int c = static_cast<int>(ch);
if (c==9 || (c >= 32 && c <= 126) || c>=128) {
return true;
}
return false;
}
1 change: 1 addition & 0 deletions src/core/esp3d_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const char* generateUUID(const char* seed);
const char* getContentType(const char* filename);
const char* encodeString(const char* s);
const char* formatBytes(uint64_t bytes);
bool isPrintableChar(char c);
} // namespace esp3d_string

#endif //_ESP3D_STRING_H
2 changes: 1 addition & 1 deletion src/include/esp3d_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#define _VERSION_ESP3D_H

// version and sources location
#define FW_VERSION "3.0.0.a226"
#define FW_VERSION "3.0.0.a227"
#define REPOSITORY "https://github.com/luc-github/ESP3D/tree/3.0"

#endif //_VERSION_ESP3D_H
3 changes: 2 additions & 1 deletion src/modules/bluetooth/BT_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#ifdef BLUETOOTH_FEATURE
#include "../../core/esp3d_commands.h"
#include "../../core/esp3d_settings.h"
#include "../../esp3d_string.h"
#include "../network/netconfig.h"
#include "BT_service.h"
#include "BluetoothSerial.h"
Expand Down Expand Up @@ -215,7 +216,7 @@ void BTService::push2buffer(uint8_t *sbuf, size_t len) {
_buffer_size++;
}
flushbuffer();
} else if (isPrintable(char(sbuf[i]))) {
} else if (esp3d_string::isPrintableChar(char(sbuf[i]))) {
if (_buffer_size < ESP3D_BT_BUFFER_SIZE) {
_buffer[_buffer_size] = sbuf[i];
_buffer_size++;
Expand Down
2 changes: 1 addition & 1 deletion src/modules/notifications/notifications_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ NotificationsService::NotificationsService() {
_started = false;
_notificationType = 0;
_token1 = "";
_token1 = "";
_token2 = "";
_settings = "";
}
NotificationsService::~NotificationsService() { end(); }
Expand Down
4 changes: 2 additions & 2 deletions src/modules/sensor/bmx280.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ uint8_t BMX280SensorDevice::GetModel(uint8_t i) {
const char *BMX280SensorDevice::GetCurrentModelString() {
uint8_t sensortype = ESP3DSettings::readByte(ESP_SENSOR_TYPE);
for (uint8_t i = 0; i < NB_TYPE_SENSOR; i++) {
if ((sensortype == SENSOR_TYPE[i]) {
if (sensortype == SENSOR_ID[i]) {
return SENSOR_NAME[i];
}
}
Expand Down Expand Up @@ -173,7 +173,7 @@ const char *BMX280SensorDevice::GetData() {
}
} else {
s = "DISCONNECTED";
log_esp3_ed("No valid data");
esp3d_log_e("No valid data");
}
}
} else {
Expand Down
6 changes: 4 additions & 2 deletions src/modules/serial/serial_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
COMMUNICATION_PROTOCOL == RAW_SERIAL || defined(ESP_SERIAL_BRIDGE_OUTPUT)
#include "../../core/esp3d_commands.h"
#include "../../core/esp3d_settings.h"
#include "../../core/esp3d_string.h"

#include "serial_service.h"

#if COMMUNICATION_PROTOCOL == MKS_SERIAL
Expand All @@ -36,7 +38,7 @@ HardwareSerial *Serials[MAX_SERIAL] = {&Serial, &Serial1};

#if defined(ARDUINO_ARCH_ESP32)

#if defined(CONFIG_IDF_TARGET_ESP32C3)
#if defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32S2)
#define MAX_SERIAL 2
HardwareSerial *Serials[MAX_SERIAL] = {&Serial, &Serial1};
#else
Expand Down Expand Up @@ -406,7 +408,7 @@ void ESP3DSerialService::push2buffer(uint8_t *sbuf, size_t len) {
_buffer_size++;
}
flushbuffer();
} else if (isPrintable(char(sbuf[i]))) {
} else if (esp3d_string::isPrintableChar(char(sbuf[i]))) {
if (_buffer_size < ESP3D_SERIAL_BUFFER_SIZE) {
_buffer[_buffer_size] = sbuf[i];
_buffer_size++;
Expand Down
3 changes: 2 additions & 1 deletion src/modules/telnet/telnet_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "../../core/esp3d_commands.h"
#include "../../core/esp3d_message.h"
#include "../../core/esp3d_settings.h"
#include "../../core/esp3d_string.h"
#include "../../include/esp3d_version.h"
#include "telnet_server.h"

Expand Down Expand Up @@ -245,7 +246,7 @@ void Telnet_Server::push2buffer(uint8_t *sbuf, size_t len) {
_buffer_size++;
}
flushbuffer();
} else if (isPrintable(char(sbuf[i]))) {
} else if (esp3d_string::isPrintableChar(char(sbuf[i]))) {
if (_buffer_size < ESP3D_TELNET_BUFFER_SIZE) {
_buffer[_buffer_size] = sbuf[i];
_buffer_size++;
Expand Down
Loading

0 comments on commit 7bee09b

Please sign in to comment.