Subversion Repositories group.electronics

Rev

Rev 178 | Blame | Compare with Previous | Last modification | View Log | RSS feed

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using vJoyInterfaceWrap;

namespace nitdcscore {


    public class NitvJoy {
        public vJoy vjs = new vJoy();
        public bool enabled = false;

        public NitvJoy() {
            if (!vjs.vJoyEnabled()) {
                Console.WriteLine("vJoy driver not enabled or installed\n");
            } else {
                Console.WriteLine("vJoy Found {0}\n", vjs.GetvJoySerialNumberString());
                UInt32 DllVer = 0, DrvVer = 0;
                bool match = vjs.DriverMatch(ref DllVer, ref DrvVer);
                if (!match) {
                    Console.WriteLine("Driver and Dll version to not match\n");
                    return;
                }

                uint id = 1;
                VjdStat status = vjs.GetVJDStatus(id);

                if ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE) && (!vjs.AcquireVJD(id)))) {
                    Console.WriteLine("Failed to acquire vJoy id {0}", id);
                    return;
                }
                vjs.ResetVJD(id);
                this.enabled = true;
            } 
        }

        public bool SetAxis(int value, uint id, HID_USAGES axis) {
            if (!this.enabled)
                return false;

            return vjs.SetAxis(value, id, axis);
        }

        public bool SetBtn(bool value, uint id, uint button) {
            if (!this.enabled)
                return false;

            return vjs.SetBtn(value, id, button);
        }
    }


}