1 | // %flair:license{
|
---|
2 | // This file is part of the Flair framework distributed under the
|
---|
3 | // CECILL-C License, Version 1.0.
|
---|
4 | // %flair:license}
|
---|
5 | // created: 2014/01/14
|
---|
6 | // filename: MetaDualShock3_impl.cpp
|
---|
7 | //
|
---|
8 | // author: Guillaume Sanahuja
|
---|
9 | // Copyright Heudiasyc UMR UTC/CNRS 7253
|
---|
10 | //
|
---|
11 | // version: $Id: $
|
---|
12 | //
|
---|
13 | // purpose: objet integrant la manette DualShock3 et les consignes joystick
|
---|
14 | //
|
---|
15 | //
|
---|
16 | /*********************************************************************/
|
---|
17 |
|
---|
18 | #include "MetaDualShock3_impl.h"
|
---|
19 | #include "MetaDualShock3.h"
|
---|
20 | #include <JoyReference.h>
|
---|
21 | #include <Tab.h>
|
---|
22 | #include <cvmatrix.h>
|
---|
23 | #include <FrameworkManager.h>
|
---|
24 |
|
---|
25 | using std::string;
|
---|
26 | using namespace flair::core;
|
---|
27 | using namespace flair::gui;
|
---|
28 | using namespace flair::filter;
|
---|
29 | using namespace flair::meta;
|
---|
30 |
|
---|
31 | MetaDualShock3_impl::MetaDualShock3_impl(MetaDualShock3 *self, string name) {
|
---|
32 | joy_ref=new JoyReference(self->controller->GetTab()->NewRow(),"consignes joy");
|
---|
33 | this->self = self;
|
---|
34 | joy_init = false;
|
---|
35 | wasRollTrimUpButtonPressed = false;
|
---|
36 | wasRollTrimDownButtonPressed = false;
|
---|
37 | wasPitchTrimUpButtonPressed = false;
|
---|
38 | wasPitchTrimDownButtonPressed = false;
|
---|
39 | }
|
---|
40 |
|
---|
41 | MetaDualShock3_impl::~MetaDualShock3_impl() {}
|
---|
42 |
|
---|
43 | // receives updates from the controler
|
---|
44 | void MetaDualShock3_impl::UpdateFrom(const io_data *data) {
|
---|
45 | cvmatrix *input = (cvmatrix *)data;
|
---|
46 |
|
---|
47 | // on prend une fois pour toute le mutex et on fait des accès directs
|
---|
48 | input->GetMutex();
|
---|
49 |
|
---|
50 | // up
|
---|
51 | if (self->controller->IsButtonPressed(12)) {
|
---|
52 | if (!wasPitchTrimDownButtonPressed) {
|
---|
53 | joy_ref->PitchTrimDown();
|
---|
54 | wasPitchTrimDownButtonPressed = true;
|
---|
55 | }
|
---|
56 | } else {
|
---|
57 | wasPitchTrimDownButtonPressed = false;
|
---|
58 | }
|
---|
59 |
|
---|
60 | // down
|
---|
61 | if (self->controller->IsButtonPressed(13)) {
|
---|
62 | if (!wasPitchTrimUpButtonPressed) {
|
---|
63 | joy_ref->PitchTrimUp();
|
---|
64 | wasPitchTrimUpButtonPressed = true;
|
---|
65 | }
|
---|
66 | } else {
|
---|
67 | wasPitchTrimUpButtonPressed = false;
|
---|
68 | }
|
---|
69 |
|
---|
70 | // right
|
---|
71 | if (self->controller->IsButtonPressed(15)) {
|
---|
72 | if (!wasRollTrimUpButtonPressed) {
|
---|
73 | joy_ref->RollTrimUp();
|
---|
74 | wasRollTrimUpButtonPressed = true;
|
---|
75 | }
|
---|
76 | } else {
|
---|
77 | wasRollTrimUpButtonPressed = false;
|
---|
78 | }
|
---|
79 |
|
---|
80 | // left
|
---|
81 | if (self->controller->IsButtonPressed(14)) {
|
---|
82 | if (!wasRollTrimDownButtonPressed) {
|
---|
83 | joy_ref->RollTrimDown();
|
---|
84 | wasRollTrimDownButtonPressed = true;
|
---|
85 | }
|
---|
86 | } else {
|
---|
87 | wasRollTrimDownButtonPressed = false;
|
---|
88 | }
|
---|
89 |
|
---|
90 | if (!getFrameworkManager()->ConnectionLost()) {
|
---|
91 | input->GetMutex();
|
---|
92 | joy_ref->SetRollAxis(input->ValueNoMutex(0, 0));
|
---|
93 | joy_ref->SetPitchAxis(input->ValueNoMutex(1, 0));
|
---|
94 | joy_ref->SetYawAxis(input->ValueNoMutex(2, 0));
|
---|
95 | joy_ref->SetAltitudeAxis(input->ValueNoMutex(3, 0));
|
---|
96 | input->ReleaseMutex();
|
---|
97 | } else {
|
---|
98 | joy_ref->SetRollAxis(0);
|
---|
99 | joy_ref->SetPitchAxis(0);
|
---|
100 | joy_ref->SetYawAxis(0);
|
---|
101 | joy_ref->SetAltitudeAxis(0);
|
---|
102 | }
|
---|
103 | input->ReleaseMutex();
|
---|
104 |
|
---|
105 | joy_ref->Update(data->DataTime());
|
---|
106 |
|
---|
107 | if (!joy_init) {
|
---|
108 | self->controller->FlashLed(1, 10, 10);
|
---|
109 | joy_init = true;
|
---|
110 | }
|
---|
111 | }
|
---|