SPI.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows.Forms;
  8. using Uestc.Auto6.Dso.ComModel;
  9. using Uestc.Auto6.Dso.Core;
  10. using Uestc.Auto6.Dso.Core.Decode;
  11. using Uni_Trend.MSO7000X.Common.Helper;
  12. namespace Uestc.Auto6.Dso.Protocol.SPI
  13. {
  14. internal class SPI : DecodeView
  15. {
  16. public override IProtocolView ProtocolView => new SPISetControl();
  17. public override ITriggerSerialView TriggerSerialView => new SPITriggerSetControl();
  18. public override SerialProtocolType ProtocolType => SerialProtocolType.SPI;
  19. public override void DrawDecodeInfo(Graphics graphics, Rectangle rectangle, IProtocolPrsnt prsnt, Color foreColor, Font font)
  20. {
  21. if(prsnt is SPIDecodePrsnt spiDecode)
  22. {
  23. String msg = spiDecode.FramingMode.ToString();
  24. Rectangle rec = GetRowRectangle(0);
  25. rec.X -= 20;
  26. TextRenderer.DrawText(graphics, msg, font,rec , foreColor, TextFormatFlags.HorizontalCenter | TextFormatFlags.Top);
  27. if(spiDecode.FramingMode == ProtocolSPI.FramingMode.Idle)
  28. {
  29. rec.X += 20;
  30. msg = SIHelper.ValueChangeToSI(spiDecode.IdleTime, 2, "s");
  31. TextRenderer.DrawText(graphics, msg, font, rec, foreColor, TextFormatFlags.Right | TextFormatFlags.Top);
  32. }
  33. if(spiDecode.DecodeChannel == ProtocolSPI.DecodeChannel.MISO|| spiDecode.DecodeChannel == ProtocolSPI.DecodeChannel.MOMI)
  34. {
  35. msg = $"{nameof(ProtocolSPI.DecodeChannel.MISO)}->{spiDecode.MISO}{(spiDecode.MISOPolarity == ProtocolSPI.Polarity.Pos?"":"↓")} {SIHelper.ValueChangeToSI(spiDecode.MISOThreshold,2,"V")}";
  36. TextRenderer.DrawText(graphics, msg, font, GetRowRectangle(1), foreColor, TextFormatFlags.Left | TextFormatFlags.Top);
  37. }
  38. if (spiDecode.DecodeChannel == ProtocolSPI.DecodeChannel.MOSI || spiDecode.DecodeChannel == ProtocolSPI.DecodeChannel.MOMI)
  39. {
  40. msg = $"{nameof(ProtocolSPI.DecodeChannel.MOSI)}->{spiDecode.MOSI}{(spiDecode.MOSIPolarity == ProtocolSPI.Polarity.Pos ? "" : "↓")} {SIHelper.ValueChangeToSI(spiDecode.MOSIThreshold, 2, "V")}";
  41. TextRenderer.DrawText(graphics, msg, font, GetRowRectangle(2), foreColor, TextFormatFlags.Left | TextFormatFlags.Top);
  42. }
  43. }
  44. }
  45. }
  46. }