Fix an issue and read Period from D-bus

1. Change the order of setTrigger(), setDelayOn() and setDelayOff(),
   because delay_on and delay_off were only displayed after the setTrigger() was excuted.

2. Read Period from D-bus instead of "periodMs = 1000" when the blinkOperation() was excuted.

Change-Id: Ia1ed328aa986be9ccc4072a4a5b48da4a07978db
Signed-off-by: tony lee <tony.lee@quantatw.com>
diff --git a/physical.cpp b/physical.cpp
index ac8bb25..d15cfcd 100644
--- a/physical.cpp
+++ b/physical.cpp
@@ -34,16 +34,13 @@
     {
         // LED is blinking. Get the on and off delays and derive percent duty
         auto delayOn = led.getDelayOn();
-        periodMs = delayOn + led.getDelayOff();
+        uint16_t periodMs = delayOn + led.getDelayOff();
         auto percentScale = periodMs / 100;
         this->dutyOn(delayOn / percentScale);
+        this->period(periodMs);
     }
     else
     {
-        // TODO: Periodicity is hardcoded for now. This will be changed to
-        // this->period() when configurable periodicity is implemented.
-        periodMs = 1000;
-
         // Cache current LED state
         auto brightness = led.getBrightness();
         if (brightness == assert)
@@ -102,12 +99,22 @@
 {
     auto dutyOn = this->dutyOn();
 
+    /*
+      The configuration of the trigger type must precede the configuration of
+      the trigger type properties. From the kernel documentation:
+      "You can change triggers in a similar manner to the way an IO scheduler
+      is chosen (via /sys/class/leds/<device>/trigger). Trigger specific
+      parameters can appear in /sys/class/leds/<device> once a given trigger is
+      selected."
+      Refer:
+      https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/leds/leds-class.txt?h=v5.2#n26
+    */
+    led.setTrigger("timer");
     // Convert percent duty to milliseconds for sysfs interface
-    auto factor = periodMs / 100;
+    auto factor = this->period() / 100.0;
     led.setDelayOn(dutyOn * factor);
     led.setDelayOff((100 - dutyOn) * factor);
 
-    led.setTrigger("timer");
     return;
 }