Ignore:
Timestamp:
Apr 8, 2016, 3:40:57 PM (5 years ago)
Author:
Bayard Gildas
Message:

sources reformatted with flair-format-dir script

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/FlairSensorActuator/src/TargetController.cpp

    r3 r15  
    3131using std::string;
    3232
    33 namespace flair
    34 {
    35 namespace sensor
    36 {
     33namespace flair {
     34namespace sensor {
    3735
    38 TargetController::TargetController(const FrameworkManager* parent,string name,uint8_t priority) :
    39     Thread(parent,name,priority),IODevice(parent,name) {
    40     main_tab=new Tab(getFrameworkManager()->GetTabWidget(),name);
    41     TabWidget* tab=new TabWidget(main_tab->NewRow(),name);
    42     setup_tab=new Tab(tab,"Reglages");
    43 
     36TargetController::TargetController(const FrameworkManager *parent, string name,
     37                                   uint8_t priority)
     38    : Thread(parent, name, priority), IODevice(parent, name) {
     39  main_tab = new Tab(getFrameworkManager()->GetTabWidget(), name);
     40  TabWidget *tab = new TabWidget(main_tab->NewRow(), name);
     41  setup_tab = new Tab(tab, "Reglages");
    4442}
    4543
    4644TargetController::~TargetController() {
    47     SafeStop();
    48     Join();
     45  SafeStop();
     46  Join();
    4947}
    5048
    5149std::string TargetController::GetAxisName(unsigned int axisId) const {
    52     return string("axis")+std::to_string(axisId);
     50  return string("axis") + std::to_string(axisId);
    5351}
    5452
    5553std::string TargetController::GetButtonName(unsigned int buttonId) const {
    56     return string("button")+std::to_string(buttonId);
     54  return string("button") + std::to_string(buttonId);
    5755}
    5856
    5957bool TargetController::SetLedOn(unsigned int ledId) {
    60     if (!IsControllerActionSupported(ControllerAction::SetLedOn)) return false;
    61     SwitchLedMessage *msgLed=new SwitchLedMessage(true,ledId);
    62     changeStateQueue.push(msgLed);
    63     return true;
     58  if (!IsControllerActionSupported(ControllerAction::SetLedOn))
     59    return false;
     60  SwitchLedMessage *msgLed = new SwitchLedMessage(true, ledId);
     61  changeStateQueue.push(msgLed);
     62  return true;
    6463}
    6564
    6665bool TargetController::SetLedOff(unsigned int ledId) {
    67     if (!IsControllerActionSupported(ControllerAction::SetLedOn)) return false;
    68     SwitchLedMessage *msgLed=new SwitchLedMessage(false,ledId);
    69     changeStateQueue.push(msgLed);
    70     return true;
     66  if (!IsControllerActionSupported(ControllerAction::SetLedOn))
     67    return false;
     68  SwitchLedMessage *msgLed = new SwitchLedMessage(false, ledId);
     69  changeStateQueue.push(msgLed);
     70  return true;
    7171}
    7272
    73 bool TargetController::Rumble(unsigned int leftForce,unsigned int leftTimeout,unsigned int rightForce,unsigned int rightTimeout) {
    74     if (!IsControllerActionSupported(ControllerAction::Rumble)) return false;
    75     RumbleMessage *msgRumble=new RumbleMessage(leftForce,leftTimeout,rightForce,rightTimeout);
    76     changeStateQueue.push(msgRumble);
    77     return true;
     73bool TargetController::Rumble(unsigned int leftForce, unsigned int leftTimeout,
     74                              unsigned int rightForce,
     75                              unsigned int rightTimeout) {
     76  if (!IsControllerActionSupported(ControllerAction::Rumble))
     77    return false;
     78  RumbleMessage *msgRumble =
     79      new RumbleMessage(leftForce, leftTimeout, rightForce, rightTimeout);
     80  changeStateQueue.push(msgRumble);
     81  return true;
    7882}
    7983
    80 bool TargetController::FlashLed(unsigned int ledId,unsigned int onTimeout,unsigned int offTimeout){
    81     if (!IsControllerActionSupported(ControllerAction::FlashLed)) return false;
    82     FlashLedMessage *msgFlashLed=new FlashLedMessage(ledId,onTimeout,offTimeout);
    83     changeStateQueue.push(msgFlashLed);
    84     return true;
     84bool TargetController::FlashLed(unsigned int ledId, unsigned int onTimeout,
     85                                unsigned int offTimeout) {
     86  if (!IsControllerActionSupported(ControllerAction::FlashLed))
     87    return false;
     88  FlashLedMessage *msgFlashLed =
     89      new FlashLedMessage(ledId, onTimeout, offTimeout);
     90  changeStateQueue.push(msgFlashLed);
     91  return true;
    8592}
    8693
    87 float TargetController::GetAxisValue(unsigned int axisId) const{
    88     //TODO we'd better throw an exception here
    89     if (axis==NULL) return 0;
     94float TargetController::GetAxisValue(unsigned int axisId) const {
     95  // TODO we'd better throw an exception here
     96  if (axis == NULL)
     97    return 0;
    9098
    91     axis->GetMutex();
    92     float axisValue=axis->Value(axisId, 0);
    93     axis->ReleaseMutex();
    94     return axisValue;
     99  axis->GetMutex();
     100  float axisValue = axis->Value(axisId, 0);
     101  axis->ReleaseMutex();
     102  return axisValue;
    95103}
    96104
    97 bool TargetController::IsButtonPressed(unsigned int buttonId) const{
    98     //TODO we'd better throw an exception here
    99     if (button==NULL) return false;
     105bool TargetController::IsButtonPressed(unsigned int buttonId) const {
     106  // TODO we'd better throw an exception here
     107  if (button == NULL)
     108    return false;
    100109
    101     button->GetMutex();
    102     bool buttonValue=button->Value(buttonId, 0);
    103     button->ReleaseMutex();
    104     return buttonValue;
     110  button->GetMutex();
     111  bool buttonValue = button->Value(buttonId, 0);
     112  button->ReleaseMutex();
     113  return buttonValue;
    105114}
    106115
    107116void TargetController::Run() {
    108     Message *message;
     117  Message *message;
    109118
    110     if(getFrameworkManager()->ErrorOccured()||!ControllerInitialization()) {
     119  if (getFrameworkManager()->ErrorOccured() || !ControllerInitialization()) {
     120    SafeStop();
     121    Thread::Err("An error occured, we don't proceed with the loop.\n");
     122  } else {
     123
     124    axis = new cvmatrix((IODevice *)this, axisNumber, 1, floatType);
     125    button =
     126        new cvmatrix((IODevice *)this, buttonNumber, 1, SignedIntegerType(8));
     127
     128    while (!ToBeStopped()) {
     129      // Thread::Info("Debug: entering acquisition loop\n");
     130      if (getFrameworkManager()->ConnectionLost() == true)
    111131        SafeStop();
    112         Thread::Err("An error occured, we don't proceed with the loop.\n");
    113     } else {
    114132
    115         axis=new cvmatrix((IODevice *)this,axisNumber,1,floatType);
    116         button=new cvmatrix((IODevice *)this,buttonNumber,1,SignedIntegerType(8));
     133      if (IsDataFrameReady()) {
     134        // Thread::Info("Debug: data frame is ready\n");
    117135
    118         while(!ToBeStopped()) {
    119             //Thread::Info("Debug: entering acquisition loop\n");
    120             if(getFrameworkManager()->ConnectionLost()==true) SafeStop();
     136        AcquireAxisData(*axis);
     137        AcquireButtonData(*button);
    121138
    122             if (IsDataFrameReady()) {
    123                 //Thread::Info("Debug: data frame is ready\n");
     139        // send the data
     140        axis->SetDataTime(GetTime());
     141        ProcessUpdate(axis);
    124142
    125                 AcquireAxisData(*axis);
    126                 AcquireButtonData(*button);
     143        // send pending controller state change request(s)
    127144
    128                 //send the data
    129                 axis->SetDataTime(GetTime());
    130                 ProcessUpdate(axis);
    131 
    132                 //send pending controller state change request(s)
    133 
    134                 while(changeStateQueue.size()!=0) {
    135                     message=changeStateQueue.front();
    136                     if (ProcessMessage(message)) {
    137                         changeStateQueue.pop();
    138                         delete message;
    139                     }
    140                 }
    141             } else {
    142                 //Thread::Info("Debug: relax...\n");
    143                 usleep(20000); //20ms
    144             }
     145        while (changeStateQueue.size() != 0) {
     146          message = changeStateQueue.front();
     147          if (ProcessMessage(message)) {
     148            changeStateQueue.pop();
     149            delete message;
     150          }
    145151        }
     152      } else {
     153        // Thread::Info("Debug: relax...\n");
     154        usleep(20000); // 20ms
     155      }
    146156    }
     157  }
    147158}
    148159
    149 Tab* TargetController::GetTab() const {
    150     return setup_tab;
    151 }
     160Tab *TargetController::GetTab() const { return setup_tab; }
    152161
    153162} // end namespace sensor
Note: See TracChangeset for help on using the changeset viewer.