Fix a bug where arduino would crash on incorrectly sized i2c payload
This commit is contained in:
parent
f6bb087799
commit
6fbb53b6bd
|
@ -41,8 +41,7 @@ void loop() {
|
||||||
|
|
||||||
// This method runs when we receive a message
|
// This method runs when we receive a message
|
||||||
void receiveEvent(int n) {
|
void receiveEvent(int n) {
|
||||||
Wire.read();
|
Wire.read(); // Remove smbus trash
|
||||||
digitalWrite(LED_BUILTIN, HIGH);
|
|
||||||
if (true) { // Dont do anything if this is not true
|
if (true) { // Dont do anything if this is not true
|
||||||
id = Wire.read(); // ID of the servo/device to access
|
id = Wire.read(); // ID of the servo/device to access
|
||||||
val = Wire.read(); // Value to assign
|
val = Wire.read(); // Value to assign
|
||||||
|
@ -56,5 +55,9 @@ void receiveEvent(int n) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
digitalWrite(LED_BUILTIN, LOW);
|
|
||||||
|
// Prevents a bug where if bytes are left in buffer, arduino crashes.
|
||||||
|
while (Wire.available()) {
|
||||||
|
Wire.read();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue