60682b48d4b68b5eba76bf1aec79eefbad21d802
[led-pattern-ed] / src / led-command-widget.vala
1 /* This file is part of LED Pattern Editor.
2  *
3  * Copyright (C) 2010 Philipp Zabel
4  *
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.
9  *
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.
14  *
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/>.
17  */
18
19 class LedCommandWidget : Gtk.HBox {
20         LedCommand command;
21
22         public LedCommandWidget (LedCommand _command) {
23                 homogeneous = true;
24                 command = _command;
25
26                 string text = "";
27                 switch (command.type) {
28                 case CommandType.UNKNOWN:
29                         LedCommandRX51 cmd = command as LedCommandRX51;
30                         if (cmd != null)
31                                 text = "??? (0x%04x)".printf (cmd.code);
32                         else
33                                 text = "???";
34                         break;
35                 case CommandType.RAMP_WAIT:
36                         text = "Ramp / Wait";
37                         break;
38                 case CommandType.SET_PWM:
39                         text = "Set PWM";
40                         break;
41                 case CommandType.RESET_MUX:
42                         text = "Reset mux";
43                         break;
44                 case CommandType.REPEAT:
45                         text = "Repeat";
46                         break;
47                 case CommandType.STOP:
48                         text = "Stop";
49                         break;
50                 }
51
52                 var label = new Gtk.Label (text);
53                 label.set_alignment (0.0f, 0.5f);
54                 pack_start (label, true, true, 0);
55
56                 switch (command.type) {
57                 case CommandType.RAMP_WAIT:
58                         var selector = new Hildon.TouchSelector.text ();
59                         for (int i = 1; i <= 31; i++)
60                                 selector.append_text ("%.2f ms".printf (i * 0.49));
61                         for (int i = 1; i <= 31; i++)
62                                 selector.append_text ("%.1f ms".printf (i * 15.6));
63                         var picker = new Hildon.PickerButton (Hildon.SizeType.FINGER_HEIGHT,
64                                                               Hildon.ButtonArrangement.VERTICAL);
65                         picker.set_title ("Step time");
66                         picker.set_selector (selector);
67                         int j;
68                         if (command.step_time <= 31*0.49)
69                                 j = (int) ((command.step_time + 0.001) / 0.49) - 1;
70                         else
71                                 j = (int) ((command.step_time + 0.01) / 15.6) + 30;
72                         picker.set_active (j);
73                         picker.value_changed.connect ((s) => {
74                                 double step_time;
75                                 int i = s.get_active ();
76                                 if (i < 31)
77                                         step_time = (i + 1) * 0.49;
78                                 else
79                                         step_time = (i - 30) * 15.6;
80                                 command.ramp_wait (step_time, command.steps);
81                         });
82                         pack_start (picker, true, true, 0);
83
84                         selector = new Hildon.TouchSelector.text ();
85                         for (int i = -255; i < 256; i++)
86                                 selector.append_text ("%+d".printf (i));
87                         picker = new Hildon.PickerButton (Hildon.SizeType.FINGER_HEIGHT,
88                                                           Hildon.ButtonArrangement.VERTICAL);
89                         picker.set_title ("Steps");
90                         picker.set_selector (selector);
91                         picker.set_active (command.steps + 255);
92                         picker.value_changed.connect ((s) => {
93                                 int steps = s.get_active () - 255;
94                                 command.ramp_wait (command.step_time, steps);
95                         });
96                         pack_start (picker, true, true, 0);
97                         break;
98                 case CommandType.SET_PWM:
99                         label = new Gtk.Label ("");
100                         pack_start (label, true, true, 0);
101                         var selector = new Hildon.TouchSelector.text ();
102                         for (int i = 0; i < 256; i++)
103                                 selector.append_text ("%d".printf (i));
104                         var picker = new Hildon.PickerButton (Hildon.SizeType.FINGER_HEIGHT,
105                                                               Hildon.ButtonArrangement.VERTICAL);
106                         picker.set_title ("Level");
107                         picker.set_selector (selector);
108                         picker.set_active (command.level);
109                         picker.value_changed.connect ((s) => {
110                                 int level = s.get_active ();
111                                 command.set_pwm (level);
112                         });
113                         pack_start (picker, true, true, 0);
114                         break;
115                 case CommandType.UNKNOWN:
116                 case CommandType.RESET_MUX:
117                 case CommandType.REPEAT:
118                 case CommandType.STOP:
119                         label = new Gtk.Label ("");
120                         pack_start (label, true, true, 0);
121                         label = new Gtk.Label ("");
122                         pack_start (label, true, true, 0);
123                         break;
124                 }
125         }
126 }