Skip to content

Commit d282017

Browse files
committed
support for selecting bluetooth devices and pair them
1 parent a237d7f commit d282017

File tree

6 files changed

+199
-1
lines changed

6 files changed

+199
-1
lines changed

src/app/i18n/locale-de.json

+8-1
Original file line numberDiff line numberDiff line change
@@ -231,5 +231,12 @@
231231
"SIDEMENU": {
232232
"ANALOG_INPUT": "Analoger Eingang",
233233
"BLUETOOTH": "Bluetooth"
234-
}
234+
},
235+
"BLUETOOTH": {
236+
"AUDIO":"Audio Device",
237+
"COMPUTER":"Computer",
238+
"CONNECT":"Verbinden",
239+
"DISCONNECT":"Trennen",
240+
"SCAN":"Suchen"
241+
}
235242
}

src/app/i18n/locale-en.json

+14
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,13 @@
232232
"ANALOG_INPUT": "ANALOG INPUT",
233233
"BLUETOOTH": "BLUETOOTH"
234234
},
235+
"BLUETOOTH": {
236+
"AUDIO":"Audio Device",
237+
"COMPUTER":"Computer",
238+
"CONNECT":"Connect",
239+
"DISCONNECT":"Disconnect",
240+
"SCAN":"Scan"
241+
},
235242
"MYVOLUMIO": {
236243
"MY_VOLUMIO": "MyVolumio (Beta)",
237244
"ERROR": "Error",
@@ -363,5 +370,12 @@
363370
"AUTO_SYNC": "Automatic Sync of Personal items",
364371
"MYVOLUMIO_6_DEVICES": "Use MyVolumio on up to 6 devices",
365372
"REMOTE_CONNECTION_6_DEVICES": "Remote connection to up to 6 devices"
373+
},
374+
"BLUETOOTH": {
375+
"AUDIO":"Audio Device",
376+
"COMPUTER":"Computer",
377+
"CONNECT":"Connect",
378+
"DISCONNECT":"Disconnect",
379+
"REFRESH":"Refresh"
366380
}
367381
}

src/app/index.module.js

+2
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ import MyVolumioPayingModalController from './components/myvolumio/modals/myvolu
124124

125125

126126
//Core plugin controller
127+
import BluetoothPluginController from './plugin/core-plugin/bluetooth-plugin.controller';
127128
import WifiPluginController from './plugin/core-plugin/wifi-plugin.controller';
128129
import NetworkStatusPluginController from './plugin/core-plugin/network-status-plugin.controller';
129130
import MyMusicPluginController from './plugin/core-plugin/my-music-plugin.controller';
@@ -305,6 +306,7 @@ angular.module('volumio', [
305306
.controller('ModalCryptoController', ModalCryptoController)
306307
.controller('MyVolumioTermsModalController', MyVolumioTermsModalController)
307308
.controller('MyVolumioPayingModalController', MyVolumioPayingModalController)
309+
.controller('BluetoothPluginController', BluetoothPluginController)
308310
.controller('WifiPluginController', WifiPluginController)
309311
.controller('NetworkStatusPluginController', NetworkStatusPluginController)
310312
.controller('MyMusicPluginController', MyMusicPluginController)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
class BluetoothPluginController {
2+
constructor($scope, socketService, mockService, $log, $translate, $interval) {
3+
'ngInject';
4+
this.socketService = socketService;
5+
this.$scope = $scope;
6+
this.$log = $log;
7+
this.$translate = $translate;
8+
this.$interval = $interval;
9+
this.init();
10+
}
11+
12+
init() {
13+
this.registerListner();
14+
this.initService();
15+
}
16+
17+
startScan() {
18+
this.socketService.emit('callMethod', {
19+
"endpoint" : "audio_interface/bluetooth_controller",
20+
"method" : "startScan",
21+
"data" : {}
22+
});
23+
}
24+
25+
refreshBluetoothDevices() {
26+
this.socketService.emit('callMethod', {
27+
"endpoint" : "audio_interface/bluetooth_controller",
28+
"method" : "getBluetoothDevices",
29+
"data" : {}
30+
});
31+
}
32+
33+
registerListner() {
34+
this.socketService.on('pushBluetoothDevices', (data) => {
35+
this.$log.debug('pushBluetoothDevices', data);
36+
this.bluetooth = data;
37+
});
38+
this.$scope.$on('$destroy', () => {
39+
this.socketService.off('pushBluetoothDevices');
40+
});
41+
}
42+
43+
initService() {
44+
this.startScan();
45+
this.$interval( () => { this.refreshBluetoothDevices(); }, 5000);
46+
}
47+
48+
connectDevice(mac) {
49+
this.socketService.emit("callMethod", {
50+
"endpoint" : "audio_interface/bluetooth_controller",
51+
"method" : "connectBluetoothDevice",
52+
"data" : {mac}
53+
});
54+
}
55+
56+
disconnectDevice(mac) {
57+
this.socketService.emit("callMethod", {
58+
"endpoint" : "audio_interface/bluetooth_controller",
59+
"method" : "disconnectBluetoothDevice",
60+
"data" : {mac}
61+
});
62+
}
63+
}
64+
65+
export default BluetoothPluginController;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<div
2+
id="bluetoothPlugin"
3+
ng-controller="BluetoothPluginController as bluetoothPlugin"
4+
class="panel panel-default">
5+
<div class="panel-heading">
6+
<h3 class="panel-title"><i class="fa fa-bluetooth"></i> Bluetooth devices </h3>
7+
</div>
8+
9+
<div class="panel-body">
10+
<!-- <h4 ng-if="false" class="sectionDescription"></h4> -->
11+
<table class="table">
12+
<tr
13+
ng-if="::bluetoothPlugin.bluetooth.devices.length > 0"
14+
ng-repeat-start="device in bluetoothPlugin.bluetooth.devices track by $index">
15+
<td class="bluetoothIcon">
16+
<i ng-if="device.signal > 0" class="fa fa-signal" title="{{::device.signal}}"></i>
17+
<i ng-if="device.signal == 0" class="fa fa-eye-slash" title="{{::device.signal}}"></i>
18+
</td>
19+
<td class="deviceIcon">
20+
<span>
21+
<i ng-if="device.icon === 'audio-card'" class="fa fa-headphones" title="{{'BLUETOOTH.AUDIO' | translate}}"></i>
22+
<i ng-if="device.icon === 'computer'" class="fa fa-laptop" title="{{'BLUETOOTH.COMPUTER' | translate}}"></i>
23+
</span>
24+
</td>
25+
<td>
26+
<span>{{::device.name}} ({{::device.mac}})</span>
27+
</td>
28+
<td class="commandCol">
29+
<button ng-if="device.connected === 'yes'"
30+
type="button"
31+
class="btn btn-info"
32+
ng-click="bluetoothPlugin.disconnectDevice(device.mac)">
33+
<i class="fa fa-unlink"></i>
34+
<span class="hidden-xs" translate="BLUETOOTH.DISCONNECT"></span>
35+
</button>
36+
<button ng-if="device.connected !== 'yes'"
37+
type="button"
38+
class="btn btn-info"
39+
ng-click="bluetoothPlugin.connectDevice(device.mac)">
40+
<i class="fa fa-link"></i>
41+
<span class="hidden-xs" translate="BLUETOOTH.CONNECT"></span>
42+
</button>
43+
</td>
44+
</tr >
45+
46+
<tr ng-repeat-end>
47+
</tr>
48+
</table >
49+
50+
51+
<button type="button" class="btn btn-info scanBluetoothDevices" ng-click="bluetoothPlugin.startScan()">
52+
<i class="fa fa-refresh" title="{{'BLUETOOTH.SCAN' | translate}}"></i>
53+
<span translate="BLUETOOTH.SCAN"></span>
54+
</button>
55+
</div>
56+
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#bluetoothPlugin {
2+
tr {
3+
td{
4+
border-top: 0 !important;
5+
border-bottom: 1px solid #7C7C7C;
6+
&.insertPasswordRow {
7+
label {
8+
margin-right: 10px;
9+
}
10+
input[type=checkbox] {
11+
width: auto;
12+
}
13+
input[type=text], input[type=password] {
14+
width: 140px;
15+
display: inline-block;
16+
margin-right: 10px;
17+
}
18+
text-align: center;
19+
}
20+
&.commandCol {
21+
max-width: 210px;
22+
text-align: right;
23+
}
24+
&.bluetoothIcon {
25+
width: 36px;
26+
text-align: center;
27+
img {
28+
width: 20px;
29+
}
30+
}
31+
&.deviceIcon {
32+
width: 30px;
33+
text-align: center;
34+
}
35+
.securitySelectWrapper {
36+
width: 120px;
37+
display: inline-block;
38+
margin-right: 15px;
39+
position: relative;
40+
.ui-select-choices {
41+
position: absolute;
42+
top: -22px;
43+
left: 0;
44+
}
45+
}
46+
.showHidePassword {
47+
margin-right: 10px;
48+
}
49+
}
50+
}
51+
.refreshbluetoothNetworks {
52+
margin-top: 15px;
53+
}
54+
}

0 commit comments

Comments
 (0)