Exemplo n.º 1
0
        public async void ProcessBasicUpdate(IBasicStatusUpdate parser)
        {
            if (parser.BatteryCase > 100)
            {
                parser.BatteryCase = DeviceMessageCache.Instance.BasicStatusUpdateWithValidCase?.BatteryCase ?? parser.BatteryCase;
            }

            _batteryCase.Content = BluetoothImpl.Instance.DeviceSpec.Supports(IDeviceSpec.Feature.CaseBattery) && parser.BatteryCase <= 100 ? $"{parser.BatteryCase}%" : string.Empty;
            _caseLabel.IsVisible = BluetoothImpl.Instance.DeviceSpec.Supports(IDeviceSpec.Feature.CaseBattery) && parser.BatteryCase <= 100;

            if (BluetoothImpl.Instance.ActiveModel != Models.Buds)
            {
                UpdatePlusPlacement(parser.PlacementL, parser.PlacementR);
                _lastPlacementL = parser.PlacementL;
                _lastPlacementR = parser.PlacementR;
            }

            if (parser is ExtendedStatusUpdateParser p &&
                BluetoothImpl.Instance.DeviceSpec.Supports(IDeviceSpec.Feature.Anc))
            {
                _ancSwitch.SetChecked(p.NoiseCancelling);
            }

            /* Update if disconnected */
            if ((_lastLeftOnline && parser.BatteryL <= 0) || (_lastRightOnline && parser.BatteryR <= 0))
            {
                UpdateConnectionState(parser.BatteryL > 0, parser.BatteryR > 0);
            }

            await BluetoothImpl.Instance.SendRequestAsync(SPPMessage.MessageIds.DEBUG_GET_ALL_DATA);
        }
Exemplo n.º 2
0
 public void ApplyStartConditions()
 {
     isTouchingEndPoint    = false;
     currentPlacementState = PlacementStates.DefaultPlaced;
     rigidbody.isKinematic = (beginningRigidbodyState & RigidbodySettings.IsKinematic) != 0;
     rigidbody.useGravity  = (beginningRigidbodyState & RigidbodySettings.UseGravity) != 0;
 }
Exemplo n.º 3
0
        public void UpdateDashboard(BaseMessageParser parser)
        {
            if (parser.GetType() == typeof(ExtendedStatusUpdateParser))
            {
                if (_allowGetAllResponse)
                {
                    BluetoothService.Instance.SendAsync(SPPMessageBuilder.Info.GetAllData());
                }
                Dispatcher.Invoke(() =>
                {
                    if (BluetoothService.Instance.ActiveModel == Model.BudsPlus ||
                        BluetoothService.Instance.ActiveModel == Model.BudsLive)
                    {
                        ExtendedStatusUpdateParser p = (ExtendedStatusUpdateParser)parser;
                        UpdatePlusPlacement(p.PlacementL, p.PlacementR);
                        _lastPlacementL      = p.PlacementL;
                        _lastPlacementR      = p.PlacementR;
                        BatteryCase.Content  = BluetoothService.Instance.ActiveModel == Model.Buds ? "" : $"{p.BatteryCase}%";
                        CaseLabel.Visibility = BluetoothService.Instance.ActiveModel == Model.Buds ? Visibility.Hidden : Visibility.Visible;
                    }

                    if (BluetoothService.Instance.ActiveModel == Model.BudsLive)
                    {
                        ExtendedStatusUpdateParser p = (ExtendedStatusUpdateParser)parser;
                        AncToggle.SetChecked(p.NoiceCancelling);
                    }
                });
            }
            else if (parser.GetType() == typeof(StatusUpdateParser))
            {
                if (_allowGetAllResponse)
                {
                    BluetoothService.Instance.SendAsync(SPPMessageBuilder.Info.GetAllData());
                }
                Dispatcher.Invoke(() =>
                {
                    if (BluetoothService.Instance.ActiveModel == Model.BudsPlus ||
                        BluetoothService.Instance.ActiveModel == Model.BudsLive)
                    {
                        StatusUpdateParser p = (StatusUpdateParser)parser;
                        UpdatePlusPlacement(p.PlacementL, p.PlacementR);
                        _lastPlacementL      = p.PlacementL;
                        _lastPlacementR      = p.PlacementR;
                        BatteryCase.Content  = BluetoothService.Instance.ActiveModel == Model.Buds ? "" : $"{p.BatteryCase}%";
                        CaseLabel.Visibility = BluetoothService.Instance.ActiveModel == Model.Buds ? Visibility.Hidden : Visibility.Visible;
                    }
                });
            }
            else if (parser.GetType() == typeof(DebugGetAllDataParser))
            {
                var p = (DebugGetAllDataParser)parser;
                UpdateBatteryPercentage((int)Math.Round(p.LeftAdcSOC), Side.L);
                UpdateBatteryPercentage((int)Math.Round(p.RightAdcSOC), Side.R);

                Dispatcher.Invoke(() => { UpdateDetails(p); });
            }
        }
Exemplo n.º 4
0
 private void UpdatePlusPlacement(PlacementStates l, PlacementStates r)
 {
     _batteryTemperatureLeft.Content  = l.GetDescription();
     _batteryTemperatureRight.Content = r.GetDescription();
 }
Exemplo n.º 5
0
 public void ResetCache()
 {
     _lastGetAllDataParser = null;
     _lastPlacementL       = PlacementStates.Disconnected;
     _lastPlacementR       = PlacementStates.Disconnected;
 }
Exemplo n.º 6
0
    /* Updates the placement state to a new state only if it is a different state
     *  This involves two main components, (1) changing the interactables rigidbody settings
     *  and (2) changing the ending location's appearance
     */
    private void UpdatePlacementState(PlacementStates newState)
    {
        PlacementStates oldState = currentPlacementState;

        currentPlacementState = newState;

        if (currentPlacementState != oldState)
        {
            // Make changes on Interactable Part to reflect state change
            switch (currentPlacementState)
            {
            case PlacementStates.UnacceptablePlaced:
            case PlacementStates.DefaultPlaced:
                SetAllTriggers(gameObject, false);
                // Placed default means that the objective is not complete and it should either retain the rigidbody
                // state of before or after completion depending on if the hand is required to complete it
                // If the hand is required, then give this object the beginning rigidbody state
                // If the hand is not required then give this object the ending rigidbody state
                rigidbody.isKinematic =
                    (partObjectiveSettings & PartObjectiveSettings.RequireHandAttached) != 0
                        ?  (beginningRigidbodyState & RigidbodySettings.IsKinematic) != 0 : (endingRigidbodyState & RigidbodySettings.IsKinematic) != 0;
                rigidbody.useGravity = (partObjectiveSettings & PartObjectiveSettings.RequireHandAttached) != 0
                        ? (beginningRigidbodyState & RigidbodySettings.UseGravity) != 0 : (endingRigidbodyState & RigidbodySettings.UseGravity) != 0;
                break;

            case PlacementStates.AcceptablePlaced:
                rigidbody.isKinematic = (endingRigidbodyState & RigidbodySettings.IsKinematic) != 0;
                rigidbody.useGravity  = (endingRigidbodyState & RigidbodySettings.UseGravity) != 0;
                SetAllTriggers(gameObject, false);
                break;

            case PlacementStates.DefaultHeld:
            case PlacementStates.UnacceptableHover:
            case PlacementStates.AcceptableHoverCanDetach:
            case PlacementStates.AcceptableHoverNoDetach:
                SetAllTriggers(gameObject, true);
                break;
            }
            // Make changes on End Point Part to reflect state change (only if its going to be visible)
            if (endPointGameObject != null && showEndPointOutline)
            {
                // change conditions coming out of specific states
                switch (oldState)
                {
                case PlacementStates.AcceptablePlaced:
                    endPointGameObject.SetActive(true);
                    break;
                }
                // change conditions going to specifc states
                switch (currentPlacementState)
                {
                case PlacementStates.DefaultPlaced:
                case PlacementStates.DefaultHeld:
                    ApplyMaterialToList(endPointObjectList, defaultOutlineMaterial);
                    break;

                case PlacementStates.UnacceptableHover:
                case PlacementStates.UnacceptablePlaced:
                    ApplyMaterialToList(endPointObjectList, unacceptablePlacementMaterial);
                    break;

                case PlacementStates.AcceptableHoverCanDetach:
                case PlacementStates.AcceptableHoverNoDetach:
                    ApplyMaterialToList(endPointObjectList, acceptablePlacementMaterial);
                    break;

                case PlacementStates.AcceptablePlaced:
                    endPointGameObject.SetActive(false);
                    break;
                }
            }
        }
        //Debug.Log("Placement State: " + currentPlacementState.ToString());
    }