fix dependency
[profile/ivi/ico-vic-carsimulator.git] / src / CJoyStickG25.cpp
1 #include <iostream>
2
3 #include "CJoyStickG25.h"
4
5 CJoyStickG25::CJoyStickG25() : CJoyStickEV() {
6 }
7
8 CJoyStickG25::~CJoyStickG25() {
9 }
10
11 int CJoyStickG25::Open() {
12     m_devName = std::string(D_DEV_NAME_G25);
13     int rfd = CJoyStickEV::Open();
14     if (rfd < 0) {
15         return rfd;
16     }
17
18     if (0 > ioctl(rfd, EVIOCGABS(ABS_X), &m_absInf[E_ABSX])) {
19         std::cerr << "ioctl(EVIOCGABS(ABS_X)) get error" << std::endl;
20         m_absInf[E_ABSX].minimum = 0;
21         m_absInf[E_ABSX].maximum = 16384;
22     }
23     if (0 > ioctl(rfd, EVIOCGABS(ABS_Y), &m_absInf[E_ABSY])) {
24         std::cerr << "ioctl(EVIOCGABS(ABS_Y)) get error" << std::endl;
25         m_absInf[E_ABSY].minimum = -32767;
26         m_absInf[E_ABSY].maximum = 32767;
27     }
28     if (0 > ioctl(rfd, EVIOCGABS(ABS_Z), &m_absInf[E_ABSZ])) {
29         std::cerr << "ioctl(EVIOCGABS(ABS_Z)) get error" << std::endl;
30         m_absInf[E_ABSZ].minimum = -32767;
31         m_absInf[E_ABSZ].maximum = 32767;
32     }
33     if (0 > ioctl(rfd, EVIOCGABS(ABS_HAT0X), &m_absInf[E_ABSHAT0X])) {
34         std::cerr << "ioctl(EVIOCGABS(ABS_HAT0X)) get error" << std::endl;
35         m_absInf[E_ABSHAT0X].minimum = -1;
36         m_absInf[E_ABSHAT0X].maximum = 1;
37     }
38     if (0 > ioctl(rfd, EVIOCGABS(ABS_HAT0Y), &m_absInf[E_ABSHAT0Y])) {
39         std::cerr << "ioctl(EVIOCGABS(ABS_HAT0Y)) get error" << std::endl;
40         m_absInf[E_ABSHAT0Y].minimum = -1;
41         m_absInf[E_ABSHAT0Y].maximum = 1;
42     }
43     return rfd;
44 }
45
46 /**
47  * @brief change input_event value to js_event value
48  * Since the direction of change value is different from the G27.
49  */
50 int CJoyStickG25::getJS_EVENT_AXIS(int& num, int& val,
51                                    const struct input_event& s)
52 {
53     int r = -1;
54     switch (s.code) {
55     case ABS_X:
56         // Convert value Steering
57         //    0 to 16353 -> -32766 to 32767
58         r = JS_EVENT_AXIS;
59         num = (int)s.code;
60         val = calc1pm32767((int)s.value, m_absInf[E_ABSX]);
61         break;
62     case ABS_Y:
63         r = JS_EVENT_AXIS;
64         num = (int)s.code;
65         val = calc3p32767Reverse((int)s.value, m_absInf[E_ABSY]);
66         break;
67     case ABS_Z:
68         r = JS_EVENT_AXIS;
69         num = (int)s.code;
70         val = calc3p32767((int)s.value, m_absInf[E_ABSZ]);
71         break;
72     case ABS_RZ:
73         r = JS_EVENT_AXIS;
74         num = (int)s.code;
75         val = calc3p32767Reverse((int)s.value, m_absInf[E_ABSRZ]);
76         break;
77     case ABS_HAT0X:
78         r = JS_EVENT_AXIS;
79         num = (int)s.code;
80         val = (int)s.value;
81         break;
82     case ABS_HAT0Y:
83         r = JS_EVENT_AXIS;
84         num = (int)s.code;
85         val = (int)s.value;
86         break;
87     defaulr:
88         break;
89     }
90     return r;
91 }