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