Files
templates/tools/dsview/native/pwm_waveform.h
T

30 lines
952 B
C++

// PWM1 annotation rendering contract: normalized start/end values, -1..+1.
// Kept outside DecodeTrace so geometry can be exercised without a capture device.
#ifndef SET_PWM_WAVEFORM_H
#define SET_PWM_WAVEFORM_H
#include <QPainter>
#include <QStringList>
#include <cmath>
namespace set_pwm {
inline bool segment(const QString &text, double &a, double &b)
{
const QStringList fields = text.split(' ');
if (fields.size() != 3 || fields[0] != "PWM1") return false;
bool okA = false, okB = false;
a = fields[1].toDouble(&okA);
b = fields[2].toDouble(&okB);
return okA && okB && std::isfinite(a) && std::isfinite(b)
&& a >= -1 && a <= 1 && b >= -1 && b <= 1;
}
inline void draw(QPainter &p, const QString &text, double x1, double x2,
double y, double amplitude)
{
double a, b;
if (segment(text, a, b))
p.drawLine(QPointF(x1, y - a * amplitude), QPointF(x2, y - b * amplitude));
}
}
#endif