button: convert long-press time to std::chrono
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: Ia97dc229b43e32a30e4e57881628ab408896dcfb
diff --git a/meson_config.hpp.in b/meson_config.hpp.in
index ed151f5..6610a44 100644
--- a/meson_config.hpp.in
+++ b/meson_config.hpp.in
@@ -1,5 +1,7 @@
#pragma once
+#include <chrono>
+
constexpr inline auto POWER_DBUS_OBJECT_NAME =
"/xyz/openbmc_project/Chassis/Buttons/Power0";
constexpr inline auto RESET_DBUS_OBJECT_NAME =
@@ -25,4 +27,5 @@
constexpr inline auto POWER_BUTTON_PROFILE = @POWER_BUTTON_PROFILE@;
constexpr inline auto ID_LED_GROUP = @ID_LED_GROUP@;
-constexpr inline const int LONG_PRESS_TIME_MS = @LONG_PRESS_TIME_MS@;
+constexpr inline const auto LONG_PRESS_TIME_MS =
+ std::chrono::milliseconds(@LONG_PRESS_TIME_MS@);
diff --git a/src/button_handler.cpp b/src/button_handler.cpp
index ae9cc5d..aec5367 100644
--- a/src/button_handler.cpp
+++ b/src/button_handler.cpp
@@ -194,8 +194,6 @@
std::string dbusIfaceName;
std::string transitionName;
std::variant<Host::Transition, Chassis::Transition> transition;
- uint64_t durationMs =
- std::chrono::duration_cast<std::chrono::milliseconds>(duration).count();
size_t hostNumber = 0;
auto isMultiHostSystem = isMultiHost();
@@ -211,7 +209,7 @@
// ignore power and reset button events if BMC is selected.
if (isMultiHostSystem && (hostNumber == BMC_POSITION) &&
(powerEventType != PowerEvent::powerReleased) &&
- (durationMs <= LONG_PRESS_TIME_MS))
+ (duration <= LONG_PRESS_TIME_MS))
{
lg2::info(
"handlePowerEvent : BMC selected on multi-host system. ignoring power and reset button events...");
@@ -222,7 +220,7 @@
{
case PowerEvent::powerReleased:
{
- if (durationMs <= LONG_PRESS_TIME_MS)
+ if (duration <= LONG_PRESS_TIME_MS)
{
objPathName = HOST_STATE_OBJECT_NAME + hostNumStr;
dbusIfaceName = hostIface;