using System.Collections;
using System.Collections.Generic;
using System.IO.Ports;
using UnityEngine;

public class SerialManager : MonoBehaviour {

	public string portNum;
	SerialPort arduino;

	// Use this for initialization
	void Start () {
		arduino = new SerialPort(portNum,9600);
		arduino.Open();
	}
	
	// Update is called once per frame
	void Update () {
		if (!arduino.IsOpen){
			//arduino.Open();
		}
	}

	private void sendString(string str){
		if (arduino.IsOpen){
			arduino.WriteLine(str);
			Debug.Log("Serial Send:"+str);
		}
		else{
			Debug.Log("Serial Error: Port is not Opened");
		}
	}

	public void sendHint(string str){
		string prefix = "t:";
		sendString(prefix+str);
	}

	public void sendHeartbeatRate(byte rate){
		string prefix = "h:";
		sendString(prefix+rate);
	}

	public void sendLife(byte life){
		string prefix = "l:";
		sendString(prefix+life);
	}
}
