physical: Fix bugprone-narrowing-conversions
```
/home/andrew/src/openbmc/phosphor-led-sysfs/build/../physical.cpp:120:20: error: narrowing conversion from 'double' to 'unsigned long' [bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions,-warnings-as-errors]
led.setDelayOn(dutyOn * factor);
^
/home/andrew/src/openbmc/phosphor-led-sysfs/build/../physical.cpp:121:21: error: narrowing conversion from 'double' to 'unsigned long' [bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions,-warnings-as-errors]
led.setDelayOff((100 - dutyOn) * factor);
^
```
Change-Id: Ic7dbacac3b636a209a743063182d324165bbbaa1
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
diff --git a/physical.cpp b/physical.cpp
index 214e31b..fc518f8 100644
--- a/physical.cpp
+++ b/physical.cpp
@@ -100,8 +100,6 @@
void Physical::blinkOperation()
{
- auto dutyOn = this->dutyOn();
-
/*
The configuration of the trigger type must precede the configuration of
the trigger type properties. From the kernel documentation:
@@ -112,11 +110,17 @@
Refer:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/leds/leds-class.txt?h=v5.2#n26
*/
+ auto d = static_cast<unsigned long>(dutyOn());
+ if (d > 100)
+ {
+ d = 100;
+ }
+
+ auto p = static_cast<unsigned long>(period());
+
led.setTrigger("timer");
- // Convert percent duty to milliseconds for sysfs interface
- auto factor = this->period() / 100.0;
- led.setDelayOn(dutyOn * factor);
- led.setDelayOff((100 - dutyOn) * factor);
+ led.setDelayOn(p * d / 100UL);
+ led.setDelayOff(p * (100UL - d) / 100UL);
}
/** @brief set led color property in DBus*/