code format

bluepill
JbLb 6 years ago
parent fe9377cc28
commit 588212519f

@ -71,14 +71,17 @@ SerialFeedback NewFeedback;
int cmd1; // normalized input values. -1000 to 1000
int cmd2;
// ########################## colorWipe ##########################
// Fill strip pixels one after another with a color. Strip is NOT cleared
// first; anything there will be covered pixel by pixel. Pass in color
// (as a single 'packed' 32-bit value, which you can get by calling
// strip.Color(red, green, blue) as shown in the loop() function above),
// and a delay time (in milliseconds) between pixels.
void colorWipe(uint32_t color, int wait) {
for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...
void colorWipe(uint32_t color, int wait)
{
for (int i = 0; i < strip.numPixels(); i++)
{ // For each pixel in strip...
strip.setPixelColor(i, color); // Set pixel's color (in RAM)
strip.show(); // Update strip to match
delay(wait); // Pause for a moment
@ -130,7 +133,6 @@ void setup()
colorWipe(strip.Color(0, 255, 0), 20); // Green
colorWipe(strip.Color(0, 0, 255), 20); // Blue
colorWipe(strip.Color(0, 0, 0), 20); // Black
}
// ########################## SEND ##########################
void Send(int16_t uSteer, int16_t uSpeed)
@ -151,10 +153,13 @@ void Receive()
{
int old_cursorX, old_cursorY;
// Check for new data availability in the Serial buffer
if (Serial1.available()) {
if (Serial1.available())
{
incomingByte = Serial1.read(); // Read the incoming byte
bufStartFrame = ((uint16_t)(incomingBytePrev) << 8) + incomingByte; // Construct the start frame
} else {
}
else
{
return;
}
@ -165,33 +170,34 @@ void Receive()
#endif
// Copy received data
if (bufStartFrame == START_FRAME) { // Initialize if new data is detected
if (bufStartFrame == START_FRAME)
{ // Initialize if new data is detected
p = (byte *)&NewFeedback;
*p++ = incomingBytePrev;
*p++ = incomingByte;
idx = 2;
} else if (idx >= 2 && idx < sizeof(SerialFeedback)) { // Save the new received data
}
else if (idx >= 2 && idx < sizeof(SerialFeedback))
{ // Save the new received data
*p++ = incomingByte;
idx++;
}
// Check if we reached the end of the package
if (idx == sizeof(SerialFeedback)) {
if (idx == sizeof(SerialFeedback))
{
uint16_t checksum;
checksum =
(uint16_t) (NewFeedback.start ^ NewFeedback.cmd1 ^ NewFeedback.
cmd2 ^ NewFeedback.speedR ^ NewFeedback.
speedL ^ NewFeedback.speedR_meas ^ NewFeedback.
speedL_meas ^ NewFeedback.batVoltage ^ NewFeedback.
boardTemp);
(uint16_t)(NewFeedback.start ^ NewFeedback.cmd1 ^ NewFeedback.cmd2 ^ NewFeedback.speedR ^ NewFeedback.speedL ^ NewFeedback.speedR_meas ^ NewFeedback.speedL_meas ^ NewFeedback.batVoltage ^ NewFeedback.boardTemp);
// Check validity of the new data
if (NewFeedback.start == START_FRAME
&& checksum == NewFeedback.checksum) {
if (NewFeedback.start == START_FRAME && checksum == NewFeedback.checksum)
{
// Copy the new data
memcpy(&Feedback, &NewFeedback, sizeof(SerialFeedback));
// Print data to CDC Serial if available
if (Serial) {
if (Serial)
{
Serial.print("1: ");
Serial.print(Feedback.cmd1);
Serial.print(" 2: ");
@ -219,7 +225,9 @@ void Receive()
display.setCursor(old_cursorX, old_cursorY);
display.print(Feedback.batVoltage);
display.display();
} else {
}
else
{
if (Serial)
Serial.println("Non-valid data skipped");
}

Loading…
Cancel
Save