Skip to content

Commit

Permalink
Mobile: Option to disable CAN scan on connect and hopefully better au…
Browse files Browse the repository at this point in the history
…to-scan behavior in general
  • Loading branch information
vedderb committed Aug 26, 2024
1 parent 7f49dbb commit 809ae62
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 9 deletions.
29 changes: 20 additions & 9 deletions mobile/CanScreen.qml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ Item {
scanButton.enabled = VescIf.isPortConnected()
}

function scanIfEmpty() {
if (canList.count == 0 &&
VescIf.isPortConnected() &&
scanButton.enabled) {
scanButton.clicked()
}
}

function selectDeviceInList() {
if (mCommands.getSendCan()) {
for (var i = 0; i < canModel.count;i++) {
Expand All @@ -63,10 +71,17 @@ Item {
mCommands.setSendCan(false, -1)
canList.currentIndex = 0;
canModel.clear()
scanButton.enabled = VescIf.isPortConnected()
scanButton.enabled = false
} else {
selectDeviceInList()
}

if (VescIf.scanCanOnConnect() &&
scanButton.enabled && canList.count == 0 &&
VescIf.isPortConnected() &&
VescIf.fwRx() && VescIf.customConfigRxDone()) {
scanButton.clicked()
}
}
}

Expand Down Expand Up @@ -259,10 +274,6 @@ Item {

function onPortConnectedChanged() {
scanButton.enabled = VescIf.isPortConnected()

if (canList.count == 0 && VescIf.isPortConnected()) {
scanButton.clicked()
}
}
}

Expand All @@ -276,6 +287,7 @@ Item {

scanButton.enabled = true
scanButton.text = qsTr("Scan")

if (VescIf.isPortConnected()) {
canModel.clear()
var params = Utility.getFwVersionBlockingCan(VescIf, -1)
Expand Down Expand Up @@ -321,18 +333,17 @@ Item {
"deviceIconPath": devicePath,
"logoIconPath": logoPath})
}

canList.currentIndex = 0
if (!isTimeout){
scanButton.enabled = true

if (!isTimeout) {
VescIf.emitStatusMessage("CAN Scan Finished", true)
} else {
scanButton.enabled = true
VescIf.emitStatusMessage("CAN Scan Timed Out", false)
}

selectDeviceInList()
} else {
scanButton.enabled = true
VescIf.emitStatusMessage("Device not connected", false)
}
}
Expand Down
9 changes: 9 additions & 0 deletions mobile/Settings.qml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ Item {
checked: VescIf.reconnectLastCan()
}

CheckBox {
id: scanCanConnectBox
Layout.fillWidth: true
text: "Scan CAN on connect"
checked: VescIf.scanCanOnConnect()
}

CheckBox {
id: darkModeBox
Layout.fillWidth: true
Expand All @@ -129,6 +136,7 @@ Item {
qmlUiBox.checked = VescIf.getLoadQmlUiOnConnect()
qmlUiAskBox.checked = VescIf.askQmlLoad()
reconnectLastCanBox.checked = VescIf.reconnectLastCan()
scanCanConnectBox.checked = VescIf.scanCanOnConnect()
}

onClosed: {
Expand All @@ -139,6 +147,7 @@ Item {
VescIf.setLoadQmlUiOnConnect(qmlUiBox.checked)
VescIf.setAskQmlLoad(qmlUiAskBox.checked)
VescIf.setReconnectLastCan(reconnectLastCanBox.checked)
VescIf.setScanCanOnConnect(scanCanConnectBox.checked)
VescIf.storeSettings()

Utility.keepScreenOn(VescIf.keepScreenOn())
Expand Down
6 changes: 6 additions & 0 deletions mobile/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ ApplicationWindow {
id: canScreen
anchors.fill: parent
}

onVisibleChanged: {
if (visible) {
canScreen.scanIfEmpty()
}
}
}
}

Expand Down
10 changes: 10 additions & 0 deletions vescinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4200,6 +4200,16 @@ void VescInterface::setReconnectLastCan(bool set)
mSettings.setValue("reconnectLastCan", set);
}

bool VescInterface::scanCanOnConnect()
{
return mSettings.value("scanCanOnConnect", true).toBool();
}

void VescInterface::setScanCanOnConnect(bool set)
{
mSettings.setValue("scanCanOnConnect", set);
}

int VescInterface::getLastTcpHubPort() const
{
return mLastTcpHubPort;
Expand Down
3 changes: 3 additions & 0 deletions vescinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,9 @@ class VescInterface : public QObject
Q_INVOKABLE bool reconnectLastCan();
Q_INVOKABLE void setReconnectLastCan(bool set);

Q_INVOKABLE bool scanCanOnConnect();
Q_INVOKABLE void setScanCanOnConnect(bool set);

signals:
void statusMessage(const QString &msg, bool isGood);
void messageDialog(const QString &title, const QString &msg, bool isGood, bool richText);
Expand Down

0 comments on commit 809ae62

Please sign in to comment.