Skip to content

Commit 5c6af60

Browse files
No errors; distance begin() completed
Added more constants that are required, along with adding more functionality for distance begin
1 parent 908c905 commit 5c6af60

File tree

4 files changed

+61
-7
lines changed

4 files changed

+61
-7
lines changed

examples/Example04_PresenceBasicReadings/Example04_PresenceBasicReadings.ino

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ void setup()
5555

5656
delay(200);
5757

58+
// Default start = 1000; Default stop = 5000
5859
int32_t sensorStartError = radarSensor.presenceDetectorStart();
5960
if(sensorStartError != 0)
6061
{
@@ -66,14 +67,28 @@ void setup()
6667
while(1); // Runs forever
6768
}
6869

70+
// Test code below - delete once complete
71+
uint32_t startVal = 0;
72+
uint32_t endVal = 0;
73+
radarSensor.getPresenceStart(startVal);
74+
radarSensor.getPresenceEnd(endVal);
75+
Serial.print("Start Val: ");
76+
Serial.println(startVal);
77+
Serial.print("End Val: ");
78+
Serial.println(endVal);
79+
6980
delay(1000);
81+
while(1);
7082
}
7183

7284
void loop()
7385
{
86+
radarSensor.setPresenceCommand(SFE_XM125_PRESENCE_START_DETECTOR);
7487
// If Presence is detected, then print out distance from device
7588
radarSensor.getPresenceDetectorPresenceDetected(presenceDetected);
76-
89+
Serial.print("Presence Detector flag: ");
90+
Serial.println(presenceDetected);
91+
7792
radarSensor.getPresenceDistance(distance);
7893
Serial.print("Presence detected at ");
7994
Serial.print(distance);

src/sfeQwiicXM125.cpp

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,42 @@ bool QwDevXM125::begin(sfeTkII2C *theBus)
5050

5151
int32_t QwDevXM125::distanceBegin()
5252
{
53+
// Set start to 1000mm
54+
if(setDistanceStart(1000) != 0)
55+
{
56+
return -1;
57+
}
58+
if(setDistanceEnd(5000) != 0)
59+
{
60+
return -2;
61+
}
62+
63+
// Apply configuration
64+
if(setPresenceCommand(SFE_XM125_DISTANCE_APPLY_CONFIGURATION) != 0)
65+
{
66+
return -3;
67+
}
68+
69+
// Wait for configuration to be done
70+
// Wait for configuration to be done
71+
if(distanceBusyWait() != 0)
72+
{
73+
return -4;
74+
}
75+
76+
// Start detector
77+
if(setDistanceCommand(SFE_XM125_DISTANCE_START_DETECTOR) != 0)
78+
{
79+
return -5;
80+
}
81+
82+
// Wait for configuration to be done
83+
// Wait for configuration to be done
84+
if(distanceBusyWait() != 0)
85+
{
86+
return -6;
87+
}
88+
5389
return 0;
5490
}
5591

@@ -420,17 +456,16 @@ int32_t QwDevXM125::distanceBusyWait()
420456

421457
// --------------------- I2C Presence Detector Functions ---------------------
422458

423-
int32_t QwDevXM125::presenceDetectorStart()
459+
int32_t QwDevXM125::presenceDetectorStart(uint32_t start, uint32_t stop)
424460
{
425-
Serial.println("Presence Sensor Start function");
426461
// Set Start to 1000mm
427-
if(setPresenceStart(1000) != 0)
462+
if(setPresenceStart(start) != 0)
428463
{
429464
return -1;
430465
}
431466

432467
// Set end at 5000mm
433-
if(setPresenceEnd(5000) != 0)
468+
if(setPresenceEnd(stop) != 0)
434469
{
435470
return -2;
436471
}

src/sfeQwiicXM125.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,10 @@ class QwDevXM125
362362

363363
/// @brief This function sets all the beginning values for a basic I2C
364364
/// example to be run on the device for presence sensing.
365+
/// @param start Value in mm to start, default 1000mm
366+
/// @param stop Value in mm to stop, default 5000mm
365367
/// @return Error code (0 no error)
366-
int32_t presenceDetectorStart();
368+
int32_t presenceDetectorStart(uint32_t start = 1000, uint32_t stop = 5000);
367369

368370
/// @brief This function returns the RSS version number
369371
/// @param version Version number
@@ -768,7 +770,8 @@ class QwDevXM125
768770
int32_t presenceReset();
769771

770772
/// @brief Completes a busy wait loop while the device is uploading
771-
/// information by waiting for the status
773+
/// information by waiting for the status. Checks the error status register
774+
/// to wait until errors are completed/gone
772775
/// @return Error code (0 no error)
773776
int32_t presenceBusyWait();
774777

src/sfeXM125Regs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ typedef enum
224224
XM125_DISTANCE_RESET_MODULE = 1381192737,
225225
} sfe_xm125_distance_command_t;
226226

227+
const uint32_t SFE_XM125_DISTANCE_APPLY_CONFIGURATION = 1;
227228
const uint32_t SFE_XM125_DISTANCE_START_DETECTOR = 2;
228229
const uint32_t SFE_XM125_DISTANCE_STOP_DETECTOR = 3;
229230
const uint32_t SFE_XM125_DISTANCE_RESET_MODULE = 1381192737;

0 commit comments

Comments
 (0)