動作確認
- ESP-WROOM-02 (以下、ESP8266)
- ユニーバサル基板実装
- Arduino IDE 1.6.6
- Canon IXY 3
開始: ESP8266 > 検討 > APPTVRepeater > 英語リスニング補助ツール (定数時間の巻き戻し機能)
APPTVRepeater (ESP8266) > ソフトウェア v0.4 > Repeaterとしのて機能は実装完了
の続き。
Apple Remote Sender on GitHub
Apple Remote Senderの処理部分を以下に上げた。
GitHub
License: GPL v3.
もともとのコードがGPL v3なので、それにならってGPL v3とした。
元コードの作者に連絡済で、問題があれば対応をする。
(追記: 2017/10/06 作者からの連絡あり。問題はなさそう)。
メインプログラム v0.5
# define KEY_MENU (0x01)
# define KEY_PLAY (0x02)
のような定義はメインプログラムに置くものでもなかった。
Apple Remote Senderのヘッダーに移した。
それによりメインプログラムは以下のようになった。
esp8266_170923_APPTVrepeater
# include <ESP8266WiFi.h>
# include "AppleRemoteSender.h"
//#define USE_REGISTER // to register to Apple TV at first
/*
* v0.5 Sep. 23, 2017
* - move [KEY_XXX] definitions to [AppleRemoteSender.h]
* 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 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
}