Esempio n. 1
0
        // write either command or data, with automatic 4/8-bit selection
        private void Send(byte value, PinValue mode)
        {
            Write(_rsPin, mode);

            // if there is a RW pin indicated, set it low to Write
            if (_rwPin != -1)
            {
                Write(_rwPin, PinValue.Low);
            }

            if (_displayFunction.HasFlag(DisplayFlags.LCD_8BITMODE))
            {
                Write8bits(value);
            }
            else
            {
                Write4bits((byte)(value >> 4));
                Write4bits(value);
            }
        }
        private void CreatePoint(ZonePoint zp,DisplayFlags flags)
        {
            Model3DGroup group = Model as Model3DGroup;
            Model3DCollection collection = new Model3DCollection();

            if (_mapping.ContainsKey(zp))
            {
                foreach (Model3D model in _mapping[zp])
                {
                    group.Children.Remove(model);
                }
            }

            double px, py, pz;
            px = zp.X == 999999 ? 0 : zp.X;
            py = zp.Y == 999999 ? 0 : zp.Y;
            pz = zp.Z == 999999 ? 0 : zp.Z;

            Point3D p = new Point3D(px,py,pz);

            if (!Clipping.DrawPoint(p)) return;

            MeshBuilder builder = new MeshBuilder();
            builder.AddBox(p, 20, 20, 2);

            //connect box to destination
            px = zp.TargetX == 999999 ? px : zp.TargetX;
            py = zp.TargetY == 999999 ? py : zp.TargetY;
            pz = zp.TargetZ == 999999 ? pz : zp.TargetZ;

            GeometryModel3D box;
            box = new GeometryModel3D(builder.ToMesh(), Materials.Red);
            collection.Add(box);

            builder = new MeshBuilder();
            Point3D destP = new Point3D(px, py, pz);
            builder.AddArrow(p, destP, 0.5);
            builder.AddBox(destP, 20, 20, 2);

            if (zp.X == 999999 || zp.Y == 999999 || zp.Z == 999999 ||
                zp.TargetX == 999999 || zp.TargetY == 999999 || zp.TargetZ == 999999)
            {
                box = new GeometryModel3D(builder.ToMesh(), Materials.Gold);
            }
            else
            {
                box = new GeometryModel3D(builder.ToMesh(), Materials.White);
            }

            collection.Add(box);

            if (flags != DisplayFlags.None)
            {
                builder = new MeshBuilder();

                if (flags.HasFlag(DisplayFlags.DarkGrayAura))
                {
                    builder.AddBox(p, 25,25, 1);
                    builder.AddBox(destP, 25, 25, 1);
                    box = new GeometryModel3D(builder.ToMesh(), Materials.DarkGray);
                    collection.Add(box);
                }
                else if (flags.HasFlag(DisplayFlags.GreenAura))
                {
                    builder.AddBox(p, 25, 25, 1);
                    builder.AddBox(destP, 25, 25, 1);
                    box = new GeometryModel3D(builder.ToMesh(), Materials.Green);
                    collection.Add(box);
                }
            }

            _mapping[zp] = collection;

            foreach (Model3D model in collection)
            {
                group.Children.Add(model);
            }
        }
        private void CreateSpawn(GroundSpawn spawn,DisplayFlags flags)
        {
            Model3DGroup group = Model as Model3DGroup;
            Model3DCollection collection = new Model3DCollection();

            if (_mapping.ContainsKey(spawn))
            {
                foreach (Model3D model in _mapping[spawn])
                {
                    group.Children.Remove(model);
                }
            }

            Point3D p = new Point3D(
                (spawn.MaxX + spawn.MinX) / 2,
                (spawn.MaxY + spawn.MinY) / 2,
                spawn.MaxZ);

            if (!Clipping.DrawPoint(p)) return;

            var xlen = spawn.MaxX - spawn.MinX;
            var ylen = spawn.MaxY - spawn.MinY;

            xlen = xlen <= 0 ? 4 : xlen;
            ylen = ylen <= 0 ? 4 : ylen;

            MeshBuilder builder = new MeshBuilder();
            builder.AddBox(p, ylen, xlen, 2);

            GeometryModel3D box = new GeometryModel3D(builder.ToMesh(), Materials.Gold);

            collection.Add(box);

            if ( flags != DisplayFlags.None )
            {
                var scale = 1.25;
                builder = new MeshBuilder();

                if (flags.HasFlag(DisplayFlags.DarkGrayAura))
                {
                    builder.AddBox(p, ylen * scale, xlen * scale, 1);
                    box = new GeometryModel3D(builder.ToMesh(), Materials.DarkGray);
                    collection.Add(box);
                }
                else if (flags.HasFlag(DisplayFlags.GreenAura))
                {
                    builder.AddBox(p, ylen * scale, xlen * scale, 1);
                    box = new GeometryModel3D(builder.ToMesh(), Materials.Green);
                    collection.Add(box);
                }
            }

            _mapping[spawn] = collection;

            foreach (Model3D model in collection)
            {
                group.Children.Add(model);
            }
        }
Esempio n. 4
0
        public void Begin(byte cols, byte lines, DisplayFlags dotSize = DisplayFlags.LCD_5x8DOTS)
        {
            if (lines > 1)
            {
                _displayFunction |= DisplayFlags.LCD_2LINE;
            }

            _numLines = lines;

            SetRowOffsets(0x00, 0x40, (byte)(0x00 + cols), (byte)(0x40 + cols));

            // for some 1 line displays you can select a 10 pixel high font
            if ((dotSize != DisplayFlags.LCD_5x8DOTS) && (lines == 1))
            {
                _displayFunction |= DisplayFlags.LCD_5x10DOTS;
            }

            SetPinMode(_rsPin, PinMode.Output);
            // we can save 1 pin by not using RW. Indicate by passing null instead of a pin
            if (_rwPin != -1)
            {
                SetPinMode(_rwPin, PinMode.Output);
            }
            SetPinMode(_enablePin, PinMode.Output);

            // Do this just once, instead of every time a character is drawn (for speed reasons).
            for (int i = 0; i < _dataPins.Length; ++i)
            {
                SetPinMode(_dataPins[i], PinMode.Output);
            }

            // SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION!
            // according to datasheet, we need at least 40ms after power rises above 2.7V
            // before sending commands. Arduino can turn on way before 4.5V so we'll wait 50
            DelayMicroseconds(50000);
            // Now we pull both RS and R/W low to begin commands
            Write(_rsPin, PinValue.Low);
            Write(_enablePin, PinValue.Low);

            if (_rwPin != -1)
            {
                Write(_rwPin, PinValue.Low);
            }

            //put the LCD into 4 bit or 8 bit mode
            if (_displayFunction.HasFlag(DisplayFlags.LCD_8BITMODE))
            {
                // this is according to the hitachi HD44780 datasheet
                // page 45 figure 23

                // Send function set command sequence
                Command((byte)Commands.LCD_FUNCTIONSET | (byte)_displayFunction);
                DelayMicroseconds(4500);  // wait more than 4.1ms

                // second try
                Command((byte)Commands.LCD_FUNCTIONSET | (byte)_displayFunction);
                DelayMicroseconds(150);

                // third go
                Command((byte)Commands.LCD_FUNCTIONSET | (byte)_displayFunction);
            }
            else
            {
                // this is according to the hitachi HD44780 datasheet
                // figure 24, pg 46

                // we start in 8bit mode, try to set 4 bit mode
                Write4bits(0x03);
                DelayMicroseconds(4500); // wait min 4.1ms

                // second try
                Write4bits(0x03);
                DelayMicroseconds(4500); // wait min 4.1ms

                // third go!
                Write4bits(0x03);
                DelayMicroseconds(150);

                // finally, set to 4-bit interface
                Write4bits(0x02);
            }

            // finally, set # lines, font size, etc.
            Command((byte)Commands.LCD_FUNCTIONSET | (byte)_displayFunction);

            // turn the display on with no cursor or blinking default
            _displayControl = DisplayFlags.LCD_DISPLAYON | DisplayFlags.LCD_CURSOROFF | DisplayFlags.LCD_BLINKOFF;
            Display();

            // clear it off
            Clear();

            // Initialize to default text direction (for romance languages)
            _displayMode = DisplayFlags.LCD_ENTRYLEFT | DisplayFlags.LCD_ENTRYSHIFTDECREMENT;
            // set the entry mode
            Command((byte)Commands.LCD_ENTRYMODESET | (byte)_displayMode);
        }