예제 #1
0
        public PhotonsViewModel()
        {
            MessageClient = App.Current.Resources["MessageClient"] as MessageClient;

            MessageClient.MessageStringReceived += messageClient_DataReceived;

            PhotonAModel = new Models.Photon(Devices.PHOTON_A);
            PhotonBModel = new Models.Photon(Devices.PHOTON_B);
            PhotonCModel = new Models.Photon(Devices.PHOTON_C);
        }
예제 #2
0
        void messageClient_DataReceived(object sender, MessageEventArgs e)
        {
            //Only consider the messages from Photon devices
            if (!(e.FromDevice.Equals(Environment.Devices.PHOTON_A) ||
                  e.FromDevice.Equals(Environment.Devices.PHOTON_B) ||
                  e.FromDevice.Equals(Environment.Devices.PHOTON_C)))
            {
                return;
            }

            Models.Photon model      = SelectModel(e.FromDevice);
            string        objectName = e.Name;
            string        parameter  = e.Parameter.ToString();

            if (objectName.Equals(Photon.OBJECT_SENSOR))
            {
                if (parameter.Equals(Photon.DATA_SENSOR_TEMPERATURE))
                {
                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        model.Temperature = e.Content.ToString();
                    });
                }
                else if (parameter.Equals(Photon.DATA_SENSOR_HUMIDITY))
                {
                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        model.Humidity = e.Content.ToString();
                    });
                }
            }
            else if (objectName.Equals(Photon.OBJECT_BOARD_LED))
            {
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    model.BoardLED = e.Content.ToString().Equals(Photon.CONTENT_LED_STATUS_ON);
                });
            }
            else if (objectName.Equals(Photon.OBJECT_GREEN_LED))
            {
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    model.GreenLED = e.Content.ToString().Equals(Photon.CONTENT_LED_STATUS_ON);
                });
            }
            else if (objectName.Equals(Photon.OBJECT_RED_LED))
            {
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    model.RedLED = e.Content.ToString().Equals(Photon.CONTENT_LED_STATUS_ON);
                });
            }
        }