11/*
2- TODO - Fix Header
32
3+ Example-02_Callback.ino
44
5+ The TMF882X Arduino library uses the TMF882X Software Development Kit (SDK) from
6+ AMS to interface with the sensor. This SDK returns results by calling a provided
7+ function and passing in a message structure.
8+
9+ This example shows how to create and regsiter a callback function to recieve results
10+ from the library.
11+
12+ Supported Boards:
13+
14+ SparkFun Qwiic dToF Imager - TMF8820 https://www.sparkfun.com/products/19036
15+ SparkFun Qwiic Mini dToF Imager - TMF8820 https://www.sparkfun.com/products/19218
16+ SparkFun Qwiic Mini dToF Imager - TMF8821 https://www.sparkfun.com/products/19451
17+ SparkFun Qwiic dToF Imager - TMF8821 https://www.sparkfun.com/products/19037
18+
19+ Written by Kirk Benell @ SparkFun Electronics, April 2022
20+
21+ Repository:
22+ https://github.com/sparkfun/SparkFun_Qwiic_TMF882X_Arduino_Library
23+
24+ Documentation:
25+ https://sparkfun.github.io/SparkFun_Qwiic_OLED_Arduino_Library/
26+
27+ SparkFun code, firmware, and software is released under the MIT License(http://opensource.org/licenses/MIT).
528*/
6- // Example 02 - using a callback to detect messages.
729
8- #include " SparkFun_TMF882X_Library.h"
30+ #include " SparkFun_TMF882X_Library.h" // http://librarymanager/All#SparkFun_Qwiic_TMPF882X
931
1032SparkFun_TMF882X myTMF882X;
1133
34+ // Each loop takes a number of samples/measurements. Define how many to take here.
35+
1236#define NUMBER_OF_SAMPLES_TO_TAKE 4
1337
14- int nSample =0 ;
15- // Define our measurement callback function
38+ int nSample =0 ; // used to count how the number of measurements taken.
39+
40+
41+ // Define our measurement callback function. The Library calls this when a
42+ // measurment is taken.
1643
1744void onMeasurementCallback (struct tmf882x_msg_meas_results *myResults){
1845
@@ -52,10 +79,10 @@ void setup(){
5279 while (1 );
5380 }
5481
55- // set our call back function
82+ // set our callback function in the library.
5683 myTMF882X.setMeasurementHandler (onMeasurementCallback);
5784
58- // Set our delay between samples - 1 second - note it's in ms
85+ // Set our delay between samples in the processing loop - 1 second - note it's in ms
5986 myTMF882X.setSampleDelay (1000 );
6087}
6188
@@ -64,7 +91,10 @@ void loop()
6491 delay (2000 );
6592
6693 // get a measurment
67- // Have the sensor take 4 measurements, the results are sent to the above callback
94+ // Have the sensor take NUMBER_OF_SAMPLES_TO_TAKE measurements.
95+ //
96+ // As measurements are taken, the results are sent to the above function,
97+ // "onMeasurementCallback()"
6898
6999 Serial.println (" ---------------------------------------------------------" );
70100 Serial.print (" Taking " );
0 commit comments