diff --git a/lib/DnWiFiDoorLock/DnWiFiDoorLock/Arduino/Esp8266/EspAsyncWebServer/Http/ServoButtonController.h b/lib/DnWiFiDoorLock/DnWiFiDoorLock/Arduino/Esp8266/EspAsyncWebServer/Http/ServoButtonController.h index 85f0f7b..f422e8f 100644 --- a/lib/DnWiFiDoorLock/DnWiFiDoorLock/Arduino/Esp8266/EspAsyncWebServer/Http/ServoButtonController.h +++ b/lib/DnWiFiDoorLock/DnWiFiDoorLock/Arduino/Esp8266/EspAsyncWebServer/Http/ServoButtonController.h @@ -529,9 +529,12 @@ namespace DnWiFiDoorLock::Arduino::Esp8266::EspAsyncWebServer::Http { return tl::unexpected{PSTR("No required data given")}; } + // todo: better conversion to int + // `toInt()` uses `atol()` and has no error handling at all… + // * https://en.cppreference.com/w/cpp/string/byte/strtol + // * https://www.cppstories.com/2018/12/fromchars/ const auto newPressingAngle = Servo::Angle::withDegrees(maybeNewPressingAngle->toInt()); const auto newNotPressingAngle = Servo::Angle::withDegrees(maybeNewNotPressingAngle->toInt()); - // todo: what if a negative number was given? const auto newMilliseconds = Button::PressingMilliseconds::create(maybeNewMilliseconds->toInt()); if (!newPressingAngle) { diff --git a/lib/DnWiFiDoorLock/DnWiFiDoorLock/Arduino/Servo/Button.h b/lib/DnWiFiDoorLock/DnWiFiDoorLock/Arduino/Servo/Button.h index b741e24..7c04b9d 100644 --- a/lib/DnWiFiDoorLock/DnWiFiDoorLock/Arduino/Servo/Button.h +++ b/lib/DnWiFiDoorLock/DnWiFiDoorLock/Arduino/Servo/Button.h @@ -21,11 +21,12 @@ namespace DnWiFiDoorLock::Arduino::Servo { public: class PressingMilliseconds final { public: + template static auto create( - uint32_t value + T value ) -> tl::expected { - if (value == 0) { + if (value <= 0) { return tl::unexpected{PSTR("Positive integer required")}; }