// ESP32 Dev Module

#include "Wire.h"
#include "MPU6050.h"

#include <OSCBoards.h>
#include <OSCMessage.h>
/*
Make an OSC message and send it over serial
 */

#ifdef BOARD_HAS_USB_SERIAL
#include <SLIPEncodedUSBSerial.h>
SLIPEncodedUSBSerial SLIPSerial( thisBoardsSerialUSB );
#else
#include <SLIPEncodedSerial.h>
 SLIPEncodedSerial SLIPSerial(Serial); // Change to Serial1 or Serial2 etc. for boards with multiple serial ports that don’t have Serial
#endif

/*
#include <BluetoothSerial.h>
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif

BluetoothSerial SerialBT;
*/

MPU6050 mpu;

// Sem dobimo vrednosti
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;

void setup() {
  Wire.begin();
  SLIPSerial.begin(115200);   // set this as high as you can reliably run on your platform 

  mpu.initialize();
//    setFullScaleGyroRange(MPU6050_GYRO_FS_250);
//    setFullScaleAccelRange(MPU6050_ACCEL_FS_2);
  
  /*
  SerialBT.begin("MotionGlove");
  */
}

void loop() {
  mpu.getMotion6(&AcX, &AcY, &AcZ, &GyX, &GyY, &GyZ);
  
  OSCMessage msg("/accel/");
  msg.add(AcX);
  msg.add(AcY);
  msg.add(AcZ);
  
  SLIPSerial.beginPacket();
  msg.send(SLIPSerial);
  SLIPSerial.endPacket();
  msg.empty();


  OSCMessage gmsg("/gyro/");
  gmsg.add(GyX);
  gmsg.add(GyY);
  gmsg.add(GyZ);
  
  SLIPSerial.beginPacket();
  gmsg.send(SLIPSerial);
  SLIPSerial.endPacket();
  gmsg.empty();
}
