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

Last change on this file since 32 was 15, checked in by Bayard Gildas, 9 years ago

sources reformatted with flair-format-dir script

File size: 2.9 KB
RevLine 
[10]1// %flair:license{
[15]2// This file is part of the Flair framework distributed under the
3// CECILL-C License, Version 1.0.
[10]4// %flair:license}
[7]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
25using std::string;
26using namespace flair::core;
27using namespace flair::gui;
28using namespace flair::filter;
29using namespace flair::meta;
30
[15]31MetaDualShock3_impl::MetaDualShock3_impl(MetaDualShock3 *self, string name)
32 : IODevice((IODevice *)self, name) {
33 joy_ref = new JoyReference(self->GetTab()->NewRow(), "consignes joy");
34 this->self = self;
35 joy_init = false;
36 wasRollTrimUpButtonPressed = false;
37 wasRollTrimDownButtonPressed = false;
38 wasPitchTrimUpButtonPressed = false;
39 wasPitchTrimDownButtonPressed = false;
[7]40}
41
[15]42MetaDualShock3_impl::~MetaDualShock3_impl() {}
[7]43
[15]44// receives updates from the controler
[7]45void MetaDualShock3_impl::UpdateFrom(const io_data *data) {
[15]46 cvmatrix *input = (cvmatrix *)data;
[7]47
[15]48 // on prend une fois pour toute le mutex et on fait des accès directs
49 input->GetMutex();
[7]50
[15]51 // up
52 if (self->IsButtonPressed(12)) {
53 if (!wasPitchTrimDownButtonPressed) {
54 joy_ref->PitchTrimDown();
55 wasPitchTrimDownButtonPressed = true;
[7]56 }
[15]57 } else {
58 wasPitchTrimDownButtonPressed = false;
59 }
[7]60
[15]61 // down
62 if (self->IsButtonPressed(13)) {
63 if (!wasPitchTrimUpButtonPressed) {
64 joy_ref->PitchTrimUp();
65 wasPitchTrimUpButtonPressed = true;
[7]66 }
[15]67 } else {
68 wasPitchTrimUpButtonPressed = false;
69 }
[7]70
[15]71 // right
72 if (self->IsButtonPressed(15)) {
73 if (!wasRollTrimUpButtonPressed) {
74 joy_ref->RollTrimUp();
75 wasRollTrimUpButtonPressed = true;
[7]76 }
[15]77 } else {
78 wasRollTrimUpButtonPressed = false;
79 }
[7]80
[15]81 // left
82 if (self->IsButtonPressed(14)) {
83 if (!wasRollTrimDownButtonPressed) {
84 joy_ref->RollTrimDown();
85 wasRollTrimDownButtonPressed = true;
[7]86 }
[15]87 } else {
88 wasRollTrimDownButtonPressed = false;
89 }
[7]90
[15]91 if (!getFrameworkManager()->ConnectionLost()) {
92 input->GetMutex();
93 joy_ref->SetRollAxis(input->ValueNoMutex(0, 0));
94 joy_ref->SetPitchAxis(input->ValueNoMutex(1, 0));
95 joy_ref->SetYawAxis(input->ValueNoMutex(2, 0));
96 joy_ref->SetAltitudeAxis(input->ValueNoMutex(3, 0));
[7]97 input->ReleaseMutex();
[15]98 } else {
99 joy_ref->SetRollAxis(0);
100 joy_ref->SetPitchAxis(0);
101 joy_ref->SetYawAxis(0);
102 joy_ref->SetAltitudeAxis(0);
103 }
104 input->ReleaseMutex();
[7]105
[15]106 joy_ref->Update(data->DataTime());
[7]107
[15]108 if (!joy_init) {
109 self->TargetEthController::FlashLed(1, 10, 10);
110 joy_init = true;
111 }
[7]112}
Note: See TracBrowser for help on using the repository browser.