public static void Main() { Display = new Driver.NextionDisplay(Driver.NextionDisplay.TemporaryChangeBaudRate("COM2", 9600, 115200), 240, 320); DisplayConfiguration.Init(Display); Display.TouchEvent += Display_TouchEvent; Display.TouchXYEvent += Display_TouchXYEvent; Display.SetSleepMode(false); Display.Backlight = 100; Display.GUI.DefaultBackgroundColor = (int)Driver.Color.Black; Display.GUI.DefaultFontColor = (int)Driver.Color.Red; Display.GUI.DefaultFontId = (byte)DisplayConfiguration.Fonts.Sanserif_40_B; Display.GUI.DefaultTextHeight = 45; RenderScorePage(); while (true) { if (State == GameState.Score) { StartGame.WaitOne(); RenderGamePage(); } } }
/// <summary> /// Construct NextionDebuggerHelper with NextionDisplay on provided port. /// </summary> /// <param name="serial"></param> /// <param name="width"></param> /// <param name="height"></param> /// <param name="lineHeight">If line height is too small there will be no text on display!</param> public NextionDebugHelper(SerialPort serial, int width, int height, int lineHeight) { _Display = new Driver.NextionDisplay(serial, width, height); LineHeight = lineHeight; AutoRefresh = true; Init(); }
/// <summary> /// Construct NextionDebuggerHelper on provided NextionDisplay /// </summary> /// <param name="display"></param> /// <param name="lineHeight">If line height is too small there will be no text on display!</param> public NextionDebugHelper(Driver.NextionDisplay display, int lineHeight) { if (_Display.Height <= 0 || _Display.Width <= 0) { throw new Exception("Plese set display size"); } _Display = display; LineHeight = lineHeight; AutoRefresh = true; Init(); }
public static void Main() { //Temporary change boudrate and create port Display = new Driver.NextionDisplay(Driver.NextionDisplay.TemporaryChangeBaudRate("COM2", 9600, 115200), 240, 320); //Display = new Driver.NextionDisplay(new System.IO.Ports.SerialPort("COM2", 9600), 240, 320); DisplayConfiguration.Init(Display); Display.TouchEvent += Display_TouchEvent; Display.TouchXYEvent += Display_TouchXYEvent; //First page is opend by default after display run, but I will init it anyway Display.PageId = DisplayConfiguration.Page0.Id; //Simulate progress for (int i = 0; i <= 100; i += 20) { DisplayConfiguration.Page0.ProgressBar.Val = i; Thread.Sleep(500); if (DisplayConfiguration.Page0.ProgressBar.Val != i) { throw new Exception("Progress bar update failed"); } } //Test colors Display.GUI.Clear(Driver.Color.Red); Thread.Sleep(200); Display.GUI.Clear(Driver.Color.Green); Thread.Sleep(200); Display.GUI.Clear(Driver.Color.Blue); Thread.Sleep(200); //Test Write text Display.GUI.WriteText("Testing text", 0, 0, 240, 320, (byte)DisplayConfiguration.Fonts.Sanserif_16_B, (int)Driver.Color.Yellow, (int)Driver.Color.Blue, Driver.HorizontalAlignment.Center, Driver.VerticalAlignment.Center); Thread.Sleep(1000); //Test write with default values Display.GUI.DefaultFontId = (int)DisplayConfiguration.Fonts.Sanserif_40; Display.GUI.DefaultBackgroundColor = (int)Driver.Color.Transparent; Display.GUI.WriteText("OK", 0, 100, 45); Thread.Sleep(1000); //Go to next page by page name and dim display Display.SetPage(DisplayConfiguration.Page1.Name); //Check if page was changed if (Display.PageId != DisplayConfiguration.Page1.Id) { throw new Exception("Page change failed"); } CurrentPage = Page.Ready; Display.Backlight = 30; //Change touch mode to allow click anywhere Display.TouchMode = Driver.TouchMode.Coordinates; SemaphoreXY.WaitOne(); //Restore full backlight, touch mode and go to next page Display.Backlight = 100; Display.TouchMode = Driver.TouchMode.Component; Display.PageId = DisplayConfiguration.Page2.Id; CurrentPage = Page.DateTime; while (true) { if (CurrentPage == Page.DateTime) { DisplayConfiguration.Page2.MainTextbox.Text = DateTime.Now.ToString(DateFormat); Thread.Sleep(1000); } } }