LibreVNA/Software/PC_Application/Device/RegisterAccess/register.h

55 lines
2.1 KiB
C
Raw Normal View History

2021-05-26 20:38:27 +02:00
#ifndef REGISTER_H
#define REGISTER_H
#include <QObject>
#include <QCheckBox>
#include <QComboBox>
#include <QSpinBox>
#include <QTableWidget>
class Register : public QObject
{
Q_OBJECT
public:
Register(QString name, int address, int width);
void assignUI(QCheckBox *cb, int bitpos, bool inverted = false);
// pos: bitpos at which the field in the register starts which is associated with the UI element
// width: amount of bits in the field
// ui_bitoffset: set to LSB of the ui element in this register field (only required for elements that
// are not represented as one field in a register, e.g. when splitting bits across multiple registers)
void assignUI(QComboBox *cb, int pos, int width, int ui_bitoffset = 0);
void assignUI(QSpinBox *sb, int pos, int width, int ui_bitoffset = 0);
2021-05-26 20:38:27 +02:00
2021-05-29 17:02:13 +02:00
// same as above but by specifying the register address instead of using the register directly
static void assignUI(std::vector<Register*> regs, int address, QCheckBox *cb, int bitpos, bool inverted = false);
static void assignUI(std::vector<Register*> regs, int address, QComboBox *cb, int pos, int width, int ui_bitoffset = 0);
static void assignUI(std::vector<Register*> regs, int address, QSpinBox *sb, int pos, int width, int ui_bitoffset = 0);
2021-05-26 20:38:27 +02:00
QString hexString();
bool setFromString(QString hex);
2021-06-06 00:04:47 +02:00
unsigned long long getValue();
unsigned long long getValue(int pos, int width);
2021-05-26 20:38:27 +02:00
QString getName() const;
static void fillTableWidget(QTableWidget *w, std::vector<Register*> regs);
int getAddress() const;
public slots:
2021-06-06 00:04:47 +02:00
void setValue(unsigned long long newval);
void setValue(unsigned long long newval, int pos, int width);
2021-05-26 20:38:27 +02:00
signals:
2021-06-06 00:04:47 +02:00
void valueChanged(unsigned long long newval);
2021-05-26 20:38:27 +02:00
private:
2021-05-29 17:02:13 +02:00
static Register *findByAddress(std::vector<Register*> regs, int address);
2021-06-06 00:04:47 +02:00
static unsigned long long createMask(int width);
2021-05-26 20:38:27 +02:00
QString name;
int address;
int width;
2021-06-06 00:04:47 +02:00
unsigned long long value;
bool updating; // for preventing endless recursion when updating register/its UI connections
2021-05-26 20:38:27 +02:00
};
#endif // REGISTER_H