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 cmd1; // normalized input values. -1000 to 1000
int cmd2; int cmd2;
// ########################## colorWipe ########################## // ########################## colorWipe ##########################
// Fill strip pixels one after another with a color. Strip is NOT cleared // 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 // 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 // (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), // strip.Color(red, green, blue) as shown in the loop() function above),
// and a delay time (in milliseconds) between pixels. // and a delay time (in milliseconds) between pixels.
void colorWipe(uint32_t color, int wait) { void colorWipe(uint32_t color, int wait)
for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip... {
for (int i = 0; i < strip.numPixels(); i++)
{ // For each pixel in strip...
strip.setPixelColor(i, color); // Set pixel's color (in RAM) strip.setPixelColor(i, color); // Set pixel's color (in RAM)
strip.show(); // Update strip to match strip.show(); // Update strip to match
delay(wait); // Pause for a moment delay(wait); // Pause for a moment
@ -126,11 +129,10 @@ void setup()
// Fill along the length of the strip in various colors... // Fill along the length of the strip in various colors...
colorWipe(strip.Color(255, 0, 0) , 20); // Red colorWipe(strip.Color(255, 0, 0), 20); // Red
colorWipe(strip.Color( 0, 255, 0) , 20); // Green colorWipe(strip.Color(0, 255, 0), 20); // Green
colorWipe(strip.Color( 0, 0, 255) , 20); // Blue colorWipe(strip.Color(0, 0, 255), 20); // Blue
colorWipe(strip.Color( 0, 0, 0) , 20); // Black colorWipe(strip.Color(0, 0, 0), 20); // Black
} }
// ########################## SEND ########################## // ########################## SEND ##########################
void Send(int16_t uSteer, int16_t uSpeed) void Send(int16_t uSteer, int16_t uSpeed)
@ -151,47 +153,51 @@ void Receive()
{ {
int old_cursorX, old_cursorY; int old_cursorX, old_cursorY;
// Check for new data availability in the Serial buffer // Check for new data availability in the Serial buffer
if (Serial1.available()) { if (Serial1.available())
{
incomingByte = Serial1.read(); // Read the incoming byte incomingByte = Serial1.read(); // Read the incoming byte
bufStartFrame = ((uint16_t) (incomingBytePrev) << 8) + incomingByte; // Construct the start frame bufStartFrame = ((uint16_t)(incomingBytePrev) << 8) + incomingByte; // Construct the start frame
} else { }
else
{
return; return;
} }
// If DEBUG_RX is defined print all incoming bytes // If DEBUG_RX is defined print all incoming bytes
#ifdef DEBUG_RX #ifdef DEBUG_RX
Serial.print(incomingByte); Serial.print(incomingByte);
return; return;
#endif #endif
// Copy received data // Copy received data
if (bufStartFrame == START_FRAME) { // Initialize if new data is detected if (bufStartFrame == START_FRAME)
p = (byte *) & NewFeedback; { // Initialize if new data is detected
p = (byte *)&NewFeedback;
*p++ = incomingBytePrev; *p++ = incomingBytePrev;
*p++ = incomingByte; *p++ = incomingByte;
idx = 2; 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; *p++ = incomingByte;
idx++; idx++;
} }
// Check if we reached the end of the package // Check if we reached the end of the package
if (idx == sizeof(SerialFeedback)) { if (idx == sizeof(SerialFeedback))
{
uint16_t checksum; uint16_t checksum;
checksum = checksum =
(uint16_t) (NewFeedback.start ^ NewFeedback.cmd1 ^ NewFeedback. (uint16_t)(NewFeedback.start ^ NewFeedback.cmd1 ^ NewFeedback.cmd2 ^ NewFeedback.speedR ^ NewFeedback.speedL ^ NewFeedback.speedR_meas ^ NewFeedback.speedL_meas ^ NewFeedback.batVoltage ^ NewFeedback.boardTemp);
cmd2 ^ NewFeedback.speedR ^ NewFeedback.
speedL ^ NewFeedback.speedR_meas ^ NewFeedback.
speedL_meas ^ NewFeedback.batVoltage ^ NewFeedback.
boardTemp);
// Check validity of the new data // Check validity of the new data
if (NewFeedback.start == START_FRAME if (NewFeedback.start == START_FRAME && checksum == NewFeedback.checksum)
&& checksum == NewFeedback.checksum) { {
// Copy the new data // Copy the new data
memcpy(&Feedback, &NewFeedback, sizeof(SerialFeedback)); memcpy(&Feedback, &NewFeedback, sizeof(SerialFeedback));
// Print data to CDC Serial if available // Print data to CDC Serial if available
if (Serial) { if (Serial)
{
Serial.print("1: "); Serial.print("1: ");
Serial.print(Feedback.cmd1); Serial.print(Feedback.cmd1);
Serial.print(" 2: "); Serial.print(" 2: ");
@ -219,7 +225,9 @@ void Receive()
display.setCursor(old_cursorX, old_cursorY); display.setCursor(old_cursorX, old_cursorY);
display.print(Feedback.batVoltage); display.print(Feedback.batVoltage);
display.display(); display.display();
} else { }
else
{
if (Serial) if (Serial)
Serial.println("Non-valid data skipped"); Serial.println("Non-valid data skipped");
} }

Loading…
Cancel
Save