mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 14:18:24 +02:00
Merge branch 'master' of https://github.com/worklist/hifi
This commit is contained in:
commit
5b873c1e8f
2 changed files with 24 additions and 21 deletions
|
@ -22,7 +22,6 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int serialFd;
|
|
||||||
const int MAX_BUFFER = 255;
|
const int MAX_BUFFER = 255;
|
||||||
char serialBuffer[MAX_BUFFER];
|
char serialBuffer[MAX_BUFFER];
|
||||||
int serialBufferPos = 0;
|
int serialBufferPos = 0;
|
||||||
|
@ -34,6 +33,10 @@ const int GRAVITY_SAMPLES = 200; // Use the first samples to
|
||||||
|
|
||||||
const bool USING_INVENSENSE_MPU9150 = 1;
|
const bool USING_INVENSENSE_MPU9150 = 1;
|
||||||
|
|
||||||
|
SerialInterface::~SerialInterface() {
|
||||||
|
close(_serialDescriptor);
|
||||||
|
}
|
||||||
|
|
||||||
void SerialInterface::pair() {
|
void SerialInterface::pair() {
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
|
@ -69,19 +72,19 @@ void SerialInterface::pair() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// connect to the serial port
|
// connect to the serial port
|
||||||
int SerialInterface::initializePort(char* portname, int baud) {
|
void SerialInterface::initializePort(char* portname, int baud) {
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
serialFd = open(portname, O_RDWR | O_NOCTTY | O_NDELAY);
|
_serialDescriptor = open(portname, O_RDWR | O_NOCTTY | O_NDELAY);
|
||||||
|
|
||||||
printLog("Opening SerialUSB %s: ", portname);
|
printLog("Opening SerialUSB %s: ", portname);
|
||||||
|
|
||||||
if (serialFd == -1) {
|
if (_serialDescriptor == -1) {
|
||||||
printLog("Failed.\n");
|
printLog("Failed.\n");
|
||||||
_failedOpenAttempts++;
|
_failedOpenAttempts++;
|
||||||
return -1; // Failed to open port
|
return;
|
||||||
}
|
}
|
||||||
struct termios options;
|
struct termios options;
|
||||||
tcgetattr(serialFd,&options);
|
tcgetattr(_serialDescriptor, &options);
|
||||||
|
|
||||||
switch(baud) {
|
switch(baud) {
|
||||||
case 9600: cfsetispeed(&options,B9600);
|
case 9600: cfsetispeed(&options,B9600);
|
||||||
|
@ -106,26 +109,26 @@ int SerialInterface::initializePort(char* portname, int baud) {
|
||||||
options.c_cflag &= ~CSTOPB;
|
options.c_cflag &= ~CSTOPB;
|
||||||
options.c_cflag &= ~CSIZE;
|
options.c_cflag &= ~CSIZE;
|
||||||
options.c_cflag |= CS8;
|
options.c_cflag |= CS8;
|
||||||
tcsetattr(serialFd,TCSANOW,&options);
|
tcsetattr(_serialDescriptor, TCSANOW, &options);
|
||||||
|
|
||||||
if (USING_INVENSENSE_MPU9150) {
|
if (USING_INVENSENSE_MPU9150) {
|
||||||
// block on invensense reads until there is data to read
|
// block on invensense reads until there is data to read
|
||||||
int currentFlags = fcntl(serialFd, F_GETFL);
|
int currentFlags = fcntl(_serialDescriptor, F_GETFL);
|
||||||
fcntl(serialFd, F_SETFL, currentFlags & ~O_NONBLOCK);
|
fcntl(_serialDescriptor, F_SETFL, currentFlags & ~O_NONBLOCK);
|
||||||
|
|
||||||
// there are extra commands to send to the invensense when it fires up
|
// there are extra commands to send to the invensense when it fires up
|
||||||
|
|
||||||
// this takes it out of SLEEP
|
// this takes it out of SLEEP
|
||||||
write(serialFd, "WR686B01\n", 9);
|
write(_serialDescriptor, "WR686B01\n", 9);
|
||||||
|
|
||||||
// delay after the wakeup
|
// delay after the wakeup
|
||||||
usleep(10000);
|
usleep(10000);
|
||||||
|
|
||||||
// this disables streaming so there's no garbage data on reads
|
// this disables streaming so there's no garbage data on reads
|
||||||
write(serialFd, "SD\n", 3);
|
write(_serialDescriptor, "SD\n", 3);
|
||||||
|
|
||||||
// flush whatever was produced by the last two commands
|
// flush whatever was produced by the last two commands
|
||||||
tcflush(serialFd, TCIOFLUSH);
|
tcflush(_serialDescriptor, TCIOFLUSH);
|
||||||
}
|
}
|
||||||
|
|
||||||
printLog("Connected.\n");
|
printLog("Connected.\n");
|
||||||
|
@ -133,8 +136,6 @@ int SerialInterface::initializePort(char* portname, int baud) {
|
||||||
|
|
||||||
active = true;
|
active = true;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset Trailing averages to the current measurement
|
// Reset Trailing averages to the current measurement
|
||||||
|
@ -148,9 +149,7 @@ void SerialInterface::renderLevels(int width, int height) {
|
||||||
int disp_x = 10;
|
int disp_x = 10;
|
||||||
const int GAP = 16;
|
const int GAP = 16;
|
||||||
char val[10];
|
char val[10];
|
||||||
for(i = 0; i < NUM_CHANNELS; i++)
|
for(i = 0; i < NUM_CHANNELS; i++) {
|
||||||
{
|
|
||||||
|
|
||||||
// Actual value
|
// Actual value
|
||||||
glLineWidth(2.0);
|
glLineWidth(2.0);
|
||||||
glColor4f(1, 1, 1, 1);
|
glColor4f(1, 1, 1, 1);
|
||||||
|
@ -207,8 +206,8 @@ void SerialInterface::readData() {
|
||||||
unsigned char gyroBuffer[20];
|
unsigned char gyroBuffer[20];
|
||||||
|
|
||||||
// ask the invensense for raw gyro data
|
// ask the invensense for raw gyro data
|
||||||
write(serialFd, "RD684306\n", 9);
|
write(_serialDescriptor, "RD684306\n", 9);
|
||||||
read(serialFd, gyroBuffer, 20);
|
read(_serialDescriptor, gyroBuffer, 20);
|
||||||
|
|
||||||
convertHexToInt(gyroBuffer + 6, _lastYaw);
|
convertHexToInt(gyroBuffer + 6, _lastYaw);
|
||||||
convertHexToInt(gyroBuffer + 10, _lastRoll);
|
convertHexToInt(gyroBuffer + 10, _lastRoll);
|
||||||
|
@ -221,7 +220,7 @@ void SerialInterface::readData() {
|
||||||
const float AVG_RATE[] = {0.002, 0.002, 0.002, 0.002, 0.002, 0.002};
|
const float AVG_RATE[] = {0.002, 0.002, 0.002, 0.002, 0.002, 0.002};
|
||||||
char bufchar[1];
|
char bufchar[1];
|
||||||
|
|
||||||
while (read(serialFd, &bufchar, 1) > 0) {
|
while (read(_serialDescriptor, &bufchar, 1) > 0) {
|
||||||
serialBuffer[serialBufferPos] = bufchar[0];
|
serialBuffer[serialBufferPos] = bufchar[0];
|
||||||
serialBufferPos++;
|
serialBufferPos++;
|
||||||
// Have we reached end of a line of input?
|
// Have we reached end of a line of input?
|
||||||
|
|
|
@ -38,6 +38,8 @@ class SerialInterface {
|
||||||
public:
|
public:
|
||||||
SerialInterface() : active(false),
|
SerialInterface() : active(false),
|
||||||
_failedOpenAttempts(0) {}
|
_failedOpenAttempts(0) {}
|
||||||
|
~SerialInterface();
|
||||||
|
|
||||||
void pair();
|
void pair();
|
||||||
void readData();
|
void readData();
|
||||||
|
|
||||||
|
@ -57,8 +59,10 @@ public:
|
||||||
glm::vec3 getGravity() {return gravity;};
|
glm::vec3 getGravity() {return gravity;};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int initializePort(char* portname, int baud);
|
void initializePort(char* portname, int baud);
|
||||||
void resetSerial();
|
void resetSerial();
|
||||||
|
|
||||||
|
int _serialDescriptor;
|
||||||
int lastMeasured[NUM_CHANNELS];
|
int lastMeasured[NUM_CHANNELS];
|
||||||
float trailingAverage[NUM_CHANNELS];
|
float trailingAverage[NUM_CHANNELS];
|
||||||
int samplesAveraged;
|
int samplesAveraged;
|
||||||
|
|
Loading…
Reference in a new issue