 
 void incomingCallHandler(telephone::ButtonState buttonState) {
   if (buttonState == PRESSED) {
-    Serial.println("Incoming call started");
-    ring.start(millis());
-  } else {
-    Serial.println("Incoming call ended");
-    ring.stop();
+    if (!isHeadsetUp) {
+      hasIncomingCall = true;
+      ring.start(millis());
+      gsmVoiceCall.retrieveCallingNumber(phoneNumberChars, 20);
+      Serial.print("Incoming call: ");
+      Serial.println(phoneNumberChars);
+    }
+  } else {
+    if (hasIncomingCall) {
+      ring.stop();
+    }
   }
 }
 

boolean isHeadsetUp;
boolean isGettingDigit;
boolean isTalking;

int digitValue;
String phoneNumber;

char phoneNumberChars[20]; // 20 - "big" number. Greater than any pnone number.

//---- gsm begin
#define SIM_PIN_NUMBER ""
GSM gsmAccess;
GSMVoiceCall gsmVoiceCall;
//---- gsm end

void pickedUpHandler(telephone::ButtonState buttonState) {
  isHeadsetUp = buttonState == PRESSED;
  if (isHeadsetUp) {
    Serial.println("Headset up");
    phoneNumber = "";
  } else {
    Serial.println("Headset down");
    isGettingDigit = false;
    if (isTalking) {
      isTalking = false;
      gsmVoiceCall.hangCall();
    }
  }
}


// Should be 25Hz, but 31 is the arduino's minimum.
// 1000 Hz is just for beeper.
const int RING_FREQ = 40;

Button buttonHandset(0, 1023);
Button buttonRotate(0, 1023);
