Esempio n. 1
0
 /// <summary>
 /// エラー発生をランプの点滅で伝達する
 /// </summary>
 /// <param name="color">色</param>
 /// <param name="round">ラウンド数</param>
 private void IndicateDebug(FEZHAT.Color color, int round)
 {
     if (debugTimer == null)
     {
         debugTimer          = new DispatcherTimer();
         debugTimer.Interval = TimeSpan.FromMilliseconds(500);
         debugTimer.Tick    += DebugTimer_Tick;
     }
     debugCount = 0;
     debugRound = round;
     debugColor = color;
     debugTimer.Start();
 }
Esempio n. 2
0
        private async void Timer_Tick(object sender, object e)
        {
            var xamlBrush = blackBrush;

            temp = hat.GetTemperature();
            if (temp > 26)
            {
                theColor  = FEZHAT.Color.Red;
                xamlBrush = redBrush;
            }
            else
            {
                theColor  = FEZHAT.Color.Blue;
                xamlBrush = blueBrush;
            }

            if (count % 2 > 0)
            {
                hat.D2.Color = theColor;
                hat.D3.TurnOff();
                D3X.Fill = xamlBrush;
                D2X.Fill = blackBrush;
            }
            else
            {
                hat.D3.Color = theColor;
                hat.D2.TurnOff();
                D2X.Fill = xamlBrush;
                D3X.Fill = blackBrush;
            }
            Debug.WriteLine("Temp is:" + temp.ToString("0.00"));

            var    request  = new HttpClient();
            string jsonTemp = "{ 'SensorName': 'Temperature 1', 'SensorValue': '" + temp.ToString("0.00") + "'}";
            var    content  = new StringContent(jsonTemp);
            HttpResponseMessage response = await request.PostAsync("http://sensorreadingapi.azurewebsites.net/Api/SensorReading", content);

            Debug.WriteLine("Response: " + response.StatusCode.ToString());
            count++;
        }
Esempio n. 3
0
        private LedColor ToLedColor(FEZHAT.Color color)
        {
            if (color == FEZHAT.Color.Red)
            {
                return(LedColor.Red);
            }
            else if (color == FEZHAT.Color.Green)
            {
                return(LedColor.Green);
            }
            else if (color == FEZHAT.Color.Blue)
            {
                return(LedColor.Blue);
            }
            else if (color == FEZHAT.Color.Cyan)
            {
                return(LedColor.Cyan);
            }
            else if (color == FEZHAT.Color.Magneta)
            {
                return(LedColor.Magenta);
            }
            else if (color == FEZHAT.Color.Yellow)
            {
                return(LedColor.Yellow);
            }
            else if (color == FEZHAT.Color.White)
            {
                return(LedColor.White);
            }
            else if (color == FEZHAT.Color.Black)
            {
                return(LedColor.Black);
            }

            return(LedColor.Black);
        }
Esempio n. 4
0
        public async Task ReceiveDataFromAzure()
        {
            Message receivedMessage;
            string  messageData;

            if (m_clt != null)
            {
                while (true)
                {
                    try
                    {
                        receivedMessage = await m_clt.ReceiveAsync();

                        if (receivedMessage != null)
                        {
                            messageData = System.Text.Encoding.ASCII.GetString(receivedMessage.GetBytes());
                            //Wykonanie polecenia
                            if (messageData.Length >= 2)
                            {
                                await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                                {
                                    double val;
                                    switch (messageData[0])
                                    {
                                    case 'L':
                                        if (m_hat != null)
                                        {
                                            try
                                            {
                                                string[] s     = messageData.Substring(1).Split(',');
                                                FEZHAT.Color c = new FEZHAT.Color(byte.Parse(s[0]), byte.Parse(s[1]), byte.Parse(s[2]));
                                                m_hat.D2.Color = c;
                                            }
                                            catch { }
                                        }
                                        break;

                                    case 'A':
                                        //All messages - interval
                                        if (double.TryParse(messageData.Substring(1), out val))
                                        {
                                            txtAll.Text = val.ToString();
                                        }
                                        break;

                                    case 'O':
                                        //On / Off
                                        if (messageData[1] == '0')
                                        {
                                            tgSend.IsOn = false;
                                        }
                                        else
                                        {
                                            tgSend.IsOn = true;
                                        }
                                        break;

                                    default:
                                        break;
                                    }
                                });
                            }
                            //await m_clt.RejectAsync(receivedMessage);
                            //await m_clt.AbandonAsync(receivedMessage); - reject, will be redelivered
                            //Confirm
                            await m_clt.CompleteAsync(receivedMessage); //potwierdza odebranie
                        }
                    }
                    catch (Exception ex)
                    {
                        txtState.Text = ex.ToString();
                    }
                }
            }
        }