Send BNO08X reset reason to the server

This commit is contained in:
Eiren Rain
2021-04-19 04:23:25 +03:00
parent bba36191b1
commit 112cb02c2d
4 changed files with 21 additions and 2 deletions

View File

@@ -36,6 +36,10 @@ namespace {
digitalWrite(LOADING_LED, HIGH);
}
}
void sendResetReason(uint8_t reason) {
sendByte(reason, PACKET_RESET_REASON);
}
}
void BNO080Sensor::motionSetup(DeviceConfig * config)
@@ -67,19 +71,30 @@ void BNO080Sensor::motionSetup(DeviceConfig * config)
imu.enableARVRStabilizedGameRotationVector(10);
else
imu.enableGameRotationVector(10);
uint8_t lastReset = imu.resetReason();
sendResetReason(lastReset);
}
unsigned long lastData = 0;
void BNO080Sensor::motionLoop()
{
//Look for reports from the IMU
if (imu.dataAvailable())
{
lastData = millis();
quaternion.x = imu.getQuatI();
quaternion.y = imu.getQuatJ();
quaternion.z = imu.getQuatK();
quaternion.w = imu.getQuatReal();
quaternion *= sensorOffset;
newData = true;
} else {
if(lastData + 5000 < millis()) {
lastData = millis();
uint8_t lastReset = imu.resetReason();
sendResetReason(lastReset);
}
}
}

View File

@@ -75,4 +75,6 @@
#define useFullCalibrationMatrix true
#define sensorIdTime 1000
#define sensorIdInterval 100
#define sensorIdInterval 100
#define batteryADCMultiplier 1.0 / 1024.0 * 5.0

View File

@@ -148,7 +148,7 @@ void loop()
}
if(now_ms - last_battery_sample >= batterySampleRate) {
last_battery_sample = now_ms;
float battery = ((float) analogRead(A0)) / 1024.0 * 6.0;
float battery = ((float) analogRead(A0)) * batteryADCMultiplier;
sendFloat(battery, PACKET_BATTERY_LEVEL);
}
}

View File

@@ -43,6 +43,7 @@
#define PACKET_SERIAL 11
#define PACKET_BATTERY_LEVEL 12
#define PACKET_TAP 13
#define PACKET_RESET_REASON 14
#define PACKET_RECIEVE_HEARTBEAT 1
#define PACKET_RECIEVE_VIBRATE 2
@@ -67,6 +68,7 @@ void sendByte(char const value, int type);
void sendRawCalibrationData(int * const data, int type);
void setConfigRecievedCallback(configRecievedCallback);
void setCommandRecievedCallback(commandRecievedCallback);
void sendSerial(uint8_t *const data, int length, int type);
void setUpWiFi(DeviceConfig * const config);
bool isConnected();