Conversation
| WIRE.requestFrom(address, 20, 1); | ||
| if (hasError()) return -1; | ||
| int error = checkError(); | ||
| if (error != 1) { |
There was a problem hiding this comment.
Bit of a subjective take here, but I think you should keep all the error handling logic in the hasError function and keep returning just true or false. The idea is to encapsulate as much as possible into the smallest units possible. If you want to check what type of error you got, or print the type of error, or do something else related to the error, that can still go into hasError() because it's not related to reading the actual co2. By having one function to handle and decide what to do when you get an error, you can reuse that logic.
If you want to send this error number to the dashboard though, that makes sense to have it return an int. Just be careful not to serial print things in the meantime as the serial lines are reserved for other (binary) communication and printing anything else will interfere
| int error = checkError(); | ||
| if (error != 1) { | ||
| Serial.print("CO2 Error: "); | ||
| Serial.println(error); |
There was a problem hiding this comment.
Prints for testing should be removed before you merge
Added explicit reporting of any errors and fixed bug with missing increment for response array.