/// <summary> /// キューブの磁気センサーの機能のモードを設定します。デフォルトでは無効化されています。 /// https://toio.github.io/toio-spec/docs/ble_configuration#磁気センサーの設定 /// </summary> /// <param name="mode">無効・磁石状態検出のいずれかを指定</param> /// <param name="timeOutSec">タイムアウト(秒)</param> /// <param name="callback">終了コールバック(設定成功フラグ, キューブ)</param> /// <param name="order">命令の優先度</param> public override async UniTask ConfigMagneticSensor(MagneticMode mode, float timeOutSec, Action <bool, Cube> callback, ORDER_TYPE order) { if (this.magneticSensorRequest == null) { this.magneticSensorRequest = new RequestInfo(this); } if (!this.isConnected || !this.isInitialized) { callback?.Invoke(false, this); return; } #if !RELEASE const float minTimeOut = 0.5f; if (minTimeOut > timeOutSec) { Debug.LogWarningFormat("[CubeReal_ver2_2_0.ConfigMagneticSensor]誤作動を避けるため, タイムアウト時間は {0} 秒以上にして下さい.", minTimeOut); } #endif // Assert mode if ((byte)mode > 1) { Debug.LogWarningFormat("Given MagneticSensorMode {0} is not supported by BLE Protocl v2.2.0", mode.ToString()); return; } bool availabe = await this.magneticSensorRequest.GetAccess(Time.time + timeOutSec, callback); if (!availabe) { return; } this.requestedMagneticMode = mode; this.magneticSensorRequest.request = () => { byte[] buff = new byte[3]; buff[0] = 0x1b; buff[1] = 0; buff[2] = (byte)mode; this.Request(CHARACTERISTIC_CONFIG, buff, true, order, "ConfigMagneticSensor", mode, timeOutSec, callback, order); }; await this.magneticSensorRequest.Run(); }
protected virtual void Recv_config(byte[] data) { // https://toio.github.io/toio-spec/docs/ble_configuration int type = data[0]; if (0x9c == type) // Motoer Read { this.motorReadRequest.hasConfigResponse = true; this.motorReadRequest.isConfigResponseSucceeded = (0x00 == data[2]); if (this.motorReadRequest.isConfigResponseSucceeded) { this.motorReadValid = this.requestedMotorReadValid; } this.motorSpeedCallback.Notify(this); } else if (0x98 == type) // ID Notification { this.idNotificationRequest.hasConfigResponse = true; this.idNotificationRequest.isConfigResponseSucceeded = (0x00 == data[2]); } else if (0x99 == type) // ID Missed Notification { this.idMissedNotificationRequest.hasConfigResponse = true; this.idMissedNotificationRequest.isConfigResponseSucceeded = (0x00 == data[2]); } else if (0x9b == type) // Mag { this.magneticSensorRequest.hasConfigResponse = true; this.magneticSensorRequest.isConfigResponseSucceeded = (0x00 == data[2]); if (this.magneticSensorRequest.isConfigResponseSucceeded) { this.magneticMode = this.requestedMagneticMode; } } }
public void MagneticMode(MagneticMode value) { _sensor.MagneticMode = value; }
public void MagneticMode(MagneticMode value) { _sensor.MagneticMode = value; }