using System;
using System.IO.Ports;
using Godot;

namespace MalagaJam18;

[GlobalClass]
public partial class Vibration : Node {
	private static SerialPort _serialPort;
	private static bool _initialized;

	public static void Init(string port) {
		GD.Print(port);
		try {
			_serialPort = new SerialPort();
			_serialPort.PortName = port;
			_serialPort.BaudRate = 9600;
			_serialPort.Open();
			_initialized = true;
		}
		catch (Exception e) {
			GD.PrintErr(e);
		}
	}

	public static void SendVibration() {
		if (!_initialized || !_serialPort.IsOpen)
			return;

		_serialPort.WriteLine("#LED1ON");
	}

	public static void UnSendVibration() {
		if (!_initialized || !_serialPort.IsOpen)
			return;

		_serialPort.WriteLine("#LED1OF");
	}
}
