[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>
|
---|
[214] | 22 | #include <Matrix.h>
|
---|
[7] | 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 |
|
---|
[38] | 31 | MetaDualShock3_impl::MetaDualShock3_impl(MetaDualShock3 *self, string name) {
|
---|
| 32 | joy_ref=new JoyReference(self->controller->GetTab()->NewRow(),"consignes joy");
|
---|
[15] | 33 | this->self = self;
|
---|
| 34 | joy_init = false;
|
---|
| 35 | wasRollTrimUpButtonPressed = false;
|
---|
| 36 | wasRollTrimDownButtonPressed = false;
|
---|
| 37 | wasPitchTrimUpButtonPressed = false;
|
---|
| 38 | wasPitchTrimDownButtonPressed = false;
|
---|
[7] | 39 | }
|
---|
| 40 |
|
---|
[15] | 41 | MetaDualShock3_impl::~MetaDualShock3_impl() {}
|
---|
[7] | 42 |
|
---|
[15] | 43 | // receives updates from the controler
|
---|
[7] | 44 | void MetaDualShock3_impl::UpdateFrom(const io_data *data) {
|
---|
[214] | 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 | }
|
---|
[7] | 51 |
|
---|
[15] | 52 | // on prend une fois pour toute le mutex et on fait des accès directs
|
---|
| 53 | input->GetMutex();
|
---|
[7] | 54 |
|
---|
[15] | 55 | // up
|
---|
[38] | 56 | if (self->controller->IsButtonPressed(12)) {
|
---|
[15] | 57 | if (!wasPitchTrimDownButtonPressed) {
|
---|
| 58 | joy_ref->PitchTrimDown();
|
---|
| 59 | wasPitchTrimDownButtonPressed = true;
|
---|
[7] | 60 | }
|
---|
[15] | 61 | } else {
|
---|
| 62 | wasPitchTrimDownButtonPressed = false;
|
---|
| 63 | }
|
---|
[7] | 64 |
|
---|
[15] | 65 | // down
|
---|
[38] | 66 | if (self->controller->IsButtonPressed(13)) {
|
---|
[15] | 67 | if (!wasPitchTrimUpButtonPressed) {
|
---|
| 68 | joy_ref->PitchTrimUp();
|
---|
| 69 | wasPitchTrimUpButtonPressed = true;
|
---|
[7] | 70 | }
|
---|
[15] | 71 | } else {
|
---|
| 72 | wasPitchTrimUpButtonPressed = false;
|
---|
| 73 | }
|
---|
[7] | 74 |
|
---|
[15] | 75 | // right
|
---|
[38] | 76 | if (self->controller->IsButtonPressed(15)) {
|
---|
[15] | 77 | if (!wasRollTrimUpButtonPressed) {
|
---|
| 78 | joy_ref->RollTrimUp();
|
---|
| 79 | wasRollTrimUpButtonPressed = true;
|
---|
[7] | 80 | }
|
---|
[15] | 81 | } else {
|
---|
| 82 | wasRollTrimUpButtonPressed = false;
|
---|
| 83 | }
|
---|
[7] | 84 |
|
---|
[15] | 85 | // left
|
---|
[38] | 86 | if (self->controller->IsButtonPressed(14)) {
|
---|
[15] | 87 | if (!wasRollTrimDownButtonPressed) {
|
---|
| 88 | joy_ref->RollTrimDown();
|
---|
| 89 | wasRollTrimDownButtonPressed = true;
|
---|
[7] | 90 | }
|
---|
[15] | 91 | } else {
|
---|
| 92 | wasRollTrimDownButtonPressed = false;
|
---|
| 93 | }
|
---|
[7] | 94 |
|
---|
[15] | 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));
|
---|
[7] | 101 | input->ReleaseMutex();
|
---|
[15] | 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();
|
---|
[7] | 109 |
|
---|
[15] | 110 | joy_ref->Update(data->DataTime());
|
---|
[7] | 111 |
|
---|
[15] | 112 | if (!joy_init) {
|
---|
[38] | 113 | self->controller->FlashLed(1, 10, 10);
|
---|
[15] | 114 | joy_init = true;
|
---|
| 115 | }
|
---|
[7] | 116 | }
|
---|