コード例 #1
0
ファイル: GraphDigital.cs プロジェクト: zoomx/xoscillo
        override public void Draw(Graphics g, DataBlock db)
        {
            DrawSelection(g);
            DrawHorizontalLines(g);
            DrawVerticalLines(g);

            float xx = 0;
            int   i  = 0;
            int   i0 = (int)(db.GetChannelLength() * MinXD / db.GetTotalTime());
            int   i1 = (int)(db.GetChannelLength() * MaxXD / db.GetTotalTime());

            try
            {
                float waveheight = m_Bounds.Height / 16;

                int last_rv = 0;

                for (i = i0; i <= i1; i++)
                {
                    int rawvolt = db.GetVoltage(0, i);

                    float time = db.GetTime(i);

                    float x = ValueXToRect(time);

                    for (int ch = 0; ch < db.m_channels; ch++)
                    {
                        //skip unselected channels
                        if ((db.m_channelsBitField & (1 << ch)) == 0)
                        {
                            continue;
                        }

                        float y = ValueYToRect((ch + 1) * DivY);

                        if (((last_rv >> ch) & 1) != ((rawvolt >> ch) & 1))
                        {
                            g.DrawLine(Pens.Red, xx, y, xx, y - waveheight);
                        }

                        if (((rawvolt >> ch) & 1) > 0)
                        {
                            y -= waveheight;
                        }

                        g.DrawLine(Pens.Red, xx, y, x, y);
                    }

                    xx      = x;
                    last_rv = rawvolt;
                }
            }
            catch
            {
                Console.WriteLine("{0} {1} {2}", db, m_Bounds, i);
            }
        }
コード例 #2
0
ファイル: GraphDigital.cs プロジェクト: Reeyaw/xoscillo
      override public void Draw(Graphics g, DataBlock db)
      {
         DrawSelection(g);
         DrawHorizontalLines(g);
         DrawVerticalLines(g);

         float xx = 0;
         int i = 0;
         int i0 = (int)(db.GetChannelLength() * MinXD / db.GetTotalTime());
         int i1 = (int)(db.GetChannelLength() * MaxXD / db.GetTotalTime());
         try
         {
            float waveheight = m_Bounds.Height / 16;

            int last_rv = 0;

            for (i = i0; i <= i1; i++)
            {
               int rawvolt = db.GetVoltage(0, i);

               float time = db.GetTime(i);

               float x = ValueXToRect( time);

               for (int ch = 0; ch < db.m_channels; ch++)
               {
                   //skip unselected channels
                   if ((db.m_channelsBitField & (1 << ch)) == 0)
                       continue;

                  float y = ValueYToRect( (ch +1) * DivY);
                  
                  if ( ((last_rv >>ch)&1) != ((rawvolt>>ch)&1))
                  {
                     g.DrawLine(Pens.Red, xx, y, xx, y - waveheight);
                  }

                  if ( ((rawvolt >> ch)&1) >0)
                  {
                     y -= waveheight;
                  }

                  g.DrawLine(Pens.Red, xx, y, x, y);
               }

               xx = x;
               last_rv = rawvolt;
            }
         }
         catch
         {
            Console.WriteLine("{0} {1} {2}", db, m_Bounds, i);
         }

      }
コード例 #3
0
ファイル: GraphControl.cs プロジェクト: zoomx/xoscillo
        private void UserControl1_Paint(object sender, PaintEventArgs e)
        {
            DateTime currentTime = DateTime.Now;
            TimeSpan duration    = currentTime - oldTime;

            oldTime = currentTime;

            if (Width == 0 || Height == 0)
            {
                return;
            }

            e.Graphics.Clear(Color.Black);
            Rectangle r = this.Bounds;

            r.Height -= hScrollBar1.Height;

            if (ScopeData != null && ScopeData.m_channels != 0)
            {
                graph.SetHorizontalRange(0, ScopeData.GetTotalTime(), m_secondsPerDiv, "Time");
                graph.SetRectangle(r);
                graph.ResizeToRectangle(hScrollBar1);
                graph.Draw(e.Graphics, ScopeData);
            }

            {
                Point pp = new Point();
                pp.X  = 0;
                pp.Y += 16;

                //display message if .5 seconds elapsed without data
                if (waitingForTrigger)
                {
                    e.Graphics.DrawString("Scope maybe waiting for trigger... ", this.Font, Brushes.White, pp);
                }
                else
                {
                    if (duration.Milliseconds > 0)
                    {
                        e.Graphics.DrawString(string.Format("{0} fps", 1000 / duration.Milliseconds), this.Font, Brushes.White, pp);
                    }

                    //reset waiting for trigger timer
                    timer.Stop();
                    timer.Start();
                }
            }
        }
コード例 #4
0
ファイル: GraphAnalog.cs プロジェクト: Reeyaw/xoscillo
      private void DrawGraph(Graphics g, Pen p, DataBlock db, int channel)
      {
         float yy = 0;
         float xx = 0;
         int i = 0;
         int i0 = (int)Math.Floor( lerp(0, db.GetChannelLength(), 0, db.GetTotalTime(), MinXD) );
         int i1 = (int)Math.Ceiling( lerp(0, db.GetChannelLength(), 0, db.GetTotalTime(), MaxXD) )+1;
         if (i1 > db.GetChannelLength())
         {
            i1 = db.GetChannelLength();
         }

         if (db.m_Annotations != null)
         {
             for (int an = 0; an < db.m_Annotations.Length; an++)
             {
                 float time = db.GetTime(db.m_Annotations[an]);
                 float x = ValueXToRect(time);
                 g.DrawLine(Pens.Green, x, 0, x, ValueYToRect(5));
             }
         }

         try
         {
            for (i = i0; i < i1; i++)
            {
               int rawvolt = db.GetVoltage(channel, i);

               float time = db.GetTime(i);

               float x = ValueXToRect(time);
               float y = ValueYToRect(rawvolt);

               if (i > 0)
               {
                  g.DrawLine(p, xx, yy, x, y);

                  if (showValueTicks)
                  {
                     g.DrawLine(p, x, y-2, x, y+2);
                     g.DrawLine(p, x - 2, y, x + 2, y);
                  }

               }
                 
               yy = y;
               xx = x;
            }
         }
         catch
         {
            Console.WriteLine("{0} {1} {2}", db, m_Bounds, i);
         }
                
         //Cursor.Hide();
         if (m_mouse != null)
         {
            DrawCross(g, Pens.Blue, m_mouse.X, m_mouse.Y);
         }

         {
            float t = (db.m_triggerPos * db.GetTotalTime()) / (float)db.GetChannelLength();
            float x = ValueXToRect(t);
            g.DrawLine(Pens.Green, x, m_Bounds.Y, x, m_Bounds.Y + m_Bounds.Height);
         }

         Point pp = new Point();
         pp.X = 0;
         pp.Y = 32;

        if (m_mouse != null)
        {
            float time = RectToValueX(m_mouse.X);
            float voltage = RectToValueY(m_mouse.Y);

            string info = string.Format("{0} ({1}, {2})", db.m_sample, ToEngineeringNotation(time), voltage);
            g.DrawString(info, parent.Font, Brushes.White, pp);
            pp.Y += 16;

            info = string.Format("({0}s/div, {1}Ks/s)", ToEngineeringNotation(DivX), db.m_sampleRate / 1000);
            g.DrawString(info, parent.Font, Brushes.White, pp);
            pp.Y += 16;
        }


         if (Selected())
         {
            if ((m_selectT0 < db.GetTotalTime()) && (m_selectT1 < db.GetTotalTime()))
            {
               g.DrawString(string.Format("({0}, {1}) - ({2}, {3})", ToEngineeringNotation(m_selectT0), db.GetVoltage(0, m_selectT0), ToEngineeringNotation(m_selectT1), db.GetVoltage(0, m_selectT1)), parent.Font, Brushes.White, pp);
               pp.Y += 16;

               g.DrawString(string.Format("ΔVoltage = {0}", db.GetVoltage(0, m_selectT1) - db.GetVoltage(0, m_selectT0)), parent.Font, Brushes.White, pp);
               pp.Y += 16;
            }
            
            string time = string.Format("ΔTime = {0}", ToEngineeringNotation(m_selectT1 - m_selectT0));
            if (m_selectT1 - m_selectT0 > 0)
            {
               time += string.Format(", {0} Hz", (int)(1.0f / (m_selectT1 - m_selectT0)));
            }
            g.DrawString(time, parent.Font, Brushes.White, pp);
            pp.Y += 16;
         }

      }
コード例 #5
0
        private void DrawGraph(Graphics g, Pen p, DataBlock db, int channel)
        {
            float yy = 0;
            float xx = 0;
            int   i  = 0;
            int   i0 = (int)Math.Floor(lerp(0, db.GetChannelLength(), 0, db.GetTotalTime(), MinXD));
            int   i1 = (int)Math.Ceiling(lerp(0, db.GetChannelLength(), 0, db.GetTotalTime(), MaxXD)) + 1;

            if (i1 > db.GetChannelLength())
            {
                i1 = db.GetChannelLength();
            }

            if (db.m_Annotations != null)
            {
                for (int an = 0; an < db.m_Annotations.Length; an++)
                {
                    float time = db.GetTime(db.m_Annotations[an]);
                    float x    = ValueXToRect(time);
                    g.DrawLine(Pens.Green, x, 0, x, ValueYToRect(5));
                }
            }

            try
            {
                for (i = i0; i < i1; i++)
                {
                    int rawvolt = db.GetVoltage(channel, i);

                    float time = db.GetTime(i);

                    float x = ValueXToRect(time);
                    float y = ValueYToRect(rawvolt);

                    if (i > 0)
                    {
                        g.DrawLine(p, xx, yy, x, y);

                        if (showValueTicks)
                        {
                            g.DrawLine(p, x, y - 2, x, y + 2);
                            g.DrawLine(p, x - 2, y, x + 2, y);
                        }
                    }

                    yy = y;
                    xx = x;
                }
            }
            catch
            {
                Console.WriteLine("{0} {1} {2}", db, m_Bounds, i);
            }

            //Cursor.Hide();
            if (m_mouse != null)
            {
                DrawCross(g, Pens.Blue, m_mouse.X, m_mouse.Y);
            }

            {
                float t = (db.m_triggerPos * db.GetTotalTime()) / (float)db.GetChannelLength();
                float x = ValueXToRect(t);
                g.DrawLine(Pens.Green, x, m_Bounds.Y, x, m_Bounds.Y + m_Bounds.Height);
            }

            Point pp = new Point();

            pp.X = 0;
            pp.Y = 32;

            if (m_mouse != null)
            {
                float time    = RectToValueX(m_mouse.X);
                float voltage = RectToValueY(m_mouse.Y);

                string info = string.Format("{0} ({1}, {2})", db.m_sample, ToEngineeringNotation(time), voltage);
                g.DrawString(info, parent.Font, Brushes.White, pp);
                pp.Y += 16;

                info = string.Format("({0}s/div, {1}Ks/s)", ToEngineeringNotation(DivX), db.m_sampleRate / 1000);
                g.DrawString(info, parent.Font, Brushes.White, pp);
                pp.Y += 16;
            }


            if (Selected())
            {
                if ((m_selectT0 < db.GetTotalTime()) && (m_selectT1 < db.GetTotalTime()))
                {
                    g.DrawString(string.Format("({0}, {1}) - ({2}, {3})", ToEngineeringNotation(m_selectT0), db.GetVoltage(0, m_selectT0), ToEngineeringNotation(m_selectT1), db.GetVoltage(0, m_selectT1)), parent.Font, Brushes.White, pp);
                    pp.Y += 16;

                    g.DrawString(string.Format("ΔVoltage = {0}", db.GetVoltage(0, m_selectT1) - db.GetVoltage(0, m_selectT0)), parent.Font, Brushes.White, pp);
                    pp.Y += 16;
                }

                string time = string.Format("ΔTime = {0}", ToEngineeringNotation(m_selectT1 - m_selectT0));
                if (m_selectT1 - m_selectT0 > 0)
                {
                    time += string.Format(", {0} Hz", (int)(1.0f / (m_selectT1 - m_selectT0)));
                }
                g.DrawString(time, parent.Font, Brushes.White, pp);
                pp.Y += 16;
            }
        }