private void OnQvgaDeviceArrived() { // First device arrival, creates the device if (_qvgaDevice == null) { _qvgaDevice = (LcdDeviceQvga)_applet.OpenDeviceByType(LcdDeviceType.Qvga); _sampleControl = new SampleControl(); _qvgaDevice.CurrentPage = new LcdWpfPage(_qvgaDevice) { Element = _sampleControl }; _qvgaDevice.SoftButtonsChanged += QvgaDevice_SoftButtonsChanged; // Starts a timer to update the screen _timer = new DispatcherTimer(TimeSpan.FromMilliseconds(5.0), DispatcherPriority.Render, Timer_Tick, Dispatcher.CurrentDispatcher); } // Subsequent device arrival means the device was removed and replugged, simply reopens it else { _qvgaDevice.ReOpen(); } _qvgaDevice.DoUpdateAndDraw(); }
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); }
private void OnQvgaDeviceArrived() { // First device arrival, creates the device if (this.lcdDevice == null) { this.lcdDevice = (LcdDeviceQvga)this.applet.OpenDeviceByType(LcdDeviceType.Qvga); this.buildScreenApplet = new G19BuildScreenApplet(); BuildInformationProvider info = new BuildInformationProvider( new ActiveDirectoryBuildInformationAuthorizer(this.tfsUri), new FinishedBuildInformationGetter()); G19BuildScreenAppletViewModel viewModel = new G19BuildScreenAppletViewModel(info.GetBuildInformation(this.buildDefinition, this.teamProject)); this.buildScreenApplet.DataContext = viewModel; this.lcdDevice.CurrentPage = new LcdWpfPage(this.lcdDevice) { Element = this.buildScreenApplet }; this.lcdDevice.SoftButtonsChanged += this.LcdDeviceSoftButtonsChanged; // Starts a timer to update the screen this.timer = new DispatcherTimer( TimeSpan.FromSeconds(5.0), DispatcherPriority.Render, this.UpdateApplet, Dispatcher.CurrentDispatcher); } // Subsequent device arrival means the device was removed and replugged, simply reopens it else { this.lcdDevice.ReOpen(); } this.lcdDevice.DoUpdateAndDraw(); }