Esempio n. 1
0
        public static void AddInputValueChangeTrigger(string triggerName, string code, int value, TriggerWay way)
        {
            Console.WriteLine("Add Trigger \"" + triggerName + "\" on " + code + " " + value);
            InputValueChangeTrigger trigger = new InputValueChangeTrigger
            {
                value = value,
                code  = UnaliasCode(code),
                way   = way
            };

            inputValuesChangeTriggers[triggerName] = trigger;
        }
Esempio n. 2
0
        // Main
        public static void Start()
        {
            logger.Debug("start()");
            int[] vJoyOutIndexes = { 7, 8 };
            vjoy.init(vJoyOutIndexes);
            vjoy.resolution = MID_RANGE - 1;
            logger.Debug("MegaVjoy initialized !");


            // init curves
            foreach (OutAxis axe in (OutAxis[])Enum.GetValues(typeof(OutAxis)))
            {
                outputCurves[axe.ToString()] = new int[MAX_RANGE];
                for (int i = 0; i < MAX_RANGE; ++i)
                {
                    outputCurves[axe.ToString()][i] = i;
                }
                debugFrmCurvedAxis[axe.ToString()] = 50.0;
            }
            // config from user
            Curves.CurveConfigure();
            logger.Debug("Curves initialized !");

            UserMain.Init();
            vjoy.applyValues();
            logger.Debug("UserConfig initialized !");

            // CurveTool.generateBitmapCurve(OutAxis.X);

            logger.JumpLine(3);

            DirectInput            directInput = new DirectInput();
            IList <DeviceInstance> devices     = directInput.GetDevices();

            logger.Debug("Available devices (" + devices.Count + "):");
            logger.JumpLine(1);

            // print available hardware devices
            foreach (DeviceInstance device in devices)
            {
                string name = Global.ReturnCleanASCII(device.InstanceName);
                Guid   guid = device.InstanceGuid;
                Console.WriteLine(name + "[" + guid.ToString() + "]");
            }

            logger.JumpLine(3);
            logger.Debug("Linking hardware devices:");
            logger.JumpLine(1);
            foreach (string expectedInputCode in inputNames)
            {
                bool found = false;

                foreach (DeviceInstance device in devices)
                {
                    string name = Global.ReturnCleanASCII(device.InstanceName);
                    Guid   guid = device.InstanceGuid;

                    if (expectedInputCode == name || expectedInputCode == name + "[" + guid.ToString() + "]")
                    {
                        Console.WriteLine("Acquiring hardware " + expectedInputCode + " ...");
                        JoystickInput joy = new JoystickInput(name, guid, expectedInputCode);
                        hardwareInput.Add(joy);
                        Console.WriteLine("   success !!");
                        logger.JumpLine(1);
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    MessageBox.Show("Input \"" + expectedInputCode + "\" not found.\n Fix code in UserLand:init().");
                    Console.WriteLine(expectedInputCode + " WAS NOT FOUND IN AVAILABLE HARDWARE. Won't be used.");
                }
            }

            // tray icon & window
            new Thread(() =>
            {
                Application.Run(new FrmTrayIcon());
            }).Start();

            if (showDebugForm)
            {
                new Thread(() =>
                {
                    Application.Run(new FrmVisualDebug());
                }).Start();
            }

            if (showKekeFrom)
            {
                new Thread(() =>
                {
                    Application.Run(new FrmStreamKeke());
                }).Start();
            }


            string inputName;
            string inputValue;

            // main refresh run
            while (true)
            {
                if (disable)
                {
                    Thread.Sleep(100);
                    continue;
                }

                Thread.Sleep(1);
                inputValuesIs.Clear();
                inputValueUpdate.Clear();
                long lagStartTick = DateTime.Now.Ticks;

                jiggleIndex++;
                if (jiggleIndex > 1001)
                {
                    jiggleIndex = 0;
                }

                foreach (JoystickInput joyInput in hardwareInput)
                {
                    joyInput.joy.Poll();
                    JoystickUpdate[] data = joyInput.joy.GetBufferedData();
                    processed += data.Length;
                    for (int i = 0; i < data.Length; ++i)
                    {
                        JoystickUpdate dat = data[i];
                        inputName  = joyInput.codeId + ":" + dat.Offset.ToString();
                        inputValue = inputName + ":" + dat.Value;

                        if (debugOutputRawInputInLog)
                        {
                            Console.WriteLine(inputValue);
                        }

                        inputValues[inputName] = dat.Value;
                        inputValuesIs.Add(inputValue);
                        inputValueUpdate[inputName] = dat.Value;
                    }
                } // foreach inputs

                // manage triggers
                foreach (string triggerName in inputValuesChangeTriggers.Keys)
                {
                    InputValueChangeTrigger trigger = inputValuesChangeTriggers[triggerName];
                    trigger.triggered = false;

                    // triggerable
                    if (inputValues.ContainsKey(trigger.code) && inputPreviousValues.ContainsKey(trigger.code))
                    {
                        int  previous  = inputPreviousValues[trigger.code];
                        int  value     = inputValues[trigger.code];
                        bool triggered = false;
                        switch (trigger.way)
                        {
                        case TriggerWay.Up:
                            if (value > trigger.value && previous <= trigger.value)
                            {
                                triggered = true;
                            }
                            break;

                        case TriggerWay.Down:
                            if (value < trigger.value && previous >= trigger.value)
                            {
                                triggered = true;
                            }
                            break;

                        case TriggerWay.Both:
                            if ((value > trigger.value && previous <= trigger.value) || (value > trigger.value && previous <= trigger.value))
                            {
                                triggered = true;
                            }
                            break;
                        }
                        if (triggered)
                        {
                            trigger.triggered = true;
                            Console.WriteLine("Triggered " + triggerName);
                            if (plzOutputToDebugFrm)
                            {
                                debugFrmEvents.Add(triggerName);
                            }
                        }
                    }
                }


                // update previous value
                foreach (string triggerName in inputValuesChangeTriggers.Keys)
                {
                    InputValueChangeTrigger trigger = inputValuesChangeTriggers[triggerName];
                    if (inputValues.ContainsKey(trigger.code))
                    {
                        inputPreviousValues[trigger.code] = inputValues[trigger.code];
                    }
                }

                UserMain.Process(); // todo: check time if too slow warn user
                vjoy.applyValues(); // I made all my modifications, apply them
                engineLag = DateTime.Now.Ticks - lagStartTick;
            } // main loop
        }