2015-03-03 23:43:50 -07:00
|
|
|
#include "DSM2.h"
|
|
|
|
|
2015-03-10 20:02:35 -06:00
|
|
|
#include <iostream>
|
2015-03-03 23:43:50 -07:00
|
|
|
#include "wiringSerial.h"
|
|
|
|
|
2015-03-10 20:02:35 -06:00
|
|
|
#define VALUE_MASK 0x3FF
|
2015-03-03 23:43:50 -07:00
|
|
|
|
2015-03-10 20:02:35 -06:00
|
|
|
DSM2::DSM2( int mode )
|
2015-03-03 23:43:50 -07:00
|
|
|
{
|
2015-03-10 20:02:35 -06:00
|
|
|
std::cout << "opening serial port..." << std::flush;
|
|
|
|
fd = serialOpen( "/dev/ttyAMA0", 115200 );
|
|
|
|
std::cout << "SUCCESS " << fd << std::endl;
|
|
|
|
std::cout << "flushing serial..." << std::flush;
|
|
|
|
serialFlush(fd);
|
|
|
|
std::cout << "SUCCESS" << std::endl;
|
2015-03-03 23:43:50 -07:00
|
|
|
}
|
|
|
|
|
2015-03-10 20:02:35 -06:00
|
|
|
void DSM2::update()
|
2015-03-03 23:43:50 -07:00
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
|
2015-03-10 20:02:35 -06:00
|
|
|
if( serialDataAvail(fd) < 16 ) return;
|
2015-03-03 23:43:50 -07:00
|
|
|
|
2015-03-10 20:02:35 -06:00
|
|
|
for( i = 0; i < 8; i++ )
|
|
|
|
data[ i ] = ( (int)(serialGetchar(fd)) << 8 ) + serialGetchar(fd);
|
2015-03-03 23:43:50 -07:00
|
|
|
|
2015-03-10 20:02:35 -06:00
|
|
|
*(values + 0) = data[7] & VALUE_MASK; //Throttle
|
|
|
|
*(values + 1) = data[1] & VALUE_MASK; //Aileron
|
|
|
|
*(values + 2) = data[3] & VALUE_MASK; //Elevator
|
|
|
|
*(values + 3) = data[5] & VALUE_MASK; //Rudder
|
|
|
|
*(values + 4) = data[4] & VALUE_MASK; //Gear
|
|
|
|
*(values + 5) = data[2] & VALUE_MASK; //Aux1
|
2015-03-03 23:43:50 -07:00
|
|
|
return;
|
|
|
|
}
|