@@ -68,21 +68,20 @@ int32_t QwDevXM125::distanceBegin()
6868 {
6969 return 2 ;
7070 }
71- delay (100 );
7271
7372 // Set Start register
7473 if (setDistanceStart (300 ) != 0 )
7574 {
7675 return 3 ;
7776 }
78- delay (100 );
77+ delay (100 ); // give time for command to set
7978
8079 // Set End register
8180 if (setDistanceEnd (2500 ) != 0 )
8281 {
8382 return 4 ;
8483 }
85- delay (100 );
84+ delay (100 ); // give time for command to set
8685
8786 // Apply configuration
8887 if (setDistanceCommand (SFE_XM125_DISTANCE_APPLY_CONFIGURATION) != 0 )
@@ -132,6 +131,7 @@ int32_t QwDevXM125::distanceDetectorReadingSetup()
132131 {
133132 return 2 ;
134133 }
134+ delay (100 ); // give time for command to set
135135
136136 // Poll detector status until busy bit is cleared - CHECK ON THIS!
137137 if (distanceBusyWait () != 0 )
@@ -769,37 +769,38 @@ int32_t QwDevXM125::distanceBusyWait()
769769int32_t QwDevXM125::presenceDetectorStart ()
770770{
771771 // Presence Sensor Setup
772- uint32_t errorStatus;
772+ uint32_t errorStatus = 0 ;
773773
774774 // Reset sensor configuration to reapply configuration registers
775775 if (setPresenceCommand (SFE_XM125_PRESENCE_RESET_MODULE) != 0 )
776776 {
777777 return 1 ;
778778 }
779+ delay (100 ); // give time for command to set
779780
780781 // Check detector status error and busy bits
781- getPresenceDetectorErrorStatus (errorStatus);
782+ if (getPresenceDetectorErrorStatus (errorStatus) != 0 )
783+ {
784+ return 2 ;
785+ }
782786 if (errorStatus != 0 )
783787 {
784- Serial.println (" Error status errrrrr" );
785- return errorStatus;
786- // return 2;
788+ return 3 ;
787789 }
788- delay (100 );
789790
790791 // Set Presence Start register
791792 if (setPresenceStart (300 ) != 0 )
792793 {
793- return 3 ;
794+ return 4 ;
794795 }
795- delay (100 );
796+ delay (100 ); // give time for command to set
796797
797798 // Set End register
798799 if (setPresenceEnd (2500 ) != 0 )
799800 {
800- return 4 ;
801+ return 5 ;
801802 }
802- delay (100 );
803+ delay (100 ); // give time for command to set
803804
804805 // Apply configuration
805806 if (setPresenceCommand (SFE_XM125_PRESENCE_APPLY_CONFIGURATION) != 0 )
@@ -808,23 +809,24 @@ int32_t QwDevXM125::presenceDetectorStart()
808809 getPresenceDetectorErrorStatus (errorStatus);
809810 if (errorStatus != 0 )
810811 {
811- return 5 ;
812+ return 6 ;
812813 }
813814
814- return 6 ;
815+ return 7 ;
815816 }
817+ delay (100 ); // give time for command to set
816818
817819 // Poll detector status until busy bit is cleared
818820 if (presenceBusyWait () != 0 )
819821 {
820- return 7 ;
822+ return 8 ;
821823 }
822824
823825 // Check detector error status
824826 getPresenceDetectorErrorStatus (errorStatus);
825827 if (errorStatus != 0 )
826828 {
827- return 8 ;
829+ return 9 ;
828830 }
829831
830832 // If no errors, return 0
@@ -849,6 +851,7 @@ int32_t QwDevXM125::getPresenceDistanceValuemm(uint32_t &presenceVal)
849851 {
850852 return 2 ;
851853 }
854+ delay (100 );
852855
853856 // Poll detector status until busy bit is cleared - CHECK ON THIS!
854857 if (presenceBusyWait () != 0 )
@@ -863,7 +866,6 @@ int32_t QwDevXM125::getPresenceDistanceValuemm(uint32_t &presenceVal)
863866 return 4 ;
864867 }
865868
866-
867869 // Read detector result register and determine detection status
868870 getPresenceDetectorPresenceDetected (presenceDetected);
869871 getPresenceDetectorPresenceStickyDetected (presenceDetectedSticky);
@@ -908,7 +910,7 @@ int32_t QwDevXM125::getPresenceDetectorStatus(uint32_t &status)
908910
909911int32_t QwDevXM125::getPresenceDetectorErrorStatus (uint32_t &status)
910912{
911- int32_t retVal;
913+ int32_t retVal = 0 ;
912914 uint32_t regVal = 0 ;
913915 retVal = _theBus->readRegister16Region (SFE_XM125_PRESENCE_DETECTOR_STATUS, (uint8_t *)®Val, 4 );
914916 flipBytes (regVal);
0 commit comments