Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

4Display Shields - Drivers


  • Please log in to reply
6 replies to this topic

#1 Omar (OZ)

Omar (OZ)

    Advanced Member

  • Members
  • PipPipPip
  • 564 posts

Posted 02 February 2011 - 04:28 PM

***I terminated these drivers. The new ones are for all their screens and the code is much better.***
Find them here: 4display shields drivers

#2 bill.french

bill.french

    Advanced Member

  • Members
  • PipPipPip
  • 260 posts
  • LocationPrinceton, NJ

Posted 02 February 2011 - 04:38 PM

Hey, Omar, here's my uLCD-144 class, I haven't spent much time to round it out but it might have something useful for you. It still has a bunch of debug.print stuff. Also some links to my other threads in case it helps someone:
http://forums.netdui...ch__1#entry7992
http://forums.netdui...ch__1#entry7521


using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.NetduinoPlus;
using System.IO.Ports;

namespace uLCD_144_Test1
{

    class uLCD_144
    {
        private byte currentline;
        public static byte[] GetByteArray(string s)
        {
            return System.Text.Encoding.UTF8.GetBytes(s);
        }
        public SerialPort _COMPORT;
        public void TextHome()
        {
            currentline = 0;
        }
        public void init()
        {
            using (OutputPort d4 = new OutputPort(Pins.GPIO_PIN_A5, true))
            {
                d4.Write(false);
                d4.Write(true);
            }
            currentline = 0;
            Thread.Sleep(2000);
            _COMPORT.DiscardInBuffer();
            _COMPORT.DiscardOutBuffer();
            this.write(new byte[] { (byte)0x55 });
            WaitForACK();
            TextMode(false);
        }
        public void WaitForACK(string note = "")
        {
            while (_COMPORT.BytesToWrite > 0)
            {
            }
            while (_COMPORT.BytesToRead == 0)
            {
            }
            dumpbuffer(note);
        }

        public void CopyPaste(byte startx, byte starty, byte endx, byte endy, byte width, byte height)
        {
            write((byte)0x63);
            write(startx);
            write(starty);
            write(endx);
            write(endy);
            write(width);
            write(height);
            WaitForACK();
            dumpbuffer("CopyPaste");

        }
        public void TextMode(bool transparent = false)
        {
            if (transparent)
            {
                write((byte)0x4f);
                write((byte)0x00);

            }
            else
            {
                write((byte)0x4f);
                write((byte)0x01);
            }
            WaitForACK();
            dumpbuffer("TextMode");
        }

        public void Print(string s)
        {

            if (currentline > 15)
            {
                CopyPaste(0, 8, 0, 0, 128, 119);
                currentline = 15;
                //DrawASCIIString("                     ", (ushort)0xFFFF, (byte)0, (byte)0, (byte)currentline);
            }
            //DrawASCIIString("                    ", (ushort)0xFFFF, (byte)0, (byte)0, (byte)currentline);
            dumpbuffer("print-cl");
            DrawASCIIString(s, (ushort)0xFFFF, (byte)0, (byte)0, (byte)currentline);
            currentline += (byte)(s.Length / 21 + 1);

            dumpbuffer("print");
        }
        public void DrawASCIIString(string s, ushort color = (ushort)0xffff, byte font = 0, byte x = 0, byte y = 0)

        //2.3.6 Draw “String” of ASCII Text (text format) - 73hex
        //Command cmd, column, row, font, stringColour(msb:lsb), “string”, terminator
        {
            byte[] textba = GetByteArray(s);
            write((byte)0x73);
            write(x);
            write(y);
            write(font);
            write((byte)(color >> 8));
            write((byte)(color & 0x00FF));
            write(textba);
            write((byte)0x00);
            WaitForACK();
        }
        public void clear()
        {
            currentline = 0;
            write((byte)0x45);
            WaitForACK();
            dumpbuffer("Clear");

        }
        public void DrawPixel(byte x, byte y, ushort color = 0xFFFF)
        {
            this.write(0x50);
            this.write(x);
            this.write(y);
            this.write(color);
            WaitForACK("Draw Pixel");

        }
        public void drawbitmap(byte[] bmp)
        {
            //2.2.5 Draw Image-Icon - 49hex
            //Command cmd, x, y, width, height, colourMode, pixel1, .. pixelN
            byte[] cmd = new byte[] { (byte)0x49, (byte)0x00, (byte)0x2A, (byte)0x80, (byte)0x28, (byte)0x08 };
            this.write(cmd);
            this.write(bmp);
            WaitForACK();
        }
        public void write(byte B)
        {
            byte[] ba = new byte[1];
            ba[0] = b;
            this.write(ba);
        }
        public void write(byte[] ba)
        {
            if (this._COMPORT.IsOpen)
            {
                this._COMPORT.Write(ba, 0, ba.Length);
                //int sleeptime = (ba.Length / 7) + 1;  //(calculate transmission time, at 115200, it can send 14 bytes / mx
                //Debug.Print(sleeptime.ToString());
                //if (pause)
                //{
                ///Thread.Sleep(sleeptime);
                //}
            }
            else
            {

            }
        }
        public void write(ushort us)
        {
            write((byte)(us >> 8));
            write((byte)(us & 0x00FF));
        }
        public void dumpbuffer(string note = "")
        {
            //_COMPORT.
            Debug.Print("(" + note + ") In buffer: " + _COMPORT.BytesToRead.ToString());
            while (_COMPORT.BytesToRead > 0)
            {
                byte[] buffer = new byte[1];
                _COMPORT.Read(buffer, 0, 1);
                Debug.Print(buffer[0].ToString());
            }
        }
        public uLCD_144(string sp = SerialPorts.COM1)
        {
            this._COMPORT = new SerialPort(sp, 115200);
            this._COMPORT.Open();
            this.init();
        }
    }
}


#3 Omar (OZ)

Omar (OZ)

    Advanced Member

  • Members
  • PipPipPip
  • 564 posts

Posted 02 February 2011 - 04:46 PM

Hey, Omar, here's my uLCD-144 class, I haven't spent much time to round it out but it might have something useful for you. It still has a bunch of debug.print stuff. Also some links to my other threads in case it helps someone:


Nice code! I'll do my own though, if I don't write it I wont understand it. but I'm sure thats going to help a lot of people. I'll definitely be taking a look at it if I ever get stuck so thanks a bunch. I hope to include the 5 button joystick stuff too, since this is the shield and not just the screen.

#4 Quiche31

Quiche31

    Advanced Member

  • Members
  • PipPipPip
  • 87 posts
  • LocationFrance

Posted 02 February 2011 - 10:38 PM

How about a third one :) I found this little device quite handy too...
Note the two handy "sprite" commands copyScreenToSD and copySDToScreen work well too; I used the application FAT-Controller to upload the sprites to screen

JP

Attached Files



#5 bill.french

bill.french

    Advanced Member

  • Members
  • PipPipPip
  • 260 posts
  • LocationPrinceton, NJ

Posted 02 February 2011 - 11:26 PM

Quiche31, is that "command complete" for SGC? Either way, awesome, the color constants alone are great!

#6 Quiche31

Quiche31

    Advanced Member

  • Members
  • PipPipPip
  • 87 posts
  • LocationFrance

Posted 02 February 2011 - 11:31 PM

Quiche31, is that "command complete" for SGC? Either way, awesome, the color constants alone are great!

The list of constants defining the command set is complete, but indeed their implementations as C# methods are not. I copied all the constants from the datasheet, and introduced the commands as I needed them, incrementally like everyone else. However I'm content with this subset so far for my own application

#7 Bendage

Bendage

    Advanced Member

  • Members
  • PipPipPip
  • 153 posts
  • LocationIrvine, CA

Posted 04 March 2012 - 01:58 AM

The original post driver page is dead :( Omar, you retiring? theshieldstore.com is dead too.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.