@@ -68,21 +68,20 @@ int32_t QwDevXM125::distanceBegin()
68
68
{
69
69
return 2 ;
70
70
}
71
- delay (100 );
72
71
73
72
// Set Start register
74
73
if (setDistanceStart (300 ) != 0 )
75
74
{
76
75
return 3 ;
77
76
}
78
- delay (100 );
77
+ delay (100 ); // give time for command to set
79
78
80
79
// Set End register
81
80
if (setDistanceEnd (2500 ) != 0 )
82
81
{
83
82
return 4 ;
84
83
}
85
- delay (100 );
84
+ delay (100 ); // give time for command to set
86
85
87
86
// Apply configuration
88
87
if (setDistanceCommand (SFE_XM125_DISTANCE_APPLY_CONFIGURATION) != 0 )
@@ -132,6 +131,7 @@ int32_t QwDevXM125::distanceDetectorReadingSetup()
132
131
{
133
132
return 2 ;
134
133
}
134
+ delay (100 ); // give time for command to set
135
135
136
136
// Poll detector status until busy bit is cleared - CHECK ON THIS!
137
137
if (distanceBusyWait () != 0 )
@@ -769,37 +769,38 @@ int32_t QwDevXM125::distanceBusyWait()
769
769
int32_t QwDevXM125::presenceDetectorStart ()
770
770
{
771
771
// Presence Sensor Setup
772
- uint32_t errorStatus;
772
+ uint32_t errorStatus = 0 ;
773
773
774
774
// Reset sensor configuration to reapply configuration registers
775
775
if (setPresenceCommand (SFE_XM125_PRESENCE_RESET_MODULE) != 0 )
776
776
{
777
777
return 1 ;
778
778
}
779
+ delay (100 ); // give time for command to set
779
780
780
781
// Check detector status error and busy bits
781
- getPresenceDetectorErrorStatus (errorStatus);
782
+ if (getPresenceDetectorErrorStatus (errorStatus) != 0 )
783
+ {
784
+ return 2 ;
785
+ }
782
786
if (errorStatus != 0 )
783
787
{
784
- Serial.println (" Error status errrrrr" );
785
- return errorStatus;
786
- // return 2;
788
+ return 3 ;
787
789
}
788
- delay (100 );
789
790
790
791
// Set Presence Start register
791
792
if (setPresenceStart (300 ) != 0 )
792
793
{
793
- return 3 ;
794
+ return 4 ;
794
795
}
795
- delay (100 );
796
+ delay (100 ); // give time for command to set
796
797
797
798
// Set End register
798
799
if (setPresenceEnd (2500 ) != 0 )
799
800
{
800
- return 4 ;
801
+ return 5 ;
801
802
}
802
- delay (100 );
803
+ delay (100 ); // give time for command to set
803
804
804
805
// Apply configuration
805
806
if (setPresenceCommand (SFE_XM125_PRESENCE_APPLY_CONFIGURATION) != 0 )
@@ -808,23 +809,24 @@ int32_t QwDevXM125::presenceDetectorStart()
808
809
getPresenceDetectorErrorStatus (errorStatus);
809
810
if (errorStatus != 0 )
810
811
{
811
- return 5 ;
812
+ return 6 ;
812
813
}
813
814
814
- return 6 ;
815
+ return 7 ;
815
816
}
817
+ delay (100 ); // give time for command to set
816
818
817
819
// Poll detector status until busy bit is cleared
818
820
if (presenceBusyWait () != 0 )
819
821
{
820
- return 7 ;
822
+ return 8 ;
821
823
}
822
824
823
825
// Check detector error status
824
826
getPresenceDetectorErrorStatus (errorStatus);
825
827
if (errorStatus != 0 )
826
828
{
827
- return 8 ;
829
+ return 9 ;
828
830
}
829
831
830
832
// If no errors, return 0
@@ -849,6 +851,7 @@ int32_t QwDevXM125::getPresenceDistanceValuemm(uint32_t &presenceVal)
849
851
{
850
852
return 2 ;
851
853
}
854
+ delay (100 );
852
855
853
856
// Poll detector status until busy bit is cleared - CHECK ON THIS!
854
857
if (presenceBusyWait () != 0 )
@@ -863,7 +866,6 @@ int32_t QwDevXM125::getPresenceDistanceValuemm(uint32_t &presenceVal)
863
866
return 4 ;
864
867
}
865
868
866
-
867
869
// Read detector result register and determine detection status
868
870
getPresenceDetectorPresenceDetected (presenceDetected);
869
871
getPresenceDetectorPresenceStickyDetected (presenceDetectedSticky);
@@ -908,7 +910,7 @@ int32_t QwDevXM125::getPresenceDetectorStatus(uint32_t &status)
908
910
909
911
int32_t QwDevXM125::getPresenceDetectorErrorStatus (uint32_t &status)
910
912
{
911
- int32_t retVal;
913
+ int32_t retVal = 0 ;
912
914
uint32_t regVal = 0 ;
913
915
retVal = _theBus->readRegister16Region (SFE_XM125_PRESENCE_DETECTOR_STATUS, (uint8_t *)®Val, 4 );
914
916
flipBytes (regVal);
0 commit comments