mirror of
https://github.com/Armored-Dragon/overte.git
synced 2025-03-11 16:13:16 +01:00
Added check for lost transmitter
This commit is contained in:
parent
82463260e4
commit
f009177aa7
4 changed files with 27 additions and 3 deletions
|
@ -877,6 +877,8 @@ void Application::idle() {
|
||||||
_serialPort.readData(deltaTime);
|
_serialPort.readData(deltaTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update transmitter
|
||||||
|
|
||||||
// Sample hardware, update view frustum if needed, and send avatar data to mixer/agents
|
// Sample hardware, update view frustum if needed, and send avatar data to mixer/agents
|
||||||
updateAvatar(deltaTime);
|
updateAvatar(deltaTime);
|
||||||
|
|
||||||
|
|
|
@ -279,6 +279,7 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
|
||||||
|
|
||||||
// Add thrusts from Transmitter
|
// Add thrusts from Transmitter
|
||||||
if (transmitter) {
|
if (transmitter) {
|
||||||
|
transmitter->checkForLostTransmitter();
|
||||||
glm::vec3 rotation = transmitter->getEstimatedRotation();
|
glm::vec3 rotation = transmitter->getEstimatedRotation();
|
||||||
const float TRANSMITTER_MIN_RATE = 1.f;
|
const float TRANSMITTER_MIN_RATE = 1.f;
|
||||||
const float TRANSMITTER_MIN_YAW_RATE = 4.f;
|
const float TRANSMITTER_MIN_YAW_RATE = 4.f;
|
||||||
|
|
|
@ -20,11 +20,25 @@ Transmitter::Transmitter() :
|
||||||
_isConnected(false),
|
_isConnected(false),
|
||||||
_lastRotationRate(0,0,0),
|
_lastRotationRate(0,0,0),
|
||||||
_lastAcceleration(0,0,0),
|
_lastAcceleration(0,0,0),
|
||||||
_estimatedRotation(0,0,0)
|
_estimatedRotation(0,0,0),
|
||||||
|
_lastReceivedPacket(NULL)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Transmitter::checkForLostTransmitter() {
|
||||||
|
// If we are in motion, check for loss of transmitter packets
|
||||||
|
if (glm::length(_estimatedRotation) > 0.f) {
|
||||||
|
timeval now;
|
||||||
|
gettimeofday(&now, NULL);
|
||||||
|
const int TIME_TO_ASSUME_LOST_MSECS = 2000;
|
||||||
|
int msecsSinceLast = diffclock(_lastReceivedPacket, &now);
|
||||||
|
if (msecsSinceLast > TIME_TO_ASSUME_LOST_MSECS) {
|
||||||
|
resetLevels();
|
||||||
|
printLog("Transmitter signal lost.\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
void Transmitter::resetLevels() {
|
void Transmitter::resetLevels() {
|
||||||
_lastRotationRate *= 0.f;
|
_lastRotationRate *= 0.f;
|
||||||
_estimatedRotation *= 0.f;
|
_estimatedRotation *= 0.f;
|
||||||
|
@ -34,6 +48,11 @@ void Transmitter::processIncomingData(unsigned char* packetData, int numBytes) {
|
||||||
const int PACKET_HEADER_SIZE = 1; // Packet's first byte is 'T'
|
const int PACKET_HEADER_SIZE = 1; // Packet's first byte is 'T'
|
||||||
const int ROTATION_MARKER_SIZE = 1; // 'R' = Rotation (clockwise about x,y,z)
|
const int ROTATION_MARKER_SIZE = 1; // 'R' = Rotation (clockwise about x,y,z)
|
||||||
const int ACCELERATION_MARKER_SIZE = 1; // 'A' = Acceleration (x,y,z)
|
const int ACCELERATION_MARKER_SIZE = 1; // 'A' = Acceleration (x,y,z)
|
||||||
|
if (!_lastReceivedPacket) {
|
||||||
|
_lastReceivedPacket = new timeval;
|
||||||
|
}
|
||||||
|
gettimeofday(_lastReceivedPacket, NULL);
|
||||||
|
|
||||||
if (numBytes == PACKET_HEADER_SIZE + ROTATION_MARKER_SIZE + ACCELERATION_MARKER_SIZE
|
if (numBytes == PACKET_HEADER_SIZE + ROTATION_MARKER_SIZE + ACCELERATION_MARKER_SIZE
|
||||||
+ sizeof(_lastRotationRate) + sizeof(_lastAcceleration)
|
+ sizeof(_lastRotationRate) + sizeof(_lastAcceleration)
|
||||||
+ sizeof(_touchState.x) + sizeof(_touchState.y) + sizeof(_touchState.state)) {
|
+ sizeof(_touchState.x) + sizeof(_touchState.y) + sizeof(_touchState.state)) {
|
||||||
|
@ -69,12 +88,12 @@ void Transmitter::processIncomingData(unsigned char* packetData, int numBytes) {
|
||||||
_estimatedRotation.y *= (1.f - DECAY_RATE * DELTA_TIME);
|
_estimatedRotation.y *= (1.f - DECAY_RATE * DELTA_TIME);
|
||||||
|
|
||||||
if (!_isConnected) {
|
if (!_isConnected) {
|
||||||
printf("Transmitter V2 Connected.\n");
|
printLog("Transmitter Connected.\n");
|
||||||
_isConnected = true;
|
_isConnected = true;
|
||||||
_estimatedRotation *= 0.0;
|
_estimatedRotation *= 0.0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
printf("Transmitter V2 packet read error, %d bytes.\n", numBytes);
|
printLog("Transmitter packet read error, %d bytes.\n", numBytes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ class Transmitter
|
||||||
public:
|
public:
|
||||||
Transmitter();
|
Transmitter();
|
||||||
void render();
|
void render();
|
||||||
|
void checkForLostTransmitter();
|
||||||
void resetLevels();
|
void resetLevels();
|
||||||
void renderLevels(int width, int height);
|
void renderLevels(int width, int height);
|
||||||
bool isConnected() { return _isConnected; };
|
bool isConnected() { return _isConnected; };
|
||||||
|
@ -41,6 +42,7 @@ private:
|
||||||
glm::vec3 _lastAcceleration;
|
glm::vec3 _lastAcceleration;
|
||||||
glm::vec3 _estimatedRotation;
|
glm::vec3 _estimatedRotation;
|
||||||
TouchState _touchState;
|
TouchState _touchState;
|
||||||
|
timeval* _lastReceivedPacket;
|
||||||
|
|
||||||
#endif /* defined(__hifi__Transmitter__) */
|
#endif /* defined(__hifi__Transmitter__) */
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue