[Rephone] 搭配 micro SIM卡來撥打/接聽電話

本範例使用 Seeed Studio 的開源智慧型手機開發套件來撥打與接聽電話,您需要做的事情有:

  1. 弄一張預付卡(中華電信$200),不然要拔來拔去很麻煩。請記得 SIM卡不可上鎖
  2. 弄一套 Rephone,這個比較有難度,因為台灣目前買不到。CAVEDU手邊的是來自 Seeed 熱情支援的測試用套件,所以也沒辦法辦研習讓更多朋友可以一起玩

把 SIM卡 (micro SIM卡) 插入 rephone 的 GSM 模組就可以了,接下來燒錄以下的程式即可。當我們在 Serial Monitor 輸入 “1”,Rephone 就會對指定的電話號碼撥打電話。另一方面有外部來電時,rephone 就會自動接聽。

2016-01-13 15.28.50

實際測試時,通話品質還不錯。當然不會比商用電話來得清晰,但也不會聽不清楚就是了。

我們下一階段要做的就是運用 rephone 的觸碰螢幕寫一些簡單的按鈕來撥打/接聽電話,總不能要打電話還要去按鍵盤…   這也太 low了 (觸碰螢幕測試:[Seeed Studio rephone開箱文] RGB 觸碰 LCD 測試)

記得,1/26晚上7:00我們在 T客邦有分享會,想要親眼看看 Rephone 與 LinkIt Smart 7688機器人的朋友,歡迎報名喔

#include <LCheckSIM.h>
#include <LGSM.h>

char *charbuffer = "XXXXXXXXXX"; //您所要撥打的電話號碼
char num[20] = {0};

void setup()
{
  Serial.begin(115200);
  Serial.print("\r\n");
  while (!Serial);  //在開啟Serial Monitor之前,程式會停在這裡
  Serial.print("Voice Call Test\r\n");
}

void loop()
{
  char KeyValue;
  if (Serial.available() > 0) {
    KeyValue = Serial.read();
    if (KeyValue == '1')
    {
      KeyValue = 0;
      if (LCheckSIM.isCheck() == 1)
      {
        Serial.print("Voice call begin.\r\n");
        LVoiceCall.voiceCall(charbuffer); //撥打電話

        while (1)
        {
          if (KeyValue == '2')
          {
            KeyValue = 0;
            LVoiceCall.hangCall();  //掛電話
            Serial.print("Hang call.\r\n");
            break;
          }
          if (LVoiceCall.getVoiceCallStatus() == IDLE_CALL)break;
          delay(50);
        }
      }
      else
      {
        Serial.print("No SIM.\r\n");
      }
    }
  }
  if (LVoiceCall.getVoiceCallStatus() == RECEIVINGCALL) //來電
  {
    Serial.print("Call come in.\r\n");
    LVoiceCall.retrieveCallingNumber(num, 20);  //取得對方電話號碼
    Serial.print("Number is ");
    Serial.println(num);
    LVoiceCall.answerCall();
    while (1)
    {
      if (Serial.available() > 0) {
        KeyValue = Serial.read();
        if (KeyValue == '2')
        {
          KeyValue = 0;
          LVoiceCall.hangCall();
          Serial.print("Hang call.\r\n");
          break;
        }
        if (LVoiceCall.getVoiceCallStatus() == IDLE_CALL)break;
        delay(50);
      }
    }
  }
  delay(50);
}

unsigned int task_uart_key()
{
  String inString = "";
  unsigned int keyValue = 0;
  unsigned char bitCount = 0;
  unsigned char dataTemp1[10] = {0};
  while (Serial.available() > 0)
  {
    unsigned char inChar = Serial.read();
    inString += (char)inChar;
    dataTemp1[bitCount] = inChar - '0';
    bitCount += 1;
    delay(10);
  }
  if (inString != "")
  {
    if (bitCount > 4)
    {
      Serial.println("Key input error.");
    }
    else
    {
      for (char i = 0; i < bitCount; i++)
      {
        unsigned int dataTemp2 = 1;
        for (char j = 0; j < (bitCount - i - 1); j++)dataTemp2 *= 10;
        keyValue += (dataTemp1[i] * dataTemp2);
      }
      Serial.print("Key value is: ");
      Serial.println(keyValue);
    }
  }
  return keyValue;
}
Rephone – 撥打電話

延伸閱讀

Seeed Studio Rephone 組裝步驟

[Seeed Studio rephone開箱文] RGB 觸碰 LCD 測試

 

About CAVEDU 阿吉 - 雜工 (2521 Articles)

CAVEDU 教育團隊 打雜

Contact: Website

Leave a comment

Your email address will not be published.


*