source: flair-src/trunk/lib/FlairMeta/src/MetaDualShock3_impl.cpp

Last change on this file was 214, checked in by Sanahuja Guillaume, 5 years ago

matrix

File size: 3.0 KB
Line 
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 <Matrix.h>
23#include <FrameworkManager.h>
24
25using std::string;
26using namespace flair::core;
27using namespace flair::gui;
28using namespace flair::filter;
29using namespace flair::meta;
30
31MetaDualShock3_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
41MetaDualShock3_impl::~MetaDualShock3_impl() {}
42
43// receives updates from the controler
44void MetaDualShock3_impl::UpdateFrom(const io_data *data) {
45 const Matrix* input = dynamic_cast<const Matrix*>(data);
46
47 if (!input) {
48 self->Warn("casting %s to Matrix failed\n",data->ObjectName().c_str());
49 return;
50 }
51
52 // on prend une fois pour toute le mutex et on fait des accès directs
53 input->GetMutex();
54
55 // up
56 if (self->controller->IsButtonPressed(12)) {
57 if (!wasPitchTrimDownButtonPressed) {
58 joy_ref->PitchTrimDown();
59 wasPitchTrimDownButtonPressed = true;
60 }
61 } else {
62 wasPitchTrimDownButtonPressed = false;
63 }
64
65 // down
66 if (self->controller->IsButtonPressed(13)) {
67 if (!wasPitchTrimUpButtonPressed) {
68 joy_ref->PitchTrimUp();
69 wasPitchTrimUpButtonPressed = true;
70 }
71 } else {
72 wasPitchTrimUpButtonPressed = false;
73 }
74
75 // right
76 if (self->controller->IsButtonPressed(15)) {
77 if (!wasRollTrimUpButtonPressed) {
78 joy_ref->RollTrimUp();
79 wasRollTrimUpButtonPressed = true;
80 }
81 } else {
82 wasRollTrimUpButtonPressed = false;
83 }
84
85 // left
86 if (self->controller->IsButtonPressed(14)) {
87 if (!wasRollTrimDownButtonPressed) {
88 joy_ref->RollTrimDown();
89 wasRollTrimDownButtonPressed = true;
90 }
91 } else {
92 wasRollTrimDownButtonPressed = false;
93 }
94
95 if (!getFrameworkManager()->ConnectionLost()) {
96 input->GetMutex();
97 joy_ref->SetRollAxis(input->ValueNoMutex(0, 0));
98 joy_ref->SetPitchAxis(input->ValueNoMutex(1, 0));
99 joy_ref->SetYawAxis(input->ValueNoMutex(2, 0));
100 joy_ref->SetAltitudeAxis(input->ValueNoMutex(3, 0));
101 input->ReleaseMutex();
102 } else {
103 joy_ref->SetRollAxis(0);
104 joy_ref->SetPitchAxis(0);
105 joy_ref->SetYawAxis(0);
106 joy_ref->SetAltitudeAxis(0);
107 }
108 input->ReleaseMutex();
109
110 joy_ref->Update(data->DataTime());
111
112 if (!joy_init) {
113 self->controller->FlashLed(1, 10, 10);
114 joy_init = true;
115 }
116}
Note: See TracBrowser for help on using the repository browser.