private void SetLinePixels(ulong TopLine, ulong BotLine, ulong TopProgress, ulong BotProgress)
 {
   lock (DWriteMutex)
   {
     var mask = new BuiltinIconMask();
     ulong optionBitmask = TopProgress << 0x20;
     optionBitmask += TopLine;
     optionBitmask &= mask.ICON_ALL;
     SendData(iMonCommand.General.SetLines0, optionBitmask);
     optionBitmask = TopProgress >> 0x18;
     optionBitmask += BotProgress << 8;
     optionBitmask += BotLine << 40;
     optionBitmask &= mask.ICON_ALL;
     SendData(iMonCommand.General.SetLines1, optionBitmask);
     optionBitmask = BotLine >> 0x10;
     SendData(iMonCommand.General.SetLines2, optionBitmask);
   }
 }
    private void UpdateIcons()
    {
      ulong optionBitmask = 0L;
      ulong num2;
      bool flag = false;
      var icon = new DiskIcon();
      Log.Debug("iMONLCDg.UpdateIcons(): Starting Icon Update Thread");
      var mask = new BuiltinIconMask();
      var drive = new CDDrive();
      if (DisplaySettings.BlankDisplayWithVideo & DisplaySettings.EnableDisplayAction)
      {
        GUIWindowManager.OnNewAction += OnExternalAction;
      }
      for (int i = 0; i < 0x1b; i++)
      {
        Inserted_Media[i] = 0;
      }
      if (DisplayOptions.DiskIcon & DisplayOptions.DiskMonitor)
      {
        char[] cDDriveLetters = CDDrive.GetCDDriveLetters();
        var arg = cDDriveLetters.Length;
        Log.Debug("iMONLCDg.UpdateIcons(): Found {0} CD/DVD Drives.", arg);
        for (int j = 0; j < cDDriveLetters.Length; j++)
        {
          if (drive.Open(cDDriveLetters[j]))
          {
            Log.Debug("iMONLCDg.UpdateIcons(): Checking media in Drive {0}.", cDDriveLetters[j]);
            bool flag2 = false;
            for (int k = 0; k < 10; k++)
            {
              if (drive.IsCDReady())
              {
                flag2 = true;
              }
              else
              {
                Thread.Sleep(50);
              }
            }
            if (flag2)
            {
              Log.Debug("iMONLCDg.UpdateIcons(): Waiting for Drive {0} to refresh.", cDDriveLetters[j]);
              drive.Refresh();
              if (drive.GetNumAudioTracks() > 0)
              {
                Inserted_Media[cDDriveLetters[j] - 'A'] = 1;
                Log.Debug("iMONLCDg.UpdateIcons(): Found Audio CD in Drive {0}.", cDDriveLetters[j]);
              }
              else if (File.Exists(cDDriveLetters[j] + @"\VIDEO_TS"))
              {
                Inserted_Media[cDDriveLetters[j] - 'A'] = 2;
                Log.Debug("iMONLCDg.UpdateIcons(): Found DVD in Drive {0}.", cDDriveLetters[j]);
              }
              else
              {
                Inserted_Media[cDDriveLetters[j] - 'A'] = 4;
                Log.Debug("iMONLCDg.UpdateIcons(): Unknown media found in Drive {0}.", cDDriveLetters[j]);
              }
            }
            else
            {
              Inserted_Media[cDDriveLetters[j] - 'A'] = 0;
              Log.Debug("iMONLCDg.UpdateIcons(): No media found in Drive {0}.", cDDriveLetters[j]);
            }
          }
          drive.Close();
        }
      }
      if (DisplayOptions.DiskIcon & DisplayOptions.DiskMonitor)
      {
        ActivateDVM();
      }
      icon.Reset();
      while (true)
      {
        do
        {
          lock (ThreadMutex)
          {
            if (DoDebug)
            {
              Log.Info("iMONLCDg.UpdateIcons(): Checking for Thread termination request");
            }
            if (_stopUpdateIconThread)
            {
              Log.Info("iMONLCDg.UpdateIcons(): Icon Update Thread terminating");
              _stopUpdateIconThread = false;
              if (DisplaySettings.BlankDisplayWithVideo & DisplaySettings.EnableDisplayAction)
              {
                GUIWindowManager.OnNewAction -= OnExternalAction;
              }
              if (DVM != null)
              {
                DVM.Dispose();
                DVM = null;
              }
              return;
            }
            if ((!DVMactive & DisplayOptions.DiskIcon) & DisplayOptions.DiskMonitor)
            {
              ActivateDVM();
            }
            num2 = optionBitmask;
            flag = !flag;
            int num7 = _CurrentLargeIcon;
            LastVolLevel = volLevel;
            LastProgLevel = progLevel;
            int num8 = 0;
            icon.Off();
            icon.Animate();
            if (DoDebug)
            {
              Log.Info("iMONLCDg.UpdateIcons(): Checking TV Card status: IsAnyCardRecording = {0}, IsViewing = {1}",
                       MiniDisplayHelper.IsCaptureCardRecording().ToString(),
                       MiniDisplayHelper.IsCaptureCardViewing().ToString());
            }
            MiniDisplayHelper.GetSystemStatus(ref MPStatus);
            Check_Idle_State();
            if (DoDebug)
            {
              Log.Info("iMONLCDg.UpdateIcons(): System Status: Plugin Status = {0}, IsIdle = {1}",
                       MPStatus.CurrentPluginStatus.ToString(), MPStatus.MP_Is_Idle);
            }
            optionBitmask = ConvertPluginIconsToDriverIcons(MPStatus.CurrentIconMask);
            if ((optionBitmask & (0x400000000L)) > 0L)
            {
              num8 = 5;
            }
            else if ((optionBitmask & (8L)) > 0L)
            {
              num8 = 1;
            }
            if (MiniDisplayHelper.IsCaptureCardViewing() && !MPStatus.Media_IsTimeshifting)
            {
              icon.On();
              icon.InvertOn();
              icon.RotateCW();
            }
            if (_mpIsIdle)
            {
              num8 = 0;
            }
            if (MPStatus.MediaPlayer_Playing)
            {
              icon.On();
              if ((MPStatus.CurrentIconMask & (0x10L)) > 0L)
              {
                icon.InvertOff();
              }
              else
              {
                icon.InvertOn();
              }
              if ((MPStatus.CurrentIconMask & (0x10000000000L)) > 0L)
              {
                icon.RotateCCW();
              }
              else
              {
                icon.RotateCW();
              }
              icon.FlashOff();
              if (((((((MPStatus.CurrentIconMask & (0x40L)) > 0L) |
                      ((MPStatus.CurrentIconMask & (8L)) > 0L)) |
                     (MPStatus.CurrentPluginStatus == Status.PlayingDVD)) |
                    (MPStatus.CurrentPluginStatus == Status.PlayingTV)) |
                   (MPStatus.CurrentPluginStatus == Status.PlayingVideo)) |
                  (MPStatus.CurrentPluginStatus == Status.Timeshifting))
              {
                if ((MPStatus.CurrentPluginStatus == Status.PlayingTV) |
                    ((MPStatus.CurrentIconMask & (8L)) > 0L))
                {
                  num8 = 1;
                }
                else
                {
                  num8 = 2;
                }
                if (DisplaySettings.BlankDisplayWithVideo)
                {
                  DisplayOff();
                }
              }
              else
              {
                num8 = 3;
              }
              GetEQ();
            }
            else if (MPStatus.MediaPlayer_Paused)
            {
              icon.On();
              lock (DWriteMutex)
              {
                EQSettings._EqDataAvailable = false;
                _iconThread.Priority = ThreadPriority.BelowNormal;
              }
              RestoreDisplayFromVideoOrIdle();
              icon.FlashOn();
              num8 = 6;
            }
            else
            {
              icon.Off();
              RestoreDisplayFromVideoOrIdle();
              lock (DWriteMutex)
              {
                EQSettings._EqDataAvailable = false;
                _iconThread.Priority = ThreadPriority.BelowNormal;
              }
            }
            if ((!MiniDisplayHelper.Player_Playing() & !MiniDisplayHelper.IsCaptureCardViewing()) ||
                (DisplayOptions.DiskIcon & !DisplayOptions.DiskMediaStatus))
            {
              int num9 = 0;
              if (DisplayOptions.DiskIcon)
              {
                for (int m = 0; m < 0x1b; m++)
                {
                  num9 |= Inserted_Media[m];
                }
                switch (num9)
                {
                  case 1:
                    optionBitmask |= mask.ICON_CDIn;
                    goto Label_06B0;

                  case 2:
                    optionBitmask |= mask.ICON_DVDIn;
                    goto Label_06B0;
                }
                if (num9 > 0)
                {
                  optionBitmask |= mask.ICON_DiskOn;
                }
              }
            }
            Label_06B0:
            if (DisplayOptions.DiskIcon & DisplayOptions.DiskMediaStatus)
            {
              optionBitmask |= icon.Mask;
            }
            if (DoDebug)
            {
              Log.Info("iMONLCDg.UpdateIcons(): last = {0}, new = {1}, disk mask = {2}",
                       num2.ToString("X0000000000000000"), optionBitmask.ToString("X0000000000000000"),
                       icon.Mask.ToString("X0000000000000000"));
            }
            if (optionBitmask != num2)
            {
              lock (DWriteMutex)
              {
                SendData(iMonCommand.General.SetIcons, optionBitmask);
              }
            }
            DisplayEQ();
            if (DisplayOptions.VolumeDisplay || DisplayOptions.ProgressDisplay)
            {
              lock (DWriteMutex)
              {
                ShowProgressBars();
              }
            }
            if (num8 != num7)
            {
              _CurrentLargeIcon = num8;
            }
          }
        } while (EQSettings._EqDataAvailable && !MPStatus.MediaPlayer_Paused);
        Thread.Sleep(200);
      }
    }
 public void DoDisplayTest()
 {
   var mask = new BuiltinIconMask();
   if ((_DisplayType == DisplayType.LCD) || (_DisplayType == DisplayType.LCD2))
   {
     Log.Debug("(IDisplay) iMONLCDg.Setup() configure - do display test");
     _displayTest = true;
     OpenLcd();
     ClearDisplay();
     Thread.Sleep(500);
     SendText("iMONLCDg", "Display Test");
     Thread.Sleep(500);
     SendText("iMONLCDg", "All Icons");
     for (int i = 0; i < 2; i++)
     {
       SendData(iMonCommand.General.SetIcons, mask.ICON_ALL);
       Thread.Sleep(500);
       SendData(iMonCommand.General.SetIcons);
       Thread.Sleep(500);
     }
     var icon = new DiskIcon();
     icon.Reset();
     icon.On();
     SendText("iMONLCDg", "Disk On");
     Thread.Sleep(500);
     SendText("iMONLCDg", "Disk Spin CW");
     icon.RotateCW();
     for (int j = 0; j < 0x10; j++)
     {
       icon.Animate();
       SendData(iMonCommand.General.SetIcons, icon.Mask);
       Thread.Sleep(250);
     }
     SendText("iMONLCDg", "Disk Spin CCW");
     icon.RotateCCW();
     for (int k = 0; k < 0x10; k++)
     {
       icon.Animate();
       SendData(iMonCommand.General.SetIcons, icon.Mask);
       Thread.Sleep(250);
     }
     SendText("iMONLCDg", "Disk Flash");
     icon.RotateOff();
     icon.FlashOn();
     for (int m = 0; m < 0x10; m++)
     {
       icon.Animate();
       SendData(iMonCommand.General.SetIcons, icon.Mask);
       Thread.Sleep(250);
     }
     CloseLcd();
     _displayTest = false;
     Log.Debug("(IDisplay) iMONLCDg.Setup() configure - display test complete");
   }
 }