OpenHantek
printutils.h
1 // SPDX-License-Identifier: GPL-2.0+
2 
3 #pragma once
4 #include <cerrno>
5 
6 #include <QString>
7 #include <QTime>
8 
12 enum Unit { UNIT_VOLTS, UNIT_DECIBEL, UNIT_SECONDS, UNIT_HERTZ, UNIT_SAMPLES, UNIT_COUNT };
13 
20 QString valueToString(double value, Unit unit, int precision = -1);
21 
28 double stringToValue(const QString &text, Unit unit, bool *ok = 0);
29 
34 QString hexDump(unsigned char *data, unsigned int length);
35 
41 unsigned int hexParse(const QString dump, unsigned char *data, unsigned int length);
42 
45 #ifdef DEBUG
46 inline void timestampDebug(const QString& text) {
47  qDebug("%s: %s", QTime::currentTime().toString("hh:mm:ss.zzz").toLatin1().constData(), text.toLatin1().constData());
48 }
49 #else
50 #define timestampDebug(ARG)
51 #endif