Skip to content

Commit

Permalink
add attribute dtype for rigister
Browse files Browse the repository at this point in the history
  • Loading branch information
fosghen committed Feb 17, 2025
1 parent 511e7b8 commit dac54cb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
11 changes: 10 additions & 1 deletion tablemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ void TableManager::pasteJsonData()
float multy = regInfo.value("multy").toDouble();
int digits = regInfo.value("digits").toInt();
int access = regInfo.value("access").toInt();
int dtype = regInfo.value("dtype").toInt();

register_.Address = address;
register_.Value = 0;
Expand All @@ -191,6 +192,7 @@ void TableManager::pasteJsonData()
register_.Multy = multy;
register_.isWrite = false;
register_.isRead = false;
register_.dtype = dtype;

registers[address] = register_;
regAddress.append(address);
Expand Down Expand Up @@ -253,7 +255,14 @@ void TableManager::chooseAllRegInTab(int index)
void TableManager::updateTable()
{
for (int i = 0; i < regAddress.size(); i++){
float value = registers[regAddress[i]].Value;
float value;
if (registers[regAddress[i]].dtype == ToUint16){
value = static_cast<uint16_t>(registers[regAddress[i]].Value);
}

if (registers[regAddress[i]].dtype == ToInt16){
value = static_cast<int16_t>(registers[regAddress[i]].Value);
}
value *= registers[regAddress[i]].Multy;

registersTalbeItem[regAddress[i]].setText(QString::number(value, 'f', registers[regAddress[i]].Digits));
Expand Down
7 changes: 7 additions & 0 deletions tablemanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,15 @@ class TableManager : public QObject {
float Multy;
bool isWrite;
bool isRead;
int dtype;
};

enum ConversionType {
ToUint16 = 0,
ToInt16 = 1
};
Q_ENUM(ConversionType)

QMap<int, Register> registers;
int numRegisterRead;
int startRegAddress;
Expand Down

0 comments on commit dac54cb

Please sign in to comment.