private void ProcessSystemEvent(CommandBuffer.Command newCommand) { if (SystemEvent != null) { SystemEvent(this, (SystemEventType)newCommand.CommandId, new SystemEventParameter()); } }
private void Serial_DataReceived() { while (true) { if (ReceiveBuffer.AddByte((byte)Serial.ReadByte())) { var newCommand = ReceiveBuffer.LastCommand; string error = ProcessCommonErrors(newCommand.CommandId, false); if (error != null) { LastCommand = null; NewResponseEvent.Set(); Debug.Print("Nextion error: " + error); continue; } switch (newCommand.CommandId) { case 0x65: #if DEBUG Debug.Print("New touch event - component"); #endif ProcessTouchComponent(newCommand); break; case 0x67: #if DEBUG Debug.Print("New touch event - XY"); #endif ProcessTouchXY(newCommand); break; case 0x68: #if DEBUG Debug.Print("New touch event - Sleep mode"); #endif ProcessTouchXY(newCommand); break; case (byte)SystemEventType.AutomaticSleepMode: case (byte)SystemEventType.AutomaticWakeUp: #if DEBUG Debug.Print("System event"); #endif ProcessSystemEvent(newCommand); break; default: LastCommand = newCommand; #if DEBUG Debug.Print("New command received: " + newCommand.CommandId.ToString("X2")); #endif NewResponseEvent.Set(); break; } } } }
private void ProcessTouchComponent(CommandBuffer.Command newCommand) { var data = newCommand.GetBuffer(); if (data == null || data.Length != 3) { return; } if (TouchEvent != null) { TouchEvent(this, new TouchEventArgs(Controls) { PageId = data[0], ControlIndex = data[1], Press = data[2] == 0x1, }); } }
private void ProcessTouchXY(CommandBuffer.Command newCommand) { var data = newCommand.GetBuffer(); if (data == null || data.Length != 5) { return; } if (TouchXYEvent != null) { TouchXYEvent(this, new TouchEventXYArgs() { X = data[0] << 8 | data[1], Y = data[2] << 8 | data[3], Press = data[4] == 0x1, SleepMode = newCommand.CommandId == 0x68, }); } }
private void EnsureResponseCommandId(CommandBuffer.Command command, byte expectedId) { EnsureResponseCommandId(command.CommandId, expectedId); }