Esempio n. 1
0
 /// <summary>
 /// Constructor for parallel LCD connection
 /// </summary>
 /// <param name="rs"></param>
 /// <param name="rw"></param>
 /// <param name="enable"></param>
 /// <param name="d4"></param>
 /// <param name="d5"></param>
 /// <param name="d6"></param>
 /// <param name="d7"></param>
 /// <param name="rows"></param>
 /// <param name="cols"></param>
 public clsLCD_MLC(Cpu.Pin rs, Cpu.Pin rw, Cpu.Pin enable, Cpu.Pin d4, Cpu.Pin d5, Cpu.Pin d6, 
     Cpu.Pin d7, byte rows, byte cols)
 {
     GpioLcdTransferProvider lcdProvider = new GpioLcdTransferProvider(rs, rw, enable, d4, d5, d6, d7);
     lcd = new Lcd(lcdProvider);
     lcd_begin(rows, cols);
 }
Esempio n. 2
0
 public clsLCD_MLC(Cpu.Pin rs, Cpu.Pin rw, Cpu.Pin enable, Cpu.Pin d4, Cpu.Pin d5, Cpu.Pin d6, 
     Cpu.Pin d7, byte rows, byte cols)
 {
     lcdProvider = new GpioLcdTransferProvider(rs, rw, enable, d4, d5, d6, d7);
     lcd = new Lcd(lcdProvider);
     SetScreenSize(rows, cols);
     lcd.Write("hello, world!");
     strBlankRow = new string(' ', cols);
 }
Esempio n. 3
0
        public static void Main()
        {
            DateTime dt = Ds1307.GetDateTime();
            Utility.SetLocalTime(dt);

            var lcdProvider = new GpioLcdTransferProvider(Stm32F4Discovery.Pins.PD1,
                                                          Stm32F4Discovery.Pins.PD2,
                                                          Stm32F4Discovery.Pins.PD9,
                                                          Stm32F4Discovery.Pins.PD11,
                                                          Stm32F4Discovery.Pins.PD10,
                                                          Stm32F4Discovery.Pins.PD8);

            var lcd = new Lcd(lcdProvider);
            lcd.Begin(Columns, 2);

            var userButton = new InterruptPort(Stm32F4Discovery.ButtonPins.User,
                                               false, Port.ResistorMode.PullDown,
                                               Port.InterruptMode.InterruptEdgeLow);

            DateTime showUptimeMode = DateTime.MinValue;
            userButton.OnInterrupt += (d1, d2, t) => showUptimeMode = DateTime.Now.AddSeconds(ShowUptimeInterval);
            
            for (;;)
            {
                var now = DateTime.Now;

                string line1, line2;

                if(showUptimeMode > now)
                {
                    TimeSpan uptime = GetUptime();
                    string uptimeStr = uptime.ToString();
                    int endIndex = uptimeStr.LastIndexOf('.');
                    if(endIndex > Columns)
                        endIndex = Columns;

                    line1 = "Uptime:   ";
                    line2 = uptimeStr.Substring(0, endIndex);
                }
                else
                {
                    line1 = now.ToString("yyyy-MM-dd");
                    line2 = now.ToString("HH:mm:ss        ");
                }

                lcd.SetCursorPosition(0, 0);
                lcd.Write(line1);
                lcd.SetCursorPosition(0, 1);
                lcd.Write(line2);

                Thread.Sleep(100);
            }
        }
Esempio n. 4
0
        public Program()
        {
            var lcdProvider = new GpioLcdTransferProvider(Pins.GPIO_PIN_D7, Pins.GPIO_PIN_D8, Pins.GPIO_PIN_D9, Pins.GPIO_PIN_D10, Pins.GPIO_PIN_D11, Pins.GPIO_PIN_D12);
            this.lcd = new Lcd(lcdProvider);
            this.lcdScreen = new LcdScreen(20, 4, this.lcd);
            this.lyncCache = new LyncCache();

            this.lcdScreenRefreshReset = new AutoResetEvent(false);

            var lcdScreenAutoRefreshThread = new Thread(this.RunLcdScreenAutoRefresh) { Priority = ThreadPriority.BelowNormal };
            lcdScreenAutoRefreshThread.Start();
        }
Esempio n. 5
0
        public PinLcd(Cpu.Pin rs, Cpu.Pin enable, Cpu.Pin d4, Cpu.Pin d5, Cpu.Pin d6, Cpu.Pin d7)
        {
            var lcdProvider = new GpioLcdTransferProvider(
                FEZCerbuino.Pin.Digital.D7,  // RS
                FEZCerbuino.Pin.Digital.D8, // enable
                FEZCerbuino.Pin.Digital.D9,  //d4
                FEZCerbuino.Pin.Digital.D10,  //d5
                FEZCerbuino.Pin.Digital.D11,  //d6
                FEZCerbuino.Pin.Digital.D12); // d7

            _display = new RawLcd(lcdProvider);
            Initialize();
        }
        public LcdDisplay()
        {
            var lcdProvider = new GpioLcdTransferProvider(Stm32F4Discovery.Pins.PD1, Stm32F4Discovery.Pins.PD2,
                                                          Stm32F4Discovery.Pins.PD9, Stm32F4Discovery.Pins.PD11,
                                                          Stm32F4Discovery.Pins.PD10, Stm32F4Discovery.Pins.PD8);

            _lcd = new Lcd(lcdProvider);

            _lcd.Begin(Columns, Rows);
            _lcd.Write("Wait...");

            //http://www.quinapalus.com/hd44780udg.html
            _lcd.CreateChar(0, new byte[] {0x8, 0x14, 0x8, 0x3, 0x4, 0x4, 0x3, 0x0});
            _lcd.Backlight = false;
        }
Esempio n. 7
0
        public static void Main()
        {
            // initialise the LCD display
            var ledPort = new OutputPort(Pins.ONBOARD_LED, false);
            var backlightPort = new OutputPort(Pins.GPIO_PIN_D3, false);
            var lcdProvider = new MicroLiquidCrystal.GpioLcdTransferProvider(
                Pins.GPIO_PIN_D8,  // RS
                Pins.GPIO_PIN_D9,  // ENABLE
                Pins.GPIO_PIN_D4,  // D4
                Pins.GPIO_PIN_D5,  // D5
                Pins.GPIO_PIN_D6,  // D6
                Pins.GPIO_PIN_D7); // D7
            var lcd = new Lcd(lcdProvider);
            lcd.Begin(16, 2);

            lcd.Clear();
            lcd.SetCursorPosition(2, 0);

            backlightPort.Write(true);

            lcd.Write("Ready ... ");

            const int interval = 10;
            const int reset = 1000;
            int duration = 0;
            while (true)
            {
                // set the cursor to column 0, line 1
                lcd.SetCursorPosition(0, 1);

                // print the number of seconds since reset:
                var time = Utility.GetMachineTime();
                lcd.Write(time.ToString());

                ledPort.Write(duration > reset/2);

                Thread.Sleep(interval);
                duration += interval;
                if (duration >= reset)
                    duration = 0;
            }
        }
Esempio n. 8
0
        public static void Main()
        {
            var lcdProvider = new GpioLcdTransferProvider(Stm32F4Discovery.Pins.PD1, Stm32F4Discovery.Pins.PD2,
                                                          Stm32F4Discovery.Pins.PD9, Stm32F4Discovery.Pins.PD11,
                                                          Stm32F4Discovery.Pins.PD10, Stm32F4Discovery.Pins.PD8);

            var lcd = new Lcd(lcdProvider);
            lcd.Begin(16, 2); //columns, rows

            //znaki specjalne
            //http://www.quinapalus.com/hd44780udg.html
            var customCharacters = new[]
                                       {
                                           new byte[] {0x00, 0x0a, 0x15, 0x11, 0x11, 0x0a, 0x04, 0x00}, //serce
                                           new byte[] {0x04, 0x02, 0x01, 0x1f, 0x01, 0x02, 0x04, 0x00} //strzalka
                                       };

            //ladowanie znakow specjalnych
            for (int i = 0; i < customCharacters.Length; i++)
                lcd.CreateChar(i, customCharacters[i]);

            lcd.Clear();
            lcd.Write("* Hello World! *");
            Thread.Sleep(3000);

//            lcd.Clear();
//            lcd.Encoding = Encoding.UTF8;
//            lcd.Write("ĄąĆćĘꣳŃńÓ󌜯ż");
//            Thread.Sleep(3000);

            lcd.Clear();
            lcd.WriteByte(0); //pierwszy znak specjalny
            Thread.Sleep(2000);
            lcd.WriteByte(1); //drugi znak specjalny
            Thread.Sleep(3000);

            //nastepna linia
            lcd.SetCursorPosition(0, 1);
            lcd.Write("#     Bye...   #");
        }
Esempio n. 9
0
        // Hold a static reference in case the GC kicks in and disposes it automatically, note that we only support one in this example!
        public static void Main()
        {
            // Subscribe to RemovableMedia events

              // Create a new storage device
              //ps = new PersistentStorage("SD");
              //ps.MountFileSystem();

              // Sleep forever

              /// Inicjalizacja ponów LED
              Program.ledPortOrange = new OutputPort(ledOrange, false);
              Program.ledPortGreen = new OutputPort(ledGreen, false);
              Program.ledPortBlue = new OutputPort(ledBlue, false);
              Program.ledPortRed = new OutputPort(ledRed, false);

              //anak a dc dziala jak talala
              //AnalogInput BatteryVoltage = new AnalogInput((Cpu.AnalogChannel)Cpu.AnalogChannel.ANALOG_0);

             //// (; ; )
             // {
             //  double voltage = BatteryVoltage.Read();

             //  var milliVolts = (voltage * (double)3300) / (double)0xFFF;
             //  var milliVolts = voltage * 130;
             // }

              string startLog = null;

              Thread.Sleep(1000);

              var lcdProvider = new GpioLcdTransferProvider(Stm32F4Discovery.Pins.PD1,
                                              Stm32F4Discovery.Pins.PD2,
                                              Stm32F4Discovery.Pins.PD9,
                                              Stm32F4Discovery.Pins.PD11,
                                              Stm32F4Discovery.Pins.PD10,
                                              Stm32F4Discovery.Pins.PD8);

              var lcd = new Lcd(lcdProvider);
              lcd.Begin(16, 2);

              //lcd.SetCursorPosition(0, 0);
              //lcd.Write("GO!");
              //Thread.Sleep(2000);

              bool sdCardIsInserted = false;

              VolumeInfo[] volumes;

              string[] availFs = VolumeInfo.GetFileSystems();
              if (availFs.Length == 0)
              {
            //lcd.SetCursorPosition(0, 0);
            Debug.Print("No FS found");
            return;
              }

              foreach (string fs in availFs)
              {
            // lcd.SetCursorPosition(0, 0);
            Debug.Print("Av FS: " + fs);
            startLog += (fs + "\n");
            //Thread.Sleep(1000);
              }

              do
              {
            //VolumeInfo.GetVolumes()[0].Refresh();

            volumes = VolumeInfo.GetVolumes();      // List of installed volumes

            foreach (VolumeInfo volume in volumes)  // Refreach all volumes - for hot swap SD inserting
            {
              volume.Refresh();
            }

            volumes = VolumeInfo.GetVolumes();      // List of installed volumes

            if (volumes.Length == 0)
            {
              //lcd.SetCursorPosition(0, 0);
              Debug.Print("No volumes found");
              blinkAllLed();
            }
            else
            {
              int totalSize = 0;
              foreach (VolumeInfo volume in volumes)
              {
            totalSize += (int)volume.TotalSize;
              }

              if (totalSize > 0)
              {
            sdCardIsInserted = true;
              }
              else
              {
            blinkAllLed();
              }
            }

              } while (!sdCardIsInserted);

              foreach (VolumeInfo volume in volumes)
              {
            //lcd.SetCursorPosition(0, 0);
            Debug.Print("Volume: " + volume.Name);
            startLog += (volume.Name + "\n");
            Thread.Sleep(1000);
              }

              // Losowa nazwa pliku
              string ext = Program.RandomString(5);

              /*
              string[] directories = Directory.GetDirectories(@"\SD");
              lcd.Write("directory count: " + directories.Length.ToString());
              startLog += ("directory count: " + directories.Length.ToString() + "\n");

              for (int i = 0; i < directories.Length; i++)
              {
            lcd.Write("directory: " + directories[i]);
            startLog += ("directory count: " + directories[i] + "\n");
              }
              */
              string[] files = Directory.GetFiles(@"\SD");
              startLog += ("file count: " + files.Length.ToString() + "\n");

              for (int i = 0; i < files.Length; i++)
              {
            startLog += ("filename: " + files[i] + "\n");
            //ledPortGreen.Write(true);
            //Thread.Sleep(500);
            //ledPortGreen.Write(false);
            //Thread.Sleep(500);
            Debug.Print("filename: " + files[i]);
              }

              string rtDir = VolumeInfo.GetVolumes()[0].RootDirectory;
              string path = rtDir + @"\" + (files.Length + 1) + "" + "dane" + ext + ".ns";
              /*
              FileStream fs0 = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);
              byte[] buffer = UTF8Encoding.UTF8.GetBytes("Start Systemu\n" + path.ToString() + "\n" + startLog.ToString() + "\n");

              if (fs0.CanRead) {
            blinkLed(ledGreen); blinkLed(ledGreen);
              } else {
            blinkLed(ledGreen);
              }

              if (fs0.CanSeek) {
            blinkLed(ledBlue); blinkLed(ledBlue);
              } else {
            blinkLed(ledBlue);
              }

              if (fs0.CanWrite) {
            blinkLed(ledRed); blinkLed(ledRed);
              } else {
            blinkLed(ledRed);
              }

              fs0.Write(buffer, 0, buffer.Length);
              fs0.Close();
              Thread.Sleep(2000);
              */
              //startLog = null; // Odśnieżanie

              for (; ; )
              {

            string tx = Program.RandomString(5);

            lcd.SetCursorPosition(0, 0);
            lcd.Write((files.Length+1) + "_ZAPIS " + tx);

            FileStream fs1;

            if (File.Exists(path)) {
              fs1 = new FileStream(path, FileMode.Append);
              Debug.Print("Exist: " + path);
              blinkLed(ledGreen); blinkLed(ledGreen);

            } else {
              fs1 = new FileStream(path, FileMode.Create);
              Debug.Print("Not Exist: " + path);
              blinkLed(ledGreen);
            }

            byte[] bff = UTF8Encoding.UTF8.GetBytes(tx + "\n");
            /*
            if (fs1.CanRead)
            {
              blinkLed(ledGreen); blinkLed(ledGreen);
            }
            else
            {
              blinkLed(ledGreen);
            }

            if (fs1.CanSeek)
            {
              blinkLed(ledBlue); blinkLed(ledBlue);
            }
            else
            {
              blinkLed(ledBlue);
            }

            if (fs1.CanWrite)
            {
              blinkLed(ledRed); blinkLed(ledRed);
            }
            else
            {
              blinkLed(ledRed);
            }
            */
            if (startLog.Length > 0)
            {
              byte[] stbff = UTF8Encoding.UTF8.GetBytes(startLog + "\n");
              fs1.Write(stbff, 0, stbff.Length);
              startLog = "";
              stbff = null;
              blinkLed(ledRed);
            }

            fs1.Write(bff, 0, bff.Length);
            fs1.Close();

            //FileStream fs2 = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, 512);
            // sr = new StreamReader(fs2);
            //string b = sr.ReadToEnd();
            //fs2.Close();
            //Thread.Sleep(50);

            //FileStream fs3 = new FileStream(path, FileMode.Append, FileAccess.Write, FileShare.None);
            //[] buffer2 = UTF8Encoding.UTF8.GetBytes("dwa" + "\n");
            //fs3.Write(buffer2, 0, buffer.Length);
            //fs3.Close();

             Thread.Sleep(500);
              }
        }
Esempio n. 10
0
        public static void Main()
        {
            #region Netduino Pin Setup
            //InputPort mainButton = new InputPort(Pins.ONBOARD_BTN, false, Port.ResistorMode.Disabled);
            OutputPort onboardLED = new OutputPort(Pins.ONBOARD_LED, false);
            OutputPort greenLed = new OutputPort(Pins.GPIO_PIN_D4, false);
            OutputPort yellowLed = new OutputPort(Pins.GPIO_PIN_D3, false);
            OutputPort redLed = new OutputPort(Pins.GPIO_PIN_D2, false);
            DistanceSensor sensor = new DistanceSensor(Pins.GPIO_PIN_D0, Pins.GPIO_PIN_D1);
            //Setup Display
            var lcdProvider = new MicroLiquidCrystal.GpioLcdTransferProvider(Pins.GPIO_PIN_D7, Pins.GPIO_PIN_D8, Pins.GPIO_PIN_D9, Pins.GPIO_PIN_D10, Pins.GPIO_PIN_D11, Pins.GPIO_PIN_D12);
            //var lcd = new Lcd(lcdProvider);
            Display.DisplaySetup(lcdProvider);
            #endregion

            //Program Start blink
            BlinkLED(onboardLED, 100, 100, 3);
            bool buttonState = false;

            //set time
            //var result = Ntp.UpdateTimeFromNtpServer("nist.time.nosc.us", -5);  // Central Daylight Time
            var result = Ntp.UpdateTimeFromNtpServer("time.nist.gov", -5);  // Central Daylight Time
            Debug.Print(result ? "Time successfully updated" : "Time not updated");

            //while (true)
            //{
                Display.DisplayMessage("Server Start", "Time: " + System.DateTime.Now.Hour.ToString() + ":" + System.DateTime.Now.Minute.ToString() + ":" + System.DateTime.Now.Second.ToString());
                //Thread.Sleep(1000);
            //}

            //Kick off the webserver on it's own thread.
            ThreadStart delegateWebMain = new ThreadStart(WebServerThreadMain);
            Thread threadWorker = new Thread(delegateWebMain);
            threadWorker.Start();

            //while (true)
            //{
            //    buttonState = mainButton.Read();
            //    BlinkLED(redLed, 30, 30, 3);
            //}

            //Clear log file
            File.Delete(@"SD\ProximityLog.csv");
            logEvent("Start");

            double distanceInInches = 0;
            //int tempo = 25;
            while (true)
            {
                // Ping and get inches
                distanceInInches = sensor.Ping();
                // Do something fancy
                if (distanceInInches > 0)
                {
                    if (distanceInInches < 5)
                    {
                        BlinkLED(redLed, 30, 30, 3);
                        logEvent("Red");
                    }
                    if (distanceInInches >= 5 && distanceInInches < 15)
                    {
                        BlinkLED(yellowLed, 50, 50, 2);
                        logEvent("Yellow");
                    }
                    if (distanceInInches >= 15 && distanceInInches < 25)
                    {
                        BlinkLED(greenLed, 75, 0, 1);
                        logEvent("Green");
                    }
                    Thread.Sleep(1000);
                }
            }
        }
Esempio n. 11
0
        private static Lcd ConfigureLiquidCrystalDisplay()
        {
            var transferProvider = new GpioLcdTransferProvider(
                    (Cpu.Pin)FEZ_Pin.Digital.Di21,
                    (Cpu.Pin)FEZ_Pin.Digital.Di23,
                    (Cpu.Pin)FEZ_Pin.Digital.Di47,
                    (Cpu.Pin)FEZ_Pin.Digital.Di46,
                    (Cpu.Pin)FEZ_Pin.Digital.Di49,
                    (Cpu.Pin)FEZ_Pin.Digital.Di48
                    );

            var display = new Lcd(transferProvider);
            display.Begin(16, 2);
            display.BlinkCursor = false;
            display.ShowCursor = false;

            return display;
        }
Esempio n. 12
0
 public static void DisplaySetup(GpioLcdTransferProvider lcdProvider)
 {
     _lcd = new Lcd(lcdProvider);
 }
Esempio n. 13
0
        private static void InitializeLCDDisplay()
        {
            lcdProvider = new GpioLcdTransferProvider(Pins.GPIO_PIN_D2, Pins.GPIO_PIN_D3, Pins.GPIO_PIN_D4, Pins.GPIO_PIN_D5, Pins.GPIO_PIN_D6, Pins.GPIO_PIN_D7);
            lcd = new Lcd(lcdProvider);
            lcd.Begin(16, 2);
            lcdInitialized = true;

            WriteLCD("PHB Detector", "...now loading");
            Thread.Sleep(5000);//show loading dialog for at least 5 sec..
        }