wip wireless
payload max 32byte problem
This commit is contained in:
+41
-95
@@ -1,114 +1,60 @@
|
||||
#include <EEPROM.h>
|
||||
#include "Joysticks.h"
|
||||
#include "Nrf.h"
|
||||
#include "SerialPasstrough.h"
|
||||
#include <TinyMPU6050.h>
|
||||
|
||||
// start reading from the first byte (address 0) of the EEPROM
|
||||
int address = 0;
|
||||
byte value;
|
||||
MPU6050 mpu (Wire);
|
||||
|
||||
const int analogInPin = A0;
|
||||
|
||||
int sensorValue = 0;
|
||||
int outputValue = 0;
|
||||
|
||||
//volatile int center[6] = {0, 0, 0, 0, 0, 0};
|
||||
volatile int minvalue[6] = {1000, 1000, 1000, 1000, 1000, 1000};
|
||||
volatile int maxvalue[6] = {0, 0, 0, 0, 0, 0};
|
||||
dataStruct2 data;
|
||||
joyStickdataStruct joystickData;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
||||
value = EEPROM.read(address);
|
||||
// Initialization
|
||||
mpu.Initialize();
|
||||
|
||||
if (value != 0)
|
||||
{
|
||||
address++;
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
address += sizeof(int);
|
||||
EEPROM.get(address, minvalue[i]);
|
||||
address += sizeof(int);
|
||||
EEPROM.get(address, maxvalue[i]);
|
||||
// Serial.println(minvalue[i]);
|
||||
// Serial.println(maxvalue[i]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// if eeprom empty
|
||||
delay(500);
|
||||
// // Calibration
|
||||
// Serial.println("=====================================");
|
||||
// Serial.println("Starting calibration...");
|
||||
// mpu.Calibrate();
|
||||
// Serial.println("Calibration complete!");
|
||||
// Serial.println("Offsets:");
|
||||
// Serial.print("AccX Offset = ");
|
||||
// Serial.println(mpu.GetAccXOffset());
|
||||
// Serial.print("AccY Offset = ");
|
||||
// Serial.println(mpu.GetAccYOffset());
|
||||
// Serial.print("AccZ Offset = ");
|
||||
// Serial.println(mpu.GetAccZOffset());
|
||||
// Serial.print("GyroX Offset = ");
|
||||
// Serial.println(mpu.GetGyroXOffset());
|
||||
// Serial.print("GyroY Offset = ");
|
||||
// Serial.println(mpu.GetGyroYOffset());
|
||||
// Serial.print("GyroZ Offset = ");
|
||||
// Serial.println(mpu.GetGyroZOffset());
|
||||
|
||||
// for (int i = 0; i < 6; i++)
|
||||
// {
|
||||
// center[i] = analogRead(analogInPin + i);
|
||||
// }
|
||||
JoystickInit();
|
||||
|
||||
int time = 10000;
|
||||
while (millis() < time)
|
||||
{
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
sensorValue = analogRead(analogInPin + i);
|
||||
if (sensorValue > maxvalue[i]) {
|
||||
maxvalue[i] = sensorValue;
|
||||
}
|
||||
if (sensorValue < minvalue[i]) {
|
||||
minvalue[i] = sensorValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// for (int i = 0; i < 6; i++)
|
||||
// {
|
||||
// minvalue[i] = center[i] - minvalue[i];
|
||||
// maxvalue[i] = (maxvalue[i] - center[i]);
|
||||
// }
|
||||
|
||||
// write callibration to eeprom
|
||||
address = 0;
|
||||
EEPROM.write(address, 1);
|
||||
|
||||
address++;
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
address += sizeof(int);
|
||||
EEPROM.put(address, minvalue[i]);
|
||||
address += sizeof(int);
|
||||
EEPROM.put(address, maxvalue[i]);
|
||||
// Serial.println(minvalue[i]);
|
||||
// Serial.println(maxvalue[i]);
|
||||
}
|
||||
}
|
||||
NrfInit();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
sensorValue = analogRead(analogInPin + i);
|
||||
// mpu.Execute();
|
||||
// Serial.print("AngX = ");
|
||||
// Serial.print(mpu.GetAngX());
|
||||
// Serial.print(" / AngY = ");
|
||||
// Serial.print(mpu.GetAngY());
|
||||
// Serial.print(" / AngZ = ");
|
||||
// Serial.println(mpu.GetAngZ());
|
||||
|
||||
joystickData = JoystickGet(true);
|
||||
|
||||
if (sensorValue > maxvalue[i])
|
||||
maxvalue[i] = sensorValue;
|
||||
if (sensorValue < minvalue[i])
|
||||
minvalue[i] = sensorValue;
|
||||
data = GetSerialData(data, false);
|
||||
|
||||
outputValue = map(sensorValue, minvalue[i], maxvalue[i], 0, 255);
|
||||
outputValue = sensorValue > maxvalue[i] ? 255 : sensorValue < minvalue[i] ? 0 : outputValue;
|
||||
// if (sensorValue <= center[i])
|
||||
// {
|
||||
// outputValue = map(sensorValue, minvalue[i], center[i], 0, 127);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// outputValue = map(sensorValue, center[i], maxvalue[i], 128, 255);
|
||||
// }
|
||||
// data.servoPositions[0] = joystickData.value[0];
|
||||
data.remotePasstroughControl = data.remotePasstroughControl + 1;
|
||||
|
||||
Serial.print(i);
|
||||
Serial.print("_");
|
||||
Serial.print(outputValue);
|
||||
if (i != 5)
|
||||
Serial.print(",");
|
||||
// Serial.print(" ");
|
||||
}
|
||||
Serial.println();
|
||||
data = NrfSendData(data, true);
|
||||
|
||||
delay(20);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user