Updates for floaty build
This commit is contained in:
parent
29d6486743
commit
f220df08ac
70
src/gyro.cpp
70
src/gyro.cpp
@ -30,22 +30,41 @@ MPU6050 accelgyro;
|
||||
#define GYRO_USE_INTERRUPT // Use interrupt to detect when new sample is ready
|
||||
#define GYRO_SHOW_MINMAX // Will calculate the min/max values when doing
|
||||
// calibration
|
||||
// #define GYRO_CALIBRATE_STARTUP // Will calibrate sensor at startup
|
||||
|
||||
//
|
||||
// Initialize the sensor chip.
|
||||
//
|
||||
bool GyroSensor::setup() {
|
||||
int clock = 400000;
|
||||
#if defined(FLOATY)
|
||||
pinMode(PIN_VCC, OUTPUT);
|
||||
pinMode(PIN_GND, OUTPUT_OPEN_DRAIN);
|
||||
digitalWrite(PIN_VCC, HIGH);
|
||||
digitalWrite(PIN_GND, LOW);
|
||||
delay(10); // Wait for the pins to settle or we will fail to connect
|
||||
#else
|
||||
#endif
|
||||
/* For testing pin config of new boards with led.
|
||||
pinMode(PIN_SDA, OUTPUT);
|
||||
pinMode(PIN_SCL, OUTPUT);
|
||||
for(int i = 0, j = LOW, k = LOW; i < 100; i++) {
|
||||
|
||||
digitalWrite(PIN_SDA, k);
|
||||
digitalWrite(PIN_SCL, j);
|
||||
k = !k;
|
||||
delay(300);
|
||||
digitalWrite(PIN_SDA, k);
|
||||
k = !k;
|
||||
j = !j;
|
||||
delay(300);
|
||||
}*/
|
||||
|
||||
#if LOG_LEVEL == 6 && !defined(GYRO_DISABLE_LOGGING)
|
||||
Log.verbose(F("GYRO: Setting up hardware." CR));
|
||||
#endif
|
||||
Wire.begin(PIN_SDA, PIN_SCL);
|
||||
Wire.setClock(400000); // 400kHz I2C clock. Comment this line if having
|
||||
// compilation difficulties
|
||||
Wire.setClock(clock); // 400kHz I2C clock.
|
||||
|
||||
uint8_t id = accelgyro.getDeviceID();
|
||||
|
||||
if (id != 0x34 && id != 0x38) { // Allow both MPU6050 and MPU6000
|
||||
if (id != 0x34 && id != 0x38) { // Allow both MPU6050 and MPU6500
|
||||
writeErrorLog("GYRO: Failed to connect to gyro, is it connected?");
|
||||
_sensorConnected = false;
|
||||
} else {
|
||||
@ -68,11 +87,6 @@ bool GyroSensor::setup() {
|
||||
accelgyro.setIntDataReadyEnabled(true);
|
||||
#endif
|
||||
|
||||
#if defined(GYRO_CALIBRATE_STARTUP)
|
||||
// Run the calibration at start, useful for testing.
|
||||
calibrateSensor();
|
||||
#endif
|
||||
|
||||
// Once we have calibration values stored we just apply them from the
|
||||
// config.
|
||||
_calibrationOffset = myConfig.getGyroCalibration();
|
||||
@ -81,19 +95,17 @@ bool GyroSensor::setup() {
|
||||
return _sensorConnected;
|
||||
}
|
||||
|
||||
//
|
||||
// Set sensor in sleep mode to conserve battery
|
||||
//
|
||||
void GyroSensor::enterSleep() {
|
||||
#if LOG_LEVEL == 6 && !defined(GYRO_DISABLE_LOGGING)
|
||||
Log.verbose(F("GYRO: Setting up hardware." CR));
|
||||
#endif
|
||||
#if defined(FLOATY)
|
||||
digitalWrite(PIN_VCC, LOW);
|
||||
#else
|
||||
accelgyro.setSleepEnabled(true);
|
||||
#endif
|
||||
}
|
||||
|
||||
//
|
||||
// Do a number of reads to get a more stable value.
|
||||
//
|
||||
void GyroSensor::readSensor(RawGyroData &raw, const int noIterations,
|
||||
const int delayTime) {
|
||||
RawGyroDataL average = {0, 0, 0, 0, 0, 0};
|
||||
@ -179,9 +191,6 @@ void GyroSensor::readSensor(RawGyroData &raw, const int noIterations,
|
||||
#endif
|
||||
}
|
||||
|
||||
//
|
||||
// Calcuate the angles (tilt)
|
||||
//
|
||||
float GyroSensor::calculateAngle(RawGyroData &raw) {
|
||||
#if LOG_LEVEL == 6 && !defined(GYRO_DISABLE_LOGGING)
|
||||
Log.verbose(F("GYRO: Calculating the angle." CR));
|
||||
@ -209,9 +218,6 @@ float GyroSensor::calculateAngle(RawGyroData &raw) {
|
||||
return vY;
|
||||
}
|
||||
|
||||
//
|
||||
// Check if the values are high that indicate that the sensor is moving.
|
||||
//
|
||||
bool GyroSensor::isSensorMoving(RawGyroData &raw) {
|
||||
#if LOG_LEVEL == 6 && !defined(GYRO_DISABLE_LOGGING)
|
||||
Log.verbose(F("GYRO: Checking for sensor movement." CR));
|
||||
@ -229,9 +235,6 @@ bool GyroSensor::isSensorMoving(RawGyroData &raw) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// Read the tilt angle from the gyro.
|
||||
//
|
||||
bool GyroSensor::read() {
|
||||
#if LOG_LEVEL == 6 && !defined(GYRO_DISABLE_LOGGING)
|
||||
Log.verbose(F("GYRO: Getting new gyro position." CR));
|
||||
@ -270,9 +273,6 @@ bool GyroSensor::read() {
|
||||
return _validValue;
|
||||
}
|
||||
|
||||
//
|
||||
// Dump the stored calibration values.
|
||||
//
|
||||
void GyroSensor::dumpCalibration() {
|
||||
#if LOG_LEVEL == 6 && !defined(GYRO_DISABLE_LOGGING)
|
||||
Log.verbose(F("GYRO: Accel offset\t%d\t%d\t%d" CR), _calibrationOffset.ax,
|
||||
@ -282,9 +282,6 @@ void GyroSensor::dumpCalibration() {
|
||||
#endif
|
||||
}
|
||||
|
||||
//
|
||||
// Update the sensor with out calculated offsets.
|
||||
//
|
||||
void GyroSensor::applyCalibration() {
|
||||
#if LOG_LEVEL == 6 && !defined(GYRO_DISABLE_LOGGING)
|
||||
Log.verbose(F("GYRO: Applying calibration offsets to sensor." CR));
|
||||
@ -306,9 +303,6 @@ void GyroSensor::applyCalibration() {
|
||||
accelgyro.setZGyroOffset(_calibrationOffset.gz);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate the offsets for calibration.
|
||||
//
|
||||
void GyroSensor::calibrateSensor() {
|
||||
#if LOG_LEVEL == 6 && !defined(GYRO_DISABLE_LOGGING)
|
||||
Log.verbose(F("GYRO: Calibrating sensor" CR));
|
||||
@ -330,14 +324,10 @@ void GyroSensor::calibrateSensor() {
|
||||
_calibrationOffset.gy = accelgyro.getYGyroOffset();
|
||||
_calibrationOffset.gz = accelgyro.getZGyroOffset();
|
||||
|
||||
// Save the calibrated values
|
||||
myConfig.setGyroCalibration(_calibrationOffset);
|
||||
myConfig.saveFile();
|
||||
}
|
||||
|
||||
//
|
||||
// Calibrate the device.
|
||||
//
|
||||
void GyroSensor::debug() {
|
||||
#if LOG_LEVEL == 6 && !defined(GYRO_DISABLE_LOGGING)
|
||||
Log.verbose(F("GYRO: Debug - Clock src %d." CR),
|
||||
|
@ -256,11 +256,8 @@ void setup() {
|
||||
millis(); // Dont include time for wifi connection
|
||||
}
|
||||
|
||||
//
|
||||
// Main loop that does gravity readings and push data to targets
|
||||
//
|
||||
// Return true if gravity reading was successful
|
||||
//
|
||||
bool loopReadGravity() {
|
||||
float angle = 0;
|
||||
|
||||
@ -339,10 +336,8 @@ bool loopReadGravity() {
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// Wrapper for loopGravity that only calls every 200ms so that we dont overload
|
||||
// this.
|
||||
//
|
||||
void loopGravityOnInterval() {
|
||||
if (abs((int32_t)(millis() - loopMillis)) > interval) {
|
||||
loopReadGravity();
|
||||
@ -358,9 +353,6 @@ void loopGravityOnInterval() {
|
||||
|
||||
bool skipRunTimeLog = false;
|
||||
|
||||
//
|
||||
// Main loop that determines if device should go to sleep
|
||||
//
|
||||
void goToSleep(int sleepInterval) {
|
||||
float volt = myBatteryVoltage.getVoltage();
|
||||
float runtime = (millis() - runtimeMillis);
|
||||
|
12
src/main.hpp
12
src/main.hpp
@ -38,6 +38,8 @@ enum RunMode {
|
||||
extern RunMode runMode;
|
||||
|
||||
#if defined(ESP8266)
|
||||
// Hardware config for ESP8266-d1, iSpindel hardware
|
||||
// ------------------------------------------------------
|
||||
#include <LittleFS.h>
|
||||
#define ESP_RESET ESP.reset
|
||||
#define PIN_SDA D3
|
||||
@ -46,6 +48,8 @@ extern RunMode runMode;
|
||||
#define PIN_LED 2
|
||||
// #define PIN_A0 A0
|
||||
#elif defined(ESP32C3)
|
||||
// Hardware config for ESP32-c3-mini, iSpindel hardware
|
||||
// ------------------------------------------------------
|
||||
#include <FS.h>
|
||||
#include <LittleFS.h>
|
||||
|
||||
@ -67,6 +71,8 @@ extern RunMode runMode;
|
||||
// cannot use both. So we point LED to pin 8 which is not used.
|
||||
#define PIN_LED 8
|
||||
#elif defined(ESP32S2)
|
||||
// Hardware config for ESP32-s2-mini, iSpindel hardware
|
||||
// ------------------------------------------------------
|
||||
#include <FS.h>
|
||||
#include <LittleFS.h>
|
||||
|
||||
@ -80,6 +86,8 @@ extern RunMode runMode;
|
||||
#define PIN_A0 A2
|
||||
#define PIN_LED LED_BUILTIN
|
||||
#elif defined(ESP32LITE)
|
||||
// Hardware config for ESP32-lite, Floaty hardware
|
||||
// ------------------------------------------------------
|
||||
#include <FS.h>
|
||||
#include <LittleFS.h>
|
||||
|
||||
@ -91,8 +99,12 @@ extern RunMode runMode;
|
||||
#define PIN_SCL A19
|
||||
#define PIN_DS A3
|
||||
#define PIN_A0 A0
|
||||
#define PIN_VCC A5
|
||||
#define PIN_GND A18
|
||||
#define PIN_LED LED_BUILTIN
|
||||
#else // defined (ESP32)
|
||||
// Hardware config for ESP32-d1-min, iSpindel hardware
|
||||
// ------------------------------------------------------
|
||||
#include <FS.h>
|
||||
#include <LittleFS.h>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user