/* 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 { private const double CYCLE_TIME_MS = 1000.0 / 32768.0; 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.GO_TO_START: text = "Go To Start"; break; case CommandType.BRANCH: text = "Branch"; break; case CommandType.END: text = "End"; break; case CommandType.TRIGGER: text = "Trigger"; 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 * (16 * CYCLE_TIME_MS))); for (int i = 1; i <= 31; i++) 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*(16 * CYCLE_TIME_MS)) j = (int) ((command.step_time + 0.001) / (16 * CYCLE_TIME_MS)) - 1; else 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) * (16 * CYCLE_TIME_MS); else step_time = (i - 30) * (512 * CYCLE_TIME_MS); 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.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.GO_TO_START: case CommandType.BRANCH: case CommandType.TRIGGER: label = new Gtk.Label (""); pack_start (label, true, true, 0); label = new Gtk.Label (""); pack_start (label, true, true, 0); break; } } }