From 8baa4d6b5dcef733d145194d0728668351977462 Mon Sep 17 00:00:00 2001 From: Philipp Zabel Date: Wed, 24 Feb 2010 18:16:42 +0100 Subject: [PATCH] Add LED command widget --- Makefile | 1 + src/led-command-widget.vala | 126 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 127 insertions(+) create mode 100644 src/led-command-widget.vala diff --git a/Makefile b/Makefile index a10f1e8..e7863fd 100644 --- a/Makefile +++ b/Makefile @@ -31,6 +31,7 @@ led_pattern_editor_SOURCES = $(patsubst %.vala,%.c,${led_pattern_editor_VALASOUR led_pattern_editor_VALASOURCES = \ src/led-pattern-editor.vala \ + src/led-command-widget.vala \ src/led-pattern.vala \ src/led-pattern-rx51.vala \ src/led-pattern-dialog.vala \ diff --git a/src/led-command-widget.vala b/src/led-command-widget.vala new file mode 100644 index 0000000..60682b4 --- /dev/null +++ b/src/led-command-widget.vala @@ -0,0 +1,126 @@ +/* This file is part of LED Pattern Editor. + * + * Copyright (C) 2010 Philipp Zabel + * + * LED Pattern Editor is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * LED Pattern Editor is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with LED Pattern Editor. If not, see . + */ + +class LedCommandWidget : Gtk.HBox { + LedCommand command; + + public LedCommandWidget (LedCommand _command) { + homogeneous = true; + command = _command; + + string text = ""; + switch (command.type) { + case CommandType.UNKNOWN: + LedCommandRX51 cmd = command as LedCommandRX51; + if (cmd != null) + text = "??? (0x%04x)".printf (cmd.code); + else + text = "???"; + break; + case CommandType.RAMP_WAIT: + text = "Ramp / Wait"; + break; + case CommandType.SET_PWM: + text = "Set PWM"; + break; + case CommandType.RESET_MUX: + text = "Reset mux"; + break; + case CommandType.REPEAT: + text = "Repeat"; + break; + case CommandType.STOP: + text = "Stop"; + break; + } + + var label = new Gtk.Label (text); + label.set_alignment (0.0f, 0.5f); + pack_start (label, true, true, 0); + + switch (command.type) { + 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)); + for (int i = 1; i <= 31; i++) + selector.append_text ("%.1f ms".printf (i * 15.6)); + 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; + else + j = (int) ((command.step_time + 0.01) / 15.6) + 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; + else + step_time = (i - 30) * 15.6; + command.ramp_wait (step_time, command.steps); + }); + pack_start (picker, true, true, 0); + + selector = new Hildon.TouchSelector.text (); + for (int i = -255; i < 256; i++) + selector.append_text ("%+d".printf (i)); + picker = new Hildon.PickerButton (Hildon.SizeType.FINGER_HEIGHT, + Hildon.ButtonArrangement.VERTICAL); + picker.set_title ("Steps"); + picker.set_selector (selector); + picker.set_active (command.steps + 255); + picker.value_changed.connect ((s) => { + int steps = s.get_active () - 255; + command.ramp_wait (command.step_time, steps); + }); + pack_start (picker, true, true, 0); + break; + case CommandType.SET_PWM: + label = new Gtk.Label (""); + pack_start (label, true, true, 0); + var selector = new Hildon.TouchSelector.text (); + for (int i = 0; i < 256; i++) + selector.append_text ("%d".printf (i)); + var picker = new Hildon.PickerButton (Hildon.SizeType.FINGER_HEIGHT, + Hildon.ButtonArrangement.VERTICAL); + picker.set_title ("Level"); + picker.set_selector (selector); + picker.set_active (command.level); + picker.value_changed.connect ((s) => { + int level = s.get_active (); + command.set_pwm (level); + }); + pack_start (picker, true, true, 0); + break; + case CommandType.UNKNOWN: + case CommandType.RESET_MUX: + case CommandType.REPEAT: + case CommandType.STOP: + label = new Gtk.Label (""); + pack_start (label, true, true, 0); + label = new Gtk.Label (""); + pack_start (label, true, true, 0); + break; + } + } +} -- 1.7.9.5