I'm trying to get just one button to work in Unity to start. I have phidget22.dll in the right place.
Here is my button class:
Code: Select all
using UnityEngine;
using Phidget22;
using System.Collections;
// https://www.phidgets.com/education/learn/projects/unity/buttons/
// https://www.phidgets.com/?prodid=1226#Tab_Code_Samples
public class PhidgetButton : MonoBehaviour
{
[SerializeField, Tooltip("The port numbers on the Phidget board")]
private int btnPort = 0, ledPort = 0;
[SerializeField] private bool initActive = true; // should the button be active at start?
[SerializeField] private float debounce = 0.25f; // how long to wait after a button press before registering a true press
private bool debounced = true;
private DigitalInput btn;
private DigitalOutput led;
private bool active = true; // true means input is measured
private void Start()
{
// button setup
btn = new DigitalInput();
btn.Channel = btnPort; // set the channel to the port number
// btn = new DigitalInput
// {
// HubPort = btnPort,
// IsHubPortDevice = true
// };
btn.Open(5000);
// led setup
led = new DigitalOutput();
led.Channel = ledPort; // set the channel to the port number
// led = new DigitalOutput
// {
// HubPort = ledPort,
// IsHubPortDevice = true
// };
led.Open(5000);
active = initActive; // init
}
private void Update()
{
if (active)
{
// light the LED if not pressing the button
led.State = !btn.State;
} else
{
led.State = false; // keep light off when not active
}
}
public void ActivateButton()
{
active = true;
}
public void DeactivateButton()
{
active = false;
}
public bool GetBtnState()
{
bool b = false; // default to false
if (active)
{
if (debounced)
{
b = btn.State; // report the current state
if (b) // if debounced and now it's true again, then start a new debounce delay
{
StartCoroutine(DebounceBtn());
}
}
}
return b;
}
private IEnumerator DebounceBtn()
{
debounced = false;
yield return new WaitForSeconds(debounce);
debounced = true;
}
//Required for Unity and Phidgets
private void OnApplicationQuit()
{
btn.Close();
btn = null;
led.Close();
led = null;
if (Application.isEditor)
{
Phidget.ResetLibrary();
}
else
{
Phidget.FinalizeLibrary(0);
}
}
}
Instead if I use this as my start function I get no lights at all:
Code: Select all
private void Start()
{
// button setup
btn = new DigitalInput();
// btn.Channel = btnPort; // set the channel to the port number
btn = new DigitalInput
{
HubPort = btnPort,
IsHubPortDevice = false
};
btn.Open(5000);
// led setup
led = new DigitalOutput();
// led.Channel = ledPort; // set the channel to the port number
led = new DigitalOutput
{
HubPort = ledPort,
IsHubPortDevice = false
};
led.Open(5000);
active = initActive; // init
}
Attached are the properties of my interface kit.