public async Task <RgbData> GetRgbData()
        {
            RgbData   rgbData   = new RgbData();
            ColorData colorData = await getRawColorData();

            if (colorData.Clear > 0)
            {
                // Find the RGB values from the raw data using the clear data as reference
                rgbData.Red   = (colorData.Red * 255 / colorData.Clear);
                rgbData.Blue  = (colorData.Blue * 255 / colorData.Clear);
                rgbData.Green = (colorData.Green * 255 / colorData.Clear);
            }
            return(rgbData);
        }
示例#2
0
        private void SetLedsAccordingToSensorValue(RgbData rgb)
        {
            // Active LEDs corresponding to not significant color components.
            // (This way, most LEDs will be active most of the time.)
            int max = rgb.Red > rgb.Green ?
                      (rgb.Red > rgb.Blue ? rgb.Red : rgb.Blue) :
                      (rgb.Green > rgb.Blue ? rgb.Green : rgb.Blue);
            int min = rgb.Red < rgb.Green ?
                      (rgb.Red < rgb.Blue ? rgb.Red : rgb.Blue) :
                      (rgb.Green < rgb.Blue ? rgb.Green : rgb.Blue);
            int threshold = (min + max) / 2 + 20;

            setLed(0, rgb.Red < threshold);
            setLed(1, rgb.Green < threshold);
            setLed(2, rgb.Blue < threshold);
        }
示例#3
0
        private async void SendReportToServer(RgbData rgb)
        {
            const string serverBaseUrl = "http://avalon.aut.bme.hu/kristof/rgbdemo/add.php";
            string       url           = string.Format("{0}?R={1}&G={2}&B={3}", serverBaseUrl, rgb.Red, rgb.Green, rgb.Blue);

            try
            {
                using (HttpClient http = new HttpClient())
                {
                    string response = await http.GetStringAsync(url);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(string.Format("SendReportToServer error:\n(URL: {0})\n{1}", url, ex.ToString()));
            }
        }