Add bluetooth pair button

This commit is contained in:
hawkeyexp 2018-08-17 16:13:44 +02:00
parent ed37925b51
commit baae26932c
8 changed files with 239 additions and 132 deletions

BIN
assets/ico_bluetooth.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

View File

@ -4,6 +4,7 @@
<file>ico_warning.png</file>
<file>ico_setting.png</file>
<file>ico_info.png</file>
<file>ico_bluetooth.png</file>
<file>connect.png</file>
<file>cursor-hot.png</file>
<file>power-hot.png</file>

View File

@ -76,6 +76,7 @@ private slots:
void showRearCamBG();
void hideRearCamBG();
void createDebuglog();
void setPairable();
private:
Ui::MainWindow* ui_;

View File

@ -47,6 +47,7 @@ public:
void loadSystemValues();
private slots:
void unpairAll();
void onSave();
void onResetToDefaults();
void onUpdateScreenDPI(int value);

View File

@ -47,7 +47,7 @@ MainWindow::MainWindow(configuration::IConfiguration::Pointer configuration, QWi
this->setStyleSheet("QMainWindow {background-color: rgb(0,0,0);} \
QPushButton { background: url(:/circle.png); border: 0; } \
QPushButton:hover { background: url(:/circle.png); } \
QPushButton:focus { background: url(:/circle.png); } \
QPushButton:focus { background: url(:/circle.png); border: none; outline: none;} \
QPushButton:pressed { background: url(:/circle-pressed.png); } \
QSlider:horizontal { background: url(:/slider.png); border: 1px solid #ffffff; border-radius: 2px; min-height: 32px;} \
QSlider::groove:horizontal { background: #6d6d6d; height: 32px;} \
@ -120,11 +120,17 @@ MainWindow::MainWindow(configuration::IConfiguration::Pointer configuration, QWi
connect(ui_->pushButtonKodi, &QPushButton::clicked, this, &MainWindow::startKodi);
connect(ui_->pushButtonBrightness, &QPushButton::clicked, this, &MainWindow::showBrightnessSlider);
connect(ui_->systemDebugging, &QPushButton::clicked, this, &MainWindow::createDebuglog);
connect(ui_->pushButtonBluetooth, &QPushButton::clicked, this, &MainWindow::setPairable);
QTimer *timer=new QTimer(this);
connect(timer, SIGNAL(timeout()),this,SLOT(showTime()));
timer->start();
QFileInfo bluetoothButtonFile("/tmp/button_bluetooth_visible");
if (! bluetoothButtonFile.exists()) {
ui_->pushButtonBluetooth->hide();
}
// Get version string
QFileInfo vFile("/etc/crankshaft.build");
if (vFile.exists()) {
@ -498,6 +504,11 @@ void f1x::openauto::autoapp::ui::MainWindow::createDebuglog()
system("/usr/local/bin/crankshaft debuglog &");
}
void f1x::openauto::autoapp::ui::MainWindow::setPairable()
{
system("/usr/local/bin/autoapp_helper enablepairing &");
}
void f1x::openauto::autoapp::ui::MainWindow::showTime()
{
using namespace std::this_thread; // sleep_for
@ -540,8 +551,9 @@ void f1x::openauto::autoapp::ui::MainWindow::showTime()
QFileInfo configInProgressFile("/tmp/config_in_progress");
QFileInfo debugInProgressFile("/tmp/debug_in_progress");
QFileInfo enablePairingFile("/tmp/enable_pairing");
if (configInProgressFile.exists() || debugInProgressFile.exists()) {
if (configInProgressFile.exists() || debugInProgressFile.exists() || enablePairingFile.exists()) {
if (ui_->systemConfigInProgress->isVisible() == false) {
if (configInProgressFile.exists()) {
ui_->systemConfigInProgress->setText("System config in progress - please wait ...");
@ -554,6 +566,11 @@ void f1x::openauto::autoapp::ui::MainWindow::showTime()
ui_->systemDebugging->hide();
ui_->systemConfigInProgress->show();
}
if (enablePairingFile.exists()) {
ui_->systemConfigInProgress->setText("Bluetooth Pairing enabled! ");
ui_->systemDebugging->hide();
ui_->systemConfigInProgress->show();
}
}
} else {
if (ui_->systemConfigInProgress->isVisible() == true) {

View File

@ -41,6 +41,7 @@ SettingsWindow::SettingsWindow(configuration::IConfiguration::Pointer configurat
ui_->setupUi(this);
connect(ui_->pushButtonCancel, &QPushButton::clicked, this, &SettingsWindow::close);
connect(ui_->pushButtonSave, &QPushButton::clicked, this, &SettingsWindow::onSave);
connect(ui_->pushButtonUnpair , &QPushButton::clicked, this, &SettingsWindow::unpairAll);
connect(ui_->horizontalSliderScreenDPI, &QSlider::valueChanged, this, &SettingsWindow::onUpdateScreenDPI);
connect(ui_->radioButtonUseExternalBluetoothAdapter, &QRadioButton::clicked, [&](bool checked) { ui_->lineEditExternalBluetoothAdapterAddress->setEnabled(checked); });
connect(ui_->radioButtonDisableBluetooth, &QRadioButton::clicked, [&]() { ui_->lineEditExternalBluetoothAdapterAddress->setEnabled(false); });
@ -51,6 +52,7 @@ SettingsWindow::SettingsWindow(configuration::IConfiguration::Pointer configurat
connect(ui_->pushButtonShowBindings, &QPushButton::clicked, this, &SettingsWindow::onShowBindings);
connect(ui_->horizontalSliderSystemVolume, &QSlider::valueChanged, this, &SettingsWindow::onUpdateSystemVolume);
connect(ui_->horizontalSliderSystemCapture, &QSlider::valueChanged, this, &SettingsWindow::onUpdateSystemCapture);
}
SettingsWindow::~SettingsWindow()
@ -195,6 +197,8 @@ void SettingsWindow::onSave()
params.append("0");
}
params.append("#");
params.append( std::string(ui_->comboBoxBluetooth->currentText().toStdString()) );
params.append("#");
if (ui_->checkBoxHardwareSave->isChecked()) {
params.append("1");
} else {
@ -258,6 +262,8 @@ void SettingsWindow::load()
const auto& audioOutputBackendType = configuration_->getAudioOutputBackendType();
ui_->radioButtonRtAudio->setChecked(audioOutputBackendType == configuration::AudioOutputBackendType::RTAUDIO);
ui_->radioButtonQtAudio->setChecked(audioOutputBackendType == configuration::AudioOutputBackendType::QT);
ui_->checkBoxHardwareSave->setChecked(false);
}
void SettingsWindow::loadButtonCheckBoxes()
@ -346,6 +352,11 @@ void SettingsWindow::onUpdateSystemCapture(int value)
ui_->labelSystemCaptureValue->setText(QString::number(value));
}
void SettingsWindow::unpairAll()
{
system("/usr/local/bin/crankshaft bluetooth unpair &");
}
void SettingsWindow::loadSystemValues()
{
// Generate param file
@ -580,12 +591,27 @@ void SettingsWindow::loadSystemValues()
// set cam
ui_->comboBoxCam->setCurrentText(getparams[33]);
// set cs bluetooth
// set bluetooth
if (getparams[34] == "1") {
// check external bluetooth enabled
if (getparams[36] == "1") {
ui_->radioButtonUseExternalBluetoothAdapter->setChecked(true);
} else {
ui_->radioButtonUseLocalBluetoothAdapter->setChecked(true);
}
// mac
ui_->lineEditExternalBluetoothAdapterAddress->setText(getparams[37]);
} else {
ui_->radioButtonDisableBluetooth->setChecked(true);
ui_->lineEditExternalBluetoothAdapterAddress->setText("");
}
if (getparams[35] == "1") {
ui_->checkBoxBluetoothAutoPair->setChecked(true);
} else {
ui_->checkBoxBluetoothAutoPair->setChecked(false);
}
// set timezone
ui_->comboBoxBluetooth->setCurrentText(getparams[38]);
}
}

View File

@ -51,6 +51,30 @@
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
<widget class="QPushButton" name="pushButtonBluetooth">
<property name="geometry">
<rect>
<x>618</x>
<y>-8</y>
<width>64</width>
<height>64</height>
</rect>
</property>
<property name="icon">
<iconset resource="../../../assets/resources.qrc">
<normaloff>:/ico_bluetooth.png</normaloff>
</iconset>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">background: rgba(255,255,255,0);</string>
</property>
</widget>
<widget class="QLabel" name="btDevice">
<property name="geometry">
<rect>
@ -75,7 +99,7 @@
</font>
</property>
<property name="styleSheet">
<string notr="true">color: #00CCFF;</string>
<string notr="true">color: #0000FF;</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
@ -815,6 +839,7 @@ QPushButton:pressed { background: orange; border: none; }</string>
<zorder>pushButtonLock</zorder>
<zorder>pushButtonWirelessConnection</zorder>
<zorder>pushButtonKodi</zorder>
<zorder>pushButtonBluetooth</zorder>
<zorder>pushButtonToggleCursor</zorder>
<zorder>pushButtonDay</zorder>
<zorder>pushButtonNight</zorder>

View File

@ -1104,106 +1104,68 @@ QSlider::groove:horizontal { background: #6d6d6d; height: 32px;}</string>
<x>0</x>
<y>10</y>
<width>646</width>
<height>101</height>
<height>111</height>
</rect>
</property>
<property name="title">
<string>Bluetooth adapter</string>
<string>Bluetooth settings</string>
</property>
<widget class="QRadioButton" name="radioButtonDisableBluetooth">
<property name="geometry">
<rect>
<x>20</x>
<y>30</y>
<width>171</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Disable bluetooth</string>
</property>
</widget>
<widget class="QRadioButton" name="radioButtonUseExternalBluetoothAdapter">
<property name="geometry">
<rect>
<x>210</x>
<y>30</y>
<width>171</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Use external adapter</string>
</property>
</widget>
<widget class="QLineEdit" name="lineEditExternalBluetoothAdapterAddress">
<property name="geometry">
<rect>
<x>410</x>
<y>66</y>
<y>26</y>
<width>231</width>
<height>31</height>
</rect>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
<widget class="QLabel" name="labelBluetoothAdapterAddress">
<property name="geometry">
<rect>
<x>340</x>
<y>66</y>
<width>67</width>
<x>290</x>
<y>26</y>
<width>111</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>Address:</string>
<string>Used Address:</string>
</property>
</widget>
<widget class="QLabel" name="labelBluetoothAddressFormatInfo">
<property name="geometry">
<rect>
<x>440</x>
<y>20</y>
<width>181</width>
<height>41</height>
</rect>
</property>
<property name="font">
<font>
<italic>true</italic>
</font>
</property>
<property name="text">
<string>Provide address in format AA:BB:CC:DD:EE:FF.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
<widget class="QLabel" name="labelBluetoothAddressFormatInfoIcon">
<property name="geometry">
<rect>
<x>410</x>
<y>30</y>
<width>21</width>
<height>21</height>
</rect>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;img src=&quot;:/ico_info.png&quot;/&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
<widget class="QRadioButton" name="radioButtonUseLocalBluetoothAdapter">
<widget class="QCheckBox" name="checkBoxBluetoothAutoPair">
<property name="geometry">
<rect>
<x>20</x>
<y>60</y>
<width>151</width>
<y>30</y>
<width>261</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Use local adapter</string>
<string>Set pairable on startup (120 secs)</string>
</property>
</widget>
<widget class="QPushButton" name="pushButtonUnpair">
<property name="geometry">
<rect>
<x>20</x>
<y>70</y>
<width>191</width>
<height>30</height>
</rect>
</property>
<property name="text">
<string>Remove all paired devices</string>
</property>
<property name="default">
<bool>false</bool>
</property>
<property name="flat">
<bool>false</bool>
</property>
</widget>
</widget>
@ -1211,7 +1173,7 @@ QSlider::groove:horizontal { background: #6d6d6d; height: 32px;}</string>
<property name="geometry">
<rect>
<x>0</x>
<y>190</y>
<y>160</y>
<width>646</width>
<height>111</height>
</rect>
@ -1259,6 +1221,9 @@ QSlider::groove:horizontal { background: #6d6d6d; height: 32px;}</string>
<height>31</height>
</rect>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
<widget class="QLabel" name="labelWifiClientSSID">
<property name="geometry">
@ -1291,7 +1256,7 @@ QSlider::groove:horizontal { background: #6d6d6d; height: 32px;}</string>
<property name="geometry">
<rect>
<x>0</x>
<y>310</y>
<y>280</y>
<width>646</width>
<height>141</height>
</rect>
@ -1386,66 +1351,93 @@ QSlider::groove:horizontal { background: #6d6d6d; height: 32px;}</string>
</property>
</widget>
</widget>
<widget class="QGroupBox" name="groupBoxBluetoothCS">
<widget class="QRadioButton" name="radioButtonUseExternalBluetoothAdapter">
<property name="geometry">
<rect>
<x>0</x>
<y>120</y>
<width>646</width>
<height>61</height>
<x>330</x>
<y>60</y>
<width>171</width>
<height>23</height>
</rect>
</property>
<property name="title">
<string>Bluetooth Pairing / Connect</string>
<property name="text">
<string>Use external adapter</string>
</property>
<widget class="QCheckBox" name="checkBoxBluetoothAutoPair">
<property name="geometry">
<rect>
<x>20</x>
<y>26</y>
<width>250</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Enable Autopairing / Autoconnect</string>
</property>
</widget>
<widget class="QLabel" name="labelBluetoothAddressFormatInfo_1">
<property name="geometry">
<rect>
<x>360</x>
<y>20</y>
<width>281</width>
<height>31</height>
</rect>
</property>
<property name="font">
<font>
<italic>true</italic>
</font>
</property>
<property name="text">
<string>Experimental and only using local adapter! Needs a reboot after changing!</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
<widget class="QLabel" name="labelUseWarningIcon_4">
<property name="geometry">
<rect>
<x>320</x>
<y>20</y>
<width>31</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;img src=&quot;:/ico_warning.png&quot;/&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</widget>
<widget class="QRadioButton" name="radioButtonUseLocalBluetoothAdapter">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>170</x>
<y>60</y>
<width>151</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Use local adapter</string>
</property>
</widget>
<widget class="QRadioButton" name="radioButtonDisableBluetooth">
<property name="geometry">
<rect>
<x>10</x>
<y>60</y>
<width>171</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Disable bluetooth</string>
</property>
</widget>
<widget class="QLabel" name="labelSettingsInfo_Icon_5">
<property name="geometry">
<rect>
<x>80</x>
<y>422</y>
<width>31</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;justify&quot;&gt;&lt;img src=&quot;:/ico_warning.png&quot;/&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
<widget class="QLabel" name="labelSettingsInfo_5">
<property name="geometry">
<rect>
<x>2</x>
<y>425</y>
<width>644</width>
<height>26</height>
</rect>
</property>
<property name="font">
<font>
<italic>true</italic>
</font>
</property>
<property name="text">
<string>To activate this settings you have to reboot after changing!</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
<zorder>radioButtonDisableBluetooth</zorder>
<zorder>radioButtonUseExternalBluetoothAdapter</zorder>
<zorder>radioButtonUseLocalBluetoothAdapter</zorder>
<zorder>groupBoxWifiClient</zorder>
<zorder>groupBoxWifiHotspot</zorder>
<zorder>groupBoxBluetoothAdapter</zorder>
<zorder>labelSettingsInfo_5</zorder>
<zorder>labelSettingsInfo_Icon_5</zorder>
</widget>
<widget class="QWidget" name="tabCSBase">
<attribute name="title">
@ -3265,7 +3257,7 @@ subcontrol-position: center left;
<x>0</x>
<y>10</y>
<width>646</width>
<height>241</height>
<height>291</height>
</rect>
</property>
<property name="title">
@ -3572,6 +3564,50 @@ subcontrol-position: center left;
</property>
</item>
</widget>
<widget class="QLabel" name="labelHardwareBluetooth">
<property name="geometry">
<rect>
<x>10</x>
<y>240</y>
<width>80</width>
<height>30</height>
</rect>
</property>
<property name="text">
<string>Bluetooth</string>
</property>
</widget>
<widget class="QComboBox" name="comboBoxBluetooth">
<property name="geometry">
<rect>
<x>90</x>
<y>240</y>
<width>300</width>
<height>30</height>
</rect>
</property>
<property name="editable">
<bool>false</bool>
</property>
<property name="currentText">
<string>none</string>
</property>
<item>
<property name="text">
<string>none</string>
</property>
</item>
<item>
<property name="text">
<string>builtin</string>
</property>
</item>
<item>
<property name="text">
<string>external</string>
</property>
</item>
</widget>
</widget>
<widget class="QLabel" name="labelSettingsInfo_3">
<property name="geometry">