replace read_flash_string

This commit is contained in:
proddy
2021-11-15 14:25:49 +01:00
parent 7197df9812
commit 72c032adff
3 changed files with 20 additions and 21 deletions

View File

@@ -296,7 +296,7 @@ uint8_t Command::call(const uint8_t device_type, const char * cmd, const char *
// add a command to the list, which does not return json // add a command to the list, which does not return json
void Command::add(const uint8_t device_type, const __FlashStringHelper * cmd, const cmd_function_p cb, const __FlashStringHelper * description, uint8_t flags) { void Command::add(const uint8_t device_type, const __FlashStringHelper * cmd, const cmd_function_p cb, const __FlashStringHelper * description, uint8_t flags) {
// if the command already exists for that device type don't add it // if the command already exists for that device type don't add it
if (find_command(device_type, uuid::read_flash_string(cmd).c_str()) != nullptr) { if (find_command(device_type, read_flash_string(cmd).c_str()) != nullptr) {
return; return;
} }
@@ -312,7 +312,7 @@ void Command::add(const uint8_t device_type, const __FlashStringHelper * cmd, co
// flag is fixed to MqttSubFlag::MQTT_SUB_FLAG_NOSUB so there will be no topic subscribed to this // flag is fixed to MqttSubFlag::MQTT_SUB_FLAG_NOSUB so there will be no topic subscribed to this
void Command::add(const uint8_t device_type, const __FlashStringHelper * cmd, const cmd_json_function_p cb, const __FlashStringHelper * description, uint8_t flags) { void Command::add(const uint8_t device_type, const __FlashStringHelper * cmd, const cmd_json_function_p cb, const __FlashStringHelper * description, uint8_t flags) {
// if the command already exists for that device type don't add it // if the command already exists for that device type don't add it
if (find_command(device_type, uuid::read_flash_string(cmd).c_str()) != nullptr) { if (find_command(device_type, read_flash_string(cmd).c_str()) != nullptr) {
return; return;
} }
@@ -334,7 +334,7 @@ Command::CmdFunction * Command::find_command(const uint8_t device_type, const ch
} }
for (auto & cf : cmdfunctions_) { for (auto & cf : cmdfunctions_) {
if (!strcmp(lowerCmd, Helpers::toLower(uuid::read_flash_string(cf.cmd_)).c_str()) && (cf.device_type_ == device_type)) { if (!strcmp(lowerCmd, Helpers::toLower(read_flash_string(cf.cmd_)).c_str()) && (cf.device_type_ == device_type)) {
return &cf; return &cf;
} }
} }
@@ -353,14 +353,14 @@ bool Command::list(const uint8_t device_type, JsonObject & output) {
std::list<std::string> sorted_cmds; std::list<std::string> sorted_cmds;
for (const auto & cf : cmdfunctions_) { for (const auto & cf : cmdfunctions_) {
if ((cf.device_type_ == device_type) && !cf.has_flags(CommandFlag::HIDDEN)) { if ((cf.device_type_ == device_type) && !cf.has_flags(CommandFlag::HIDDEN)) {
sorted_cmds.push_back(uuid::read_flash_string(cf.cmd_)); sorted_cmds.push_back(read_flash_string(cf.cmd_));
} }
} }
sorted_cmds.sort(); sorted_cmds.sort();
for (auto & cl : sorted_cmds) { for (auto & cl : sorted_cmds) {
for (const auto & cf : cmdfunctions_) { for (const auto & cf : cmdfunctions_) {
if ((cf.device_type_ == device_type) && !cf.has_flags(CommandFlag::HIDDEN) && cf.description_ && (cl == uuid::read_flash_string(cf.cmd_))) { if ((cf.device_type_ == device_type) && !cf.has_flags(CommandFlag::HIDDEN) && cf.description_ && (cl == read_flash_string(cf.cmd_))) {
output[cl] = cf.description_; output[cl] = cf.description_;
} }
} }
@@ -380,7 +380,7 @@ void Command::show(uuid::console::Shell & shell, uint8_t device_type, bool verbo
std::list<std::string> sorted_cmds; std::list<std::string> sorted_cmds;
for (const auto & cf : cmdfunctions_) { for (const auto & cf : cmdfunctions_) {
if ((cf.device_type_ == device_type) && !cf.has_flags(CommandFlag::HIDDEN)) { if ((cf.device_type_ == device_type) && !cf.has_flags(CommandFlag::HIDDEN)) {
sorted_cmds.push_back(uuid::read_flash_string(cf.cmd_)); sorted_cmds.push_back(read_flash_string(cf.cmd_));
} }
} }
sorted_cmds.sort(); sorted_cmds.sort();
@@ -400,7 +400,7 @@ void Command::show(uuid::console::Shell & shell, uint8_t device_type, bool verbo
for (auto & cl : sorted_cmds) { for (auto & cl : sorted_cmds) {
// find and print the description // find and print the description
for (const auto & cf : cmdfunctions_) { for (const auto & cf : cmdfunctions_) {
if ((cf.device_type_ == device_type) && !cf.has_flags(CommandFlag::HIDDEN) && cf.description_ && (cl == uuid::read_flash_string(cf.cmd_))) { if ((cf.device_type_ == device_type) && !cf.has_flags(CommandFlag::HIDDEN) && cf.description_ && (cl == read_flash_string(cf.cmd_))) {
uint8_t i = cl.length(); uint8_t i = cl.length();
shell.print(" "); shell.print(" ");
if (cf.has_flags(MQTT_SUB_FLAG_HC)) { if (cf.has_flags(MQTT_SUB_FLAG_HC)) {
@@ -420,7 +420,7 @@ void Command::show(uuid::console::Shell & shell, uint8_t device_type, bool verbo
shell.print(EMSdevice::tag_to_string(TAG_DEVICE_DATA_WW)); shell.print(EMSdevice::tag_to_string(TAG_DEVICE_DATA_WW));
shell.print(' '); shell.print(' ');
} }
shell.print(uuid::read_flash_string(cf.description_)); shell.print(read_flash_string(cf.description_));
if (!cf.has_flags(CommandFlag::ADMIN_ONLY)) { if (!cf.has_flags(CommandFlag::ADMIN_ONLY)) {
shell.print(' '); shell.print(' ');
shell.print(COLOR_BRIGHT_RED); shell.print(COLOR_BRIGHT_RED);

View File

@@ -235,7 +235,7 @@ void EMSESPShell::add_console_commands() {
shell.printfln(F_(bus_id_fmt), settings.ems_bus_id); shell.printfln(F_(bus_id_fmt), settings.ems_bus_id);
char buffer[4]; char buffer[4];
shell.printfln(F_(master_thermostat_fmt), shell.printfln(F_(master_thermostat_fmt),
settings.master_thermostat == 0 ? uuid::read_flash_string(F_(auto)).c_str() settings.master_thermostat == 0 ? read_flash_string(F_(auto)).c_str()
: Helpers::hextoa(buffer, settings.master_thermostat)); : Helpers::hextoa(buffer, settings.master_thermostat));
shell.printfln(F_(board_profile_fmt), settings.board_profile.c_str()); shell.printfln(F_(board_profile_fmt), settings.board_profile.c_str());
}); });
@@ -278,8 +278,7 @@ void EMSESPShell::add_console_commands() {
settings.master_thermostat = value; settings.master_thermostat = value;
EMSESP::actual_master_thermostat(value); // set the internal value too EMSESP::actual_master_thermostat(value); // set the internal value too
char buffer[5]; char buffer[5];
shell.printfln(F_(master_thermostat_fmt), shell.printfln(F_(master_thermostat_fmt), !value ? read_flash_string(F_(auto)).c_str() : Helpers::hextoa(buffer, value));
!value ? uuid::read_flash_string(F_(auto)).c_str() : Helpers::hextoa(buffer, value));
return StateUpdateResult::CHANGED; return StateUpdateResult::CHANGED;
}, },
"local"); "local");
@@ -446,7 +445,7 @@ void EMSESPShell::add_console_commands() {
if (Command::device_has_commands(device_type)) { if (Command::device_has_commands(device_type)) {
for (const auto & cf : Command::commands()) { for (const auto & cf : Command::commands()) {
if (cf.device_type_ == device_type) { if (cf.device_type_ == device_type) {
command_list.emplace_back(uuid::read_flash_string(cf.cmd_)); command_list.emplace_back(read_flash_string(cf.cmd_));
} }
} }
return command_list; return command_list;
@@ -823,14 +822,14 @@ std::string EMSESPShell::prompt_suffix() {
} }
void EMSESPShell::end_of_transmission() { void EMSESPShell::end_of_transmission() {
invoke_command(uuid::read_flash_string(F_(exit))); invoke_command(read_flash_string(F_(exit)));
} }
EMSESPStreamConsole::EMSESPStreamConsole(Stream & stream, bool local) EMSESPStreamConsole::EMSESPStreamConsole(Stream & stream, bool local)
: uuid::console::Shell(commands, ShellContext::MAIN, local ? (CommandFlags::USER | CommandFlags::LOCAL) : CommandFlags::USER) : uuid::console::Shell(commands, ShellContext::MAIN, local ? (CommandFlags::USER | CommandFlags::LOCAL) : CommandFlags::USER)
, uuid::console::StreamConsole(stream) , uuid::console::StreamConsole(stream)
, EMSESPShell() , EMSESPShell()
, name_(uuid::read_flash_string(F("Serial"))) , name_(read_flash_string(F("Serial")))
, pty_(SIZE_MAX) , pty_(SIZE_MAX)
, addr_() , addr_()
, port_(0) { , port_(0) {

View File

@@ -126,9 +126,9 @@ char * Helpers::smallitoa(char * result, const uint16_t value) {
char * Helpers::render_boolean(char * result, bool value) { char * Helpers::render_boolean(char * result, bool value) {
uint8_t bool_format_ = EMSESP::bool_format(); uint8_t bool_format_ = EMSESP::bool_format();
if (bool_format_ == BOOL_FORMAT_ONOFF) { if (bool_format_ == BOOL_FORMAT_ONOFF) {
strlcpy(result, value ? uuid::read_flash_string(F_(on)).c_str() : uuid::read_flash_string(F_(off)).c_str(), 5); strlcpy(result, value ? read_flash_string(F_(on)).c_str() : read_flash_string(F_(off)).c_str(), 5);
} else if (bool_format_ == BOOL_FORMAT_ONOFF_CAP) { } else if (bool_format_ == BOOL_FORMAT_ONOFF_CAP) {
strlcpy(result, value ? uuid::read_flash_string(F_(ON)).c_str() : uuid::read_flash_string(F_(OFF)).c_str(), 5); strlcpy(result, value ? read_flash_string(F_(ON)).c_str() : read_flash_string(F_(OFF)).c_str(), 5);
} else if (bool_format_ == BOOL_FORMAT_TRUEFALSE) { } else if (bool_format_ == BOOL_FORMAT_TRUEFALSE) {
strlcpy(result, value ? "true" : "false", 7); strlcpy(result, value ? "true" : "false", 7);
} else { } else {
@@ -306,7 +306,7 @@ char * Helpers::render_value(char * result, const uint32_t value, const uint8_t
// creates string of hex values from an arrray of bytes // creates string of hex values from an arrray of bytes
std::string Helpers::data_to_hex(const uint8_t * data, const uint8_t length) { std::string Helpers::data_to_hex(const uint8_t * data, const uint8_t length) {
if (length == 0) { if (length == 0) {
return uuid::read_flash_string(F("<empty>")); return read_flash_string(F("<empty>"));
} }
std::string str(160, '\0'); std::string str(160, '\0');
@@ -464,12 +464,12 @@ bool Helpers::value2bool(const char * v, bool & value) {
std::string bool_str = toLower(v); // convert to lower case std::string bool_str = toLower(v); // convert to lower case
if ((bool_str == uuid::read_flash_string(F_(on))) || (bool_str == "1") or (bool_str == "true")) { if ((bool_str == read_flash_string(F_(on))) || (bool_str == "1") or (bool_str == "true")) {
value = true; value = true;
return true; // is a bool return true; // is a bool
} }
if ((bool_str == uuid::read_flash_string(F_(off))) || (bool_str == "0") or (bool_str == "false")) { if ((bool_str == read_flash_string(F_(off))) || (bool_str == "0") or (bool_str == "false")) {
value = false; value = false;
return true; // is a bool return true; // is a bool
} }
@@ -484,8 +484,8 @@ bool Helpers::value2enum(const char * v, uint8_t & value, const __FlashStringHel
} }
std::string str = toLower(v); std::string str = toLower(v);
for (value = 0; strs[value]; value++) { for (value = 0; strs[value]; value++) {
std::string str1 = toLower(uuid::read_flash_string(strs[value])); std::string str1 = toLower(read_flash_string(strs[value]));
if ((str1 == uuid::read_flash_string(F_(off)) && str == "false") || (str1 == uuid::read_flash_string(F_(on)) && str == "true") || (str == str1) if ((str1 == read_flash_string(F_(off)) && str == "false") || (str1 == read_flash_string(F_(on)) && str == "true") || (str == str1)
|| (v[0] == ('0' + value) && v[1] == '\0')) { || (v[0] == ('0' + value) && v[1] == '\0')) {
return true; return true;
} }