Subversion Repositories group.electronics

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
178 pfowler 1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Threading.Tasks;
6
using vJoyInterfaceWrap;
7
 
8
namespace nitdcscore {
9
 
10
 
11
    public class NitvJoy {
12
        public vJoy vjs = new vJoy();
13
        public bool enabled = false;
14
 
15
        public NitvJoy() {
16
            if (!vjs.vJoyEnabled()) {
17
                Console.WriteLine("vJoy driver not enabled or installed\n");
18
            } else {
19
                Console.WriteLine("vJoy Found {0}\n", vjs.GetvJoySerialNumberString());
20
                UInt32 DllVer = 0, DrvVer = 0;
21
                bool match = vjs.DriverMatch(ref DllVer, ref DrvVer);
22
                if (!match) {
23
                    Console.WriteLine("Driver and Dll version to not match\n");
24
                    return;
25
                }
26
 
27
                uint id = 0;
28
                VjdStat status = vjs.GetVJDStatus(id);
29
 
30
                if ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE) && (!vjs.AcquireVJD(id)))) {
31
                    Console.WriteLine("Failed to acquire vJoy id {0}", id);
32
                    return;
33
                }
34
                vjs.ResetVJD(id);
35
                this.enabled = true;
36
            } 
37
        }
38
 
39
        public bool SetAxis(int value, uint id, HID_USAGES axis) {
40
            if (!this.enabled)
41
                return false;
42
 
43
            return vjs.SetAxis(value, id, axis);
44
        }
45
 
46
        public bool SetBtn(bool value, uint id, uint button) {
47
            if (!this.enabled)
48
                return false;
49
 
50
            return vjs.SetBtn(value, id, button);
51
        }
52
    }
53
 
54
 
55
}