private void Service_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (e.PropertyName.Equals("InvalidRequest"))
            {
                rootPage.NotifyUser("Invalid request!", NotifyType.ErrorMessage);
            }

            //new characteristic value received
            if (e.PropertyName.Equals("Value"))
            {
                // switch (sender) ...
                Debug.WriteLine($"Lightbulb service received value from : {sender}");

                String receivedWrite = BLEServices.Helpers.ToHexString(rootPage.Ble.lightBulbService.LightBulbSwitch.Value);
                rootPage.NotifyUser("WRITE received: " + receivedWrite, NotifyType.StatusMessage);

                //check if value is 01, otherwise error?
                if (receivedWrite.Equals("01"))
                {
                    LightBulb.On();
                    if (isSolved == false)
                    {
                        isSolved = true;
                        rootPage.NotifyCorrect(scenarioName);
                        Solved.Visibility = Visibility.Visible;
                    }
                }
                else if (receivedWrite.Equals("00"))
                {
                    LightBulb.Off();
                }
            }
        }
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            // set up BLE advertising for this scenario
            var ret = await rootPage.Ble.AdvertisingForScenario(scenarioName);

            if (ret == true && rootPage.Ble.lightBulbService != null)
            {
                rootPage.Ble.lightBulbService.LightBulbSwitch.PropertyChanged += Service_PropertyChanged;
            }
            else
            {
                Debug.WriteLine("Error, lightbulb service is null!");
                rootPage.NotifyUser("Problem starting device simulation", NotifyType.ErrorMessage, NotifyButton.RestartDevice);
            }
            if (rootPage.isSolved.ContainsKey(scenarioName))
            {
                if (rootPage.isSolved[scenarioName] == true)
                {
                    Solved.Visibility = Visibility.Visible;
                }
            }

            // turn on if previously set state
            var currentValue = BLEServices.Helpers.ToHexString(rootPage.Ble.lightBulbService.LightBulbSwitch.Value);

            if (currentValue == "01")
            {
                LightBulb.On();
            }
        }
        private void Service_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (e.PropertyName.Equals("InvalidRequest"))
            {
                rootPage.NotifyUser("Invalid request!", NotifyType.ErrorMessage);
            }

            else if (e.PropertyName.Equals("BlinkPassed"))
            {
                rootPage.NotifyCorrect(scenarioName);
                Solved.Visibility = Visibility.Visible;
                LightBulb.Checked(true);
                isSolved = true;
            }

            //new characteristic value received
            else if (e.PropertyName.Equals("Value"))
            {
                String receivedWrite = BLEServices.Helpers.ToHexString(rootPage.Ble.lightBulbService.LightBulbSwitch.Value);

                // notify of every write until solved, otherwise it will overwrite the "congratulations" notification
                if (!isSolved)
                {
                    rootPage.NotifyUser("Write received: " + receivedWrite, NotifyType.StatusMessage);
                }

                if (receivedWrite.Equals("01"))
                {
                    LightBulb.On();
                }
                else if (receivedWrite.Equals("00"))
                {
                    LightBulb.Off();
                }
            }
        }
Example #4
0
 public void lightBulbOn()
 {
     lightbulb.On();
 }
Example #5
0
 public void execute()
 {
     lightBulb.On();
 }