Skip to content

Commit

Permalink
[BLE] Display charging status
Browse files Browse the repository at this point in the history
  • Loading branch information
deXol committed Jul 2, 2021
1 parent ab6313d commit 37e1700
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 1 deletion.
Binary file added img/charge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions img/images.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@
<file>systray_white.png</file>
<file>uid_spinner.gif</file>
<file>note.png</file>
<file>charge.png</file>
</qresource>
</RCC>
9 changes: 8 additions & 1 deletion src/MPDeviceBleImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1083,7 +1083,14 @@ void MPDeviceBleImpl::readBatteryPercent(const QByteArray& statusData)
{
if (STATUS_MSG_SIZE_WITH_BATTERY == bleProt->getMessageSize(statusData))
{
int batteryPct = bleProt->getPayloadByteAt(statusData, BATTERY_BYTE);
quint8 batteryPct = bleProt->getPayloadByteAt(statusData, BATTERY_BYTE);
bool charging = batteryPct|BATTERY_CHARGING_BIT;
if (charging)
{
// Unset charging bit for battery percent
batteryPct &= ~(BATTERY_CHARGING_BIT);
}
set_chargingStatus(charging);
qDebug() << "Battery percent: " << batteryPct;
if (batteryPct != m_battery)
{
Expand Down
2 changes: 2 additions & 0 deletions src/MPDeviceBleImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class MPDeviceBleImpl: public QObject
QT_WRITABLE_PROPERTY(bool, advancedMenu, false)
QT_WRITABLE_PROPERTY(bool, bluetoothEnabled, false)
QT_WRITABLE_PROPERTY(bool, knockDisabled, false)
QT_WRITABLE_PROPERTY(bool, chargingStatus, false)

enum UserSettingsMask : quint8
{
Expand Down Expand Up @@ -252,6 +253,7 @@ public slots:
const static int FIRST_DATA_STARTING_ADDR = 10;
const static int STATUS_MSG_SIZE_WITH_BATTERY = 5;
const static int BATTERY_BYTE = 1;
const static int BATTERY_CHARGING_BIT = 0x80;
const static int SECRET_KEY_LENGTH = 64;
static constexpr int UPLOAD_PASSWORD_BYTE_SIZE = 16;
static constexpr int DATA_FETCH_NO_NEXT_ADDR_SIZE = 2;
Expand Down
19 changes: 19 additions & 0 deletions src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,19 @@ MainWindow::MainWindow(WSClient *client, DbMasterController *mc, QWidget *parent
ui->pbBleBattery->setValue(battery);
});

connect(wsClient, &WSClient::updateChargingStatus,
[this](bool charging)
{
if (charging)
{
ui->label_charging->show();
}
else
{
ui->label_charging->hide();
}
});

connect(wsClient, &WSClient::reconditionFinished, this, &MainWindow::onReconditionFinished);

// temporary hide 'CSV Export' until it will be implemented
Expand Down Expand Up @@ -617,6 +630,11 @@ MainWindow::MainWindow(WSClient *client, DbMasterController *mc, QWidget *parent
// hide widget with prompts by default
ui->promptWidget->setVisible(false);

ui->label_charging->setPixmap(QString::fromUtf8(":/charge.png"));
ui->label_charging->setMaximumSize(13,25);
ui->label_charging->setPixmap(ui->label_charging->pixmap()->scaled(13,25, Qt::KeepAspectRatio));
ui->label_charging->hide();

updateSerialInfos();
updatePage();

Expand Down Expand Up @@ -2030,6 +2048,7 @@ void MainWindow::onDeviceDisconnected()
if (wsClient->isMPBLE())
{
ui->pbBleBattery->hide();
ui->label_charging->hide();
if (wsClient->get_status() == Common::NoBundle)
{
handleNoBundleDisconnected();
Expand Down
8 changes: 8 additions & 0 deletions src/MainWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,13 @@ QWidget {background-color: #EFEFEF;}</string>
<property name="rightMargin">
<number>5</number>
</property>
<item>
<widget class="QLabel" name="label_charging">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QProgressBar" name="pbBleBattery">
<property name="sizePolicy">
Expand Down Expand Up @@ -4726,6 +4733,7 @@ Hint: keep your mouse positioned over an option to get more details.</string>
<resources>
<include location="../img/images.qrc"/>
<include location="../img/images.qrc"/>
<include location="../img/images.qrc"/>
</resources>
<connections/>
</ui>
5 changes: 5 additions & 0 deletions src/WSClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,11 @@ void WSClient::onTextMessageReceived(const QString &message)
QJsonObject o = rootobj["data"].toObject();
emit updateBatteryPercent(o["battery"].toInt());
}
else if (rootobj["msg"] == "send_charging_status")
{
QJsonObject o = rootobj["data"].toObject();
emit updateChargingStatus(o["charging_status"].toBool());
}
else if (rootobj["msg"] == "request_security_challenge")
{
QJsonObject o = rootobj["data"].toObject();
Expand Down
1 change: 1 addition & 0 deletions src/WSClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ class WSClient: public QObject
void updateBLEDeviceLanguage(const QJsonObject& langs);
void updateBLEKeyboardLayout(const QJsonObject& layouts);
void updateBatteryPercent(int battery);
void updateChargingStatus(int charging);
void challengeResultReceived(QString result);
void challengeResultFailed();
void reconditionFinished(bool success, double dischargeTime);
Expand Down
11 changes: 11 additions & 0 deletions src/WSServerCon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,7 @@ void WSServerCon::resetDevice(MPDevice *dev)
connect(mpBle, &MPDeviceBleImpl::userCategoriesFetched, this, &WSServerCon::sendUserCategories);
connect(mpBle, &MPDeviceBleImpl::bundleVersionChanged, this, &WSServerCon::sendVersion);
connect(mpBle, &MPDeviceBleImpl::notesFetched, this, &WSServerCon::sendNotes);
connect(mpBle, &MPDeviceBleImpl::chargingStatusChanged, this, &WSServerCon::sendChargingStatus);
connect(mpdevice, &MPDevice::displayMiniImportWarning, this, &WSServerCon::sendMiniImportWarning);
}
}
Expand Down Expand Up @@ -656,6 +657,7 @@ void WSServerCon::sendInitialStatus()
if (mpdevice->isBLE())
{
sendIsConnectedWithBluetooth();
sendChargingStatus(mpdevice->ble()->get_chargingStatus());
}
}
}
Expand Down Expand Up @@ -904,6 +906,15 @@ void WSServerCon::sendBatteryPercent(int batteryPct)
sendJsonMessage(oroot);
}

void WSServerCon::sendChargingStatus(bool charging)
{
QJsonObject oroot = { {"msg", "send_charging_status"} };
QJsonObject data;
data.insert("charging_status", charging);
oroot["data"] = data;
sendJsonMessage(oroot);
}

void WSServerCon::sendMiniImportWarning()
{
QJsonObject oroot = { {"msg", "display_mini_import_warning"} };
Expand Down
1 change: 1 addition & 0 deletions src/WSServerCon.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ private slots:
void sendUserCategories(QJsonObject categories);

void sendBatteryPercent(int batteryPct);
void sendChargingStatus(bool charging);

void sendMiniImportWarning();
private:
Expand Down

0 comments on commit 37e1700

Please sign in to comment.