Пример #1
0
    static void Main(string[] args)
    {
        // Checks if device parameter is defined properly.
        string deviceFile = "";

        if (args.Length == 2 && args[0] == "-d")
        {
            deviceFile = args[1];
        }
        else
        {
            Console.WriteLine("Wrong parameters. Example: ' -d /dev/input/js0'");
            return;
        }

        // Device file from parameter.
        Console.Clear();
        Console.WriteLine(string.Format("Device file: {0}", deviceFile));

        // Check if it exist.
        if (!File.Exists(deviceFile))
        {
            Console.WriteLine("Does not exists !");
            return;
        }

        // Read loop.
        using (FileStream fs = new FileStream(deviceFile, FileMode.Open))
        {
            byte[]   buff = new byte [8];
            Joystick j    = new Joystick();

            while (true)
            {
                // Read 8 bytes from file and analyze.
                fs.Read(buff, 0, 8);
                j.DetectChange(buff);

                int top = 1;

                // Prints Axis values
                foreach (byte key in j.Axis.Keys)
                {
                    writeLine(top, string.Format("Axis{0}: {1}", key, j.Axis[key]));
                    top += 1;
                }

                // Prints Buttons values
                foreach (byte key in j.Button.Keys)
                {
                    writeLine(top, string.Format("Button{0}: {1}", key, j.Button[key]));
                    top += 1;
                }
            }
        }
    }
Пример #2
0
        void JoypadReader(object obj)
        {
            try {
                using (FileStream fs = new FileStream("/dev/input/js0", FileMode.Open))
                {
                    byte[]   buff = new byte [8];
                    Joystick j    = new Joystick();

                    while (true)
                    {
                        // Read 8 bytes from file and analyze.
                        fs.Read(buff, 0, 8);
                        j.DetectChange(buff);

                        // Prints Axis values
                        //foreach (byte key in j.Axis.Keys)
                        //{
                        //	writeLine(top, string.Format("Axis{0}: {1}", key, j.Axis[key]));
                        //}

                        foreach (byte key in j.Button.Keys)
                        {
                            FeuerwehrCloud.Helper.Logger.WriteLine(string.Format("Button{0}: {1}", key, j.Button[key]));
                        }

                        if (j.Button[0] == true)
                        {
                            My.Execute("FeuerwehrCloud.Output.LCDProc", "1", "1", "1. Hauptmenü");
                            My.Execute("FeuerwehrCloud.Output.LCDProc", "1", "2", "2. Service");
                        }
                    }
                }
            } catch (Exception ex) {
                //Helper.Logger.WriteLine (ex.ToString ());
            }
        }