diff --git a/lib/bno080/BNO080.cpp b/lib/bno080/BNO080.cpp index 62e2787..0231b43 100644 --- a/lib/bno080/BNO080.cpp +++ b/lib/bno080/BNO080.cpp @@ -1478,8 +1478,8 @@ boolean BNO080::getData(uint16_t bytesRemaining) while (bytesRemaining > 0) { uint16_t numberOfBytesToRead = bytesRemaining; - if (numberOfBytesToRead > (I2C_BUFFER_LENGTH - 4)) - numberOfBytesToRead = (I2C_BUFFER_LENGTH - 4); + if (numberOfBytesToRead > (BNO_I2C_BUFFER_LENGTH - 4)) + numberOfBytesToRead = (BNO_I2C_BUFFER_LENGTH - 4); _i2cPort->requestFrom((uint8_t)_deviceAddress, (size_t)(numberOfBytesToRead + 4)); if (waitForI2C() == false) @@ -1544,7 +1544,7 @@ boolean BNO080::sendPacket(uint8_t channelNumber, uint8_t dataLength) } else //Do I2C { - //if(packetLength > I2C_BUFFER_LENGTH) return(false); //You are trying to send too much. Break into smaller packets. + //if(packetLength > BNO_I2C_BUFFER_LENGTH) return(false); //You are trying to send too much. Break into smaller packets. _i2cPort->beginTransmission(_deviceAddress); diff --git a/lib/bno080/BNO080.h b/lib/bno080/BNO080.h index 07202b7..24bac9c 100644 --- a/lib/bno080/BNO080.h +++ b/lib/bno080/BNO080.h @@ -65,7 +65,7 @@ #else //The catch-all default is 32 -#define I2C_BUFFER_LENGTH 32 +#define BNO_I2C_BUFFER_LENGTH 32 #endif //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= diff --git a/lib/i2cdev/I2Cdev.h b/lib/i2cdev/I2Cdev.h index 70b652c..4473649 100644 --- a/lib/i2cdev/I2Cdev.h +++ b/lib/i2cdev/I2Cdev.h @@ -75,6 +75,9 @@ THE SOFTWARE. #endif #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE #include + #ifndef BUFFER_LENGTH + #define BUFFER_LENGTH I2C_BUFFER_LENGTH + #endif #endif #else #include "ArduinoWrapper.h" diff --git a/lib/math/vector3.h b/lib/math/vector3.h index 12e551e..38e4cce 100644 --- a/lib/math/vector3.h +++ b/lib/math/vector3.h @@ -99,7 +99,6 @@ struct Vector3 { inline Vector3 floor() const; inline Vector3 sign() const; inline Vector3 ceil() const; - inline Vector3 round() const; inline double distance_to(const Vector3& p_b) const; inline double distance_squared_to(const Vector3& p_b) const; @@ -179,10 +178,6 @@ Vector3 Vector3::ceil() const { return Vector3(std::ceil(x), std::ceil(y), std::ceil(z)); } -Vector3 Vector3::round() const { - return Vector3(std::round(x), std::round(y), std::round(z)); -} - Vector3 Vector3::lerp(const Vector3& p_b, double p_t) const { return Vector3( x + (p_t * (p_b.x - x)), diff --git a/lib/mpu9250/MPU9250.h b/lib/mpu9250/MPU9250.h index 31c873e..2e1feeb 100644 --- a/lib/mpu9250/MPU9250.h +++ b/lib/mpu9250/MPU9250.h @@ -39,7 +39,7 @@ THE SOFTWARE. #include "I2Cdev.h" #include "helper_3dmath.h" -#include +#include // MotionApps 2.0 DMP implementation, built using the MPU-6050EVB evaluation board #define MPU9250_INCLUDE_DMP_MOTIONAPPS20 diff --git a/lib/mpu9250/MPU9250MotionApps.cpp b/lib/mpu9250/MPU9250MotionApps.cpp index 2cabd83..93d1f48 100644 --- a/lib/mpu9250/MPU9250MotionApps.cpp +++ b/lib/mpu9250/MPU9250MotionApps.cpp @@ -37,50 +37,7 @@ THE SOFTWARE. #include "MPU9250.h" -// Tom Carpenter's conditional PROGMEM code -// http://forum.arduino.cc/index.php?topic=129407.0 -#ifdef __AVR__ - #include -#else - // Teensy 3.0 library conditional PROGMEM code from Paul Stoffregen - #ifndef _PGMSPACE_H_ - #define _PGMSPACE_H_ 1 - #include - - #define PROGMEM - #define PGM_P const char * - #define PSTR(str) (str) - #define F(x) x - - typedef void prog_void; - typedef char prog_char; - typedef unsigned char prog_uchar; - typedef int8_t prog_int8_t; - typedef uint8_t prog_uint8_t; - typedef int16_t prog_int16_t; - typedef uint16_t prog_uint16_t; - typedef int32_t prog_int32_t; - typedef uint32_t prog_uint32_t; - - #define strcpy_P(dest, src) strcpy((dest), (src)) - #define strcat_P(dest, src) strcat((dest), (src)) - #define strcmp_P(a, b) strcmp((a), (b)) - - #define pgm_read_byte(addr) (*(const unsigned char *)(addr)) - #define pgm_read_word(addr) (*(const unsigned short *)(addr)) - #define pgm_read_dword(addr) (*(const unsigned long *)(addr)) - #define pgm_read_float(addr) (*(const float *)(addr)) - - #define pgm_read_byte_near(addr) pgm_read_byte(addr) - #define pgm_read_word_near(addr) pgm_read_word(addr) - #define pgm_read_dword_near(addr) pgm_read_dword(addr) - #define pgm_read_float_near(addr) pgm_read_float(addr) - #define pgm_read_byte_far(addr) pgm_read_byte(addr) - #define pgm_read_word_far(addr) pgm_read_word(addr) - #define pgm_read_dword_far(addr) pgm_read_dword(addr) - #define pgm_read_float_far(addr) pgm_read_float(addr) - #endif -#endif +#include /* Source is from the InvenSense MotionApps v2 demo code. Original source is * unavailable, unless you happen to be amazing as decompiling binary by diff --git a/platformio.ini b/platformio.ini index 8141fb2..4d8f3be 100644 --- a/platformio.ini +++ b/platformio.ini @@ -11,12 +11,8 @@ [env] lib_deps= https://github.com/pvizeli/CmdParser.git - -[env:esp12e] -platform = espressif8266 -board = esp12e +monitor_speed = 115200 framework = arduino -monitor_speed = 115200 ; If you want to enable OTA Updates, uncomment and set OTA password here and in credentials.h ; You can set upload_port to device's ip after it's set up for the first time @@ -24,4 +20,16 @@ monitor_speed = 115200 ;upload_protocol = espota ;upload_port = 192.168.1.49 ;upload_flags = -; --auth=SlimeVR-OTA \ No newline at end of file +; --auth=SlimeVR-OTA + +; Settings for different boards + +[env:esp12e] +platform = espressif8266 +board = esp12e + +; Uncomment below if you want to build for esp32 +; Check your board name at https://docs.platformio.org/en/latest/platforms/espressif32.html#boards +;[env:esp32] +;platform = espressif32 +;board = esp-wrover-kit \ No newline at end of file diff --git a/src/bno080sensor.cpp b/src/bno080sensor.cpp index 8c5899a..bad294b 100644 --- a/src/bno080sensor.cpp +++ b/src/bno080sensor.cpp @@ -100,6 +100,8 @@ void BNO080Sensor::motionLoop() sendResetReason(rr); digitalWrite(LOADING_LED, LOW); } + Serial.print("[ERR] Sensor was reset: "); + Serial.println(rr); } } diff --git a/src/configuration.h b/src/configuration.h index 02782e8..274680e 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -24,6 +24,10 @@ #ifndef _OWO_CONFIG_H_ #define _OWO_CONFIG_H_ +#ifndef LED_BUILTIN +#define LED_BUILTIN 2 +#endif + #define LOADING_LED LED_BUILTIN #define CALIBRATING_LED LED_BUILTIN diff --git a/src/main.cpp b/src/main.cpp index c916597..3200c0e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -25,7 +25,7 @@ #include "ota.h" #include "sensor.h" #include "configuration.h" -#include "wifi.h" +#include "wifihandler.h" #include "udpclient.h" #include "defines.h" #include "credentials.h" @@ -100,7 +100,9 @@ void setup() // join I2C bus Wire.begin(PIN_IMU_SDA, PIN_IMU_SCL); +#ifdef ESP8266 Wire.setClockStretchLimit(150000L); // Default streatch limit 150mS +#endif Wire.setClock(100000); if (hasConfigStored()) diff --git a/src/serialcommands.cpp b/src/serialcommands.cpp index 0876174..b8ac920 100644 --- a/src/serialcommands.cpp +++ b/src/serialcommands.cpp @@ -22,7 +22,7 @@ */ #include "serialcommands.h" -#include "wifi.h" +#include "wifihandler.h" #include CmdCallback<5> cmdCallbacks; diff --git a/src/udpclient.cpp b/src/udpclient.cpp index 967cdec..cfed480 100644 --- a/src/udpclient.cpp +++ b/src/udpclient.cpp @@ -22,9 +22,6 @@ */ #include "udpclient.h" -#include "configuration.h" -#include "defines.h" -#include "wifi.h" #define TIMEOUT 3000UL @@ -36,8 +33,6 @@ unsigned char buf[128]; configRecievedCallback fp_configCallback; commandRecievedCallback fp_commandCallback; -IPAddress broadcast = IPAddress(255, 255, 255, 255); - int port = 6969; IPAddress host = IPAddress(255, 255, 255, 255); bool connected = false; @@ -152,7 +147,7 @@ void sendFloat(float const value, int type) } } -void sendByte(char const value, int type) +void sendByte(unsigned char const value, int type) { if (Udp.beginPacket(host, port) > 0) { @@ -298,7 +293,7 @@ void sendSerial(uint8_t *const data, int length, int type) { } } -void sendSensorInfo(char const sensorId, char const sensorState, int type) { +void sendSensorInfo(unsigned char const sensorId, unsigned char const sensorState, int type) { if (Udp.beginPacket(host, port) > 0) { sendType(type); @@ -347,7 +342,7 @@ void sendHandshake() { Udp.write(convert_to_chars((uint32_t) 0, buf), sizeof(uint32_t)); Udp.write(convert_to_chars((uint32_t) 0, buf), sizeof(uint32_t)); Udp.write(convert_to_chars((uint32_t) FIRMWARE_BUILD_NUMBER, buf), sizeof(uint32_t)); - Udp.write(FIRMWARE_VERSION, sizeof(FIRMWARE_VERSION)); + Udp.write((const unsigned char *) FIRMWARE_VERSION, sizeof(FIRMWARE_VERSION)); if (Udp.endPacket() == 0) { Serial.print("Write error: "); diff --git a/src/udpclient.h b/src/udpclient.h index 21d0109..774ced4 100644 --- a/src/udpclient.h +++ b/src/udpclient.h @@ -24,12 +24,18 @@ #ifndef _UDP_CLIENT_H_ #define _UDP_CLIENT_H_ -#include +#ifdef ESP8266 + #include +#else + #include +#endif #include #include #include "quat.h" #include "configuration.h" #include "sensor.h" +#include "wifihandler.h" +#include "defines.h" #define PACKET_HEARTBEAT 0 #define PACKET_ROTATION 1 @@ -68,8 +74,8 @@ void sendQuat(Quat * const quaternion, int type); void sendVector(float * const result, int type); void sendConfig(DeviceConfig * const config, int type); void sendFloat(float const value, int type); -void sendByte(char const value, int type); -void sendSensorInfo(char const sensorId, char const sensorState, int type); +void sendByte(unsigned char const value, int type); +void sendSensorInfo(unsigned char const sensorId, unsigned char const sensorState, int type); void sendRawCalibrationData(int * const data, int type); void setConfigRecievedCallback(configRecievedCallback); void setCommandRecievedCallback(commandRecievedCallback); diff --git a/src/wifi.cpp b/src/wifihandler.cpp similarity index 99% rename from src/wifi.cpp rename to src/wifihandler.cpp index c88225a..227484e 100644 --- a/src/wifi.cpp +++ b/src/wifihandler.cpp @@ -21,7 +21,7 @@ THE SOFTWARE. */ -#include "wifi.h" +#include "wifihandler.h" #include "udpclient.h" #include "defines.h" diff --git a/src/wifi.h b/src/wifihandler.h similarity index 100% rename from src/wifi.h rename to src/wifihandler.h