Send heartbeat response for better owoTrack compatibility

This commit is contained in:
Eiren Rain
2021-06-19 16:05:49 +03:00
parent bd9cede20f
commit bd1986a4a8
3 changed files with 26 additions and 3 deletions

View File

@@ -58,6 +58,7 @@ unsigned long blinkStart = 0;
unsigned long now_ms, last_ms = 0; //millis() timers
unsigned long last_battery_sample = 0;
unsigned long const start = millis();
bool secondImuActive = false;
void setConfig(DeviceConfig newConfig)
{
@@ -112,7 +113,6 @@ void setup()
// Wait for IMU to boot
delay(500);
bool secondImuActive = false;
// Currently only second BNO08X is supported
#if IMU == IMU_BNO080 || IMU == IMU_BNO085
#ifdef HAS_SECOND_IMU
@@ -159,7 +159,9 @@ void loop()
if(isConnected()) {
#endif
sensor.motionLoop();
#ifdef HAS_SECOND_IMU
sensor2.motionLoop();
#endif
#ifndef UPDATE_IMU_UNCONNECTED
}
#endif
@@ -174,7 +176,9 @@ void loop()
if(isConnected()) {
#endif
sensor.sendData();
#ifdef HAS_SECOND_IMU
sensor2.sendData();
#endif
#ifndef SEND_UPDATES_UNCONNECTED
}
#endif

View File

@@ -298,8 +298,7 @@ void sendSerial(uint8_t *const data, int length, int type) {
}
}
void sendSensorInfo(char const sensorId, char const sensorState, int type)
{
void sendSensorInfo(char const sensorId, char const sensorState, int type) {
if (Udp.beginPacket(host, port) > 0)
{
sendType(type);
@@ -319,6 +318,24 @@ void sendSensorInfo(char const sensorId, char const sensorState, int type)
}
}
void sendHeartbeat() {
if (Udp.beginPacket(host, port) > 0)
{
sendType(PACKET_HEARTBEAT);
Udp.write(convert_to_chars((uint64_t) 0, buf), sizeof(uint64_t));
if (Udp.endPacket() == 0)
{
//Serial.print("Write error: ");
//Serial.println(Udp.getWriteError());
}
}
else
{
//Serial.print("Write error: ");
//Serial.println(Udp.getWriteError());
}
}
void sendHandshake() {
if (Udp.beginPacket(host, port) > 0)
{
@@ -402,6 +419,7 @@ void clientUpdate(Sensor * const sensor, Sensor * const sensor2)
switch (convert_chars<int>(incomingPacket))
{
case PACKET_RECIEVE_HEARTBEAT:
sendHeartbeat();
break;
case PACKET_RECIEVE_VIBRATE:
if(fp_commandCallback) {

View File

@@ -31,6 +31,7 @@
#include "configuration.h"
#include "sensor.h"
#define PACKET_HEARTBEAT 0
#define PACKET_ROTATION 1
#define PACKET_GYRO 2
#define PACKET_HANDSHAKE 3