added button on/off

This commit is contained in:
2025-07-04 03:01:18 +07:00
parent bdd09484f4
commit 9a7ebbca9f

View File

@@ -216,10 +216,7 @@ void Mainwindows::onReadReady() {
auto reply = qobject_cast<QModbusReply *>(sender());
if (!reply) return;
// Увеличиваем счетчик ответов при успешном чтении
if (reply->error() == QModbusDevice::NoError) {
m_responseCounter++;
updateStatusBar();
const QModbusDataUnit unit = reply->result();
int address = unit.startAddress();
int value = unit.value(0);
@@ -243,8 +240,17 @@ void Mainwindows::onReadReady() {
if (address == m_buttonRegisters[i]) {
m_buttonValues[i] = value;
bool bitState = (value >> m_buttonBits[i]) & 1;
m_buttons[i]->setText(QString("%1")
.arg(bitState ? "Закрыть" : "Открыть"));
// Проверяем, есть ли индикатор для этой кнопки
bool hasIndicator = false;
for (int j = 0; j < m_indicatorRegisters.size(); ++j) {
if (m_indicatorLabels[j].contains(m_buttonLabels[i], Qt::CaseInsensitive)) {
hasIndicator = true;
break;
}
}
m_buttons[i]->setText(hasIndicator ?
QString("%1").arg(bitState ? "Выкл" : "Вкл") :
QString("%1").arg(bitState ? "Закрыть" : "Открыть"));
}
}
}