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

sources reformatted with flair-format-dir script

File:
1 edited

Legend:

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

    r3 r15  
    2929using namespace flair::actuator;
    3030
    31 XBldc_impl::XBldc_impl(XBldc* self,I2cPort* i2cport) {
    32     this->self=self;
    33         this->i2cport=i2cport;
     31XBldc_impl::XBldc_impl(XBldc *self, I2cPort *i2cport) {
     32  this->self = self;
     33  this->i2cport = i2cport;
    3434
    35     i2cport->SetTxTimeout(5000000);
     35  i2cport->SetTxTimeout(5000000);
    3636}
    3737
    38 XBldc_impl::~XBldc_impl() {
    39 }
     38XBldc_impl::~XBldc_impl() {}
    4039
    41 void XBldc_impl::SetMotors(float* value) {
    42     uint8_t tosend_value[5];
     40void XBldc_impl::SetMotors(float *value) {
     41  uint8_t tosend_value[5];
    4342
    44     for(int i=0;i<4;i++) tosend_value[i]=(uint8_t)(MAX_VALUE*value[i]);
     43  for (int i = 0; i < 4; i++)
     44    tosend_value[i] = (uint8_t)(MAX_VALUE * value[i]);
    4545
    46     ssize_t written;
    47     tosend_value[4]=0xaa;
    48     for(int i=0;i<4;i++) tosend_value[4]+=tosend_value[i];
    49     self->Err("please verify motors adresses\n");
    50     //todo faire la procedure changement addresse par la station sol
    51 /*
    52     i2cport->GetMutex();
    53     i2cport->SetSlave(BASE_ADDRESS);
     46  ssize_t written;
     47  tosend_value[4] = 0xaa;
     48  for (int i = 0; i < 4; i++)
     49    tosend_value[4] += tosend_value[i];
     50  self->Err("please verify motors adresses\n");
     51  // todo faire la procedure changement addresse par la station sol
     52  /*
     53      i2cport->GetMutex();
     54      i2cport->SetSlave(BASE_ADDRESS);
    5455
    55     written =i2cport->Write(tosend_value, sizeof(tosend_value));
    56     if(written<0)
    57     {
    58         self->Err("rt_dev_write error (%s)\n",strerror(-written));
    59     }
    60     else if (written != sizeof(tosend_value))
    61     {
    62         self->Err("rt_dev_write error %i/%i\n",written,sizeof(tosend_value));
    63     }
     56      written =i2cport->Write(tosend_value, sizeof(tosend_value));
     57      if(written<0)
     58      {
     59          self->Err("rt_dev_write error (%s)\n",strerror(-written));
     60      }
     61      else if (written != sizeof(tosend_value))
     62      {
     63          self->Err("rt_dev_write error %i/%i\n",written,sizeof(tosend_value));
     64      }
    6465
    65     i2cport->ReleaseMutex();*/
    66 
     66      i2cport->ReleaseMutex();*/
    6767}
    6868/*
     
    9494*/
    9595void XBldc_impl::ChangeDirection(uint8_t moteur) {
    96     unsigned char tx[4];
    97     ssize_t written;
     96  unsigned char tx[4];
     97  ssize_t written;
    9898
    99     tx[0]=254;
    100     tx[1]=moteur;
    101     tx[2]=0;
    102     tx[3]=234+moteur;
     99  tx[0] = 254;
     100  tx[1] = moteur;
     101  tx[2] = 0;
     102  tx[3] = 234 + moteur;
    103103
    104     i2cport->GetMutex();
    105     i2cport->SetSlave(BASE_ADDRESS);
     104  i2cport->GetMutex();
     105  i2cport->SetSlave(BASE_ADDRESS);
    106106
    107     written =i2cport->Write(tx, sizeof(tx));
    108     if(written<0) {
    109         self->Err("rt_dev_write (%s) error\n",strerror(-written));
    110     } else if (written != sizeof(tx)) {
    111         self->Err("rt_dev_write %i/%i error\n",written,sizeof(tx));
    112     }
     107  written = i2cport->Write(tx, sizeof(tx));
     108  if (written < 0) {
     109    self->Err("rt_dev_write (%s) error\n", strerror(-written));
     110  } else if (written != sizeof(tx)) {
     111    self->Err("rt_dev_write %i/%i error\n", written, sizeof(tx));
     112  }
    113113
    114     i2cport->ReleaseMutex();
     114  i2cport->ReleaseMutex();
    115115}
    116116
    117 void XBldc_impl::ChangeAdress(uint8_t old_add,uint8_t new_add) {
    118     unsigned char tx[4];
    119     ssize_t written;
     117void XBldc_impl::ChangeAdress(uint8_t old_add, uint8_t new_add) {
     118  unsigned char tx[4];
     119  ssize_t written;
    120120
    121     tx[0]=250;
    122     tx[1]=old_add;
    123     tx[2]=new_add;
    124     tx[3]=230+old_add+new_add;
     121  tx[0] = 250;
     122  tx[1] = old_add;
     123  tx[2] = new_add;
     124  tx[3] = 230 + old_add + new_add;
    125125
    126     i2cport->GetMutex();
    127     i2cport->SetSlave(BASE_ADDRESS);
     126  i2cport->GetMutex();
     127  i2cport->SetSlave(BASE_ADDRESS);
    128128
    129     written =i2cport->Write(tx, sizeof(tx));
    130     if(written<0) {
    131         self->Err("rt_dev_write error (%s)\n",strerror(-written));
    132     } else if (written != sizeof(tx)) {
    133         self->Err("rt_dev_write error %i/%i\n",written,sizeof(tx));
    134     }
     129  written = i2cport->Write(tx, sizeof(tx));
     130  if (written < 0) {
     131    self->Err("rt_dev_write error (%s)\n", strerror(-written));
     132  } else if (written != sizeof(tx)) {
     133    self->Err("rt_dev_write error %i/%i\n", written, sizeof(tx));
     134  }
    135135
    136     i2cport->ReleaseMutex();
     136  i2cport->ReleaseMutex();
    137137}
    138138
    139 uint8_t XBldc_impl::Sat(float value,uint8_t min,uint8_t max) {
    140   uint8_t sat_value=(uint8_t)value;
     139uint8_t XBldc_impl::Sat(float value, uint8_t min, uint8_t max) {
     140  uint8_t sat_value = (uint8_t)value;
    141141
    142   if(value>((float)sat_value+0.5)) sat_value++;
     142  if (value > ((float)sat_value + 0.5))
     143    sat_value++;
    143144
    144   if(value<(float)min) sat_value=min;
    145   if(value>(float)max) sat_value=max;
     145  if (value < (float)min)
     146    sat_value = min;
     147  if (value > (float)max)
     148    sat_value = max;
    146149
    147150  return sat_value;
Note: See TracChangeset for help on using the changeset viewer.