Align with the LP5521 datasheet
[led-pattern-ed] / src / led-command-widget.vala
index 60682b4..36f18d7 100644 (file)
@@ -17,6 +17,8 @@
  */
 
 class LedCommandWidget : Gtk.HBox {
+       private const double CYCLE_TIME_MS = 1000.0 / 32768.0;
+
        LedCommand command;
 
        public LedCommandWidget (LedCommand _command) {
@@ -39,13 +41,19 @@ class LedCommandWidget : Gtk.HBox {
                        text = "Set PWM";
                        break;
                case CommandType.RESET_MUX:
-                       text = "Reset mux";
+                       text = "Reset Mux";
+                       break;
+               case CommandType.GO_TO_START:
+                       text = "Go To Start";
                        break;
-               case CommandType.REPEAT:
-                       text = "Repeat";
+               case CommandType.BRANCH:
+                       text = "Branch";
                        break;
-               case CommandType.STOP:
-                       text = "Stop";
+               case CommandType.END:
+                       text = "End";
+                       break;
+               case CommandType.TRIGGER:
+                       text = "Trigger";
                        break;
                }
 
@@ -57,26 +65,26 @@ class LedCommandWidget : Gtk.HBox {
                case CommandType.RAMP_WAIT:
                        var selector = new Hildon.TouchSelector.text ();
                        for (int i = 1; i <= 31; i++)
-                               selector.append_text ("%.2f ms".printf (i * 0.49));
+                               selector.append_text ("%.2f ms".printf (i * (16 * CYCLE_TIME_MS)));
                        for (int i = 1; i <= 31; i++)
-                               selector.append_text ("%.1f ms".printf (i * 15.6));
+                               selector.append_text ("%.1f ms".printf (i * (512 * CYCLE_TIME_MS)));
                        var picker = new Hildon.PickerButton (Hildon.SizeType.FINGER_HEIGHT,
                                                              Hildon.ButtonArrangement.VERTICAL);
                        picker.set_title ("Step time");
                        picker.set_selector (selector);
                        int j;
-                       if (command.step_time <= 31*0.49)
-                               j = (int) ((command.step_time + 0.001) / 0.49) - 1;
+                       if (command.step_time <= 31*(16 * CYCLE_TIME_MS))
+                               j = (int) ((command.step_time + 0.001) / (16 * CYCLE_TIME_MS)) - 1;
                        else
-                               j = (int) ((command.step_time + 0.01) / 15.6) + 30;
+                               j = (int) ((command.step_time + 0.01) / (512 * CYCLE_TIME_MS)) + 30;
                        picker.set_active (j);
                        picker.value_changed.connect ((s) => {
                                double step_time;
                                int i = s.get_active ();
                                if (i < 31)
-                                       step_time = (i + 1) * 0.49;
+                                       step_time = (i + 1) * (16 * CYCLE_TIME_MS);
                                else
-                                       step_time = (i - 30) * 15.6;
+                                       step_time = (i - 30) * (512 * CYCLE_TIME_MS);
                                command.ramp_wait (step_time, command.steps);
                        });
                        pack_start (picker, true, true, 0);
@@ -112,10 +120,23 @@ class LedCommandWidget : Gtk.HBox {
                        });
                        pack_start (picker, true, true, 0);
                        break;
+               case CommandType.END:
+                       var check = new Hildon.CheckButton (Hildon.SizeType.FINGER_HEIGHT);
+                       check.set_label ("Reset");
+                       check.set_active (command.steps == -255);
+                       check.toggled.connect ((s) => {
+                               command.steps = s.get_active () ? -255 : 0;
+                               command.changed ();
+                       });
+                       pack_start (check, true, true, 0);
+                       label = new Gtk.Label ("");
+                       pack_start (label, true, true, 0);
+                       break;
                case CommandType.UNKNOWN:
                case CommandType.RESET_MUX:
-               case CommandType.REPEAT:
-               case CommandType.STOP:
+               case CommandType.GO_TO_START:
+               case CommandType.BRANCH:
+               case CommandType.TRIGGER:
                        label = new Gtk.Label ("");
                        pack_start (label, true, true, 0);
                        label = new Gtk.Label ("");