예제 #1
0
        public static void Main()
        {
            var application = new Application();

            application.RenderException += (_, args) => Console.WriteLine(args.Exception);
            using (var timerFactory = new TimerFactory())
                using (var gpioConnectionDriverFactory = new GpioConnectionDriverFactory(true))
                {
                    var(textDisplayDevice, lcd) = Create(gpioConnectionDriverFactory);
                    using (lcd)
                    {
                        // var textViewNavigator = application.StartRendering(new TextViewRendererFactory(textDisplayDevice, timerFactory));
                        var menuButton = new PullDownButtonDevice(ConnectorPin.P1Pin13);
                        var playButton = new PullDownButtonDevice(ConnectorPin.P1Pin15);
                        var nextButton = new PullDownButtonDevice(ConnectorPin.P1Pin16);
                        var prevButton = new PullDownButtonDevice(ConnectorPin.P1Pin18);
                        using (var gpioConnection = new GpioConnection(gpioConnectionDriverFactory, menuButton.PinConfiguration, playButton.PinConfiguration, nextButton.PinConfiguration, prevButton.PinConfiguration))
                        {
                            using (var rfidTransceiver = new Mfrc522Connection("/dev/spidev0.0", ConnectorPin.P1Pin22, gpioConnectionDriverFactory, null, new RfidConnectionLogger()))
                                using (var rotaryEncoder = new Ky040Device(ConnectorPin.P1Pin36, ConnectorPin.P1Pin38, ConnectorPin.P1Pin40, gpioConnectionDriverFactory, new Ky040ConsoleReporter()))
                                {
                                    menuButton.Pressed          += (sender, eventArgs) => Console.WriteLine("Menu");
                                    playButton.Pressed          += (sender, eventArgs) => Console.WriteLine("Play");
                                    nextButton.Pressed          += (sender, eventArgs) => Console.WriteLine("Next");
                                    prevButton.Pressed          += (sender, eventArgs) => Console.WriteLine("Prev");
                                    rotaryEncoder.Pressed       += (sender, args) => Console.WriteLine("Rotary");
                                    rotaryEncoder.Rotated       += RotaryEncoder_Rotated;
                                    rfidTransceiver.TagDetected += RfidTransceiver_TagDetected;
                                    // textViewNavigator.NavigateToAsync(new MainTextView(rfidTransceiver, rotaryEncoder, menuButton,
                                    //    playButton, nextButton, prevButton));
                                    // application.Run();
                                    var i     = 0;
                                    var token = new CancellationTokenSource();
                                    Console.CancelKeyPress += (sender, args) => token.Cancel();
                                    while (!token.IsCancellationRequested)
                                    {
                                        textDisplayDevice.WriteLine(AlignedString.Format("Hello: {0:9, <>}", i++));
                                        Thread.Sleep(100);
                                        textDisplayDevice.WriteLine("                ");
                                        Thread.Sleep(1000);
                                    }
                                }
                        }
                    }
                }

            Console.WriteLine("Ending...");
        }
예제 #2
0
 public MainTextView(Mfrc522Connection rfidTransceiver, Ky040Device rotaryEncoder, PullDownButtonDevice menuButton, PullDownButtonDevice playButton, PullDownButtonDevice nextButton, PullDownButtonDevice prevButton)
 {
     this.rfidTransceiver              = rfidTransceiver;
     this.rotaryEncoder                = rotaryEncoder;
     this.menuButton                   = menuButton;
     this.playButton                   = playButton;
     this.nextButton                   = nextButton;
     this.prevButton                   = prevButton;
     this.menuButton.Pressed          += (_, e) => this.Pressed('M');
     this.playButton.Pressed          += (_, e) => this.Pressed('P');
     this.nextButton.Pressed          += (_, e) => this.Pressed('N');
     this.prevButton.Pressed          += (_, e) => this.Pressed('B');
     this.rotaryEncoder.Pressed       += (_, e) => this.Pressed('R');
     this.rotaryEncoder.Rotated       += this.OnRotaryEncoderRotated;
     this.rfidTransceiver.TagDetected += this.OnRfidTransceiverTagDetected;
     this.thread = new ThreadFactory(Board.Current, true).Create();
 }
예제 #3
0
        /// <summary>
        /// Creates the specified gpio connection driver.
        /// </summary>
        /// <param name="gpioConnectionDriverFactory">The gpio connection driver factory.</param>
        /// <returns>
        /// The input controls.
        /// </returns>
        public static InputControls Create(IGpioConnectionDriverFactory gpioConnectionDriverFactory)
        {
            var lircConnection  = new LircDevice();
            var playPauseButton = new PullDownButtonDevice(ConnectorPin.P1Pin15);
            var nextButton      = new PullDownButtonDevice(ConnectorPin.P1Pin18);
            var previousButton  = new PullDownButtonDevice(ConnectorPin.P1Pin16);
            var menuButton      = new PullDownButtonDevice(ConnectorPin.P1Pin13);
            var rfidTransceiver = new Mfrc522Connection("/dev/spidev0.0", ConnectorPin.P1Pin22, gpioConnectionDriverFactory);
            var ky040Connection = new Ky040Device(
                ConnectorPin.P1Pin36,
                ConnectorPin.P1Pin38,
                ConnectorPin.P1Pin40,
                gpioConnectionDriverFactory,
                null);
            var buttonsGpioConnection = new GpioConnection(
                gpioConnectionDriverFactory,
                new[]
            {
                playPauseButton.PinConfiguration,
                nextButton.PinConfiguration,
                previousButton.PinConfiguration,
                menuButton.PinConfiguration,
            }.Where(x => x != null));

            return(new InputControls(
                       playPauseButton,
                       nextButton,
                       previousButton,
                       menuButton,
                       rfidTransceiver,
                       lircConnection,
                       ky040Connection,
                       buttonsGpioConnection));

            /* new Rfid(),
             * new Lirc(),
             * new Rotary(),
             * new Dispo());*/
        }