Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ngscopeclient/scopehal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 56fe4f3a9350
Choose a base ref
...
head repository: ngscopeclient/scopehal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: d276ed05522d
Choose a head ref
  • 1 commit
  • 7 files changed
  • 1 contributor

Commits on Oct 27, 2019

  1. Initial support for temperature reading on multimeters. Added negativ…

    …e Y coordinate support to Graph widget.
    azonenberg committed Oct 27, 2019
    Copy the full SHA
    d276ed0 View commit details
76 changes: 42 additions & 34 deletions scopehal/Graph.cpp
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
* *
* ANTIKERNEL v0.1 *
* *
* Copyright (c) 2012-2018 Andrew D. Zonenberg *
* Copyright (c) 2012-2019 Andrew D. Zonenberg *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
@@ -78,6 +78,9 @@ Graph::Graph()
m_scaleBump = 10;
m_units = "%";
m_unitScale = 1;
m_timeScale = 10;
m_timeTick = 10;
m_drawLegend = true;

//Redlines default to off scale
m_minRedline = -1;
@@ -167,7 +170,7 @@ bool Graph::on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
vector<double> dashes;
dashes.push_back(1);
float pos = m_right;
for(int dt=0; ; dt += 10) //Vertical grid lines
for(int dt=0; ; dt += m_timeTick) //Vertical grid lines
{
//Get current position
pos = timeToPosition(m_now - dt);
@@ -189,7 +192,7 @@ bool Graph::on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
cr->set_line_width(1.0);
DrawString(pos - 20, m_bottom + 5, cr, buf, false);
}
for(float i=m_scaleBump; i<=m_maxScale; i += m_scaleBump) //Horizontal grid lines
for(float i=m_minScale + m_scaleBump; i<=m_maxScale; i += m_scaleBump) //Horizontal grid lines
{
//Get current position
float pos = valueToPosition(i);
@@ -207,11 +210,11 @@ bool Graph::on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
//Draw text
char buf[32];
sprintf(buf, "%.0f %s", i * m_unitScale, m_units.c_str());
if(m_unitScale < 0.1)
if(m_unitScale <= 0.1)
sprintf(buf, "%.1f %s", i * m_unitScale, m_units.c_str());
if(m_unitScale < 0.01)
if(m_unitScale <= 0.01)
sprintf(buf, "%.2f %s", i * m_unitScale, m_units.c_str());
if(m_unitScale < 0.001)
if(m_unitScale <= 0.001)
sprintf(buf, "%.3f %s", i * m_unitScale, m_units.c_str());
cr->set_line_width(1.0);
DrawString(m_left - 60, pos - 5, cr, buf, false);
@@ -228,33 +231,36 @@ bool Graph::on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
DrawSeries(pNode->m_series[m_seriesName], cr, pNode->m_color);
}

//Draw legend background
int legendmargin = 2;
int legendoffset = 2;
int legendright = m_left + legendw + 2*legendmargin + legendoffset;
cr->set_source_rgb(1, 1, 1);
cr->move_to(m_left + legendoffset, m_top + legendoffset);
cr->line_to(m_left + legendoffset, legendh + 2*legendmargin + m_top + legendoffset);
cr->line_to(legendright, legendh + 2*legendmargin + m_top + legendoffset);
cr->line_to(legendright, m_top + legendoffset);
cr->fill();

//Draw text
int y = legendmargin + lineheight + legendoffset;
for(size_t i=0; i<m_series.size(); i++)
if(m_drawLegend)
{
Graphable* pSeries = m_series[i];
Gdk::Color& color = pSeries->m_color;
cr->set_source_rgb(color.get_red_p(), color.get_green_p(), color.get_blue_p());

DrawString(
m_left + legendmargin + legendoffset,
y,
cr,
pSeries->m_name,
false);

y += lineheight;
//Draw legend background
int legendmargin = 2;
int legendoffset = 2;
int legendright = m_left + legendw + 2*legendmargin + legendoffset;
cr->set_source_rgb(1, 1, 1);
cr->move_to(m_left + legendoffset, m_top + legendoffset);
cr->line_to(m_left + legendoffset, legendh + 2*legendmargin + m_top + legendoffset);
cr->line_to(legendright, legendh + 2*legendmargin + m_top + legendoffset);
cr->line_to(legendright, m_top + legendoffset);
cr->fill();

//Draw text
int y = legendmargin + lineheight + legendoffset;
for(size_t i=0; i<m_series.size(); i++)
{
Graphable* pSeries = m_series[i];
Gdk::Color& color = pSeries->m_color;
cr->set_source_rgb(color.get_red_p(), color.get_green_p(), color.get_blue_p());

DrawString(
m_left + legendmargin + legendoffset,
y,
cr,
pSeries->m_name,
false);

y += lineheight;
}
}

cr->restore();
@@ -304,12 +310,14 @@ void Graph::DrawSeries(Series* pSeries, const Cairo::RefPtr<Cairo::Context>& cr,

float Graph::valueToPosition(float val)
{
return m_top + (m_maxScale - val)*m_pheight;
float range = m_maxScale - m_minScale; //units of plot height
float scale = m_bodyheight / range; //pixels per unit
return m_top + m_bodyheight - (val - m_minScale)*scale;
}

float Graph::timeToPosition(double time)
{
return m_right - ((m_now - time) * 10);
return m_right - ((m_now - time) * m_timeScale);
}

bool Graph::OnTimer(int nTimer)
7 changes: 6 additions & 1 deletion scopehal/Graph.h
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
* *
* ANTIKERNEL v0.1 *
* *
* Copyright (c) 2012-2018 Andrew D. Zonenberg *
* Copyright (c) 2012-2019 Andrew D. Zonenberg *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
@@ -91,6 +91,11 @@ class Graph : public Gtk::Layout
float m_maxRedline;
float m_minRedline;

float m_timeScale;
float m_timeTick;

bool m_drawLegend;

std::string m_yAxisTitle;

protected:
6 changes: 6 additions & 0 deletions scopehal/LeCroyOscilloscope.cpp
Original file line number Diff line number Diff line change
@@ -526,6 +526,12 @@ double LeCroyOscilloscope::GetCurrent()
return 0;
}

double LeCroyOscilloscope::GetTemperature()
{
//DMM does not support current
return 0;
}

double LeCroyOscilloscope::GetPeakToPeak()
{
lock_guard<recursive_mutex> lock(m_mutex);
1 change: 1 addition & 0 deletions scopehal/LeCroyOscilloscope.h
Original file line number Diff line number Diff line change
@@ -113,6 +113,7 @@ class LeCroyOscilloscope
virtual double GetPeakToPeak();
virtual double GetFrequency();
virtual double GetCurrent();
virtual double GetTemperature();

//DMM configuration
virtual int GetMeterChannelCount();
4 changes: 3 additions & 1 deletion scopehal/Multimeter.h
Original file line number Diff line number Diff line change
@@ -42,7 +42,8 @@ class Multimeter : public virtual Instrument
AC_RMS_AMPLITUDE = 0x04,
FREQUENCY = 0x08,
DC_CURRENT = 0x10,
AC_CURRENT = 0x20
AC_CURRENT = 0x20,
TEMPERATURE = 0x40

//TODO: other types
};
@@ -70,6 +71,7 @@ class Multimeter : public virtual Instrument
virtual double GetPeakToPeak() =0;
virtual double GetFrequency() =0;
virtual double GetCurrent() =0;
virtual double GetTemperature() =0;
};

#endif
18 changes: 17 additions & 1 deletion scopehal/RohdeSchwarzHMC8012Multimeter.cpp
Original file line number Diff line number Diff line change
@@ -71,7 +71,7 @@ unsigned int RohdeSchwarzHMC8012Multimeter::GetInstrumentTypes()

unsigned int RohdeSchwarzHMC8012Multimeter::GetMeasurementTypes()
{
return DC_VOLTAGE | FREQUENCY | DC_CURRENT | AC_CURRENT;
return DC_VOLTAGE | FREQUENCY | DC_CURRENT | AC_CURRENT | TEMPERATURE;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -161,6 +161,16 @@ double RohdeSchwarzHMC8012Multimeter::GetCurrent()
return d;
}

double RohdeSchwarzHMC8012Multimeter::GetTemperature()
{
//assume we're in the right mode for now
m_transport->SendCommand("READ?");
string str = m_transport->ReadReply();
double d;
sscanf(str.c_str(), "%lf", &d);
return d;
}

int RohdeSchwarzHMC8012Multimeter::GetMeterChannelCount()
{
return 1;
@@ -194,6 +204,8 @@ Multimeter::MeasurementTypes RohdeSchwarzHMC8012Multimeter::GetMeterMode()
return DC_CURRENT;
else if(smode == "CURR:AC")
return AC_CURRENT;
else if(smode == "SENS")
return TEMPERATURE;

//unknown, pick something
else
@@ -216,6 +228,10 @@ void RohdeSchwarzHMC8012Multimeter::SetMeterMode(Multimeter::MeasurementTypes ty
m_transport->SendCommand("MEAS:CURR:AC?");
break;

case TEMPERATURE:
m_transport->SendCommand("MEAS:TEMP:?");
break;

//whatever it is, not supported
default:
break;
1 change: 1 addition & 0 deletions scopehal/RohdeSchwarzHMC8012Multimeter.h
Original file line number Diff line number Diff line change
@@ -71,6 +71,7 @@ class RohdeSchwarzHMC8012Multimeter
virtual double GetPeakToPeak();
virtual double GetFrequency();
virtual double GetCurrent();
virtual double GetTemperature();

protected:
MeasurementTypes m_mode;