More fixes

This commit is contained in:
2023-08-13 20:15:53 +02:00
parent a9794b13bd
commit cca17b7ded
11 changed files with 36 additions and 36 deletions

View File

@ -20,7 +20,7 @@ struct RefAccessorSaveSettings : public virtual espgui::RefAccessor<T>
espgui::RefAccessor<T>::setValue(value); espgui::RefAccessor<T>::setValue(value);
if (!saveProfileSettings()) if (!saveProfileSettings())
return tl::make_unexpected("saveProfileSettings() failed!"); return std::unexpected("saveProfileSettings() failed!");
return {}; return {};
}; };

View File

@ -32,7 +32,7 @@ struct NMotMaxKmhAccessor : public virtual espgui::AccessorInterface<int16_t>
{ {
profileSettings.limits.nMotMax = convertFromKmh(value); profileSettings.limits.nMotMax = convertFromKmh(value);
if (!saveProfileSettings()) if (!saveProfileSettings())
return tl::make_unexpected("saveProfileSettings() failed!"); return std::unexpected("saveProfileSettings() failed!");
return {}; return {};
} }
}; };
@ -80,7 +80,7 @@ struct WheelDiameterInchAccessor : public virtual espgui::AccessorInterface<floa
{ {
// profileSettings.controllerHardware.wheelDiameter = convertFromInch(value); // profileSettings.controllerHardware.wheelDiameter = convertFromInch(value);
// if (!saveProfileSettings()) // if (!saveProfileSettings())
// return tl::make_unexpected("saveProfileSettings() failed!"); // return std::unexpected("saveProfileSettings() failed!");
// return {}; // return {};
return configs.write_config(configs.controllerHardware.wheelDiameter, convertFromInch(value)); return configs.write_config(configs.controllerHardware.wheelDiameter, convertFromInch(value));
} }

View File

@ -199,7 +199,7 @@ typename std::enable_if<
, std::expected<void, std::string>>::type , std::expected<void, std::string>>::type
set_config(ConfigWrapper<T> &config, std::string_view newValue) set_config(ConfigWrapper<T> &config, std::string_view newValue)
{ {
return tl::make_unexpected("Unsupported config type"); return std::unexpected("Unsupported config type");
} }
template<typename T> template<typename T>
@ -211,7 +211,7 @@ set_config(ConfigWrapper<T> &config, std::string_view newValue)
if (cpputils::is_in(newValue, "true", "false")) if (cpputils::is_in(newValue, "true", "false"))
return configs.write_config(config, newValue == "true"); return configs.write_config(config, newValue == "true");
else else
return tl::make_unexpected(fmt::format("only true and false allowed, not {}", newValue)); return std::unexpected(fmt::format("only true and false allowed, not {}", newValue));
} }
template<typename T> template<typename T>
@ -224,7 +224,7 @@ set_config(ConfigWrapper<T> &config, std::string_view newValue)
if (auto parsed = cpputils::fromString<T>(newValue)) if (auto parsed = cpputils::fromString<T>(newValue))
return configs.write_config(config, *parsed); return configs.write_config(config, *parsed);
else else
return tl::make_unexpected(fmt::format("could not parse {}", newValue)); return std::unexpected(fmt::format("could not parse {}", newValue));
} }
template<typename T> template<typename T>
@ -245,7 +245,7 @@ set_config(ConfigWrapper<T> &config, std::string_view newValue)
if (const auto parsed = wifi_stack::fromString<wifi_stack::ip_address_t>(newValue); parsed) if (const auto parsed = wifi_stack::fromString<wifi_stack::ip_address_t>(newValue); parsed)
return configs.write_config(config, *parsed); return configs.write_config(config, *parsed);
else else
return tl::make_unexpected(parsed.error()); return std::unexpected(parsed.error());
} }
template<typename T> template<typename T>
@ -257,7 +257,7 @@ set_config(ConfigWrapper<T> &config, std::string_view newValue)
if (const auto parsed = wifi_stack::fromString<wifi_stack::mac_t>(newValue); parsed) if (const auto parsed = wifi_stack::fromString<wifi_stack::mac_t>(newValue); parsed)
return configs.write_config(config, *parsed); return configs.write_config(config, *parsed);
else else
return tl::make_unexpected(parsed.error()); return std::unexpected(parsed.error());
} }
template<typename T> template<typename T>
@ -271,7 +271,7 @@ set_config(ConfigWrapper<T> &config, std::string_view newValue)
else if (const auto parsed = wifi_stack::fromString<wifi_stack::mac_t>(newValue); parsed) else if (const auto parsed = wifi_stack::fromString<wifi_stack::mac_t>(newValue); parsed)
return configs.write_config(config, *parsed); return configs.write_config(config, *parsed);
else else
return tl::make_unexpected(parsed.error()); return std::unexpected(parsed.error());
} }
template<typename T> template<typename T>
@ -290,7 +290,7 @@ set_config(ConfigWrapper<T> &config, std::string_view newValue)
if (auto parsed = cpputils::fromString<std::underlying_type_t<T>>(newValue)) if (auto parsed = cpputils::fromString<std::underlying_type_t<T>>(newValue))
return configs.write_config(config, T(*parsed)); return configs.write_config(config, T(*parsed));
else else
return tl::make_unexpected(fmt::format("could not parse {}", newValue)); return std::unexpected(fmt::format("could not parse {}", newValue));
} }
void send_config(uint32_t skipCount) void send_config(uint32_t skipCount)
@ -448,7 +448,7 @@ void send_information()
if (const auto *display = currentDisplay->asMenuDisplay()) if (const auto *display = currentDisplay->asMenuDisplay())
{ {
displayObject["name"] = display->text(); displayObject["name"] = display->title();
} }
} }
else else

View File

@ -273,7 +273,7 @@ void CanDebugMenu::update()
if (const auto result = twai_get_status_info(&status_info); result != ESP_OK) if (const auto result = twai_get_status_info(&status_info); result != ESP_OK)
{ {
ESP_LOGE(TAG, "twai_get_status_info() failed with %s", esp_err_to_name(result)); ESP_LOGE(TAG, "twai_get_status_info() failed with %s", esp_err_to_name(result));
m_last_can_status_info = tl::make_unexpected(result); m_last_can_status_info = std::unexpected(result);
} }
else else
{ {

View File

@ -203,7 +203,7 @@ const MenuItemIcon *RandomIcon::icon() const
std::expected<void, std::string> ToggleAccessor::setValue(bool value) std::expected<void, std::string> ToggleAccessor::setValue(bool value)
{ {
if (toggleLocked) if (toggleLocked)
return tl::make_unexpected("cannot be changed while is locked!"); return std::unexpected("cannot be changed while is locked!");
toggle = value; toggle = value;
return {}; return {};
} }

View File

@ -21,7 +21,7 @@ void QrImportDisplay::start()
else else
{ {
ESP_LOGE(TAG, "could not start request: %.*s", result.error().size(), result.error().data()); ESP_LOGE(TAG, "could not start request: %.*s", result.error().size(), result.error().data());
m_result = tl::make_unexpected(std::move(result).error()); m_result = std::unexpected(std::move(result).error());
} }
} }
@ -43,7 +43,7 @@ void QrImportDisplay::update()
{ {
ESP_LOGI(TAG, "%.*s => %.*s", m_nvs_key.size(), m_nvs_key.data(), m_result->size(), m_result->data()); ESP_LOGI(TAG, "%.*s => %.*s", m_nvs_key.size(), m_nvs_key.data(), m_result->size(), m_result->data());
if (const auto result = qrimport::set_qr_code(m_nvs_key, *m_result); !result) if (const auto result = qrimport::set_qr_code(m_nvs_key, *m_result); !result)
m_result = tl::make_unexpected(fmt::format("saving qr failed: {}", esp_err_to_name(result.error()))); m_result = std::unexpected(fmt::format("saving qr failed: {}", esp_err_to_name(result.error())));
} }
else else
ESP_LOGW(TAG, "failed %.*s => %.*s", m_nvs_key.size(), m_nvs_key.data(), m_result.error().size(), m_result.error().data()); ESP_LOGW(TAG, "failed %.*s => %.*s", m_nvs_key.size(), m_nvs_key.data(), m_result.error().size(), m_result.error().data());

View File

@ -29,7 +29,7 @@ void handleOta()
std::expected<void, std::string> triggerOta(std::string_view url) std::expected<void, std::string> triggerOta(std::string_view url)
{ {
if (!configs.feature.ota.isEnabled.value()) if (!configs.feature.ota.isEnabled.value())
return tl::make_unexpected("OTA is not enabled!"); return std::unexpected("OTA is not enabled!");
ESP_LOGI(TAG, "%.*s", url.size(), url.data()); ESP_LOGI(TAG, "%.*s", url.size(), url.data());
@ -41,14 +41,14 @@ std::expected<void, std::string> triggerOta(std::string_view url)
if (const auto result = asyncOta->startTask(); !result) if (const auto result = asyncOta->startTask(); !result)
{ {
ESP_LOGE(TAG, "starting OTA task failed: %.*s", result.error().size(), result.error().data()); ESP_LOGE(TAG, "starting OTA task failed: %.*s", result.error().size(), result.error().data());
return tl::make_unexpected(fmt::format("starting OTA task failed: {}", result.error())); return std::unexpected(fmt::format("starting OTA task failed: {}", result.error()));
} }
asyncOtaTaskStarted = true; asyncOtaTaskStarted = true;
} }
if (const auto result = asyncOta->trigger(url, {}, {}, {}); !result) if (const auto result = asyncOta->trigger(url, {}, {}, {}); !result)
return tl::make_unexpected(std::move(result).error()); return std::unexpected(std::move(result).error());
wifi_stack::delete_scan_result(); wifi_stack::delete_scan_result();

View File

@ -46,7 +46,7 @@ std::expected<std::string, esp_err_t> get_qr_code(std::string_view key)
{ {
if (result != ESP_ERR_NVS_NOT_FOUND) if (result != ESP_ERR_NVS_NOT_FOUND)
ESP_LOGW(TAG, "nvs_get_str() size-only for key %.*s failed with %s", key.size(), key.data(), esp_err_to_name(result)); ESP_LOGW(TAG, "nvs_get_str() size-only for key %.*s failed with %s", key.size(), key.data(), esp_err_to_name(result));
return tl::make_unexpected(result); return std::unexpected(result);
} }
// empty string optimization // empty string optimization
@ -58,7 +58,7 @@ std::expected<std::string, esp_err_t> get_qr_code(std::string_view key)
if (const esp_err_t result = nvs_get_str(handle, key.data(), buf.data(), &length); result != ESP_OK) if (const esp_err_t result = nvs_get_str(handle, key.data(), buf.data(), &length); result != ESP_OK)
{ {
ESP_LOGW(TAG, "nvs_get_str() for key %.*s failed with %s", key.size(), key.data(), esp_err_to_name(result)); ESP_LOGW(TAG, "nvs_get_str() for key %.*s failed with %s", key.size(), key.data(), esp_err_to_name(result));
return tl::make_unexpected(result); return std::unexpected(result);
} }
if (buf.back() == '\n') if (buf.back() == '\n')
@ -74,7 +74,7 @@ std::expected<void, esp_err_t> set_qr_code(std::string_view key, std::string_vie
if (const esp_err_t result = nvs_set_str(handle, key.data(), qrcode.data()); result != ESP_OK) if (const esp_err_t result = nvs_set_str(handle, key.data(), qrcode.data()); result != ESP_OK)
{ {
ESP_LOGW(TAG, "nvs_set_str() for key %.*s failed with %s", key.size(), key.data(), esp_err_to_name(result)); ESP_LOGW(TAG, "nvs_set_str() for key %.*s failed with %s", key.size(), key.data(), esp_err_to_name(result));
return tl::make_unexpected(result); return std::unexpected(result);
} }
return {}; return {};
@ -87,7 +87,7 @@ std::expected<void, esp_err_t> delete_qr_code(std::string_view key)
if (const esp_err_t result = nvs_erase_key(handle, key.data()); result != ESP_OK) if (const esp_err_t result = nvs_erase_key(handle, key.data()); result != ESP_OK)
{ {
ESP_LOGW(TAG, "nvs_erase_key() for key %.*s failed with %s", key.size(), key.data(), esp_err_to_name(result)); ESP_LOGW(TAG, "nvs_erase_key() for key %.*s failed with %s", key.size(), key.data(), esp_err_to_name(result));
return tl::make_unexpected(result); return std::unexpected(result);
} }
return {}; return {};
@ -106,7 +106,7 @@ std::expected<void, std::string> start_qr_request()
{ {
if (!http_request.constructed()) if (!http_request.constructed())
{ {
return tl::make_unexpected("request im oarsch"); return std::unexpected("request im oarsch");
} }
if (auto res = http_request->start(fmt::format("http://qr.bobbycar.cloud/qr/{}.qr", configs.otaUsername.value())); !res) if (auto res = http_request->start(fmt::format("http://qr.bobbycar.cloud/qr/{}.qr", configs.otaUsername.value())); !res)
@ -120,25 +120,25 @@ std::expected<std::string, std::string> check_request()
{ {
if (!http_request.constructed()) if (!http_request.constructed())
{ {
return tl::make_unexpected("request im oarsch"); return std::unexpected("request im oarsch");
} }
if (!http_request->finished()) if (!http_request->finished())
{ {
return tl::make_unexpected("request has not finished"); return std::unexpected("request has not finished");
} }
const auto helper = cpputils::makeCleanupHelper([](){ http_request->clearFinished(); }); const auto helper = cpputils::makeCleanupHelper([](){ http_request->clearFinished(); });
if (const auto result = http_request->result(); !result) if (const auto result = http_request->result(); !result)
{ {
return tl::make_unexpected(result.error()); return std::unexpected(result.error());
} }
else if (http_request->statusCode() != 200) else if (http_request->statusCode() != 200)
{ {
DynamicJsonDocument doc(256); DynamicJsonDocument doc(256);
deserializeJson(doc, http_request->takeBuffer()); deserializeJson(doc, http_request->takeBuffer());
return tl::make_unexpected(fmt::format("{} {}", http_request->statusCode(), doc["error"].as<std::string>())); return std::unexpected(fmt::format("{} {}", http_request->statusCode(), doc["error"].as<std::string>()));
} }
else else
{ {

View File

@ -123,7 +123,7 @@ std::expected<bool, std::string> checkInitializedByName(const std::string& name)
if (schedulerTask.name() == name) if (schedulerTask.name() == name)
return schedulerTask.isInitialized(); return schedulerTask.isInitialized();
} }
return tl::make_unexpected("Task not found: " + std::string{name}); return std::unexpected("Task not found: " + std::string{name});
} }
bool checkEnabledByName(const std::string& name) { bool checkEnabledByName(const std::string& name) {

View File

@ -102,7 +102,7 @@ std::expected<void, std::string> time_requestSync()
{ {
ESP_LOGI("BOBBY", "called"); ESP_LOGI("BOBBY", "called");
if (!sntp_restart()) if (!sntp_restart())
return tl::make_unexpected("sntp_restart() failed"); return std::unexpected("sntp_restart() failed");
return {}; return {};
} }

View File

@ -358,7 +358,7 @@ typename std::enable_if<
, std::expected<void, std::string>>::type , std::expected<void, std::string>>::type
saveSetting(ConfigWrapper<T> &config, std::string_view newValue) saveSetting(ConfigWrapper<T> &config, std::string_view newValue)
{ {
return tl::make_unexpected("Unsupported config type"); return std::unexpected("Unsupported config type");
} }
template<typename T> template<typename T>
@ -370,7 +370,7 @@ saveSetting(ConfigWrapper<T> &config, std::string_view newValue)
if (cpputils::is_in(newValue, "true", "false")) if (cpputils::is_in(newValue, "true", "false"))
return configs.write_config(config, newValue == "true"); return configs.write_config(config, newValue == "true");
else else
return tl::make_unexpected(fmt::format("only true and false allowed, not {}", newValue)); return std::unexpected(fmt::format("only true and false allowed, not {}", newValue));
} }
template<typename T> template<typename T>
@ -383,7 +383,7 @@ saveSetting(ConfigWrapper<T> &config, std::string_view newValue)
if (auto parsed = cpputils::fromString<T>(newValue)) if (auto parsed = cpputils::fromString<T>(newValue))
return configs.write_config(config, *parsed); return configs.write_config(config, *parsed);
else else
return tl::make_unexpected(fmt::format("could not parse {}", newValue)); return std::unexpected(fmt::format("could not parse {}", newValue));
} }
template<typename T> template<typename T>
@ -404,7 +404,7 @@ saveSetting(ConfigWrapper<T> &config, std::string_view newValue)
if (const auto parsed = wifi_stack::fromString<wifi_stack::ip_address_t>(newValue); parsed) if (const auto parsed = wifi_stack::fromString<wifi_stack::ip_address_t>(newValue); parsed)
return configs.write_config(config, *parsed); return configs.write_config(config, *parsed);
else else
return tl::make_unexpected(parsed.error()); return std::unexpected(parsed.error());
} }
template<typename T> template<typename T>
@ -416,7 +416,7 @@ saveSetting(ConfigWrapper<T> &config, std::string_view newValue)
if (const auto parsed = wifi_stack::fromString<wifi_stack::mac_t>(newValue); parsed) if (const auto parsed = wifi_stack::fromString<wifi_stack::mac_t>(newValue); parsed)
return configs.write_config(config, *parsed); return configs.write_config(config, *parsed);
else else
return tl::make_unexpected(parsed.error()); return std::unexpected(parsed.error());
} }
template<typename T> template<typename T>
@ -430,7 +430,7 @@ saveSetting(ConfigWrapper<T> &config, std::string_view newValue)
else if (const auto parsed = wifi_stack::fromString<wifi_stack::mac_t>(newValue); parsed) else if (const auto parsed = wifi_stack::fromString<wifi_stack::mac_t>(newValue); parsed)
return configs.write_config(config, *parsed); return configs.write_config(config, *parsed);
else else
return tl::make_unexpected(parsed.error()); return std::unexpected(parsed.error());
} }
template<typename T> template<typename T>
@ -448,7 +448,7 @@ saveSetting(ConfigWrapper<T> &config, std::string_view newValue)
if (auto parsed = cpputils::fromString<std::underlying_type_t<T>>(newValue)) if (auto parsed = cpputils::fromString<std::underlying_type_t<T>>(newValue))
return configs.write_config(config, T(*parsed)); return configs.write_config(config, T(*parsed));
else else
return tl::make_unexpected(fmt::format("could not parse {}", newValue)); return std::unexpected(fmt::format("could not parse {}", newValue));
} }
} // namespace } // namespace