コード例 #1
0
ファイル: Form1.cs プロジェクト: Tango600/EngineEmu
        private void loop()
        {
            if (sensor == 1)
            {
                if (deltaTime > 0 && deltaTime < 200000)
                {
                    sensor = 0;
                    byte i = 0;
                    while (i < tableRPMPoints.Length && (ulong)tableRPMPoints[i] > deltaTime)
                    {
                        i++;
                    }
                    if (i >= tableRPMPoints.Length)
                    {
                        i = Convert.ToByte(tableRPMPoints.Length - 1);
                    }

                    for (int j = 0; j < dgIgnitionMoments.Rows.Count; j++)
                    {
                        dgIgnitionMoments.Rows[j].DefaultCellStyle.BackColor = Color.White;
                    }
                    dgIgnitionMoments.Rows[i].DefaultCellStyle.BackColor = Color.DodgerBlue;

                    if (tableIgnDelays[i] == 0)
                    {
                        tableIgnDelays[i] = 1;
                    }

                    if (chOptimalCalc1024.Checked)
                    {
                        ignitionDelay = (deltaTime * (((ulong)tableIgnDelays[i] * 1024) / 360)) / 1024;
                    }
                    else
                    {
                        ignitionDelay = (deltaTime * (((ulong)tableIgnDelays[i] * 1000) / 360)) / 1000;
                    }

                    lastIgnitionDegree = Convert.ToInt32(360M / ((decimal)deltaTime / ignitionDelay));

                    startTime    = lastTime + ignitionDelay;
                    lastStopTime = stopTime;
                    stopTime     = startTime + (ulong)speFlashDuration.Value;
                }
            }

            if ((startTime < micros() && stopTime > micros()) || lastStopTime > micros())
            {
                pnLed.BackColor = Color.Red;

                monAngle.Text = CalcDegreeMonitor(lastIgnitionDegree).ToString() + " deg.";
                if (chMonitor.Checked)
                {
                    DrawingObjects.DrawIgnitionMoment(graphics, lastIgnitionDegree, deltaTime, (int)speFlashDuration.Value, FigureType.Figure);
                    int igntSector = DrawingObjects.DrawIgnitFlashSector(graphics, lastIgnitionDegree, deltaTime, flashDurationAngle, FigureType.Figure);
                    if (lastIgnitionDegree + igntSector < 360 && lastIgnitionDegree + igntSector > 180)
                    {
                        lbWarring.Visible   = true;
                        lbWarring.ForeColor = Color.Red;
                    }
                    else
                    {
                        if (lastIgnitionDegree + igntSector < 180 && lastIgnitionDegree + igntSector > 90)
                        {
                            lbWarring.Visible   = true;
                            lbWarring.ForeColor = Color.Orange;
                        }
                        else
                        {
                            lbWarring.Visible = false;
                        }
                    }
                }
            }
            else
            {
                if (chMonitor.Checked)
                {
                    if (lastIgnitionDegree != -1)
                    {
                        DrawingObjects.DrawIgnitionMoment(graphics, lastIgnitionDegree, 0, 0, FigureType.Mask);
                        DrawingObjects.DrawIgnitFlashSector(graphics, lastIgnitionDegree, 0, 0, FigureType.Mask);
                    }
                }

                pnLed.BackColor = Color.Gray;
            }
        }