Skip to content

Commit 4d59101

Browse files
committed
BIG refactor of class structure - broke the main class into two classes with a core base. The two main classes now correspond to the application running on the XM125 - v1 of this library had one class that contained everything - nuts. This will break backward compatablity, but the end user just needs to change the name of the class they are using
1 parent b2b59ec commit 4d59101

File tree

18 files changed

+1765
-1684
lines changed

18 files changed

+1765
-1684
lines changed

examples/Example01_PresenceBasicReadings/Example01_PresenceBasicReadings.ino

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
Using the Acconeer XM125 A121 60GHz Pulsed Coherent Radar Sensor.
55
66
This example shows how operate the XM125 when the device is in Presence Reading Mode.
7-
The sensor is initialized, then the presence distance values will print out
7+
The sensor is initialized, then the presence distance values will print out
88
to the terminal.
99
1010
By: Madison Chodikov
1111
SparkFun Electronics
1212
Date: 2024/1/22
1313
SparkFun code, firmware, and software is released under the MIT License.
14-
Please see LICENSE.md for further details.
14+
Please see LICENSE.md for further details.
1515
1616
Hardware Connections:
1717
QWIIC --> QWIIC
@@ -21,15 +21,15 @@
2121
Feel like supporting our work? Buy a board from SparkFun!
2222
https://www.sparkfun.com/products/ - Qwiic XM125 Breakout
2323
*/
24-
#include <Arduino.h>
2524
#include "SparkFun_Qwiic_XM125_Arduino_Library.h"
25+
#include <Arduino.h>
2626

27-
SparkFunXM125 radarSensor;
27+
SparkFunXM125Presence radarSensor;
2828

2929
// I2C default address
3030
uint8_t i2cAddress = SFE_XM125_I2C_ADDRESS;
3131

32-
// Presence distance values
32+
// Presence distance values
3333
uint32_t distance = 0;
3434

3535
// Error statuses
@@ -50,7 +50,7 @@ void setup()
5050

5151
// If begin is successful (1), then start example
5252
int startErr = radarSensor.begin(i2cAddress, Wire);
53-
if(startErr == 1)
53+
if (startErr == 1)
5454
{
5555
Serial.println("Begin");
5656
}
@@ -59,15 +59,16 @@ void setup()
5959
Serial.print("Start Error Code: ");
6060
Serial.println(startErr);
6161
Serial.println("Device failed to setup - Freezing code.");
62-
while(1); // Runs forever
62+
while (1)
63+
; // Runs forever
6364
}
6465

6566
// Start the sensor with default register values
6667
int32_t setupError = radarSensor.presenceDetectorStart();
67-
if(setupError != 0)
68+
if (setupError != 0)
6869
{
69-
Serial.print("Presence Detection Start Setup Error: ");
70-
Serial.println(setupError);
70+
Serial.print("Presence Detection Start Setup Error: ");
71+
Serial.println(setupError);
7172
}
7273

7374
// New line and delay for easier reading
@@ -83,23 +84,23 @@ void loop()
8384
// Get the presence distance value and print out if no errors
8485
presValError = radarSensor.getPresenceDistanceValuemm(distance);
8586

86-
if(presValError == 0)
87+
if (presValError == 0)
8788
{
88-
Serial.print("Presence Detected: ");
89-
Serial.print(distance);
90-
Serial.println("mm");
91-
//Serial.print(distance * .1);
92-
//Serial.println("cm");
93-
//Serial.print(distance * .001);
94-
//Serial.println("m");
95-
//Serial.print(distance * .001);
96-
//Serial.println("m");
97-
//Serial.print(distance * .03937008);
98-
//Serial.println("In");
89+
Serial.print("Presence Detected: ");
90+
Serial.print(distance);
91+
Serial.println("mm");
92+
// Serial.print(distance * .1);
93+
// Serial.println("cm");
94+
// Serial.print(distance * .001);
95+
// Serial.println("m");
96+
// Serial.print(distance * .001);
97+
// Serial.println("m");
98+
// Serial.print(distance * .03937008);
99+
// Serial.println("In");
99100
}
100101
else
101102
{
102-
Serial.println("Error returning presence distance value");
103+
Serial.println("Error returning presence distance value");
103104
}
104105

105106
// Delay 0.5 seconds between readings

examples/Example02_PresenceGPIO0Usage/Example02_PresenceGPIO0Usage.ino

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
Using the Acconeer XM125 A121 60GHz Pulsed Coherent Radar Sensor.
55
66
This example shows how operate the XM125 when the device is in Presence Reading Mode.
7-
The sensor is initialized, then the presence values will print out to the terminal
8-
and trigger the GPIO0 pin high when there is a presence detected.
7+
The sensor is initialized, then the presence values will print out to the terminal
8+
and trigger the GPIO0 pin high when there is a presence detected.
99
1010
By: Madison Chodikov
1111
SparkFun Electronics
1212
Date: 2024/1/22
1313
SparkFun code, firmware, and software is released under the MIT License.
14-
Please see LICENSE.md for further details.
14+
Please see LICENSE.md for further details.
1515
1616
Hardware Connections:
1717
QWIIC --> QWIIC
@@ -21,15 +21,15 @@
2121
Feel like supporting our work? Buy a board from SparkFun!
2222
https://www.sparkfun.com/products/ - Qwiic XM125 Breakout
2323
*/
24-
#include <Arduino.h>
2524
#include "SparkFun_Qwiic_XM125_Arduino_Library.h"
25+
#include <Arduino.h>
2626

27-
SparkFunXM125 radarSensor;
27+
SparkFunXM125Presence radarSensor;
2828

2929
// I2C default address
3030
uint8_t i2cAddress = SFE_XM125_I2C_ADDRESS;
3131

32-
// Presence distance values
32+
// Presence distance values
3333
uint32_t distance = 0;
3434
uint32_t presenceDetected = 0;
3535
uint32_t presenceDetectedSticky = 0;
@@ -46,14 +46,14 @@ void setup()
4646
{
4747
// Start serial
4848
Serial.begin(115200);
49-
Serial.println("XM125 Example 2: Presence GPIO0 Pin Usage");
49+
Serial.println("XM125 Example 2: Presence GPIO0 Pin Usage");
5050
Serial.println("");
5151

5252
Wire.begin();
5353

5454
// If begin is successful (0), then start example
5555
int startErr = radarSensor.begin(i2cAddress, Wire);
56-
if(startErr == 1)
56+
if (startErr == 1)
5757
{
5858
Serial.println("Begin");
5959
}
@@ -62,64 +62,65 @@ void setup()
6262
Serial.print("Start Error Code: ");
6363
Serial.println(startErr);
6464
Serial.println("Device failed to setup - Freezing code.");
65-
while(1); // Runs forever
65+
while (1)
66+
; // Runs forever
6667
}
6768

6869
delay(200);
6970

70-
// Presence Sensor Setup
71+
// Presence Sensor Setup
7172
// Reset sensor configuration to reapply configuration registers
7273
radarSensor.setPresenceCommand(SFE_XM125_PRESENCE_RESET_MODULE);
7374

74-
// Check error and busy bits
75+
// Check error and busy bits
7576
radarSensor.getPresenceDetectorErrorStatus(errorStatus);
76-
if(errorStatus != 0)
77+
if (errorStatus != 0)
7778
{
78-
Serial.print("Detector status error: ");
79-
Serial.println(errorStatus);
79+
Serial.print("Detector status error: ");
80+
Serial.println(errorStatus);
8081
}
8182

8283
delay(100);
8384

84-
// Turn presence detection on GPIO0 on
85-
if(radarSensor.setPresenceDetectionOnGPIO(1) != 0)
85+
// Turn presence detection on GPIO0 on
86+
if (radarSensor.setPresenceDetectionOnGPIO(1) != 0)
8687
{
87-
Serial.println("GPIO0 Pin Setup Error");
88+
Serial.println("GPIO0 Pin Setup Error");
8889
}
8990
radarSensor.getPresenceDetectionOnGPIO(gpioUsage);
9091
Serial.print("GPIO0 Detection Status: ");
9192
Serial.println(gpioUsage);
9293

93-
// Apply configuration
94-
if(radarSensor.setPresenceCommand(SFE_XM125_PRESENCE_APPLY_CONFIGURATION) != 0)
94+
// Apply configuration
95+
if (radarSensor.setPresenceCommand(SFE_XM125_PRESENCE_APPLY_CONFIGURATION) != 0)
9596
{
96-
// Check for errors
97-
radarSensor.getPresenceDetectorErrorStatus(errorStatus);
98-
if(errorStatus != 0)
99-
{
100-
Serial.print("Detector status error: ");
101-
Serial.println(errorStatus);
102-
}
103-
104-
Serial.println("Configuration application error");
97+
// Check for errors
98+
radarSensor.getPresenceDetectorErrorStatus(errorStatus);
99+
if (errorStatus != 0)
100+
{
101+
Serial.print("Detector status error: ");
102+
Serial.println(errorStatus);
103+
}
104+
105+
Serial.println("Configuration application error");
105106
}
106107

107108
// Poll detector status until busy bit is cleared
108-
if(radarSensor.presenceBusyWait() != 0)
109+
if (radarSensor.presenceBusyWait() != 0)
109110
{
110-
Serial.print("Busy wait error");
111+
Serial.print("Busy wait error");
111112
}
112113

113-
// Check detector status
114+
// Check detector status
114115
radarSensor.getPresenceDetectorErrorStatus(errorStatus);
115-
if(errorStatus != 0)
116+
if (errorStatus != 0)
116117
{
117-
Serial.print("Detector status error: ");
118-
Serial.println(errorStatus);
118+
Serial.print("Detector status error: ");
119+
Serial.println(errorStatus);
119120
}
120121

121122
Serial.println();
122-
123+
123124
delay(1000);
124125
}
125126

@@ -131,15 +132,15 @@ void loop()
131132
// Get the presence distance value and print out if no errors
132133
presValError = radarSensor.getPresenceDistanceValuemm(distance);
133134

134-
if(presValError == 0)
135+
if (presValError == 0)
135136
{
136-
Serial.print("Presence Detected: ");
137-
Serial.print(distance);
138-
Serial.println("mm");
137+
Serial.print("Presence Detected: ");
138+
Serial.print(distance);
139+
Serial.println("mm");
139140
}
140141
else
141142
{
142-
Serial.println("Error returning presence distance value");
143+
Serial.println("Error returning presence distance value");
143144
}
144145

145146
// Delay 0.5 seconds between readings

examples/Example03_PresenceSerialPlotter/Example03_PresenceSerialPlotter.ino

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
SparkFun Electronics
1212
Date: 2024/1/22
1313
SparkFun code, firmware, and software is released under the MIT License.
14-
Please see LICENSE.md for further details.
14+
Please see LICENSE.md for further details.
1515
1616
Hardware Connections:
1717
QWIIC --> QWIIC
@@ -21,15 +21,15 @@
2121
Feel like supporting our work? Buy a board from SparkFun!
2222
https://www.sparkfun.com/products/ - Qwiic XM125 Breakout
2323
*/
24-
#include <Arduino.h>
2524
#include "SparkFun_Qwiic_XM125_Arduino_Library.h"
25+
#include <Arduino.h>
2626

27-
SparkFunXM125 radarSensor;
27+
SparkFunXM125Presence radarSensor;
2828

2929
// I2C default address
3030
uint8_t i2cAddress = SFE_XM125_I2C_ADDRESS;
3131

32-
// Presence distance values
32+
// Presence distance values
3333
uint32_t distance = 0;
3434
uint32_t presenceDetected = 0;
3535
uint32_t presenceDetectedSticky = 0;
@@ -52,7 +52,7 @@ void setup()
5252

5353
// If begin is successful (0), then start example
5454
int startErr = radarSensor.begin(i2cAddress, Wire);
55-
if(startErr == 1)
55+
if (startErr == 1)
5656
{
5757
Serial.println("Begin");
5858
}
@@ -61,17 +61,18 @@ void setup()
6161
Serial.print("Start Error Code: ");
6262
Serial.println(startErr);
6363
Serial.println("Device failed to setup - Freezing code.");
64-
while(1); // Runs forever
64+
while (1)
65+
; // Runs forever
6566
}
6667

6768
delay(200);
6869

6970
// Start the sensor with default register values
7071
int32_t setupError = radarSensor.presenceDetectorStart();
71-
if(setupError != 0)
72+
if (setupError != 0)
7273
{
73-
Serial.print("Presence Detection Start Setup Error: ");
74-
Serial.println(setupError);
74+
Serial.print("Presence Detection Start Setup Error: ");
75+
Serial.println(setupError);
7576
}
7677

7778
// New line and delay for easier reading
@@ -87,10 +88,10 @@ void loop()
8788
// Get the presence distance value and print out if no errors
8889
presValError = radarSensor.getPresenceDistanceValuemm(distance);
8990

90-
if(presValError == 0)
91+
if (presValError == 0)
9192
{
92-
radarSensor.getPresenceDistance(distance);
93-
Serial.println(distance);
93+
radarSensor.getPresenceDistance(distance);
94+
Serial.println(distance);
9495
}
9596

9697
// Delay 0.5 seconds between readings

0 commit comments

Comments
 (0)