Пример #1
0
        public static void Main()
        {
            Applet = new LcdApplet("G15 Process Manager", LcdAppletCapabilities.Monochrome);

            Applet.Configure += new EventHandler(Applet_Configure);

            Applet.Connect();

            Device = (LcdDeviceMonochrome)Applet.OpenDeviceByType(LcdDeviceType.Monochrome);

            Device.SoftButtonsChanged += new EventHandler<LcdSoftButtonsEventArgs>(Device_SoftButtonsChanged);

            CurrentIndex = 0;
            CreateGDIPages();

            do
            {
                Device.DoUpdateAndDraw();
                Thread.Sleep(3000);
            }
            while (!_mustExit);

            Applet.Disconnect();

               //Console.ReadKey();
        }
Пример #2
0
        internal static void Main()
        {
            LcdApplet applet = new LcdApplet("GammaJul LgLcd GDI+ Sample", LcdAppletCapabilities.Both);

            // Register to events to know when a device arrives, then connects the applet to the LCD Manager
            applet.Configure        += Applet_Configure;
            applet.DeviceArrival    += Applet_DeviceArrival;
            applet.DeviceRemoval    += Applet_DeviceRemoval;
            applet.IsEnabledChanged += Applet_IsEnabledChanged;
            applet.Connect();

            // We are waiting for the handler thread to warn us for device arrival
            LcdDeviceMonochrome monoDevice = null;

            _waitAre.WaitOne();

            do
            {
                // A monochrome device was connected: creates a monochrome device or reopens an old one
                if (_monoArrived)
                {
                    if (monoDevice == null)
                    {
                        monoDevice = (LcdDeviceMonochrome)applet.OpenDeviceByType(LcdDeviceType.Monochrome);
                        monoDevice.SoftButtonsChanged += MonoDevice_SoftButtonsChanged;
                        CreateMonochromeGdiPages(monoDevice);
                    }
                    else
                    {
                        monoDevice.ReOpen();
                    }
                    _monoArrived = false;
                }

                if (_qvgaArrived)
                {
                    _qvgaArrived = false;
                }

                // We are calling DoUpdateAndDraw in this loop.
                // Note that updating and drawing only happens if the objects in a LcdGdiPage are modified.
                // Even if you call this method very quickly, update and draw will only occur at the frame
                // rate specified by LcdPage.DesiredFrameRate, which is 30 by default.
                if (applet.IsEnabled && monoDevice != null && !monoDevice.IsDisposed)
                {
                    monoDevice.DoUpdateAndDraw();
                }

                Thread.Sleep(5);
            }while (!_mustExit);
        }
        internal static void Main(string[] args)
        {
            Application.EnableVisualStyles();

            devicesList.Lock = new object();
            entriesList.Lock = new object();

            LcdApplet applet = new LcdApplet("Yubico Authenticator", LcdAppletCapabilities.Monochrome);

            // Register to events to know when a device arrives, then connects the applet to the LCD Manager
            applet.Configure        += AppletConfigure;
            applet.DeviceArrival    += AppletDeviceArrival;
            applet.DeviceRemoval    += AppletDeviceRemoval;
            applet.IsEnabledChanged += AppletIsEnableChanged;
            applet.Connect();

            LcdDeviceMonochrome device = null;
            int tick = 0;

            while (true)
            {
                lock (deviceArrivedLock)
                {
                    if (deviceArrived)
                    {
                        if (device == null)
                        {
                            device = (LcdDeviceMonochrome)applet.OpenDeviceByType(LcdDeviceType.Monochrome);
                            device.SoftButtonsChanged += DeviceSoftButtonsChanged;
                            CreatePages(device);
                            device.SetAsForegroundApplet = true;
                        }
                        else
                        {
                            device.ReOpen();
                        }
                    }

                    deviceArrived = false;
                }

                if (applet.IsEnabled && device != null && !device.IsDisposed)
                {
                    device.DoUpdateAndDraw();
                }

                TickTimers(33, ref tick);
                Thread.Sleep(33);
            }
        }
Пример #4
0
        static void Main(string[] args)
        {
            LcdApplet applet = new LcdApplet("My Test App", LcdAppletCapabilities.Both);

            applet.Configure        += Applet_Configure;
            applet.DeviceArrival    += Applet_DeviceArrival;
            applet.DeviceRemoval    += Applet_DeviceRemoval;
            applet.IsEnabledChanged += Applet_IsEnabledChanged;
            applet.Connect();

            LcdDeviceMonochrome monoDevice = null;

            _waitAre.WaitOne();

            do
            {
                if (_monoArrived)
                {
                    if (monoDevice == null)
                    {
                        monoDevice = (LcdDeviceMonochrome)applet.OpenDeviceByType(LcdDeviceType.Monochrome);
                        monoDevice.SoftButtonsChanged += MonoDevice_SoftButtonsChanged;
                        CreateMonochromeGdiPages(monoDevice);
                    }
                    else
                    {
                        monoDevice.ReOpen();
                    }
                    _monoArrived = false;
                }
                if (_qvgaArrived)
                {
                    _qvgaArrived = false;
                }
                if (applet.IsEnabled && monoDevice != null && !monoDevice.IsDisposed)
                {
                    monoDevice.DoUpdateAndDraw();
                }

                Thread.Sleep(5);
            }while (!_mustExit);
        }
        static void Main()
        {
            Program program = new Program();

            program.StartTrayIcon();

            LcdApplet app = new LcdApplet("Test Logitech LCD Keyboard", LcdAppletCapabilities.Both);

            //set event handling
            app.Configure        += AppletConfigure;
            app.DeviceArrival    += program.DeviceArrival;
            app.DeviceRemoval    += program.DeviceRemoval;
            app.IsEnabledChanged += program.AppletIsEnabledChanged;
            app.Connect();

            // We are waiting for the handler thread to warn us for device arrival
            LcdDeviceMonochrome monoDevice = null;
            LcdDeviceQvga       qvgaDevice = null;

            program.waitAutoResetEvent.WaitOne();

            //enter main loop
            do
            {
                //Handle device arrival
                if (program.arrived && program.deviceType == LcdDeviceType.Monochrome)
                {
                    if (monoDevice == null)
                    {
                        monoDevice = (LcdDeviceMonochrome)app.OpenDeviceByType(program.deviceType);
                        monoDevice.SoftButtonsChanged   += program.MonoDeviceSoftButtonsChanged;
                        program.lcdGraphics              = new LcdGraphics(monoDevice);
                        monoDevice.SetAsForegroundApplet = true;
                    }
                    else
                    {
                        monoDevice.ReOpen();
                    }

                    //reset the arrival flag
                    program.arrived = false;
                }
                if (program.arrived && program.deviceType == LcdDeviceType.Qvga)
                {
                    if (qvgaDevice == null)
                    {
                        qvgaDevice = (LcdDeviceQvga)app.OpenDeviceByType(program.deviceType);
                        qvgaDevice.SoftButtonsChanged   += program.MonoDeviceSoftButtonsChanged;
                        program.lcdGraphics              = new LcdGraphics(qvgaDevice);
                        qvgaDevice.SetAsForegroundApplet = true;
                    }
                    else
                    {
                        qvgaDevice.ReOpen();
                    }

                    //reset the arrival flag
                    program.arrived = false;
                }

                //if there is no lcd keyboard, sleep for a while and look again
                if (monoDevice == null && qvgaDevice == null)
                {
                    Thread.Sleep(20000);
                    continue;
                }

                //Disposed, skip draw, next check loop exits
                if (monoDevice != null && monoDevice.IsDisposed ||
                    qvgaDevice != null && qvgaDevice.IsDisposed)
                {
                    continue;
                }

                //update and draw
                if (app.IsEnabled)
                {
                    if (program.button1Pressed)
                    {
                        //set warning page in object and redraw
                        program.lcdGraphics.SetWarning();
                        monoDevice.DoUpdateAndDraw();

                        //wait and reset
                        Thread.Sleep(2000);
                        program.lcdGraphics.SetMain();

                        //reset flag
                        program.button1Pressed = false;
                    }

                    monoDevice.DoUpdateAndDraw();

                    //let the user enjoy the magical LCD graphics
                    Thread.Sleep(30);
                }
            }while (program.stillAlive);
        }
Пример #6
0
        internal static void Main()
        {
            SoundPlayer = new SoundPlayer();
            // Create a new applet for the monochrome LCD Screen and set it to auto-start.
            LcdApplet applet = new LcdApplet("League Of Legends Timer G15", LcdAppletCapabilities.Monochrome, true);

            // Register to events to know when a device arrives, then connects the applet to the LCD Manager
            applet.DeviceArrival += Applet_DeviceArrival;
            applet.DeviceRemoval += Applet_DeviceRemoval;
            applet.Connect();

            // We are waiting for the handler thread to warn us for device arrival
            _waitAre.WaitOne();
            do
            {

                // A monochrome device was connected: creates a monochrome device or reopens an old one
                if (_monoArrived)
                {
                    if (monoDevice == null)
                    {
                        monoDevice = (LcdDeviceMonochrome)applet.OpenDeviceByType(LcdDeviceType.Monochrome);
                        monoDevice.SoftButtonsChanged += MonoDevice_SoftButtonsChanged;
                        CreateMonochromeGdiPages(monoDevice);
                    }
                    else
                        monoDevice.ReOpen();
                    _monoArrived = false;
                }

                // We are calling DoUpdateAndDraw in this loop.
                // Note that updating and drawing only happens if the objects in a LcdGdiPage are modified.
                // Even if you call this method very quickly, update and draw will only occur at the frame
                // rate specified by LcdPage.DesiredFrameRate, which is 30 by default.
                if (applet.IsEnabled && monoDevice != null && !monoDevice.IsDisposed)
                    monoDevice.DoUpdateAndDraw();

                Thread.Sleep(5);
            }
            while (!_mustExit);
        }
Пример #7
0
        internal static void Main(string[] args)
        {
            bool showTitles = true;

            if (args != null && args.Length != 0)
            {
                if (args[0] == "notitles")
                {
                    showTitles = false;
                }
            }

            try
            {
                SpotifyStatusApplet ssa = new SpotifyStatusApplet(showTitles);
                ssa.setupSpotify();

                ssa.setupTrayIcon();

                LcdApplet applet = new LcdApplet("Spotify Status Applet", LcdAppletCapabilities.Both);

                // Register to events to know when a device arrives, then connects the applet to the LCD Manager
                applet.Configure        += appletConfigure;
                applet.DeviceArrival    += ssa.appletDeviceArrival;
                applet.DeviceRemoval    += ssa.appletDeviceRemoval;
                applet.IsEnabledChanged += ssa.appletIsEnabledChanged;
                applet.Connect();

                // We are waiting for the handler thread to warn us for device arrival
                LcdDeviceMonochrome monoDevice = null;
                ssa.m_waitAutoResetEvent.WaitOne();

                do
                {
                    // A monochrome device is connected: creates a monochrome device or reopens an old one
                    if (true == ssa.m_monoArrived)
                    {
                        if (null == monoDevice)
                        {
                            monoDevice = (LcdDeviceMonochrome)applet.OpenDeviceByType(LcdDeviceType.Monochrome);
                            monoDevice.SoftButtonsChanged += ssa.monoDeviceSoftButtonsChanged;
                            ssa.m_lcdGraphics              = new LcdGraphics();
                            ssa.m_lcdGraphics.createMonochromeGdiPages(monoDevice);
                            monoDevice.SetAsForegroundApplet = true;
                        }
                        else
                        {
                            monoDevice.ReOpen();
                        }

                        // serviced the last device connection so reset the arrival flag
                        ssa.m_monoArrived = false;
                    }

                    if (ssa.m_qvgaArrived)
                    {
                        // TODO add the implementation as a future project
                        ssa.m_qvgaArrived = false;
                    }

                    // DoUpdateAndDraw only occurs at the framerate specified by LcdPage.DesiredFrameRate, which is 30 by default.
                    if (true == applet.IsEnabled &&
                        null != monoDevice &&
                        false == monoDevice.IsDisposed)
                    {
                        ssa.m_lcdGraphics.setMediaPlayerDetails(ssa.getCurrentSpotifyDetails());
                        ssa.m_lcdGraphics.setShowTitles(ssa.m_showTitles);
                        monoDevice.DoUpdateAndDraw();
                    }

                    Thread.Sleep(33);
                }while (true == ssa.m_keepRunning);
            }
            catch (Exception e)
            {
                Console.WriteLine("Caught exception, application exited " + e.ToString());
            }
        }
Пример #8
0
        internal static int Main(string[] args)
        {
            bool showTitles = true;

            if (args != null && args.Length != 0)
            {
                if (args[0] == "notitles")
                {
                    showTitles = false;
                }
            }

            try
            {
                SpotifyStatusApplet ssa = new SpotifyStatusApplet(showTitles);
                a_ConnectionStatus = ssa.SetupSpotify();
                if (a_ConnectionStatus != 0)
                {
                    Trace.TraceError("Critical Error: Spotify couldn't start.\n\tTerminating SpotifyStatusApplet.\t\nReturn Value of SetupSpotify(): " + a_ConnectionStatus);
                    //Applet cannot function if Spotify or SpotifyWebHelper is unable to open. Return from Main thread with error 1.
                    return(1);
                }

                StatusResponse spotify_Status = ssa.s_spotify.GetStatus();
                //The applet crashes when having to wait for the Spotify song information (When the app is completely exited).
                //This waits until it loads in and has a 2 second timeout.
                for (int i = 0; (spotify_Status.Track == null); i++)
                {
                    Thread.Sleep(1);
                    if (i > 2000)
                    {
                        break;
                    }
                    if (i > 1998)
                    {
                        a_SongLoadTimeoutExpired = true;
                    }
                }
                if (a_SongLoadTimeoutExpired == true)
                {
                    Trace.TraceWarning("Couldn't load track information. \n\tTerminating SpotifyStatusApplet.");
                    return(1);
                }

                ssa.setupTrayIcon();

                LcdApplet applet = new LcdApplet("Spotify Status Applet", LcdAppletCapabilities.Both);

                // Register to events to know when a device arrives, then connects the applet to the LCD Manager
                applet.Configure        += appletConfigure;
                applet.DeviceArrival    += ssa.appletDeviceArrival;
                applet.DeviceRemoval    += ssa.appletDeviceRemoval;
                applet.IsEnabledChanged += ssa.appletIsEnabledChanged;
                applet.Connect();

                // We are waiting for the handler thread to warn us for device arrival
                LcdDeviceMonochrome monoDevice = null;
                ssa.m_waitAutoResetEvent.WaitOne();

                do
                {
                    // A monochrome device is connected: creates a monochrome device or reopens an old one
                    if (true == ssa.m_monoArrived)
                    {
                        if (null == monoDevice)
                        {
                            monoDevice = (LcdDeviceMonochrome)applet.OpenDeviceByType(LcdDeviceType.Monochrome);
                            monoDevice.SoftButtonsChanged += ssa.monoDeviceSoftButtonsChanged;
                            ssa.m_lcdGraphics              = new LcdGraphics();
                            ssa.m_lcdGraphics.createMonochromeGdiPages(monoDevice);
                            monoDevice.SetAsForegroundApplet = true;
                        }
                        else
                        {
                            monoDevice.ReOpen();
                        }

                        // serviced the last device connection so reset the arrival flag
                        ssa.m_monoArrived = false;
                    }

                    if (ssa.m_qvgaArrived)
                    {
                        // TODO add the implementation as a future project
                        ssa.m_qvgaArrived = false;
                    }

                    // DoUpdateAndDraw only occurs at the framerate specified by LcdPage.DesiredFrameRate, which is 30 by default.
                    if (true == applet.IsEnabled &&
                        null != monoDevice &&
                        false == monoDevice.IsDisposed)
                    {
                        ssa.m_lcdGraphics.setMediaPlayerDetails(ssa.getCurrentSpotifyDetails());
                        ssa.m_lcdGraphics.setShowTitles(ssa.m_showTitles);
                        monoDevice.DoUpdateAndDraw();
                    }

                    Thread.Sleep(33);
                }while (true == ssa.m_keepRunning);
            }
            catch (Exception e)
            {
                Trace.TraceError("Caught exception, application exited " + e.ToString());
            }
            return(0);
        }
        /// <summary>
        /// Event handler for button press on a device.
        /// </summary>
        /// <param name="sender">Device on which button was pressed</param>
        /// <param name="e">Button event arguments</param>
        private static void DeviceSoftButtonsChanged(object sender, LcdSoftButtonsEventArgs e)
        {
            LcdDeviceMonochrome device = (LcdDeviceMonochrome)sender;

            // First button
            if ((e.SoftButtons & LcdSoftButtons.Button0) == LcdSoftButtons.Button0)
            {
                if (button0Up)
                {
                    button0Up = false;

                    if (device.CurrentPage == device.Pages[0])
                    {
                        DecrementListState(ref devicesList);
                    }
                    else if (device.CurrentPage == device.Pages[2])
                    {
                        DecrementListState(ref entriesList);
                    }
                }
            }
            else
            {
                button0Up = true;
            }

            // Second button
            if ((e.SoftButtons & LcdSoftButtons.Button1) == LcdSoftButtons.Button1)
            {
                if (button1Up)
                {
                    button1Up = false;

                    if (device.CurrentPage == device.Pages[0])
                    {
                        IncrementListState(ref devicesList, 3);
                    }
                    else if (device.CurrentPage == device.Pages[2])
                    {
                        IncrementListState(ref entriesList, 3);
                    }
                }
            }
            else
            {
                button1Up = true;
            }

            // Third button
            if ((e.SoftButtons & LcdSoftButtons.Button2) == LcdSoftButtons.Button2)
            {
                if (button2Up)
                {
                    button2Up = false;

                    if (device.CurrentPage == device.Pages[0])
                    {
                        lock (devicesList.Lock)
                        {
                            if (devicesList.Items != null && devicesList.Items.Length > 0)
                            {
                                actions.Add(Action.Connect);
                                device.Pages[1].SetAsCurrentDevicePage();
                            }
                        }
                    }
                    else if (device.CurrentPage == device.Pages[1] && ccid == null)
                    {
                        actions.Add(Action.Connect);
                    }
                    else if (device.CurrentPage == device.Pages[2])
                    {
                        lock (entriesList.Lock)
                        {
                            if (entryCode.HasValue && !entryCode.Value.Credential.Name.Equals(entriesList.Items[entriesList.Selected].Name))
                            {
                                // Reset code object
                                entryCode = null;

                                // Reset text elements
                                LcdGdiPage         page       = (LcdGdiPage)device.Pages[3];
                                LcdGdiScrollViewer scrollView = (LcdGdiScrollViewer)page.Children[4];
                                LcdGdiText         textName   = (LcdGdiText)scrollView.Child;
                                LcdGdiText         textCode   = (LcdGdiText)page.Children[5];
                                textName.Text = null;
                                textCode.Text = null;
                            }
                        }

                        device.Pages[3].SetAsCurrentDevicePage();
                    }
                    else if (device.CurrentPage == device.Pages[3])
                    {
                        lock (entriesList.Lock)
                        {
                            LcdGdiPage  page        = (LcdGdiPage)device.Pages[3];
                            LcdGdiImage refreshIcon = (LcdGdiImage)page.Children[0];

                            if (refreshIcon.IsVisible)
                            {
                                entryCode = null;
                            }
                        }
                    }
                }
            }
            else
            {
                button2Up = true;
            }

            // Fourth button
            if ((e.SoftButtons & LcdSoftButtons.Button3) == LcdSoftButtons.Button3)
            {
                if (button3Up)
                {
                    button3Up = false;

                    if (device.CurrentPage == device.Pages[1] || device.CurrentPage == device.Pages[2])
                    {
                        device.Pages[0].SetAsCurrentDevicePage();
                    }
                    else if (device.CurrentPage == device.Pages[3])
                    {
                        device.Pages[2].SetAsCurrentDevicePage();
                    }
                }
            }
            else
            {
                button3Up = true;
            }
        }
        /// <summary>
        /// Creates default state of pages on the device.
        /// </summary>
        /// <param name="device">Logitech LCD device</param>
        private static void CreatePages(LcdDeviceMonochrome device)
        {
            // LCD Resolution = 160x43

            LcdGdiPage pageDevices = new LcdGdiPage(device);

            pageDevices.Updating += UpdateDevicePage;
            device.Pages.Add(pageDevices);

            LcdGdiPage pageConnectionStatus = new LcdGdiPage(device)
            {
                Children =
                {
                    new LcdGdiImage
                    {
                        Image     = Properties.Resources.Refresh,
                        Margin    = new MarginF(97.0f, 33.0f, 0.0f, 0.0f),
                        IsVisible = false
                    },
                    new LcdGdiImage
                    {
                        Image     = Properties.Resources.Back,
                        Margin    = new MarginF(138.0f, 33.0f, 0.0f, 0.0f),
                        IsVisible = false
                    },
                    new LcdGdiRectangle
                    {
                        Size  = new SizeF(160.0f, 12.0f),
                        Brush = Brushes.Black
                    },
                    new LcdGdiScrollViewer
                    {
                        Child = new LcdGdiText
                        {
                            Brush = Brushes.White
                        },
                        Margin = new MarginF(0.0f, 0.0f, 0.0f, 0.0f),
                        HorizontalAlignment = LcdGdiHorizontalAlignment.Stretch,
                        VerticalAlignment   = LcdGdiVerticalAlignment.Stretch,
                        AutoScrollX         = true
                    },
                    new LcdGdiText
                    {
                        Margin = new MarginF(0.0f, 12.0f, 0.0f, 0.0f)
                    }
                }
            };

            pageConnectionStatus.Updating += UpdateConnectionStatusPage;
            device.Pages.Add(pageConnectionStatus);

            LcdGdiPage pageEntries = new LcdGdiPage(device);

            pageEntries.Updating += UpdateEntriesPage;
            device.Pages.Add(pageEntries);

            LcdGdiPage pageEntry = new LcdGdiPage(device)
            {
                Children =
                {
                    new LcdGdiImage
                    {
                        Image     = Properties.Resources.Refresh,
                        Margin    = new MarginF(97.0f, 33.0f, 0.0f, 0.0f),
                        IsVisible = false
                    },
                    new LcdGdiImage
                    {
                        Image  = Properties.Resources.Back,
                        Margin = new MarginF(138.0f, 33.0f, 0.0f, 0.0f)
                    },
                    new LcdGdiProgressBar
                    {
                        Margin        = new MarginF(0.0f, 28.0f, 0.0f, 0.0f),
                        Size          = new SizeF(160.0f, 5.0f),
                        Brush         = Brushes.White,
                        ProgressBrush = Brushes.Black,
                        Minimum       = 0,
                        Maximum       = 100,
                        Value         = 50,
                        IsVisible     = false
                    },
                    new LcdGdiRectangle
                    {
                        Size  = new SizeF(160.0f, 12.0f),
                        Brush = Brushes.Black
                    },
                    new LcdGdiScrollViewer
                    {
                        Child = new LcdGdiText
                        {
                            Brush = Brushes.White
                        },
                        Margin = new MarginF(0.0f, 0.0f, 0.0f, 0.0f),
                        HorizontalAlignment = LcdGdiHorizontalAlignment.Stretch,
                        VerticalAlignment   = LcdGdiVerticalAlignment.Stretch,
                        AutoScrollX         = true
                    },
                    new LcdGdiText
                    {
                        Margin = new MarginF(0.0f, 11.0f, 0.0f, 0.0f),
                        Font   = new Font(FontFamily.GenericSansSerif, 11.0f)
                    }
                }
            };

            pageEntry.Updating += UpdateEntryPage;
            device.Pages.Add(pageEntry);

            pageDevices.SetAsCurrentDevicePage();
        }