Exemplo n.º 1
0
 public virtual void Draw(VirtualCanvas canvas)
 {
     if (!Dirty)
     {
         return;
     }
     if (Area.Radius == 0)
     {
         if (Clicked)
         {
             canvas.DrawRectangleFilled(Area.X, Area.Y, Area.X + Area.Width - 1, Area.Y + Area.Height - 1, (ushort)BasicColor.Red);
         }
         else
         {
             canvas.DrawRectangleFilled(Area.X, Area.Y, Area.X + Area.Width - 1, Area.Y + Area.Height - 1, (ushort)BasicColor.Black);
         }
     }
     else
     {
         if (Clicked)
         {
             canvas.DrawCircleFilled(Area.X, Area.Y, Area.Radius, (ushort)BasicColor.Red);
         }
         else
         {
             canvas.DrawCircleFilled(Area.X, Area.Y, Area.Radius, (ushort)BasicColor.Black);
         }
     }
     Dirty = false;
 }
Exemplo n.º 2
0
        protected void DrawPlayground(VirtualCanvas canvas)
        {
            canvas.SetOrientation(Orientation.Landscape);
            canvas.DrawFill(ColorHelpers.GetRGB24toRGB565(255, 255, 255));
            canvas.DrawString(
                50, 4,
                ColorHelpers.GetRGB24toRGB565(0, 0, 0),
                VerdanaBold14.ID,
                "RGB Pixel Drawing");
            DrawGrid(canvas);
            // red
            canvas.DrawRectangleFilled(
                260, 42,
                290, 72,
                ColorHelpers.GetRGB24toRGB565(255, 0, 0));
            // green
            canvas.DrawRectangleFilled(
                260, 77,
                290, 107,
                ColorHelpers.GetRGB24toRGB565(0, 250, 0));
            // blue
            canvas.DrawRectangleFilled(
                260, 112,
                290, 142,
                ColorHelpers.GetRGB24toRGB565(0, 0, 255));
            // Reset
            canvas.DrawButton(
                80, 150,
                160, 20,
                Verdana9.ID, 12,
                ColorHelpers.GetRGB24toRGB565(0, 0, 0),
                ColorHelpers.GetRGB24toRGB565(255, 255, 255),
                ColorHelpers.GetRGB24toRGB565(0, 0, 0),
                "Reset Drawing",
                RoundedCornerStyle.All);
            // Exit
            canvas.DrawButton(
                32, 197,
                250, 36,
                VerdanaBold14.ID, 20,
                ColorHelpers.GetRGB24toRGB565(0, 0, 0),
                ColorHelpers.GetRGB24toRGB565(255, 255, 255),
                ColorHelpers.GetRGB24toRGB565(0, 0, 0),
                "Click To Exit",
                RoundedCornerStyle.All);

            canvas.Execute();
        }
Exemplo n.º 3
0
 public static void RenderPrimitiveShapes(VirtualCanvas canvas)
 {
     canvas.DrawLine(5, 65, 200, 65, (ushort)BasicColor.Red);
     canvas.DrawLine(5, 67, 200, 67, (ushort)BasicColor.Green);
     canvas.DrawLine(5, 69, 200, 69, (ushort)BasicColor.Blue);
     canvas.DrawCircleFilled(30, 105, 23, (ushort)ColorHelpers.GetRGB24toRGB565(0x33, 0x00, 0x00));
     canvas.DrawCircleFilled(30, 105, 19, (ushort)ColorHelpers.GetRGB24toRGB565(0x66, 0x00, 0x00));
     canvas.DrawCircleFilled(30, 105, 15, (ushort)ColorHelpers.GetRGB24toRGB565(0x99, 0x00, 0x00));
     canvas.DrawCircleFilled(30, 105, 11, (ushort)ColorHelpers.GetRGB24toRGB565(0xCC, 0x00, 0x00));
     canvas.DrawCircleFilled(30, 105, 7, (ushort)ColorHelpers.GetRGB24toRGB565(0xFF, 0x00, 0x00));
     canvas.DrawRectangleFilled(80, 80, 180, 125, (ushort)GrayScaleValues.Gray_15);
     canvas.DrawRectangleFilled(85, 85, 175, 120, (ushort)GrayScaleValues.Gray_30);
     canvas.DrawRectangleFilled(90, 90, 170, 115, (ushort)GrayScaleValues.Gray_50);
     canvas.DrawRectangleFilled(95, 95, 165, 110, (ushort)GrayScaleValues.Gray_80);
     canvas.DrawRectangleFilled(100, 100, 160, 105, (ushort)GrayScaleValues.Gray_128);
 }
Exemplo n.º 4
0
        public void DisplayJoystickInput(VirtualCanvas canvas, ushort x, ushort y)
        {
            string text = "X: " + x / 100 + ", " + " Y: " + y / 100;

            canvas.DrawRectangleFilled(0, 110, canvas.Width, 110 + 20, (ushort)BasicColor.White);
            canvas.DrawString(20, 110, (ushort)BasicColor.Black, VerdanaBold14.ID, text);
            canvas.Execute();
        }
Exemplo n.º 5
0
        public void Render(VirtualCanvas canvas)
        {
            Relay.Initialize(RelaySocket);
            ThermoCouple.Initialize(ThermoCoupleSocket);

            canvas.SetOrientation(Orientation.Landscape);
            canvas.DrawFill(BackgroundColor);
            canvas.DrawString(55, 4, 0, VerdanaBold14.ID, "Temperature & Relay");
            canvas.DrawString(32, 74, 0, VerdanaBold14.ID, "Celsius:");
            canvas.DrawString(32, 116, 0, VerdanaBold14.ID, "Fahrenheit:");
            canvas.DrawString(32, 154, 0, VerdanaBold14.ID, "Relay:");
            canvas.DrawButton(
                32, 197,
                250, 36,
                VerdanaBold14.ID, 20,
                ColorHelpers.GetRGB24toRGB565(0, 0, 0),
                ColorHelpers.GetRGB24toRGB565(255, 255, 255),
                ColorHelpers.GetRGB24toRGB565(0, 0, 0),
                "Click To Exit",
                RoundedCornerStyle.All);
            canvas.Execute();
            canvas.Touch += TouchEventHandler;
            while (LastTouchIsValid == 0)
            {
                ReadTemp();
                Thread.Sleep(100);
                canvas.DrawRectangleFilled(93, 153, 158, 176, BackgroundColor);
                canvas.DrawRectangleFilled(105, 69, 175, 94, BackgroundColor);
                canvas.DrawRectangleFilled(138, 112, 205, 137, BackgroundColor);
                canvas.DrawString(32, 74, 0, VerdanaBold14.ID, "Celsius: " + Shorten(ThermoCouple.Celsius.ToString()));
                canvas.DrawString(32, 116, 0, VerdanaBold14.ID, "Fahrenheit: " + Shorten(ThermoCouple.Farenheit.ToString()));
                canvas.DrawString(32, 154, 0, VerdanaBold14.ID, "Relay: " + ((RelayStatus) ? "ON" : "OFF"));
                canvas.Execute();
                canvas.TouchscreenWaitForEvent(TouchScreenEventMode.NonBlocking);
            }
            canvas.Touch -= TouchEventHandler;
            Relay.Dispose();
            ThermoCouple.Dispose();
        }
Exemplo n.º 6
0
 public static void RenderCompoundShapes(VirtualCanvas canvas, FontInfo fontInfo)
 {
     canvas.DrawProgressBar(
         70, 140,
         75, 12,
         CornerStyle,
         CornerStyle,
         (ushort)BasicColor.Black,
         (ushort)GrayScaleValues.Gray_128,
         (ushort)GrayScaleValues.Gray_30,
         (ushort)BasicColor.Green,
         78);
     canvas.DrawString(5, 144, (ushort)BasicColor.Black, fontInfo.ID, "Progress");
     canvas.DrawString(155, 144, (ushort)BasicColor.Black, fontInfo.ID, "78%");
     canvas.DrawRectangleFilled(0, 275, 239, 319, (ushort)GrayScaleValues.Gray_80);
 }
Exemplo n.º 7
0
 public static void UpdateDisplay(ushort temp, ushort humidity, Int32 pressurePa, UInt32 lux, UInt16 infraredSpectrum, AdcSample sample)
 {
     canvas.DrawRectangleFilled(
         180, 30,
         300, 162,
         ColorHelpers.GetRGB24toRGB565(0, 0, 0));
     canvas.DrawString(
         TextAlignmentX, 40,
         ColorHelpers.GetRGB24toRGB565(255, 255, 255),
         VerdanaBold14.ID,
         temp.ToString());
     canvas.DrawString(
         TextAlignmentX, 65,
         ColorHelpers.GetRGB24toRGB565(255, 255, 255),
         VerdanaBold14.ID,
         humidity.ToString());
     canvas.DrawString(
         TextAlignmentX, 90,
         ColorHelpers.GetRGB24toRGB565(255, 255, 255),
         VerdanaBold14.ID,
         lux.ToString());
     canvas.DrawString(
         TextAlignmentX, 115,
         ColorHelpers.GetRGB24toRGB565(255, 255, 255),
         VerdanaBold14.ID,
         infraredSpectrum.ToString());
     canvas.DrawString(
         TextAlignmentX, 140,
         ColorHelpers.GetRGB24toRGB565(255, 255, 255),
         VerdanaBold14.ID,
         pressurePa.ToString());
     canvas.DrawProgressBar(
         148, 171,
         154, 10,
         RoundedCornerStyle.All,
         RoundedCornerStyle.All,
         ColorHelpers.GetRGB24toRGB565(214, 214, 214),
         ColorHelpers.GetRGB24toRGB565(108, 224, 217),
         ColorHelpers.GetRGB24toRGB565(255, 255, 255),
         ColorHelpers.GetRGB24toRGB565(233, 15, 7),
         (int)DaqUtility.MapRange(0, 4095, 0, 100, (double)sample.Values[(int)ADC.A0]));
     canvas.Execute();
 }
Exemplo n.º 8
0
        public void Render(VirtualCanvas canvas)
        {
            var SendContext = new BasicTypeSerializerContext();
            var ComPort     = new SerialMessenger();

            ComPort.Messenger += OnMessage;
            ComPort.Initialize(bufferSize: 1024);

            int contentSize = 0;

            BasicTypeSerializer.Put(SendContext, (UInt16)RGBLedDisplayCommand.Reset);
            var buffer = SendContext.GetBuffer(out contentSize);

            ComPort.Send(buffer, 0, (byte)contentSize);

            DrawPlayground(canvas);
            canvas.Touch += TouchEventHandler;
            var    exit = false;
            ushort r = 127, g = 0, b = 0;

            while (!exit)
            {
                LastTouchIsValid = 0;
                canvas.TouchscreenWaitForEvent(TouchScreenEventMode.NonBlocking);
                if (LastTouchIsValid != 0)
                {
                    if (LastTouchX >= 260 && LastTouchY >= 42 && LastTouchX <= 290 && LastTouchY <= 72)   // red
                    {
                        r         = 127;
                        g         = 0;
                        b         = 0;
                        LastColor = ColorHelpers.GetRGB24toRGB565(255, 0, 0);
                    }
                    else if (LastTouchX >= 260 && LastTouchY >= 77 && LastTouchX <= 290 && LastTouchY <= 107)   // green
                    {
                        r         = 0;
                        g         = 127;
                        b         = 0;
                        LastColor = ColorHelpers.GetRGB24toRGB565(0, 255, 0);
                    }
                    else if (LastTouchX >= 260 && LastTouchY >= 112 && LastTouchX <= 290 && LastTouchY <= 142)   // blue
                    {
                        r         = 0;
                        g         = 0;
                        b         = 127;
                        LastColor = ColorHelpers.GetRGB24toRGB565(0, 0, 255);
                    }
                    else if (LastTouchX >= 80 && LastTouchY >= 150 && LastTouchX <= 80 + 160 && LastTouchY <= 170)   // reset
                    {
                        canvas.DrawRectangleFilled(
                            79, 40,
                            241, 141,
                            ColorHelpers.GetRGB24toRGB565(255, 255, 255));
                        DrawGrid(canvas);
                        BasicTypeSerializer.Put(SendContext, (UInt16)RGBLedDisplayCommand.Reset);
                        buffer = SendContext.GetBuffer(out contentSize);
                        ComPort.Send(buffer, 0, (byte)contentSize);
                        Thread.Sleep(250);
                    }
                    else if (LastTouchX >= 80 && LastTouchY >= 42 && LastTouchX < 240 && LastTouchY < 140)   // canvas
                    {
                        var x = (LastTouchX - 80) / 10;
                        var y = (LastTouchY - 42) / 10;
                        if (LastSquareX != x || LastSquareY != y)
                        {
                            LastSquareX = x;
                            LastSquareY = y;
                            canvas.DrawRectangleFilled(80 + (x * 10) + 1, 42 + (y * 10) + 1, 80 + (x * 10) + 1 + 8, 42 + (y * 10) + 1 + 8, LastColor);
                            canvas.Execute();
                            BasicTypeSerializer.Put(SendContext, (UInt16)RGBLedDisplayCommand.SetPixel);
                            BasicTypeSerializer.Put(SendContext, (ushort)x);
                            BasicTypeSerializer.Put(SendContext, (ushort)y);
                            BasicTypeSerializer.Put(SendContext, r);
                            BasicTypeSerializer.Put(SendContext, g);
                            BasicTypeSerializer.Put(SendContext, b);
                            buffer = SendContext.GetBuffer(out contentSize);
                            ComPort.Send(buffer, 0, (byte)contentSize);
                        }
                    }
                    else if (LastTouchX >= 32 && LastTouchY >= 197 && LastTouchX <= 32 + 250 && LastTouchY <= 197 + 36)   // exit
                    {
                        exit = true;
                    }
                }
            }
            canvas.Touch -= TouchEventHandler;
            ComPort.Dispose();
        }
Exemplo n.º 9
0
        public void Render(VirtualCanvas canvas)
        {
            var Pot         = new NetduinoGo.Potentiometer(GoSockets.Socket1);
            var SendContext = new BasicTypeSerializerContext();
            var ComPort     = new SerialMessenger();

            ComPort.Messenger += OnMessage;
            ComPort.Initialize();

            int contentSize = 0;

            BasicTypeSerializer.Put(SendContext, (UInt16)RGBLedDisplayCommand.Reset);
            var buffer = SendContext.GetBuffer(out contentSize);

            MessageReceivedEvent.Reset();
            ComPort.Send(buffer, 0, (byte)contentSize);
            MessageReceivedEvent.WaitOne(100, true);

            DrawPlayground(canvas);
            canvas.Touch += TouchEventHandler;
            var exit = false;

            while (!exit)
            {
                LastTouchIsValid = 0;
                canvas.TouchscreenWaitForEvent(TouchScreenEventMode.NonBlocking);
                ushort color = Wheel((ushort)MapRange(0, 1, 0, 384, Pot.GetValue()));
                if (color != LastColor)
                {
                    LastColor = color;
                    canvas.DrawRectangleFilled(184, 153, 213, 179, LastColor);
                    canvas.Execute();
                }
                if (LastTouchIsValid != 0)
                {
                    if (LastTouchX >= 80 && LastTouchY >= 42 && LastTouchX < 240 && LastTouchY <= 140)
                    {
                        var x = (LastTouchX - 80) / 10;
                        var y = (LastTouchY - 42) / 10;
                        canvas.DrawRectangleFilled(80 + (x * 10) + 1, 42 + (y * 10) + 1, 80 + (x * 10) + 1 + 8, 42 + (y * 10) + 1 + 8, LastColor);
                        canvas.Execute();
                        BasicTypeSerializer.Put(SendContext, (UInt16)RGBLedDisplayCommand.SetPixel);
                        BasicTypeSerializer.Put(SendContext, (int)x);
                        BasicTypeSerializer.Put(SendContext, (int)y);
                        BasicTypeSerializer.Put(SendContext, (uint)LastColor);
                        buffer = SendContext.GetBuffer(out contentSize);

                        MessageReceivedEvent.Reset();
                        ComPort.Send(buffer, 0, (byte)contentSize);
                        MessageReceivedEvent.WaitOne(100, true);
                    }
                    else if (LastTouchX >= 32 && LastTouchY >= 197 && LastTouchX <= 32 + 250 && LastTouchY <= 197 + 36)
                    {
                        exit = true;
                    }
                }
            }
            canvas.Touch -= TouchEventHandler;
            ComPort.Dispose();
            Pot.Dispose();
        }