Align with the LP5521 datasheet
authorPhilipp Zabel <philipp.zabel@gmail.com>
Sat, 27 Feb 2010 09:14:59 +0000 (10:14 +0100)
committerPhilipp Zabel <philipp.zabel@gmail.com>
Sat, 27 Feb 2010 09:14:59 +0000 (10:14 +0100)
Use "End" instead of "Stop", "Go To Start" instead of "Repeat" and
improve the timing information.

src/led-command-widget.vala
src/led-pattern-rx51.vala
src/led-pattern-view.vala
src/led-pattern.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 ("");
index 84c7ca8..fe2dc79 100644 (file)
@@ -158,6 +158,8 @@ class LedPatternRX51 : LedPattern {
 }
 
 class LedCommandRX51 : LedCommand {
+       private const double CYCLE_TIME_MS = 1000.0 / 32768.0;
+
        public uint16 code;
 
        public LedCommandRX51 () {
@@ -165,17 +167,18 @@ class LedCommandRX51 : LedCommand {
 
        public LedCommandRX51.with_code (uint16 _code) {
                code = _code;
+               duration = 16 * CYCLE_TIME_MS;
                if ((code & 0x8000) == 0) {
                        if (code == 0x0000) {
-                               type = CommandType.REPEAT;
+                               type = CommandType.GO_TO_START;
                        } else if ((code & 0x3e00) != 0) {
                                type = CommandType.RAMP_WAIT;
                                steps = code & 0xff;
                                step_time = code >> 9;
                                if ((code & 0x4000) == 0)
-                                       step_time = (code >> 9) * 0.49;
+                                       step_time = (code >> 9) * 16 * CYCLE_TIME_MS;
                                else {
-                                       step_time = ((code & 0x3e00) >> 9) * 15.6;
+                                       step_time = ((code & 0x3e00) >> 9) * 512 * CYCLE_TIME_MS;
                                }
                                duration = step_time * (steps + 1);
                                if ((code & 0x100) != 0)
@@ -185,12 +188,24 @@ class LedCommandRX51 : LedCommand {
                                level = code & 0xff;
                        }
                } else {
-                       if (code == 0x9d80)
+                       if (code == 0x9d80) {
                                type = CommandType.RESET_MUX;
-                       if (code == 0xc000)
-                               type = CommandType.STOP;
-                       //if (code == 0xe0??)
-                       //      type = CommandType.TRIGGER_WAIT;
+                       } else if ((code & ~0x1f8f) == 0xa000) {
+                               type = CommandType.BRANCH;
+                               // 0x1f80: (loop count - 1) << 7
+                               // 0x000f: step number
+                       } else if ((code & ~0x1800) == 0xc000) {
+                               type = CommandType.END;
+                               // 0x1000: interrupt
+                               if ((code & 0x0800) != 0) // Reset
+                                       steps = -255;
+                       } else if ((code & ~ 0x13f0) == 0xe000) {
+                               type = CommandType.TRIGGER;
+                               // 0x1000: wait ext
+                               // 0x0380: wait B G R
+                               // 0x0040: set ext
+                               // ??: set B G R
+                       }
                }
        }
 
@@ -199,16 +214,16 @@ class LedCommandRX51 : LedCommand {
                base.set_pwm (_level);
        }
 
-       public override void ramp_wait (double _step_time, int _steps) requires (_step_time >= 0.49) {
+       public override void ramp_wait (double _step_time, int _steps) requires (_step_time >= (16 * CYCLE_TIME_MS)) {
                int step_time;
-               if (_step_time <= 31*0.49) {
-                       step_time = (int) ((_step_time + 0.001) / 0.49);
+               if (_step_time <= 31 * (16 * CYCLE_TIME_MS)) {
+                       step_time = (int) ((_step_time + 0.001) / (16 * CYCLE_TIME_MS));
                        code = (uint16) step_time << 9;
-                       _step_time = step_time * 0.49;
-               } else if (_step_time <= 31*15.6) {
-                       step_time = (int) ((_step_time + 0.01) / 15.6);
+                       _step_time = step_time * (16 * CYCLE_TIME_MS);
+               } else if (_step_time <= 31*(512 * CYCLE_TIME_MS)) {
+                       step_time = (int) ((_step_time + 0.01) / (512 * CYCLE_TIME_MS));
                        code = 0x4000 | (step_time << 9);
-                       _step_time = step_time * 15.6;
+                       _step_time = step_time * (512 * CYCLE_TIME_MS);
                } else {
                        return;
                }
index a4f7444..89b6163 100644 (file)
@@ -144,23 +144,30 @@ class LedPatternView : Gtk.DrawingArea {
                        ctx.set_line_width (1.0);
 
                        CommandType type = CommandType.UNKNOWN;
+                       int steps = 0;
                        foreach (LedCommandRX51 command in pattern.engine1) {
-                               if (command.type == CommandType.STOP ||
-                                   command.type == CommandType.REPEAT) {
+                               if (command.type == CommandType.END ||
+                                   command.type == CommandType.GO_TO_START) {
                                        type = command.type;
+                                       steps = command.steps;
                                        break;
                                }
                        }
 
-                       if (type == CommandType.STOP) {
+                       if (type == CommandType.END) {
                                ctx.new_path ();
 
                                ctx.move_to (x, y);
-                               ctx.line_to (width - 0.5, y);
+                               if (steps == -255) {
+                                       ctx.line_to (x, height - 0.5);
+                                       ctx.line_to (width - 0.5, height - 0.5);
+                               } else {
+                                       ctx.line_to (width - 0.5, y);
+                               }
 
                                ctx.stroke ();
                        }
-                       if (type == CommandType.REPEAT && pattern.duration > 0.0) {
+                       if (type == CommandType.GO_TO_START && pattern.duration >= 3 * 0.49) {
                                ctx.new_path ();
 
                                for (double offset = pattern.duration; (offset * pps/1000.0) <= width; offset += pattern.duration) {
@@ -189,7 +196,7 @@ class LedPatternView : Gtk.DrawingArea {
 
                                ctx.stroke ();
                        }
-                       if (type == CommandType.REPEAT && pattern.duration == 0.0) {
+                       if (type == CommandType.GO_TO_START && pattern.duration < 3 * 0.49) {
                                ctx.new_path ();
 
 
index 25f1ae5..002048c 100644 (file)
@@ -41,8 +41,10 @@ enum CommandType {
        RESET_MUX,
        SET_PWM,
        RAMP_WAIT,
-       REPEAT,
-       STOP
+       GO_TO_START,
+       BRANCH,
+       END,
+       TRIGGER
 }
 
 class LedCommand : Object {