public override int GetHashCode() { unchecked { int hashCode = (int)EventType; hashCode = (hashCode * 397) ^ (int)DeviceType; hashCode = (hashCode * 397) ^ (int)PointerId; hashCode = (hashCode * 397) ^ Position.GetHashCode(); hashCode = (hashCode * 397) ^ Timestamp.GetHashCode(); hashCode = (hashCode * 397) ^ (int)KeyModifiers; hashCode = (hashCode * 397) ^ ContactRect.GetHashCode(); hashCode = (hashCode * 397) ^ IsBarrelButtonPressed.GetHashCode(); hashCode = (hashCode * 397) ^ IsCanceled.GetHashCode(); hashCode = (hashCode * 397) ^ IsEraser.GetHashCode(); hashCode = (hashCode * 397) ^ IsHorizontalMouseWheel.GetHashCode(); hashCode = (hashCode * 397) ^ IsInRange.GetHashCode(); hashCode = (hashCode * 397) ^ IsInverted.GetHashCode(); hashCode = (hashCode * 397) ^ IsLeftButtonPressed.GetHashCode(); hashCode = (hashCode * 397) ^ IsMiddleButtonPressed.GetHashCode(); hashCode = (hashCode * 397) ^ IsRightButtonPressed.GetHashCode(); hashCode = (hashCode * 397) ^ IsXButton1Pressed.GetHashCode(); hashCode = (hashCode * 397) ^ IsXButton2Pressed.GetHashCode(); hashCode = (hashCode * 397) ^ IsPrimary.GetHashCode(); hashCode = (hashCode * 397) ^ MouseWheelDelta; hashCode = (hashCode * 397) ^ Orientation.GetHashCode(); hashCode = (hashCode * 397) ^ TouchConfidence.GetHashCode(); hashCode = (hashCode * 397) ^ Twist.GetHashCode(); hashCode = (hashCode * 397) ^ XTilt.GetHashCode(); hashCode = (hashCode * 397) ^ YTilt.GetHashCode(); hashCode = (hashCode * 397) ^ (int)PointerUpdateKind; return(hashCode); } }
// link the instance to a real YoctoAPI object internal override void linkToHardware(string hwdName) { YTilt hwd = YTilt.FindTilt(hwdName); // first redo base_init to update all _func pointers base_init(hwd, hwdName); // then setup Yocto-API pointers and callbacks init(hwd); }
// Configure the value callbacks on the currently selected device // private void setupDevice() { YAccelerometer accelerometer; YCompass compass; YTilt tilt1, tilt2; YGyro gyro; YQt qt1, qt2, qt3, qt4; if (currentSerialNumber != prevSerialNumber && prevSerialNumber != "") { // Unregister previous device tilt1 = YTilt.FindTilt(prevSerialNumber + ".tilt1"); tilt2 = YTilt.FindTilt(prevSerialNumber + ".tilt2"); compass = YCompass.FindCompass(prevSerialNumber + ".compass"); gyro = YGyro.FindGyro(prevSerialNumber + ".gyro"); compass.registerValueCallback(null); tilt1.registerValueCallback(null); tilt2.registerValueCallback(null); gyro.registerAnglesCallback(null); } if (currentSerialNumber == "") { return; } // Register the newly selected device accelerometer = YAccelerometer.FindAccelerometer(currentSerialNumber + ".accelerometer"); tilt1 = YTilt.FindTilt(currentSerialNumber + ".tilt1"); tilt2 = YTilt.FindTilt(currentSerialNumber + ".tilt2"); compass = YCompass.FindCompass(currentSerialNumber + ".compass"); gyro = YGyro.FindGyro(currentSerialNumber + ".gyro"); qt1 = YQt.FindQt(currentSerialNumber + ".qt1"); qt2 = YQt.FindQt(currentSerialNumber + ".qt2"); qt3 = YQt.FindQt(currentSerialNumber + ".qt3"); qt4 = YQt.FindQt(currentSerialNumber + ".qt4"); compass.registerValueCallback(valueCallback); tilt1.registerValueCallback(valueCallback); tilt2.registerValueCallback(valueCallback); if (modeChooser.SelectedIndex != 1) { accelerometer.set_bandwidth(7); qt1.set_logicalName("w"); qt2.set_logicalName("x"); qt3.set_logicalName("y"); qt4.set_logicalName("z"); gyro.registerAnglesCallback(anglesCallback); } else { accelerometer.set_bandwidth(50); qt2.set_logicalName("ax"); qt3.set_logicalName("ay"); qt4.set_logicalName("az"); gyro.registerQuaternionCallback(accelCallback); } }
// perform the 2nd stage setup that requires YoctoAPI object protected void init(YTilt hwd) { if (hwd == null) { return; } base.init(hwd); InternalStuff.log("registering Tilt callback"); _func.registerValueCallback(valueChangeCallback); }
public override async Task <int> Run() { try { await YAPI.RegisterHub(HubURL); YTilt anytilt, tilt1, tilt2; YCompass compass; YAccelerometer accel; YGyro gyro; if (Target.ToLower() == "any") { anytilt = YTilt.FirstTilt(); if (anytilt == null) { WriteLine("No module connected (check USB cable)"); return(-1); } } else { anytilt = YTilt.FindTilt(Target + ".tilt1"); } string serial = await(await anytilt.get_module()).get_serialNumber(); tilt1 = YTilt.FindTilt(serial + ".tilt1"); tilt2 = YTilt.FindTilt(serial + ".tilt2"); compass = YCompass.FindCompass(serial + ".compass"); accel = YAccelerometer.FindAccelerometer(serial + ".accelerometer"); gyro = YGyro.FindGyro(serial + ".gyro"); int count = 0; while (await tilt1.isOnline()) { if (count++ % 10 == 0) { WriteLine("tilt1 tilt2 compass acc gyro"); } Write(await tilt1.get_currentValue() + "\t"); Write(await tilt2.get_currentValue() + "\t"); Write(await compass.get_currentValue() + "\t"); Write(await accel.get_currentValue() + "\t"); WriteLine("" + await gyro.get_currentValue()); await YAPI.Sleep(250); } WriteLine("Module not connected (check identification and USB cable)"); } catch (YAPI_Exception ex) { WriteLine("error: " + ex.Message); } YAPI.FreeAPI(); return(0); }
/** * <summary> * Retrieves a tilt sensor for a given identifier. * <para> * The identifier can be specified using several formats: * </para> * <para> * </para> * <para> * - FunctionLogicalName * </para> * <para> * - ModuleSerialNumber.FunctionIdentifier * </para> * <para> * - ModuleSerialNumber.FunctionLogicalName * </para> * <para> * - ModuleLogicalName.FunctionIdentifier * </para> * <para> * - ModuleLogicalName.FunctionLogicalName * </para> * <para> * </para> * <para> * This function does not require that the tilt sensor is online at the time * it is invoked. The returned object is nevertheless valid. * Use the method <c>YTilt.isOnline()</c> to test if the tilt sensor is * indeed online at a given time. In case of ambiguity when looking for * a tilt sensor by logical name, no error is notified: the first instance * found is returned. The search is performed first by hardware name, * then by logical name. * </para> * </summary> * <param name="func"> * a string that uniquely characterizes the tilt sensor * </param> * <returns> * a <c>YTilt</c> object allowing you to drive the tilt sensor. * </returns> */ public static YTilt FindTilt(string func) { YTilt obj; obj = (YTilt)YFunction._FindFromCache("Tilt", func); if (obj == null) { obj = new YTilt(func); YFunction._AddToCache("Tilt", func, obj); } return(obj); }
public static YTiltProxy FindTilt(string name) { // cases to handle: // name ="" no matching unknwn // name ="" unknown exists // name != "" no matching unknown // name !="" unknown exists YTilt func = null; YTiltProxy res = (YTiltProxy)YFunctionProxy.FindSimilarUnknownFunction("YTiltProxy"); if (name == "") { if (res != null) { return(res); } res = (YTiltProxy)YFunctionProxy.FindSimilarKnownFunction("YTiltProxy"); if (res != null) { return(res); } func = YTilt.FirstTilt(); if (func != null) { name = func.get_hardwareId(); if (func.get_userData() != null) { return((YTiltProxy)func.get_userData()); } } } else { func = YTilt.FindTilt(name); if (func.get_userData() != null) { return((YTiltProxy)func.get_userData()); } } if (res == null) { res = new YTiltProxy(func, name); } if (func != null) { res.linkToHardware(name); if (func.isOnline()) { res.arrival(); } } return(res); }
/** * <summary> * Enumerates all functions of type Tilt available on the devices * currently reachable by the library, and returns their unique hardware ID. * <para> * Each of these IDs can be provided as argument to the method * <c>YTilt.FindTilt</c> to obtain an object that can control the * corresponding device. * </para> * </summary> * <returns> * an array of strings, each string containing the unique hardwareId * of a device function currently connected. * </returns> */ public static new string[] GetSimilarFunctions() { List <string> res = new List <string>(); YTilt it = YTilt.FirstTilt(); while (it != null) { res.Add(it.get_hardwareId()); it = it.nextTilt(); } return(res.ToArray()); }
public override async Task <int> Run() { try { await YAPI.RegisterHub(HubURL); YTilt anytilt, tilt1, tilt2, tilt3; if (Target.ToLower() == "any") { anytilt = YTilt.FirstTilt(); if (anytilt == null) { WriteLine("No module connected (check USB cable)"); return(-1); } } else { anytilt = YTilt.FindTilt(Target + ".tilt1"); } string serial = await(await anytilt.get_module()).get_serialNumber(); tilt1 = YTilt.FindTilt(serial + ".tilt1"); tilt2 = YTilt.FindTilt(serial + ".tilt2"); tilt3 = YTilt.FindTilt(serial + ".tilt3"); int count = 0; while (await tilt1.isOnline()) { if (count++ % 10 == 0) { WriteLine("tilt1 tilt2 tilt3"); } Write(await tilt1.get_currentValue() + "\t"); Write(await tilt2.get_currentValue() + "\t"); WriteLine("" + await tilt3.get_currentValue()); await YAPI.Sleep(250); } WriteLine("Module not connected (check identification and USB cable)"); } catch (YAPI_Exception ex) { WriteLine("error: " + ex.Message); } YAPI.FreeAPI(); return(0); }
void YoctopuceInitialisation() { Debug.Log("Use Yoctopuce Lib " + YAPI.GetAPIVersion()); string errmsg = ""; int res = YAPI.RegisterHub("usb", ref errmsg); if (res != YAPI.SUCCESS) { Debug.Log("error with RegisterHub:" + errmsg); errorText.text = errmsg; return; } YModule module = YModule.FirstModule(); while (module != null) { string product = module.get_productName(); if (product == "Yocto-3D" || product == "Yocto-3D-V2") { Debug.Log("Use " + product + " " + module.get_serialNumber()); break; } module = module.nextModule(); } if (module == null) { errorText.text = "No Yocto-3D or Yocto-3D-V2 found"; return; } string serial = module.get_serialNumber(); tilt_x = YTilt.FindTilt(serial + ".tilt1"); tilt_z = YTilt.FindTilt(serial + ".tilt2"); tilt_x.registerValueCallback(TiltCallbackX); tilt_z.registerValueCallback(TiltCallbackZ); }
void TiltCallbackX(YTilt sensor, string value) { _x = double.Parse(value); }
static void Main(string[] args) { string errmsg = ""; string target; YTilt anytilt, tilt1, tilt2; YCompass compass; YAccelerometer accelerometer; YGyro gyro; if (args.Length < 1) { usage(); } target = args[0].ToUpper(); // Setup the API to use local USB devices if (YAPI.RegisterHub("usb", ref errmsg) != YAPI.SUCCESS) { Console.WriteLine("RegisterHub error: " + errmsg); Environment.Exit(0); } if (target == "ANY") { anytilt = YTilt.FirstTilt(); if (anytilt == null) { Console.WriteLine("No module connected (check USB cable)"); Environment.Exit(0); } } else { anytilt = YTilt.FindTilt(target + ".tilt1"); if (!anytilt.isOnline()) { Console.WriteLine("Module not connected"); Console.WriteLine("check identification and USB cable"); Environment.Exit(0); } } string serial = anytilt.get_module().get_serialNumber(); tilt1 = YTilt.FindTilt(serial + ".tilt1"); tilt2 = YTilt.FindTilt(serial + ".tilt2"); compass = YCompass.FindCompass(serial + ".compass"); accelerometer = YAccelerometer.FindAccelerometer(serial + ".accelerometer"); gyro = YGyro.FindGyro(serial + ".gyro"); int count = 0; if (!tilt1.isOnline()) { Console.WriteLine("device disconnected"); Environment.Exit(0); } while (tilt1.isOnline()) { if (count % 10 == 0) { Console.WriteLine("tilt1 tilt2 compass acc gyro"); } Console.Write(tilt1.get_currentValue().ToString() + "\t"); Console.Write(tilt2.get_currentValue().ToString() + "\t"); Console.Write(compass.get_currentValue().ToString() + "\t"); Console.Write(accelerometer.get_currentValue().ToString() + "\t"); Console.WriteLine(gyro.get_currentValue().ToString()); YAPI.Sleep(250, ref errmsg); } YAPI.FreeAPI(); }
// perform the initial setup that may be done without a YoctoAPI object (hwd can be null) internal override void base_init(YFunction hwd, string instantiationName) { _func = (YTilt)hwd; base.base_init(hwd, instantiationName); }
/// <summary> /// Indicates whether the current object is equal to another object of the same type. /// </summary> /// <param name="other">An object to compare with this object.</param> /// <returns>true if the current object is equal to the <paramref name="other" /> parameter; otherwise, false.</returns> public bool Equals(PointerPoint other) { return(EventType == other.EventType && DeviceType == other.DeviceType && PointerId == other.PointerId && Position.Equals(other.Position) && Timestamp == other.Timestamp && KeyModifiers == other.KeyModifiers && ContactRect.Equals(other.ContactRect) && IsBarrelButtonPressed.Equals(other.IsBarrelButtonPressed) && IsCanceled.Equals(other.IsCanceled) && IsEraser.Equals(other.IsEraser) && IsHorizontalMouseWheel.Equals(other.IsHorizontalMouseWheel) && IsInRange.Equals(other.IsInRange) && IsInverted.Equals(other.IsInverted) && IsLeftButtonPressed.Equals(other.IsLeftButtonPressed) && IsMiddleButtonPressed.Equals(other.IsMiddleButtonPressed) && IsRightButtonPressed.Equals(other.IsRightButtonPressed) && IsXButton1Pressed.Equals(other.IsXButton1Pressed) && IsXButton2Pressed.Equals(other.IsXButton2Pressed) && IsPrimary.Equals(other.IsPrimary) && MouseWheelDelta == other.MouseWheelDelta && Orientation.Equals(other.Orientation) && TouchConfidence.Equals(other.TouchConfidence) && Twist.Equals(other.Twist) && XTilt.Equals(other.XTilt) && YTilt.Equals(other.YTilt) && PointerUpdateKind == other.PointerUpdateKind); }
void TiltCallbackZ(YTilt sensor, string value) { _z = -double.Parse(value); }
//--- (end of YTilt definitions) //--- (YTilt implementation) internal YTiltProxy(YTilt hwd, string instantiationName) : base(hwd, instantiationName) { InternalStuff.log("Tilt " + instantiationName + " instantiation"); base_init(hwd, instantiationName); }
/** * <summary> * Retrieves a tilt sensor for a given identifier. * <para> * The identifier can be specified using several formats: * </para> * <para> * </para> * <para> * - FunctionLogicalName * </para> * <para> * - ModuleSerialNumber.FunctionIdentifier * </para> * <para> * - ModuleSerialNumber.FunctionLogicalName * </para> * <para> * - ModuleLogicalName.FunctionIdentifier * </para> * <para> * - ModuleLogicalName.FunctionLogicalName * </para> * <para> * </para> * <para> * This function does not require that the tilt sensor is online at the time * it is invoked. The returned object is nevertheless valid. * Use the method <c>YTilt.isOnline()</c> to test if the tilt sensor is * indeed online at a given time. In case of ambiguity when looking for * a tilt sensor by logical name, no error is notified: the first instance * found is returned. The search is performed first by hardware name, * then by logical name. * </para> * </summary> * <param name="func"> * a string that uniquely characterizes the tilt sensor * </param> * <returns> * a <c>YTilt</c> object allowing you to drive the tilt sensor. * </returns> */ public static YTilt FindTilt(string func) { YTilt obj; obj = (YTilt) YFunction._FindFromCache("Tilt", func); if (obj == null) { obj = new YTilt(func); YFunction._AddToCache("Tilt", func, obj); } return obj; }