Skip to content

Instantly share code, notes, and snippets.

@elfgoh
Last active August 29, 2015 14:08
Show Gist options
  • Save elfgoh/298724f27df9c514354a to your computer and use it in GitHub Desktop.
Save elfgoh/298724f27df9c514354a to your computer and use it in GitHub Desktop.
VC0706 library motion detection method debugging
boolean VC0706::motionDetected(void)
{
if (_read(4, 200) != 4) {
Serial.println("in read");
return false;
}
if (!_verify(VC0706_COMM_MOTION_DETECTED)){
Serial.println("in verify");
Serial.println(_verify(VC0706_COMM_MOTION_DETECTED));
Serial.println("in verify 2");
Serial.println(VC0706_COMM_MOTION_DETECTED);
return false;
}
return true;
}
@notthetup
Copy link

boolean VC0706::motionDetected(void)
{

    // try to read 4 bytes. If you cannot successfully read 4 bytes, return false;
    if (_read(4, 200) != 4) {
        Serial.println("in read");
        return false;
    }
    // having read 4 bytes, verify if the read data payload was VC0706_COMM_MOTION_DETECTED
   // if not print some debug statements and return false
   // else return true
    if (!_verify(VC0706_COMM_MOTION_DETECTED))
        Serial.println("in verify");
        Serial.println(_verify(VC0706_COMM_MOTION_DETECTED));

        Serial.println("in verify 2");
        Serial.println(VC0706_COMM_MOTION_DETECTED);
        return false;
    return true;
}

@elfgoh
Copy link
Author

elfgoh commented Oct 25, 2014

I am trying to follow the code logic of invocation from !_verify(VC0706_COMM_MOTION_DETECTED)

Based on debug messages and documentation, it seems that the return from this method will be 0 if comms is happening correctly. If that is the case, why is the ! operator used in the 2nd if? If comms happens correctly, this will evaluate to true and subsequently, false will be returned for motionDetected().

PS. I might have made a mistake in my code somewhere. But just wanna make sure my logic is correct so far

@notthetup
Copy link

Yup. You're right. That seems like a bit weird. It should be _verify(VC0706_COMM_MOTION_DETECTED) without the !.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment