/// <summary> /// Hidden constructor -- forces callers to use one of the static factory methods /// on this class. /// Creates a new PHCCDeviceMonitor object /// <param name="deviceInfo">a PHCCPhysicalDeviceInfo object representing the device to monitor.</param> /// <param name="axisRangeMin"> /// an integer specifying the value that should be reported when an axis is at its minimum /// value /// </param> /// <param name="axisRangeMax"> /// an integer specifying the value that should be reported when an axis is at its maximum /// value /// </param> /// </summary> private PHCCDeviceMonitor(PHCCPhysicalDeviceInfo deviceInfo, int axisRangeMin, int axisRangeMax) { DeviceInfo = deviceInfo; _axisRangeMin = axisRangeMin; _axisRangeMax = axisRangeMax; Prepare(); }
public static PHCCPhysicalDeviceInfo[] GetDevices(bool throwOnFail) { var devices = new List <PHCCPhysicalDeviceInfo>(); var ports = new Ports(); foreach (var portName in ports.SerialPortNames) { var deviceInfo = new PHCCPhysicalDeviceInfo(portName, "PHCC device on " + portName); try { if ( PHCCDeviceMonitor.GetInstance(deviceInfo, MinAnalogDataSourceVal, MaxAnalogDataSourceVal) .IsDeviceAttached(false)) { devices.Add(deviceInfo); } } catch (Exception ex) { _log.Debug(ex.Message, ex); } } var toReturn = devices.ToArray(); return(toReturn); }
public static bool IsDeviceAttached(PHCCPhysicalDeviceInfo device, bool throwOnFail) { if (device == null) { throw new ArgumentNullException(nameof(device)); } return (PHCCDeviceMonitor.GetInstance(device, MinAnalogDataSourceVal, MaxAnalogDataSourceVal) .IsDeviceAttached(throwOnFail)); }
public static PHCCPhysicalControlInfo[] GetControlsOnDevice(PHCCPhysicalDeviceInfo device, bool throwOnFail) { if (device == null) { throw new ArgumentNullException(nameof(device)); } var controls = new List <PHCCPhysicalControlInfo>(); for (var i = 0; i < 1024; i++) { var thisControl = new PHCCPhysicalControlInfo(device, i, ControlType.Button, "Button " + (i + 1)); controls.Add(thisControl); } for (var i = 0; i < 35; i++) { var thisControl = new PHCCPhysicalControlInfo(device, i, ControlType.Axis, "Axis " + (i + 1)); controls.Add(thisControl); } var toReturn = controls.ToArray(); return(toReturn); }
/// <summary> /// Factory method to create instances of this class. Stands in place of a constructor, /// in order to re-use instances /// when relevant constructor parameters are the same /// </summary> /// <param name="deviceInfo">a PHCCPhysicalDeviceInfo object representing the PHCC device to monitor</param> /// <param name="axisRangeMin">an integer specifying the value that should be reported when an axis is at its minimum value</param> /// <param name="axisRangeMax">an integer specifying the value that should be reported when an axis is at its maximum value</param> /// <returns> /// a PHCCDeviceMonitor object representing the PHCC device /// being monitored, either created newly from-scratch, or returned from /// this class's internal object pool if a monitor instance already exists /// </returns> public static PHCCDeviceMonitor GetInstance(PHCCPhysicalDeviceInfo deviceInfo, int axisRangeMin, int axisRangeMax) { PHCCDeviceMonitor monitor = null; if (_monitors.ContainsKey(deviceInfo)) { return(_monitors[deviceInfo]); } try { monitor = new PHCCDeviceMonitor(deviceInfo, axisRangeMin, axisRangeMax); _monitors.Add(deviceInfo, monitor); } catch (TimeoutException e) { _log.Debug(e.Message, e); } catch (IOException e) { _log.Debug(e.Message, e); } return(monitor); }
public static PHCCPhysicalControlInfo[] GetControlsOnDevice(PHCCPhysicalDeviceInfo device) { return(GetControlsOnDevice(device, true)); }
/// <summary> /// Creates a new PHCCPhysicalControlInfo object. /// </summary> /// <param name="parent"> /// a PHCCPhysicalDeviceInfo object representing /// the physical device on which this control appears /// </param> /// <param name="controlNum"> /// an integer indicating the relative zero-based /// "offset" of this control in the collection of similar controls on the /// same device. Button 1 would be controlNum=0; the first slider would /// similarily be controlNum=0; as would the first Pov control, etc. /// </param> /// <param name="controlType">the type of control this PHCCPhysicalDeviceInfo represents (axis, button, POV, etc.)</param> /// <param name="alias">a friendly name for this control to display to a user</param> public PHCCPhysicalControlInfo(PHCCPhysicalDeviceInfo parent, int controlNum, ControlType controlType, string alias) : base(parent, controlNum, controlType, AxisType.Unknown, alias) { }