private void Kodi_Applet_Load(object sender, EventArgs e) { if (DMcLgLCD.ERROR_SUCCESS == DMcLgLCD.LcdInit()) { connection = DMcLgLCD.LcdConnectEx("Kodi Media Keys", 0, 0); // Initializes the display with a useful name to identify the application if (DMcLgLCD.LGLCD_INVALID_CONNECTION != connection) { device = DMcLgLCD.LcdOpenByType(connection, DMcLgLCD.LGLCD_DEVICE_QVGA); if (DMcLgLCD.LGLCD_INVALID_DEVICE == device) // Determines whether or not the keyboard is a G15 or G19 (currently the application is only tested on a G15) { device = DMcLgLCD.LcdOpenByType(connection, DMcLgLCD.LGLCD_DEVICE_BW); if (DMcLgLCD.LGLCD_INVALID_DEVICE != device) { deviceType = DMcLgLCD.LGLCD_DEVICE_BW; } } else { deviceType = DMcLgLCD.LGLCD_DEVICE_QVGA; } if (DMcLgLCD.LGLCD_DEVICE_BW == deviceType) { LCD = new Bitmap(160, 43); // Sets the screen size of the keyboard display Graphics g = Graphics.FromImage(LCD); g.Clear(Color.White); g.Dispose(); DMcLgLCD.LcdUpdateBitmap(device, LCD.GetHbitmap(), DMcLgLCD.LGLCD_DEVICE_BW); DMcLgLCD.LcdSetAsLCDForegroundApp(device, DMcLgLCD.LGLCD_FORE_YES); pbLCD.Width = 160; // Sets the picture box display (that is shown when the user double clicks the icon). pbLCD.Height = 43; } if (deviceType > 0) // Only update the screen if there is a screen to update. { DMcLgLCD.LcdSetConfigCallback(cfgCallback); updateTimer = new System.Timers.Timer(100); updateTimer.Elapsed += new System.Timers.ElapsedEventHandler(OnTimedEvent); updateTimer.Interval = 100; // Wil. update the display every 100ms. Likely only required to use a value of 1000. This is required to update the current song time. updateTimer.Enabled = true; } } } }
private void frmMain_Load(object sender, EventArgs e) { if (DMcLgLCD.ERROR_SUCCESS == DMcLgLCD.LcdInit()) { Instance = this; LetterMgr.Instance.Init(); SettingsMgr.Instance.Load(); if (SettingsMgr.Instance.IsFirstRun) { SettingsMgr.Instance.IsFirstRun = false; SettingsMgr.Instance.Save(); try { AutoStart.SetAutoStart(); } catch {} } LCDShotFolder = string.Format("{0}/LCD Shots/", Application.StartupPath); if (!Directory.Exists(LCDShotFolder)) { Directory.CreateDirectory(LCDShotFolder); } Visible = false; ShowInTaskbar = false; #region Tray if (SettingsMgr.Instance.UseTrayIcon) { TrayMenu = new ContextMenu(); TrayMenu.MenuItems.Add("Take LCD &Shot", OnLCDShot); TrayMenu.MenuItems.Add("&Config", OnConfig); TrayMenu.MenuItems.Add("-"); TrayMenu.MenuItems.Add("&Exit", OnExit); TrayIcon = new NotifyIcon(); TrayIcon.Text = "Learn Japanese"; TrayIcon.Icon = new Icon(Application.StartupPath + "/Icon.ico", 32, 32); // Add menu to tray icon and show it. TrayIcon.ContextMenu = TrayMenu; TrayIcon.Visible = true; } #endregion #region Font if (DMcLgLCD.LGLCD_DEVICE_BW == deviceType) { GFont = new Font("Arial", 5, FontStyle.Regular); } else { GFont = new Font("Arial", 12, FontStyle.Regular); } #endregion connection = DMcLgLCD.LcdConnectEx("Learn Japanese", 0, 0); if (DMcLgLCD.LGLCD_INVALID_CONNECTION != connection) { device = DMcLgLCD.LcdOpenByType(connection, DMcLgLCD.LGLCD_DEVICE_QVGA); if (DMcLgLCD.LGLCD_INVALID_DEVICE == device) { device = DMcLgLCD.LcdOpenByType(connection, DMcLgLCD.LGLCD_DEVICE_BW); if (DMcLgLCD.LGLCD_INVALID_DEVICE != device) { deviceType = DMcLgLCD.LGLCD_DEVICE_BW; } } else { deviceType = DMcLgLCD.LGLCD_DEVICE_QVGA; } if (DMcLgLCD.LGLCD_DEVICE_BW == deviceType) { LCD = new Bitmap(160, 43); Graphics g = Graphics.FromImage(LCD); g.Clear(Color.White); g.Dispose(); DMcLgLCD.LcdUpdateBitmap(device, LCD.GetHbitmap(), DMcLgLCD.LGLCD_DEVICE_BW); DMcLgLCD.LcdSetAsLCDForegroundApp(device, DMcLgLCD.LGLCD_FORE_YES); } else { LCD = new Bitmap(320, 240); Graphics g = Graphics.FromImage(LCD); g.Clear(Color.White); g.Dispose(); DMcLgLCD.LcdUpdateBitmap(device, LCD.GetHbitmap(), DMcLgLCD.LGLCD_DEVICE_QVGA); DMcLgLCD.LcdSetAsLCDForegroundApp(device, DMcLgLCD.LGLCD_FORE_YES); } if (deviceType > 0) { //commented out in favor of polling routine. //DMcLgLCD.LcdSetButtonCallback(btnCallback); DMcLgLCD.LcdSetConfigCallback(cfgCallback); //The fastest you should send updates to the LCD is around 30fps or 34ms. 100ms is probably a good typical update speed. timInput.Enabled = true; } timWorkaround.Enabled = true; // sometimes the LCD just shows a white screen for some reason on startup. this 100ms delay fixes that. } } else { MessageBox.Show("Error: The G-keyboard was not detected. The application will not close.", "Hardware not found.", MessageBoxButtons.OK, MessageBoxIcon.Error); Close(); } }