LoginSignup
0
0

More than 5 years have passed since last update.

APPTVRepeater (ESP8266) > ソフトウェア v0.4 > Repeaterとしのて機能は実装完了

Last updated at Posted at 2017-09-23
動作確認
- ESP-WROOM-02 (以下、ESP8266)
- ユニーバサル基板実装
- Arduino IDE 1.6.6
- Canon IXY 3

開始: ESP8266 > 検討 > APPTVRepeater > 英語リスニング補助ツール (定数時間の巻き戻し機能)

APPTVRepeater (ESP8266) > ソフトウェア v0.3 > リモコン登録完了
の続き。

だいたい5秒程度戻す

LEFT, 待機, PLAYを実行して、だいたい5秒程度戻す。

コード v0.4

esp8266_170923_APPTVrepeater
#include <ESP8266WiFi.h>
#include "AppleRemoteSender.h"

//#define USE_REGISTER // to register to Apple TV at first

/*
 * v0.4 Sep. 23, 2017
 *   - repeat 5 seconds (LEFT and PLAY)
 * v0.3 Sep. 23, 2017
 *   - send keys to register ESP8266 remote controller to Apple TV
 * v0.2 Sep. 23, 2017
 *   - send UP signal to register the remote controller
 * v0.1 Sep. 23, 2017
 *   - turn on/off the IR pin to check the device
 */

static const int kPinIR = 4;

#define KEY_MENU (0x01)
#define KEY_PLAY (0x02)
#define KEY_RIGHT (0x03)
#define KEY_LEFT (0x04)
#define KEY_UP (0x05)
#define KEY_DOWN (0x06)

#define BACK_SEC (5)

void setup() {
  WiFi.disconnect(); // watch dog reset対処
  Serial.begin(115200);
  pinMode(kPinIR, OUTPUT);

  APPTV_setup(kPinIR);
}

static const int keylist[] = {
  KEY_UP,
  KEY_DOWN,
  KEY_LEFT,
  KEY_RIGHT,
  KEY_PLAY, // SELECT
  KEY_MENU,
};

void RegisterController(void)
{
  static int pos = 0;

  int size_key = sizeof(keylist) / sizeof(keylist[0]);

  delay(2000); // msec

  if (pos >= 0) {
    Serial.println(F("Send Key")); // F() to reduce RAM usage  
    for(int loop=0; loop < 20; loop++) {
      APPTV_SendKey(kPinIR, keylist[pos]);
      delay(100); // msec
    }
    pos++;
    if (pos == size_key) {
      pos = -1;
    }
  }
}

void RepeatSeconds()
{
    static int start = 1;

    if (start != 1) {
      return;
    }

    APPTV_SendKey(kPinIR, KEY_LEFT);
    delay(100); // msec

    delay(BACK_SEC * 1000 * 0.38); // msec (0.38: adjusted to 5 seconds interval)

    APPTV_SendKey(kPinIR, KEY_PLAY);
    delay(100); // msec

    start = 0;
}

void loop() {
  static int pos = 0;
  int size_key = sizeof(keylist) / sizeof(keylist[0]);

  delay(2000); // msec

#ifdef USE_REGISTER
  RegisterController();
#else
  RepeatSeconds();
#endif
}

実行タイミング

戻したいタイミングで基板の電源(CR123A)を入れる。

起動待ち、LEFT送信、待機、PLAY送信にて、だいたい5秒程度戻る。

起動待ちの分は誤差になる。
このあたりを正確にするには、基板上にスイッチを搭載して、スイッチ押下時に送信、などするといいかもしれない。
(今回は未実施)。

実行例

Netflixの
Star Trek: Deep Space 9
にて試してみた。

Vedek Bareil

I hope you don't mind if I do a little planting while we talk.

上記のようなフレーズを繰り返し聞くことができる。

余談

iPad mini4にApple Remoteというソフトをインストールすると、上記のようなことがボタン一つでできるようだ(10秒戻る機能)。

基板実装前に知った。。。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0