Author: lslezak
Date: Tue Oct 11 09:43:49 2011
New Revision: 66373
URL: http://svn.opensuse.org/viewcvs/yast?rev=66373&view=rev
Log:
merged changes from tmp/lslezak/sound branch
(hackweek project - USB joystick support)
Modified:
trunk/sound/ (props changed)
trunk/sound/sound/src/Joystick.ycp
trunk/sound/sound/src/Sound.ycp
trunk/sound/sound/src/card_wizard.ycp
trunk/sound/sound/src/joy_dialog.ycp
trunk/sound/sound/src/joystick.ycp
trunk/sound/sound/src/ui.ycp
trunk/sound/sound/src/volume.ycp
Modified: trunk/sound/sound/src/Joystick.ycp
URL: http://svn.opensuse.org/viewcvs/yast/trunk/sound/sound/src/Joystick.ycp?rev=66373&r1=66372&r2=66373&view=diff
==============================================================================
--- trunk/sound/sound/src/Joystick.ycp (original)
+++ trunk/sound/sound/src/Joystick.ycp Tue Oct 11 09:43:49 2011
@@ -39,6 +39,27 @@
// database entry
global string generic_joystick_translated = _("Generic Analog Joystick");
+ list<map> detected_joysticks = [];
+
+ global list<map> Detected()
+ {
+ return detected_joysticks;
+ }
+
+ global void Detect()
+ {
+ detected_joysticks = (list<map>)SCR::Read(.probe.joystick);
+ }
+
+ /* Reverts the internal joystick configuration to the original state
+ * read by Read() function
+ */
+ global void Revert()
+ {
+ y2milestone("Reverting the joystick config back to: %1", joystick_backup);
+ joystick = joystick_backup;
+ }
+
/**
* Get list of all required joystick kernel modules
* @return list list of modules
@@ -70,6 +91,26 @@
return ret;
}
+ string format_model_line(string model, string attached_to)
+ {
+ return sformat("# Model: %1, Attached to: %2\n", model, attached_to);
+ }
+
+ list<string> parse_model_line(string line)
+ {
+ string regexp = "^#[ \t]*Model: (.*),[ \t]*Attached to:[ \t]*(.*)$";
+
+ string model = regexpsub(line, regexp, "\\1");
+ string attached_to = regexpsub(line, regexp, "\\2");
+
+ if (model == nil) model = "";
+ if (attached_to == nil) attached_to = "";
+
+ y2milestone("Parsed model line: %1 -> model: %2, attached_to: %3", line, model, attached_to);
+
+ return [model, attached_to];
+ }
+
/**
* Read all joystick settings from the SCR
* @param abort A block that can be called by Read to find
@@ -107,6 +148,7 @@
// read model comment
string model = (string) SCR::Read(topath(
sformat(".sysconfig.joystick.JOYSTICK_MODULE_%1.comment",pos)));
+ string attached_to = "";
y2debug("Read model comment: %1", model);
@@ -144,28 +186,14 @@
}
else
{
- // remove comment char
- if (substring(model, 0, 1) == "#")
- {
- if (size(model) > 1)
- {
- model = substring(model, 1);
- }
- else
- {
- model = "";
- }
- }
+ list<string> info = parse_model_line(model);
- // remove new line char
- if (size(model) > 1 &&
- substring(model, size(model) - 1, 1) == "\n")
- {
- model = substring(model, 0, size(model) - 1);
- }
+ model = info[0]:"";
+ attached_to = info[1]:"";
}
- j = add(j, "model", model);
+ j["model"] = model;
+ j["attached_to"] = attached_to;
joystick = add(joystick, j);
@@ -173,6 +201,8 @@
}
joystick_backup = joystick;
+
+ Detect();
return true;
}
@@ -215,13 +245,14 @@
// write model comment
string model = j["model"]:"";
+ string attached_to = j["attached_to"]:"";
// add comment before first model
if (pos == 0)
{
if (size(model) > 0)
{
- model = module_comment + "\n#" + model + "\n";
+ model = module_comment + "\n" + format_model_line(model, attached_to);
}
else
{
@@ -232,7 +263,7 @@
{
if (size(model) > 0)
{
- model = "#" + model + "\n";
+ model = format_model_line(model, attached_to);
}
}
Modified: trunk/sound/sound/src/Sound.ycp
URL: http://svn.opensuse.org/viewcvs/yast/trunk/sound/sound/src/Sound.ycp?rev=66373&r1=66372&r2=66373&view=diff
==============================================================================
--- trunk/sound/sound/src/Sound.ycp (original)
+++ trunk/sound/sound/src/Sound.ycp Tue Oct 11 09:43:49 2011
@@ -138,9 +138,6 @@
*/
global string curr_model = "";
- // if joystick dialog should be started after sound card config
- global boolean conf_joystick = true;
-
/**
* default value of volume for new card
*/
Modified: trunk/sound/sound/src/card_wizard.ycp
URL: http://svn.opensuse.org/viewcvs/yast/trunk/sound/sound/src/card_wizard.ycp?rev=66373&r1=66372&r2=66373&view=diff
==============================================================================
--- trunk/sound/sound/src/card_wizard.ycp (original)
+++ trunk/sound/sound/src/card_wizard.ycp Tue Oct 11 09:43:49 2011
@@ -33,15 +33,8 @@
string modelname = Sound::save_entry["model"]:"";
string modname = Sound::save_entry["module"]:"";
- boolean has_joy = false;
- if (Sound::db_modules[modname, "joystick"]:$[] != $[])
- {
- has_joy = true;
- }
-
- map res = DisplayName (
- modelname, Sound::save_entry["alias"]:"", card_id, flags, has_joy);
+ map res = DisplayName (modelname, Sound::save_entry["alias"]:"", card_id, flags);
symbol ui = res["ui"]:`back;
Modified: trunk/sound/sound/src/joy_dialog.ycp
URL: http://svn.opensuse.org/viewcvs/yast/trunk/sound/sound/src/joy_dialog.ycp?rev=66373&r1=66372&r2=66373&view=diff
==============================================================================
--- trunk/sound/sound/src/joy_dialog.ycp (original)
+++ trunk/sound/sound/src/joy_dialog.ycp Tue Oct 11 09:43:49 2011
@@ -14,18 +14,21 @@
textdomain "sound";
import "Wizard";
+ import "WizardHW";
import "Joystick";
import "Sound";
- import "Joystick";
import "Package";
import "Label";
import "Popup";
+ import "String";
include "sound/joysticks.ycp";
include "sound/ui.ycp";
include "sound/volume_routines.ycp";
+ include "sound/routines.ycp";
- list joylist = [];
+ // notice about USB devices, used at several places
+ string usb_notice = _("USB joysticks do not need any configuration, just connect them.");
/**
* Update the sound card configuration of joystick
@@ -61,380 +64,60 @@
return false;
}
-/**
- * Dialog for joystick testing.
- * @param card_id Sound card card_id
- * @param joymodidx model id
- * @param joymod joystick module
- * @return boolean false when Abort was pressed or some problems occurred
- */
-define boolean joy_test_popup (integer card_id, integer joymodidx,
- string joymod) ``{
- any ret = nil;
- UI::OpenDialog(`opt(`decorated), `HBox(`HSpacing(1.5),
- `VBox(
- `VSpacing(1),
- // Wait text label
- `Label(_("Initializing joystick -- please wait...")),
- `VSpacing(1),
- `PushButton(`id(`done), `opt(`default), Label::AbortButton()),
- `VSpacing(1)
- ),
- `HSpacing(1.5)
- ));
-
- // store old joystick configuration:
- list current_conf = (list) eval (Joystick::joystick);
-
- // if new joystick type was selected:
- boolean testing_new = false;
-
- string modname = Sound::modules_conf [card_id, "module"]:"";
- map joy_entry = Sound::GetJoystickSettings(modname);
- string model = joylist [joymodidx, 1]:"";
-
- // do not translate model in /etc/sysconfig/joystick
- if (model == Joystick::generic_joystick_translated)
- {
- model = Joystick::generic_joystick;
- }
- joy_entry = add(joy_entry, "JOYSTICK_MODULE", joymod);
- joy_entry = add(joy_entry, "model", model);
-
- if (model != current_conf [card_id, "model"]:"")
- testing_new = true;
-
- Joystick::joystick[card_id] = joy_entry;
- y2milestone("Tested joystick configuration: %1", joy_entry);
-
- // unload old and load new modules if necessary:
- if (testing_new)
- {
- Joystick::Stop();
- Joystick::SaveOneJoystick(card_id);
- Joystick::WriteConfig();
- Joystick::StartAndEnable();
- }
-
- // sound card configuration must be changed...
- if (update_sound_card_joy_config (card_id, true))
- {
- // popup text (yes/no)
- if (Popup::YesNo (_("For proper joystick initialization,
-a restart of the sound system is necessary.
-Proceed?")))
- {
- sound_stop ();
- sound_start_tmp(true);
- }
- }
-
- integer js_id = card_id; // default number of device
- list joysticks = [];
- integer i = 0;
-
- sleep (100);
- while (i < 4)
- {
- if (SCR::Execute(.target.bash,
- sformat("echo 2>/dev/null < /dev/input/js%1",i)) == 0)
- {
- joysticks = add (joysticks, i);
- y2milestone("existing device: /dev/input/js%1", i);
- }
- i = i + 1;
- }
- i = 0;
-
- if (size (joysticks) == 0)
- {
- // popup message
- Popup::Message(_("No joystick is connected."));
- if (testing_new)
- {
- Joystick::joystick = current_conf;
- Joystick::Stop();
- Joystick::SaveOneJoystick(card_id);
- Joystick::WriteConfig();
- Joystick::StartAndEnable();
- }
- UI::CloseDialog();
- return false;
- }
-
- if (size (joysticks) > 1)
- {
- UI::CloseDialog ();
- UI::OpenDialog (`opt(`decorated), `HBox(`HSpacing(1.5), `VBox(
- `VSpacing(1),
- // text label
- `Label(_("More than one joystick is connected.
-Select the one to test
-and press some of its buttons several times.
-")),
- `VSpacing(1),
- `PushButton(`id(`abort), `opt(`default), Label::AbortButton()),
- `VSpacing(1)),
- `HSpacing(1.5)
- ));
-
- // more joysticks are connected: run jstest alternately for all ones,
- // until user pushs some button of joystick he want to test
- while (ret == nil)
- {
- ret = UI::PollInput();
- js_id = joysticks [i]:0;
-
- SCR::Execute (.background.run_output,
- sformat("/usr/bin/jstest --event /dev/input/js%1", js_id));
- sleep (500);
-
- if ((boolean) SCR::Read(.background.output_open) &&
- (integer) SCR::Read(.background.newlines)>0)
- {
- list test_output = (list)SCR::Read(.background.newout);
- string last_output = test_output [size (test_output)-1]:"";
- last_output = deletechars (last_output, ",");
- list listed_output = splitstring (last_output," ");
- integer event_type = tointeger (listed_output[2]:"0");
- integer value = tointeger (listed_output [8]:"0");
- if (event_type == 1)
- {
- y2debug ("output from /dev/js%1: %2", js_id, listed_output);
- ret = `found;
- }
- }
- SCR::Execute(.background.kill);
- if (ret != `found)
+ /*
+ * Find index of the sound card in Sound::modules_conf
+ * @param sound card map (as returned from .probe.sound)
+ * @return integer index in Sound::modules_conf
+ */
+ integer find_sound_card_id(map sound_card)
+ {
+ integer i = 0;
+ integer ret = nil;
+
+ foreach(map card, Sound::modules_conf, {
+ if (card["unique_key"]:"" == sound_card["unique_key"]:"")
{
- if (i == size (joysticks))
- i = 0;
- else
- i = i + 1;
+ ret = i;
}
- }
- }
- if (ret == `abort)
- {
- y2debug ("Abort pressed");
- if (testing_new)
- {
- Joystick::joystick = current_conf;
- Joystick::Stop();
- Joystick::SaveOneJoystick(card_id);
- Joystick::WriteConfig();
- Joystick::StartAndEnable();
- }
- UI::CloseDialog();
- return false;
- }
-
- // number of device could be different from card number...
- js_id = joysticks [i]:0;
- SCR::Execute(.background.run_output,
- sformat("/usr/bin/jstest --event /dev/input/js%1",js_id));
-
- // read the output of joystick initialization
- while ((boolean)SCR::Read(.background.output_open) &&
- (integer)SCR::Read(.background.newlines) == 0)
- {
- ret = UI::PollInput();
- if (ret != nil)
- {
- SCR::Execute(.background.kill);
- if (testing_new)
- {
- Joystick::joystick = current_conf;
- Joystick::Stop();
- Joystick::SaveOneJoystick(card_id);
- Joystick::WriteConfig();
- Joystick::StartAndEnable();
- }
- UI::CloseDialog();
- return false;
- }
- }
- // get the number of axes and buttons from the initial jstest output line
- list test_output = (list)SCR::Read(.background.newout);
- string last_output = test_output[0]:"";
- list<string> listed_output = splitstring (last_output," ");
- integer axes = 2;
- integer buttons = 2;
- i = 0;
-
- while (i < size(listed_output))
- {
- // all text parts ("has") depend on output of jstest!
- if (listed_output[i]:"" == "has" && listed_output[i+2]:"" == "axes" )
- axes = tointeger (listed_output[i+1]:"2");
-
- if (listed_output[i]:"" == "and" && listed_output[i+2]:"" == "buttons.")
- buttons = tointeger (listed_output[i+1]:"2");
- i = i + 1;
- }
-
- // generate appropriate dialog for the joystick
- term joy_attrib = `VBox();
- string widget_name = "";
- string widget_id = "";
- integer min = -32767; // see js_event.value in linux/joystick.h
- integer max = 32767;
- i = 0;
-
- while (i < axes)
- {
- // progress bar label
- widget_name = sformat(_("Axis %1"), i);
- widget_id = sformat("Axis %1", i);
- joy_attrib = add (joy_attrib, `ProgressBar(`id(widget_id),
- `opt(`autoShortcut), widget_name, 2*max, max));
- joy_attrib = add (joy_attrib, `VSpacing(1));
- i = i + 1;
- }
-
- i = 0;
- term joy_buttons = `HBox();
- string not_pressed = " ";
- string pressed = UI::Glyph(`CheckMark);
- while (i < buttons)
- {
- // label
- widget_name = sformat(_("Button %1"), i);
- widget_id = sformat ("Button %1", i);
- joy_buttons = add (joy_buttons,
- `Label (`id(widget_id), widget_name + " " + not_pressed));
- joy_buttons = add (joy_buttons, `HSpacing(2));
- i = i + 1;
- }
- joy_attrib = add (joy_attrib, joy_buttons);
-
- UI::CloseDialog();
- UI::OpenDialog(`opt(`decorated), `HBox(`HSpacing(1.5),
- `VSpacing(18),
- `VBox(
- `HSpacing(50),
- `VSpacing(1),
- // Popup label
- `Label(_("Joystick Test")),
- `VSpacing(1),
- joy_attrib,
- `VSpacing(1),
- `PushButton(`id(`done), `opt(`default), Label::OKButton()),
- `VSpacing(1)
- ),
- `HSpacing(1.5)
- ));
-
- // read the jstest output until "OK" button is pushed
- do
- {
- if ((boolean)SCR::Read(.background.output_open) &&
- (integer)SCR::Read(.background.newlines)>0)
- {
- // read the output line from jstest:
- test_output = (list)SCR::Read(.background.newout);
- // select the last item of the list:
- last_output = test_output [ size(test_output) - 1 ]:"";
- last_output = deletechars (last_output, ",");
-
- listed_output = splitstring (last_output," ");
- listed_output = filter (string l, listed_output, ``(l != ""));
-
- // positions in list depend on jstest output!
- integer type = tointeger (listed_output[2]:"0");
- integer number = tointeger (listed_output[6]:"0");
- integer val = tointeger (listed_output[8]:"0");
-
- if (type == 1)
- {
- // button pressed
- if (val == 1)
- UI::ChangeWidget(`id(sformat("Button %1", number)), `Value,
- // label text ("Button" is joystick's button no. %1)
- sformat(_("Button %1"), number) + " " + pressed);
- else
- UI::ChangeWidget(`id(sformat("Button %1", number)), `Value,
- sformat(_("Button %1"), number) + " " + not_pressed);
- }
- else if (type == 2)
- {
- // change in some axis
- UI::ChangeWidget(`id(sformat ("Axis %1", number)), `Value, max + val) ;
- }
- }
- ret = UI::PollInput();
- }
- while (ret == nil);
-
- SCR::Execute(.background.kill);
-
- // back to the old values
- Joystick::joystick = current_conf;
- if (testing_new)
- {
- Joystick::Stop();
- Joystick::SaveOneJoystick(card_id);
- Joystick::WriteConfig();
- Joystick::StartAndEnable();
+
+ i = i + 1;
+ });
+
+ return ret;
}
- UI::CloseDialog();
- return true;
-}
/**
* Joystick configuration dialog.
* Configuration of joystick attached to specified sound card.
- * @param card_id Sound card card_id
+ * @param joy_id Joystick index (in the sysconfig file)
* @param button Label for `next button: `finish, `ok or `next
* @return symbol Id of pressed button in the dialog
*/
- define symbol joy_dialog (integer card_id, symbol button) ``{
-
- // item in joystick types
- string nonejoy = _("No joystick");
-
- if (card_id == nil)
+ define symbol joy_dialog (integer joy_id, symbol button, map sound_card) ``{
+ if (joy_id == nil)
{
return `back;
}
- list jcards = Sound::GetSoundCardListWithJoy();
-
// find card name
- string cardname = "";
- foreach (map card, (list