The sample code that you have provided for R307 sensor is working only for 'Enrolled Fingerprints' . It is not detecting 'Invalid Fingerprints'.
Can you help me with that(Invalid Fingerprint) part of the code?
This is not a direct line to whoever wrote the mysterious sample code you mentioned. You will be much more likely to get help if you post a link to where you downloaded this code from and if there are multiple samples there, explain exactly which one you're using.
I think you need to do something like this in your code:
if (enrolled) {
// handle enrolled fingerprint
}
else {
// handle invalid fingerprint
}