public LCDWrapper(GPIOPins rs, GPIOPins enable, GPIOPins d4, GPIOPins d5, GPIOPins d6, GPIOPins d7, int columns = 40, int rows = 2, DisplayMode displayMode = DisplayMode.LCD_ONLY)
 {
     DisplayMode = displayMode;
     Columns = columns;
     Rows = rows;
     if (DisplayMode != DisplayMode.CONSOLE_ONLY) {
         transferProvider = new RaspPiGPIOMemLcdTransferProvider(
             fourBitMode: true,
             rs: rs,
             rw: GPIOPins.GPIO_NONE,
             enable: enable,
             d0: GPIOPins.GPIO_NONE,
             d1: GPIOPins.GPIO_NONE,
             d2: GPIOPins.GPIO_NONE,
             d3: GPIOPins.GPIO_NONE,
             d4: d4,
             d5: d5,
             d6: d6,
             d7: d7
         );
         lcd = new Lcd(transferProvider);
         lcd.Begin(Convert.ToByte(columns), Convert.ToByte(rows));
         lcd.Backlight = true;
         lcd.BlinkCursor = false;
         lcd.ShowCursor = false;
         lcd.Visible = true;
     }
     if(DisplayMode != DisplayMode.LCD_ONLY){
         Console.Clear();
         Console.ForegroundColor = ConsoleColor.White;
         Console.BackgroundColor = ConsoleColor.Black;
         Console.CursorVisible = false;
     }
 }
Exemple #2
0
        static void Main(string[] args)
        {
            ArgumentParser pp = new ArgumentParser(args);
            pp.AddExpanded("-l", "--light");
            pp.AddExpanded("-nl", "--no-light");
            pp.Parse();

            var lcdProvider = new RaspPiGPIOMemLcdTransferProvider(GPIOPins.GPIO_07, GPIOPins.GPIO_08, GPIOPins.GPIO_25, GPIOPins.GPIO_24, GPIOPins.GPIO_23, GPIOPins.GPIO_18);
            var lcd = new Lcd(lcdProvider);

            GPIOMem backlit = new GPIOMem(GPIOPins.GPIO_15, GPIODirection.Out);
            //backlit.Write(false);

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

            if (pp.SwitchExists("--light"))
            {
                backlit.Write(true);
            }

            if (pp.SwitchExists("--no-light"))
            {
                backlit.Write(false);
            }

            string text = String.Empty;
            try
            {
                var isKey = System.Console.KeyAvailable;
                text = Console.ReadLine();
            }
            catch (InvalidOperationException)
            {
                // when we're in piped output, InvalidOperationException is thrown for KeyAvaliable
                // and we're using it here to check... dirty, dirty hack!
                text = Console.In.ReadToEnd();
            }

            //Console.WriteLine(text);

            text = text.Replace("\r\n", "\n");
            if (text.Length > 32) text = text.Substring(0, 32);
            if (text.Length > 16) text = text.Insert(16, "\n");

            if (text.IndexOf('\n') > -1)
            {
                lcd.Write(text.Substring(0, text.IndexOf('\n')));
                lcd.SetCursorPosition(0, 1);
                lcd.Write(text.Substring(text.IndexOf('\n') +1));
            }
            else
                lcd.Write(text);
        }
        private static void ThreadSmartCard()
        {
            RaspPiGPIOMemLcdTransferProvider lcdProvider = new RaspPiGPIOMemLcdTransferProvider(
            GPIOPins.V2_GPIO_07,
            GPIOPins.V2_GPIO_08,
            GPIOPins.V2_GPIO_25,
            GPIOPins.V2_GPIO_24,
            GPIOPins.V2_GPIO_23,
            GPIOPins.V2_GPIO_18);
            Lcd lcd = new Lcd(lcdProvider);
            lcd.Begin(16, 2);
            lcd.Clear();
            lcd.SetCursorPosition(0, 0);
            lcd.Write("No NFC Card!");

            var gpio22 = TinyGPIO.Export(22);
            gpio22.Direction = (GPIODirection)GPIODirection.Out;

            List<string> deviceNameList = new List<string>();
            NFCContext nfcContext = new NFCContext();
            NFCDevice nfcDevice = nfcContext.OpenDevice(null);
            deviceNameList = nfcContext.ListDeviceNames();
            Console.WriteLine("Device Count: " + deviceNameList.Count());
            foreach (string deviceName in deviceNameList)
            {
                Console.WriteLine("Device Name: " + deviceName);
            }
            int rtn = nfcDevice.initDevice();
            if (rtn < 0)
            {
                Console.WriteLine("Context init failed");
            }

            nfc_target nfcTarget = new nfc_target();
            List<nfc_modulation> nfc_modulationList = new List<nfc_modulation>();
            nfc_modulation nfcModulation = new nfc_modulation();
            nfcModulation.nbr = nfc_baud_rate.NBR_106;
            nfcModulation.nmt = nfc_modulation_type.NMT_ISO14443A;
            nfc_modulationList.Add(nfcModulation);

            string currentSignalRStr = null;
            string currentConsoleStr = null;
            string currentlcdStr = null;
            string signalRStr;
            string consoleStr;
            string lcdStr;
            string state = "---";

            for (; ; )
            {
                gpio22.Value = 0;
                Thread.Sleep(100);
                rtn = nfcDevice.Pool(nfc_modulationList, 1, 2, out nfcTarget);

                if (rtn < 0)
                {
                    consoleStr = "NFC-Poll Targert Not Found!";
                    signalRStr = "---";
                    lcdStr = "No NFC Card!";
                    gpio22.Value = 0;
                }
                else
                {
                    signalRStr = string.Join(
                        separator: "",
                        values: nfcTarget.nti.abtUid.Take((int)nfcTarget.nti.szUidLen).Select(b => b.ToString("X2").ToLower())
                     );
                    signalRStr = "0x" + signalRStr;
                    consoleStr = string.Format("NFC-Poll Target Found: uid is [{0}]", signalRStr);
                    lcdStr = "NFC Detected!";
                }
                if (signalRStr != state)
                {
                    if (signalRStr != currentSignalRStr)
                    {
                        NFC.Instance.UpdateNFCStatus(signalRStr);
                        currentSignalRStr = signalRStr;
                        gpio22.Value = 1;
                        lcd.Begin(16, 2);
                        lcd.Clear();
                        lcd.SetCursorPosition(0, 0);
                        lcd.Write("NFC Detected!");
                        lcd.SetCursorPosition(0, 1);
                        lcd.Write(signalRStr);
                        currentlcdStr = lcdStr;
                        Thread.Sleep(100);
                    }
                    else
                    {
                        gpio22.Value = 0;
                    }
                }
                else
                {
                    if (lcdStr != currentlcdStr)
                    {
                        gpio22.Value = 0;
                        NFC.Instance.UpdateNFCStatus(signalRStr);
                        currentSignalRStr = signalRStr;
                        lcd.Begin(16, 2);
                        lcd.Clear();
                        lcd.SetCursorPosition(0, 0);
                        lcd.Write("No NFC Card!");
                        currentlcdStr = lcdStr;
                    }
                }
                if (consoleStr != currentConsoleStr)
                {
                    Console.WriteLine(consoleStr);
                    currentConsoleStr = consoleStr;
                }
            }
        }