1 /* This file is part of LED Pattern Editor.
3 * Copyright (C) 2010 Philipp Zabel
5 * LED Pattern Editor is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * LED Pattern Editor is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with LED Pattern Editor. If not, see <http://www.gnu.org/licenses/>.
19 class LedCommandWidget : Gtk.HBox {
20 private const double CYCLE_TIME_MS = 1000.0 / 32768.0;
24 public LedCommandWidget (LedCommand _command) {
29 switch (command.type) {
30 case CommandType.UNKNOWN:
31 LedCommandRX51 cmd = command as LedCommandRX51;
33 text = "??? (0x%04x)".printf (cmd.code);
37 case CommandType.RAMP_WAIT:
40 case CommandType.SET_PWM:
43 case CommandType.RESET_MUX:
46 case CommandType.GO_TO_START:
49 case CommandType.BRANCH:
55 case CommandType.TRIGGER:
60 var label = new Gtk.Label (text);
61 label.set_alignment (0.0f, 0.5f);
62 pack_start (label, true, true, 0);
64 switch (command.type) {
65 case CommandType.RAMP_WAIT:
66 var selector = new Hildon.TouchSelector.text ();
67 for (int i = 1; i <= 31; i++)
68 selector.append_text ("%.2f ms".printf (i * (16 * CYCLE_TIME_MS)));
69 for (int i = 1; i <= 31; i++)
70 selector.append_text ("%.1f ms".printf (i * (512 * CYCLE_TIME_MS)));
71 var picker = new Hildon.PickerButton (Hildon.SizeType.FINGER_HEIGHT,
72 Hildon.ButtonArrangement.VERTICAL);
73 picker.set_title ("Step time");
74 picker.set_selector (selector);
76 if (command.step_time <= 31*(16 * CYCLE_TIME_MS))
77 j = (int) ((command.step_time + 0.001) / (16 * CYCLE_TIME_MS)) - 1;
79 j = (int) ((command.step_time + 0.01) / (512 * CYCLE_TIME_MS)) + 30;
80 picker.set_active (j);
81 picker.value_changed.connect ((s) => {
83 int i = s.get_active ();
85 step_time = (i + 1) * (16 * CYCLE_TIME_MS);
87 step_time = (i - 30) * (512 * CYCLE_TIME_MS);
88 command.ramp_wait (step_time, command.steps);
90 pack_start (picker, true, true, 0);
92 selector = new Hildon.TouchSelector.text ();
93 for (int i = -255; i < 256; i++)
94 selector.append_text ("%+d".printf (i));
95 picker = new Hildon.PickerButton (Hildon.SizeType.FINGER_HEIGHT,
96 Hildon.ButtonArrangement.VERTICAL);
97 picker.set_title ("Steps");
98 picker.set_selector (selector);
99 picker.set_active (command.steps + 255);
100 picker.value_changed.connect ((s) => {
101 int steps = s.get_active () - 255;
102 command.ramp_wait (command.step_time, steps);
104 pack_start (picker, true, true, 0);
106 case CommandType.SET_PWM:
107 label = new Gtk.Label ("");
108 pack_start (label, true, true, 0);
109 var selector = new Hildon.TouchSelector.text ();
110 for (int i = 0; i < 256; i++)
111 selector.append_text ("%d".printf (i));
112 var picker = new Hildon.PickerButton (Hildon.SizeType.FINGER_HEIGHT,
113 Hildon.ButtonArrangement.VERTICAL);
114 picker.set_title ("Level");
115 picker.set_selector (selector);
116 picker.set_active (command.level);
117 picker.value_changed.connect ((s) => {
118 int level = s.get_active ();
119 command.set_pwm (level);
121 pack_start (picker, true, true, 0);
123 case CommandType.END:
124 var check = new Hildon.CheckButton (Hildon.SizeType.FINGER_HEIGHT);
125 check.set_label ("Reset");
126 check.set_active (command.steps == -255);
127 check.toggled.connect ((s) => {
128 command.steps = s.get_active () ? -255 : 0;
131 pack_start (check, true, true, 0);
132 label = new Gtk.Label ("");
133 pack_start (label, true, true, 0);
135 case CommandType.UNKNOWN:
136 case CommandType.RESET_MUX:
137 case CommandType.GO_TO_START:
138 case CommandType.BRANCH:
139 case CommandType.TRIGGER:
140 label = new Gtk.Label ("");
141 pack_start (label, true, true, 0);
142 label = new Gtk.Label ("");
143 pack_start (label, true, true, 0);