Changeset 22 in pacpussensors for trunk/Dualshock/controller.cpp


Ignore:
Timestamp:
08/02/13 16:19:44 (11 years ago)
Author:
phudelai
Message:

New control mode added + Security with the controller

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Dualshock/controller.cpp

    r21 r22  
     1/*********************************************************************
     2//  created:    2012/03/01 - 14:06
     3//  filename:   controller.cpp
     4//
     5//  author:     Pierre Hudelaine
     6//              Copyright Heudiasyc UMR UTC/CNRS 7253
     7//
     8//  version:    $Id: $
     9//
     10//  purpose:    Read the dualshock 3 button using bluetooth
     11//
     12*********************************************************************/
     13
    114#include "controller.h"
    215
     
    4558    struct dualshockButtons_s d;
    4659    d.available = controller.paired;
     60    d.timeout = controller.timeout;
    4761    d.buttons = controller.buttons;
    4862    d.time = road_time();
     
    7387        //std::cerr << "    elem\n";
    7488        //std::cerr << "Select\n";
    75         struct timeval tv = {2, 0}; //timeout = 2s
    76         if (select(fdmax + 1, &fds, NULL, NULL, &tv) < 0)
     89        struct timeval tv = {0, 500 * 1000}; //timeout = 0.5s
     90        int ret = 0;
     91        ret = select(fdmax + 1, &fds, NULL, NULL, &tv);
     92        if (ret < 0)
    7793            throw "Select";
     94       
     95        controller.timeout = (ret == 0 && controller.paired);
    7896
    7997        if (FD_ISSET(csk, &fds))
     
    87105                handle_report(report, nr);
    88106        }
     107        update_shared_memory();
    89108    }
    90109    quit = 2;
     
    129148    controller.addr = baddr;
    130149    controller.paired = 1;
     150    controller.timeout = 0;
    131151    controller.csk = cs;
    132152    controller.isk = is;
     
    149169        HIDP_TRANS_SET_REPORT | HIDP_DATA_RTYPE_OUTPUT, 0x01,
    150170        '\00', '\00', '\00', '\00', '\00', '\00', '\00', '\00',
    151         '\00', static_cast<char>(ledmask[index % 10] << 1),
     171        '\00', static_cast<char>(index << 1),
    152172        LED_PERMANENT,
    153173        LED_PERMANENT,
     
    217237    controller.buttons.axis.z                = buf[47];
    218238    controller.buttons.axis.gZ               = buf[47];
    219 
    220     update_shared_memory();
    221239}
    222240
Note: See TracChangeset for help on using the changeset viewer.