LoginSignup
13
5

More than 5 years have passed since last update.

HoloLens、Firebase、Node.js、irMagicianを使ってテレビを操作する

Posted at

こちらの記事を参考にさせて頂き、HoloLensを使ってテレビの電源をON/OFF出来るようにしてみました。

処理の流れ

webhook.png.001.png

使ったもの

実装イメージ

irMagicianの準備

irMagicianをRaspberry Piで使えるように設定します。

irMagicianの使い方、Node.jsモジュールのインストールについては以下の記事を参照下さい。
Nodeモジュール「irmagician」を作りました。

Unity画面設定

テレビ操作のボタンを用意して、HoloLensCameraInputManagerCursorWithFeedbackはヒエラルキービューに設定しておきます。

s100.png

ネットワーク接続設定

ネットワーク接続するので、Internet Clientにチェックを入れておきます

s101.png

タッチ処理

ボタンにAirTapした時の処理を記述します。新しいスクリプトをボタンに追加します。
AirTapするとFirebaseの対象ファイルにtv オンと書き込みます。
描き込むと更新情報がNode.jsに送られそこで処理をしています。

TouchAction.cs
using HoloToolkit.Unity.InputModule;
using System.Collections;
using UnityEngine;
using System.Text;
using UnityEngine.Networking;

public class TouchAction : MonoBehaviour, IInputClickHandler
{
    // Firebaseの更新先URL
    string fb_url = "https://xxxxxxxxxxxxx.firebaseio.com/googlehome/word.json";

    // AirTap処理
    public void OnInputClicked(InputClickedEventData eventData)
    {
        Debug.Log("Touch!");
        StartCoroutine(Put(fb_url, "\"tv オン\""));
    }


    public IEnumerator Put(string url, string jsonStr)
    {

        var request = new UnityWebRequest();
        request.url = url;
        byte[] body = Encoding.UTF8.GetBytes(jsonStr);
        request.uploadHandler = new UploadHandlerRaw(body);
        request.downloadHandler = new DownloadHandlerBuffer();
        request.SetRequestHeader("Content-Type", "application/json; charset=UTF-8");
        request.method = UnityWebRequest.kHttpVerbPUT;
        yield return request.Send();

        if (request.isNetworkError)
        {
            Debug.Log(request.error);
        }
        else
        {
            if (request.responseCode == 200)
            {
                Debug.Log("success");
                Debug.Log(request.downloadHandler.text);

            }
            else
            {
                Debug.Log("failed");
            }
        }
    }

    // Use this for initialization
    void Start () {

    }

    // Update is called once per frame
    void Update () {

    }

}

まとめ

うまく反応する事が出来ました。でもこの距離だと直接リモコン操作した方が早いですけどね。。。
様々なボタンを用意してやれば、HoloLensでボタンを押すだけで反応することが出来ますね。

でも、はたから見れば指をタップするとテレビがついたり、消えたりするんで異様な感じになりますね。

13
5
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
13
5