|
|
|
@ -159,11 +159,11 @@ void Receive()
|
|
|
|
if (idx == sizeof(SerialFeedback)) {
|
|
|
|
if (idx == sizeof(SerialFeedback)) {
|
|
|
|
uint16_t checksum;
|
|
|
|
uint16_t checksum;
|
|
|
|
checksum =
|
|
|
|
checksum =
|
|
|
|
(uint16_t) (NewFeedback.start ^ NewFeedback.
|
|
|
|
(uint16_t) (NewFeedback.start ^ NewFeedback.cmd1 ^ NewFeedback.
|
|
|
|
cmd1 ^ NewFeedback.cmd2 ^ NewFeedback.
|
|
|
|
cmd2 ^ NewFeedback.speedR ^ NewFeedback.
|
|
|
|
speedR ^ NewFeedback.speedL ^ NewFeedback.
|
|
|
|
speedL ^ NewFeedback.speedR_meas ^ NewFeedback.
|
|
|
|
speedR_meas ^ NewFeedback.speedL_meas ^
|
|
|
|
speedL_meas ^ NewFeedback.batVoltage ^ NewFeedback.
|
|
|
|
NewFeedback.batVoltage ^ NewFeedback.boardTemp);
|
|
|
|
boardTemp);
|
|
|
|
|
|
|
|
|
|
|
|
// Check validity of the new data
|
|
|
|
// Check validity of the new data
|
|
|
|
if (NewFeedback.start == START_FRAME
|
|
|
|
if (NewFeedback.start == START_FRAME
|
|
|
|
@ -201,11 +201,44 @@ void Receive()
|
|
|
|
incomingBytePrev = incomingByte;
|
|
|
|
incomingBytePrev = incomingByte;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ########################## nunchuk ##########################
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Nunchuk_display()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!nchuk.update()) {
|
|
|
|
|
|
|
|
if (Serial) {
|
|
|
|
|
|
|
|
Serial.println("Controller disconnected!");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
nchuk.reconnect();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if (Serial) {
|
|
|
|
|
|
|
|
// Read a button (on/off, C and Z)
|
|
|
|
|
|
|
|
Serial.print("Z: ");
|
|
|
|
|
|
|
|
nchuk.buttonZ()? Serial.print("On ") : Serial.print("Off ");
|
|
|
|
|
|
|
|
Serial.print("C: ");
|
|
|
|
|
|
|
|
nchuk.buttonC()? Serial.print("On ") : Serial.print("Off ");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Read joystick axis (0-255, X and Y)
|
|
|
|
|
|
|
|
Serial.print("The joystick's Y axis is at ");
|
|
|
|
|
|
|
|
Serial.print(nchuk.joyY());
|
|
|
|
|
|
|
|
Serial.print(" and X axis is at ");
|
|
|
|
|
|
|
|
Serial.print(nchuk.joyX());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Read an accelerometer and print values (0-1023, X, Y, and Z)
|
|
|
|
|
|
|
|
Serial.print(" - The accelerometer's X-axis is at ");
|
|
|
|
|
|
|
|
Serial.println(nchuk.accelX());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ########################## LOOP ##########################
|
|
|
|
// ########################## LOOP ##########################
|
|
|
|
|
|
|
|
|
|
|
|
unsigned long iTimeSend = 0;
|
|
|
|
unsigned long iTimeSend = 0;
|
|
|
|
int iTestMax = SPEED_MAX_TEST;
|
|
|
|
int iTestMax = SPEED_MAX_TEST;
|
|
|
|
int iTest = 0;
|
|
|
|
int iTest = 0;
|
|
|
|
|
|
|
|
int16_t old_cursorX;
|
|
|
|
|
|
|
|
int16_t old_cursorY;
|
|
|
|
|
|
|
|
|
|
|
|
void loop(void)
|
|
|
|
void loop(void)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -213,28 +246,7 @@ void loop(void)
|
|
|
|
|
|
|
|
|
|
|
|
// Check for new received data
|
|
|
|
// Check for new received data
|
|
|
|
Receive();
|
|
|
|
Receive();
|
|
|
|
// Get new data from the controller
|
|
|
|
Nunchuk_display();
|
|
|
|
if (!nchuk.update()) {
|
|
|
|
|
|
|
|
Serial.println("Controller disconnected!");
|
|
|
|
|
|
|
|
nchuk.reconnect();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// Read a button (on/off, C and Z)
|
|
|
|
|
|
|
|
Serial.print("Z: ");
|
|
|
|
|
|
|
|
nchuk.buttonZ()? Serial.print("On ") : Serial.print("Off ");
|
|
|
|
|
|
|
|
Serial.print("C: ");
|
|
|
|
|
|
|
|
nchuk.buttonC()? Serial.print("On ") : Serial.print("Off ");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Read joystick axis (0-255, X and Y)
|
|
|
|
|
|
|
|
Serial.print("The joystick's Y axis is at ");
|
|
|
|
|
|
|
|
Serial.print(nchuk.joyY());
|
|
|
|
|
|
|
|
Serial.print(" and X axis is at ");
|
|
|
|
|
|
|
|
Serial.print(nchuk.joyX());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Read an accelerometer and print values (0-1023, X, Y, and Z)
|
|
|
|
|
|
|
|
Serial.print(" - The accelerometer's X-axis is at ");
|
|
|
|
|
|
|
|
Serial.println(nchuk.accelX());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Send commands
|
|
|
|
// Send commands
|
|
|
|
if (iTimeSend > timeNow)
|
|
|
|
if (iTimeSend > timeNow)
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|