Esempio n. 1
0
        static unsafe void Demo1(RGBLedMatrix matrix)
        {
            play = true;

            try
            {
                BdfFont font  = BdfFont.Load(@"fonts/10x20.bdf");
                BdfFont font1 = BdfFont.Load(@"fonts/8x13B.bdf");
                matrix.Fill(0, 0, 0);
                Thread.Sleep(100);

                int    x             = matrix.Width - 1;
                string text          = "Hello .NET IoT";
                int    fullTextWidth = text.Length * font.Width;

                while (play)
                {
                    matrix.DrawText(x, 0, text, font, 0, 0, 255, 0, 0, 0);
                    x--;
                    if (x == -fullTextWidth)
                    {
                        x = matrix.Width - 1;
                    }

                    string d = DateTime.Now.ToString("hh:mm:ss");
                    matrix.DrawText(0, font.Height + 1, d, font1, 128, 128, 0, 0, 0, 0);

                    Thread.Sleep(25);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Esempio n. 2
0
        static unsafe void Demo4(RGBLedMatrix matrix)
        {
            play = true;

            byte blue = 0x15;

            matrix.Fill(0, 0, blue);

            using (WebClient client = new WebClient())
            {
                int    lastMinute  = -1;
                string temperature = "";

                BdfFont font  = BdfFont.Load(@"fonts/6x12.bdf");
                BdfFont font1 = BdfFont.Load(@"fonts/5x7.bdf");

                Bitmap weatherIcon = null;
                string lastIcon    = null;
                string description = "";

                while (play)
                {
                    DateTime time = DateTime.Now;
                    if (Math.Abs(time.Minute - lastMinute) > 4)
                    {
                        lastMinute = time.Minute;
                        string xml = client.DownloadString("http://api.openweathermap.org/data/2.5/weather?q=Redmond,US&mode=xml&units=imperial&APPID=" + s_weatherKey);

                        XDocument doc     = XDocument.Parse(xml);
                        XElement  element = doc.Root.Element("temperature");
                        temperature = ((int)Math.Round(Double.Parse(element.Attribute("value").Value))).ToString(CultureInfo.InvariantCulture);

                        element = doc.Root.Element("weather");
                        string icon = element.Attribute("icon").Value;
                        description = element.Attribute("value").Value;

                        if (lastIcon != icon)
                        {
                            weatherIcon = new Bitmap("bitmaps/" + icon + ".bmp");
                        }

                        matrix.DrawBitmap(20, 2, weatherIcon, 255, 255, 255, 0, 0, blue);
                        matrix.DrawText(Math.Max(0, matrix.Width - description.Length * font1.Width), 42, description, font1, 128, 128, 128, 0, 0, blue);
                        matrix.DrawText(2, 2 + font.Height, temperature + "\u00B0", font, 128, 128, 128, 0, 0, blue);
                    }

                    matrix.DrawText(2, 2, time.ToString("ddd"), font, 128, 128, 128, 0, 0, blue);
                    matrix.DrawText(2, matrix.Height - font.Height, time.ToString("hh:mm:sstt"), font, 128, 128, 128, 0, 0, blue);

                    Thread.Sleep(200);
                }
            }
        }
Esempio n. 3
0
        static unsafe void Demo6(RGBLedMatrix matrix)
        {
            play = true;

            try
            {
                matrix.Fill(0, 0, 0);

                Bitmap [] bitmaps = new Bitmap []
                {
                    new Bitmap(@"bitmaps/dotnet-bot-branded-32x32.bmp"),
                    new Bitmap(@"bitmaps/i-love-dotnet.bmp")
                };

                int x           = matrix.Width - 1;
                int bitmapIndex = 0;
                while (play)
                {
                    matrix.DrawBitmap(x, 0, bitmaps[bitmapIndex]);

                    if (x + bitmaps[bitmapIndex].Width < matrix.Width)
                    {
                        matrix.FillRectangle(x + bitmaps[bitmapIndex].Width, 0, matrix.Width - x - bitmaps[bitmapIndex].Width, matrix.Height, 0, 0, 0);
                    }

                    x--;

                    if (x == -bitmaps[bitmapIndex].Width)
                    {
                        bitmapIndex = (bitmapIndex + 1) % bitmaps.Length;
                        x           = matrix.Width - 1;
                    }

                    Thread.Sleep(25);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Esempio n. 4
0
        static unsafe void Demo7(RGBLedMatrix matrix)
        {
            play = true;

            try
            {
                matrix.Fill(0, 0, 0);

                while (play)
                {
                    matrix.SetPixel(matrix.Width / 2, matrix.Height / 2, 255, 0, 0);
                    matrix.DrawCircle(matrix.Width / 2, matrix.Height / 2, 14, 255, 0, 0);
                    matrix.DrawCircle(matrix.Width / 2, matrix.Height / 2, 9, 0, 255, 0);
                    matrix.DrawCircle(matrix.Width / 2, matrix.Height / 2, 6, 0, 0, 255);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Esempio n. 5
0
        static void Demo3(RGBLedMatrix matrix)
        {
            try
            {
                play = true;

                byte blue = 0x10;
                matrix.Fill(0, 0, blue);

                TimeZoneInfo [] zones       = new TimeZoneInfo [s_citiesData.Length];
                string []       weatherUrls = new string [s_citiesData.Length];
                for (int i = 0; i < s_citiesData.Length; i++)
                {
                    weatherUrls[i] = String.Format("http://api.openweathermap.org/data/2.5/weather?q={0},{1}&mode=xml&units=imperial&APPID={2}", s_citiesData[i].City, s_citiesData[i].CountryCode, s_weatherKey);
                    zones[i]       = TimeZoneInfo.FindSystemTimeZoneById(s_citiesData[i].ZoneId);
                }

                using (WebClient client = new WebClient())
                {
                    BdfFont font  = BdfFont.Load(@"fonts/6x12.bdf");
                    BdfFont font1 = BdfFont.Load(@"fonts/5x7.bdf");
                    BdfFont font2 = BdfFont.Load(@"fonts/4x6.bdf");

                    int cityIndex = 0;

                    while (play)
                    {
                        string    xml         = client.DownloadString(weatherUrls[cityIndex]);
                        XDocument doc         = XDocument.Parse(xml);
                        XElement  element     = doc.Root.Element("temperature");
                        string    temperature = ((int)Math.Round(Double.Parse(element.Attribute("value").Value))).ToString(CultureInfo.InvariantCulture);

                        element = doc.Root.Element("weather");
                        string description = element.Attribute("value").Value + "                                           ";

                        element = doc.Root.Element("humidity");
                        string humidity = element.Attribute("value").Value + element.Attribute("unit").Value + "             ";
                        element = doc.Root.Element("city").Element("sun");
                        string sunRise = TimeZoneInfo.ConvertTimeFromUtc(DateTime.Parse(element.Attribute("rise").Value, CultureInfo.InvariantCulture), zones[cityIndex]).ToString("hh:mm tt");
                        string sunSet  = TimeZoneInfo.ConvertTimeFromUtc(DateTime.Parse(element.Attribute("set").Value, CultureInfo.InvariantCulture), zones[cityIndex]).ToString("hh:mm tt");

                        int pos = Math.Max(0, (matrix.Width - (s_citiesData[cityIndex].City.Length * font.Width))) / 2;
                        ScrollText(
                            matrix,
                            s_citiesData[cityIndex].City,
                            font,
                            matrix.Width - 1,
                            pos,
                            128, 128, 128, 0, 0, blue);

                        int y = font.Height;
                        matrix.DrawText((matrix.Width - (temperature.Length + 1) * font1.Width) / 2, y, temperature + "\u00B0", font1, 255, 255, 0, 0, 0, blue);

                        y += font1.Height + 2;
                        matrix.DrawText(2, y, description, font2, 128, 128, 128, 0, 0, blue);

                        y += font2.Height + 2;
                        matrix.DrawText(2, y, "humidity: ", font2, 128, 128, 128, 0, 0, blue);
                        matrix.DrawText(font2.Width * "humidity: ".Length + 2, y, humidity, font2, 255, 255, 0, 0, 0, blue);

                        y += font2.Height;
                        string localTime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, zones[cityIndex]).ToString("hh:mm tt");
                        matrix.DrawText((matrix.Width - localTime.Length * font.Width) / 2, y, localTime, font, 255, 255, 0, 0, 0, blue);

                        y += font.Height + 2;
                        matrix.DrawText(2, y, "Sun Rise: ", font2, 128, 128, 128, 0, 0, blue);
                        matrix.DrawText(2 + "Sun Rise: ".Length * font2.Width, y, sunRise, font2, 255, 255, 0, 0, 0, blue);

                        y += font2.Height + 2;
                        matrix.DrawText(2, y, "Sun Set:  ", font2, 128, 128, 128, 0, 0, blue);
                        matrix.DrawText(2 + "Sun Set:  ".Length * font2.Width, y, sunSet, font2, 255, 255, 0, 0, 0, blue);

                        Thread.Sleep(4000);

                        ScrollText(
                            matrix,
                            s_citiesData[cityIndex].City,
                            font,
                            pos,
                            -(pos + s_citiesData[cityIndex].City.Length * font.Width),
                            128, 128, 128, 0, 0, blue);

                        y = font.Height;
                        matrix.DrawText((matrix.Width - (temperature.Length + 1) * font1.Width) / 2, y, temperature + "\u00B0", font1, 0, 0, blue, 0, 0, blue);

                        y += font1.Height + 2;
                        matrix.DrawText(2, y, description, font2, 0, 0, blue, 0, 0, blue);

                        y += font2.Height + 2;
                        matrix.DrawText(2, y, "humidity: ", font2, 0, 0, blue, 0, 0, blue);
                        matrix.DrawText(font2.Width * "humidity: ".Length + 2, y, humidity, font2, 0, 0, blue, 0, 0, blue);

                        y += font2.Height;
                        matrix.DrawText((matrix.Width - localTime.Length * font.Width) / 2, y, localTime, font, 0, 0, blue, 0, 0, blue);

                        y += font.Height + 2;
                        matrix.DrawText(2, y, "Sun Rise: ", font2, 0, 0, blue, 0, 0, blue);
                        matrix.DrawText(2 + "Sun Rise: ".Length * font2.Width, y, sunRise, font2, 0, 0, blue, 0, 0, blue);

                        y += font2.Height + 2;
                        matrix.DrawText(2, y, "Sun Set:  ", font2, 0, 0, blue, 0, 0, blue);
                        matrix.DrawText(2 + "Sun Set:  ".Length * font2.Width, y, sunSet, font2, 0, 0, blue, 0, 0, blue);

                        cityIndex = (cityIndex + 1) % s_citiesData.Length;
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Esempio n. 6
0
        private static void WeatherDemo(RGBLedMatrix matrix)
        {
            BdfFont font  = BdfFont.Load(@"fonts/10x20.bdf");
            BdfFont font1 = BdfFont.Load(@"fonts/8x13B.bdf");

            matrix.Fill(0, 0, 0);
            Thread.Sleep(100);

            int textLeft = 0;

            const int feedUpdateMs   = 500;
            const int drawIntervalMs = 25;
            const int iterations     = feedUpdateMs / drawIntervalMs;

            byte Col(float x)
            {
                return((byte)Math.Clamp(x * 255, 0, 255));
            }

            string text          = string.Empty;
            int    fullTextWidth = 0;

            Stopwatch sw = Stopwatch.StartNew();

            while (s_scenario != null)
            {
                text          = " * " + string.Join(" * ", WeatherFeed());
                fullTextWidth = text.Length * font.Width;

                for (int i = 0; i < iterations && s_scenario != null; i++, textLeft--)
                {
                    matrix.DrawText(textLeft, -2, text, font, 0, 0, 255, 0, 0, 0);

                    if (textLeft + fullTextWidth < matrix.Width)
                    {
                        matrix.DrawText(textLeft + fullTextWidth, -2, text, font, 0, 0, 255, 0, 0, 0);
                    }

                    if (textLeft + fullTextWidth <= 0)
                    {
                        textLeft += fullTextWidth;
                    }

                    DateTimeOffset localNow = DateTimeOffset.Now;
                    DateTimeOffset pstNow   = TimeZoneInfo.ConvertTime(localNow, s_timeZonePst);
                    string         d        = pstNow.ToString("hh:mm:ss");
                    matrix.DrawText(0, font.Height + 1 - 2, d, font1, 0, 255, 0, 0, 0, 0);

                    int   halfHeight = matrix.Height / 2;
                    int   halfWidth  = matrix.Width / 2;
                    float time       = sw.ElapsedMilliseconds / 1000f;
                    for (int x = 0; x < matrix.Width; x++)
                    {
                        if (x < halfWidth)
                        {
                            for (int y = halfHeight; y < matrix.Height; y++)
                            {
                                Vector3 col3  = Clock(new Vector2((float)x / halfWidth, (float)(y - halfHeight) / halfHeight), pstNow);
                                Color   color = Color.FromArgb(Col(col3.X), Col(col3.Y), Col(col3.Z));
                                matrix.SetPixel(x, y, color.R, color.G, color.B);
                            }
                        }
                        else
                        {
                            for (int y = halfHeight; y < matrix.Height; y++)
                            {
                                Vector2 uv    = new Vector2((float)(x - halfWidth) / halfWidth, (float)(y - halfHeight) / halfHeight);
                                Vector3 col3  = OpenWeatherIcon(uv, s_weatherResponse.Weather[0].Icon, time);
                                Color   color = Color.FromArgb(Col(col3.X), Col(col3.Y), Col(col3.Z));
                                matrix.SetPixel(x, y, color.R, color.G, color.B);
                            }
                        }
                    }

                    Thread.Sleep(drawIntervalMs);
                }
            }
        }