[10] | 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}
|
---|
[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 |
|
---|
| 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): IODevice((IODevice*)self,name) {
|
---|
| 32 | joy_ref=new JoyReference(self->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 | }
|
---|
| 44 |
|
---|
| 45 | //receives updates from the controler
|
---|
| 46 | void MetaDualShock3_impl::UpdateFrom(const io_data *data) {
|
---|
| 47 | cvmatrix *input=(cvmatrix*)data;
|
---|
| 48 |
|
---|
| 49 | //on prend une fois pour toute le mutex et on fait des accès directs
|
---|
| 50 | input->GetMutex();
|
---|
| 51 |
|
---|
| 52 | //up
|
---|
| 53 | if(self->IsButtonPressed(12)) {
|
---|
| 54 | if(!wasPitchTrimDownButtonPressed) {
|
---|
| 55 | joy_ref->PitchTrimDown();
|
---|
| 56 | wasPitchTrimDownButtonPressed=true;
|
---|
| 57 | }
|
---|
| 58 | } else {
|
---|
| 59 | wasPitchTrimDownButtonPressed=false;
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | //down
|
---|
| 63 | if(self->IsButtonPressed(13)) {
|
---|
| 64 | if(!wasPitchTrimUpButtonPressed) {
|
---|
| 65 | joy_ref->PitchTrimUp();
|
---|
| 66 | wasPitchTrimUpButtonPressed=true;
|
---|
| 67 | }
|
---|
| 68 | } else {
|
---|
| 69 | wasPitchTrimUpButtonPressed=false;
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | //right
|
---|
| 73 | if(self->IsButtonPressed(15)) {
|
---|
| 74 | if(!wasRollTrimUpButtonPressed) {
|
---|
| 75 | joy_ref->RollTrimUp();
|
---|
| 76 | wasRollTrimUpButtonPressed=true;
|
---|
| 77 | }
|
---|
| 78 | } else {
|
---|
| 79 | wasRollTrimUpButtonPressed=false;
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | //left
|
---|
| 83 | if(self->IsButtonPressed(14)) {
|
---|
| 84 | if(!wasRollTrimDownButtonPressed) {
|
---|
| 85 | joy_ref->RollTrimDown();
|
---|
| 86 | wasRollTrimDownButtonPressed=true;
|
---|
| 87 | }
|
---|
| 88 | } else {
|
---|
| 89 | wasRollTrimDownButtonPressed=false;
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | if(!getFrameworkManager()->ConnectionLost()) {
|
---|
| 93 | input->GetMutex();
|
---|
| 94 | joy_ref->SetRollAxis(input->ValueNoMutex(0,0));
|
---|
| 95 | joy_ref->SetPitchAxis(input->ValueNoMutex(1,0));
|
---|
| 96 | joy_ref->SetYawAxis(input->ValueNoMutex(2,0));
|
---|
| 97 | joy_ref->SetAltitudeAxis(input->ValueNoMutex(3,0));
|
---|
| 98 | input->ReleaseMutex();
|
---|
| 99 | } else {
|
---|
| 100 | joy_ref->SetRollAxis(0);
|
---|
| 101 | joy_ref->SetPitchAxis(0);
|
---|
| 102 | joy_ref->SetYawAxis(0);
|
---|
| 103 | joy_ref->SetAltitudeAxis(0);
|
---|
| 104 | }
|
---|
| 105 | input->ReleaseMutex();
|
---|
| 106 |
|
---|
| 107 | joy_ref->Update(data->DataTime());
|
---|
| 108 |
|
---|
| 109 | if(!joy_init) {
|
---|
| 110 | self->TargetEthController::FlashLed(1,10,10);
|
---|
| 111 | joy_init=true;
|
---|
| 112 | }
|
---|
| 113 | }
|
---|