1
+ #include " SparkFun_u-blox_Cellular_Arduino_Library.h"
2
+
3
+ // Uncomment the line below that you need for Serial on your platform
4
+ #define mySerial Serial1
5
+ // SoftwareSerial mySerial(16, 17);
6
+
7
+ // Uncomment the module you're using. If your module is not listed below, then
8
+ // it's not supported for this example
9
+ UBX_CELL_VOICE_BASE myModule; // This example works with all voice-enabled modules, so this base class can be used
10
+ // LARA_R6001 myModule;
11
+ // LARA_R6401 myModule;
12
+ // LARA_R6801_00B myModule;
13
+
14
+ bool callInProgress = false ;
15
+ bool incomingCall = false ;
16
+
17
+ void ringCallback ()
18
+ {
19
+ Serial.println (F (" Incoming call! Enter \" A\" to answer, or anything else to reject" ));
20
+ incomingCall = true ;
21
+ }
22
+
23
+ void setup ()
24
+ {
25
+ String currentOperator = " " ;
26
+
27
+ Serial.begin (115200 ); // Start the serial console
28
+
29
+ // Wait for user to press key to begin
30
+ Serial.println (F (" u-blox Cellular Audio Example 3 - Call Control" ));
31
+
32
+ Serial.println ();
33
+ Serial.println (F (" !!!!!!!! ATTENTION !!!!!!!! ATTENTION !!!!!!!! ATTENTION !!!!!!!!" ));
34
+ Serial.println (F (" This example requires an audio codec attached to the I2S interface" ));
35
+ Serial.println (F (" of the cellular modem. Please add one and update this example as" ));
36
+ Serial.println (F (" needed to configure your audio codec!" ));
37
+ Serial.println (F (" !!!!!!!! ATTENTION !!!!!!!! ATTENTION !!!!!!!! ATTENTION !!!!!!!!" ));
38
+ Serial.println ();
39
+
40
+ Serial.println (F (" Press any key to begin" ));
41
+
42
+ while (!Serial.available ()) // Wait for the user to press a key (send any serial character)
43
+ ;
44
+ while (Serial.available ()) // Empty the serial RX buffer
45
+ Serial.read ();
46
+
47
+ Serial.println (F (" Beginning..." ));
48
+
49
+ // myModule.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial
50
+
51
+ // For the MicroMod Asset Tracker, we need to invert the power pin so it pulls high instead of low
52
+ // Uncomment the next line if required
53
+ // myModule.invertPowerPin(true);
54
+
55
+ // Initialize the module
56
+ if (myModule.begin (mySerial, UBX_CELL_DEFAULT_BAUD_RATE) )
57
+ {
58
+ Serial.println (F (" Module connected!" ));
59
+ }
60
+ else
61
+ {
62
+ Serial.println (F (" Unable to communicate with the module." ));
63
+ Serial.println (F (" Manually power-on (hold the module's On button for 3 seconds) and try again." ));
64
+ while (1 ) ; // Loop forever on fail
65
+ }
66
+ Serial.println ();
67
+
68
+ // First check to see if we're connected to an operator:
69
+ if (myModule.getOperator (¤tOperator) == UBX_CELL_SUCCESS)
70
+ {
71
+ Serial.print (F (" Connected to: " ));
72
+ Serial.println (currentOperator);
73
+ }
74
+ else
75
+ {
76
+ Serial.print (F (" The module is not yet connected to an operator. Please use the previous examples to connect. Or wait and retry. Freezing..." ));
77
+ while (1 )
78
+ ; // Do nothing more
79
+ }
80
+
81
+ // Set callback function for when a new call is received
82
+ myModule.setRingCallback (&ringCallback);
83
+
84
+ Serial.println (F (" Enter a number to dial" ));
85
+
86
+ // Clear any input
87
+ while (Serial.available ()){Serial.read ();}
88
+ }
89
+
90
+ void loop ()
91
+ {
92
+ String inputString;
93
+
94
+ myModule.bufferedPoll ();
95
+
96
+ if (Serial.available ())
97
+ {
98
+ inputString = Serial.readStringUntil (' \n ' );
99
+ while (Serial.available ()){Serial.read ();}
100
+
101
+ if (incomingCall)
102
+ {
103
+ if (inputString == " A" || inputString == " a" )
104
+ {
105
+ Serial.println (F (" Answering call, enter any key to hang up" ));
106
+ myModule.answer ();
107
+ callInProgress = true ;
108
+ }
109
+ else
110
+ {
111
+ Serial.println (F (" Rejecting call" ));
112
+ myModule.hangUp ();
113
+ }
114
+ incomingCall = false ;
115
+ }
116
+ else if (callInProgress == false )
117
+ {
118
+ Serial.println (" Dialing " + inputString + " , enter any key to hang up" );
119
+ myModule.dial (inputString);
120
+ callInProgress = true ;
121
+ }
122
+ else
123
+ {
124
+ Serial.println (F (" Hanging up, enter a new number to dial" ));
125
+ myModule.hangUp ();
126
+ callInProgress = false ;
127
+ }
128
+ }
129
+ }
0 commit comments