1+ /* *
2+ * This sketch assumes that the tag is doing positioning through a master tag (or through the cloud app)
3+ * This sketch will check on the pozyx device if a new position is available.
4+ * The sketch itself does not initiate the positioning, it is assumed that this is iniated by another tag through remote positioning.
5+ * When a tag is being remotely positioned, it is only possible to perform read operations, any other operations
6+ * may result in problems positioning.
7+ *
8+ * Note that in order to use this sketch, it is necessary to enable the CR (carriage return) in the Serial Monitor
9+ *
10+ * Author, Laurent Van Acker, Pozyx Labs
11+ *
12+ */
13+
14+ #include < Pozyx.h>
15+ #include < Pozyx_definitions.h>
16+ #include < Wire.h>
17+
18+ void setup (){
19+ Serial.begin (115200 );
20+ if (Pozyx.begin () == POZYX_FAILURE){
21+ Serial.println (F (" ERROR: Unable to connect to POZYX shield" ));
22+ Serial.println (F (" Reset required" ));
23+ delay (100 );
24+ abort ();
25+ }
26+ }
27+
28+ void loop (){
29+ coordinates_t position;
30+ int status = checkLocalNewPosition (&position);
31+ if (status == POZYX_SUCCESS){
32+ // prints out the result
33+ printCoordinates (position);
34+ }else {
35+ // prints out the error code
36+ printErrorCode (" positioning" );
37+ }
38+ }
39+
40+ int checkLocalNewPosition (coordinates_t *position)
41+ {
42+ assert (position != NULL );
43+ int status;
44+ uint8_t int_status = 0 ;
45+ // now wait for the positioning to finish or generate an error
46+ if (Pozyx.waitForFlag_safe (POZYX_INT_STATUS_POS | POZYX_INT_STATUS_ERR, 2 *POZYX_DELAY_INTERRUPT, &int_status)){
47+ if ((int_status & POZYX_INT_STATUS_ERR) == POZYX_INT_STATUS_ERR)
48+ {
49+ // An error occured during positioning.
50+ // Please read out the register POZYX_ERRORCODE to obtain more information about the error
51+ return POZYX_FAILURE;
52+ }else {
53+ status = Pozyx.getCoordinates (position);
54+ return status;
55+ }
56+ }else {
57+ return POZYX_TIMEOUT;
58+ }
59+ }
60+
61+ // prints the coordinates for either humans or for processing
62+ void printCoordinates (coordinates_t coor){
63+ Serial.print (" POS" );
64+ Serial.print (" , x(mm): " );
65+ Serial.print (coor.x );
66+ Serial.print (" , y(mm): " );
67+ Serial.print (coor.y );
68+ Serial.print (" , z(mm): " );
69+ Serial.println (coor.z );
70+ }
71+
72+ // error printing function for debugging
73+ void printErrorCode (String operation){
74+ uint8_t error_code;
75+ Pozyx.getErrorCode (&error_code);
76+ Serial.print (" ERROR " );
77+ Serial.print (operation);
78+ Serial.print (" , local error code: 0x" );
79+ Serial.println (error_code, HEX);
80+ }
0 commit comments