OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * Javascript for CharacteristicList and CharacteristicListItem, served from | 6 * Javascript for CharacteristicList and CharacteristicListItem, served from |
7 * chrome://bluetooth-internals/. | 7 * chrome://bluetooth-internals/. |
8 */ | 8 */ |
9 | 9 |
10 cr.define('characteristic_list', function() { | 10 cr.define('characteristic_list', function() { |
(...skipping 27 matching lines...) Expand all Loading... |
38 write_encrypted_authenticated: 'Write Encrypted Authenticated', | 38 write_encrypted_authenticated: 'Write Encrypted Authenticated', |
39 }; | 39 }; |
40 | 40 |
41 /** | 41 /** |
42 * A list item that displays the properties of a CharacteristicInfo object. | 42 * A list item that displays the properties of a CharacteristicInfo object. |
43 * Two fieldsets are created within the element: one for the primitive | 43 * Two fieldsets are created within the element: one for the primitive |
44 * properties, 'id' and 'uuid', and one for the 'properties' bitfield in the | 44 * properties, 'id' and 'uuid', and one for the 'properties' bitfield in the |
45 * CharacteristicInfo object. | 45 * CharacteristicInfo object. |
46 * @constructor | 46 * @constructor |
47 * @param {!interfaces.BluetoothDevice.CharacteristicInfo} characteristicInfo | 47 * @param {!interfaces.BluetoothDevice.CharacteristicInfo} characteristicInfo |
| 48 * @param {string} deviceAddress |
| 49 * @param {string} serviceId |
48 */ | 50 */ |
49 function CharacteristicListItem(characteristicInfo) { | 51 function CharacteristicListItem( |
| 52 characteristicInfo, deviceAddress, serviceId) { |
50 var listItem = new ExpandableListItem(); | 53 var listItem = new ExpandableListItem(); |
51 listItem.__proto__ = CharacteristicListItem.prototype; | 54 listItem.__proto__ = CharacteristicListItem.prototype; |
52 | 55 |
53 listItem.info = characteristicInfo; | 56 listItem.info = characteristicInfo; |
| 57 listItem.deviceAddress_ = deviceAddress; |
| 58 listItem.serviceId_ = serviceId; |
54 listItem.decorate(); | 59 listItem.decorate(); |
55 | 60 |
56 return listItem; | 61 return listItem; |
57 } | 62 } |
58 | 63 |
59 CharacteristicListItem.prototype = { | 64 CharacteristicListItem.prototype = { |
60 __proto__: ExpandableListItem.prototype, | 65 __proto__: ExpandableListItem.prototype, |
61 | 66 |
62 /** | 67 /** |
63 * Decorates the element as a characteristic list item. Creates and caches | 68 * Decorates the element as a characteristic list item. Creates and caches |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 writable_auxiliaries: (this.info.properties & | 101 writable_auxiliaries: (this.info.properties & |
97 Property.WRITABLE_AUXILIARIES) > 0, | 102 Property.WRITABLE_AUXILIARIES) > 0, |
98 read_encrypted: (this.info.properties & Property.READ_ENCRYPTED) > 0, | 103 read_encrypted: (this.info.properties & Property.READ_ENCRYPTED) > 0, |
99 write_encrypted: (this.info.properties & Property.WRITE_ENCRYPTED) > 0, | 104 write_encrypted: (this.info.properties & Property.WRITE_ENCRYPTED) > 0, |
100 read_encrypted_authenticated: (this.info.properties & | 105 read_encrypted_authenticated: (this.info.properties & |
101 Property.READ_ENCRYPTED_AUTHENTICATED) > 0, | 106 Property.READ_ENCRYPTED_AUTHENTICATED) > 0, |
102 write_encrypted_authenticated: (this.info.properties & | 107 write_encrypted_authenticated: (this.info.properties & |
103 Property.WRITE_ENCRYPTED_AUTHENTICATED) > 0, | 108 Property.WRITE_ENCRYPTED_AUTHENTICATED) > 0, |
104 }); | 109 }); |
105 | 110 |
| 111 /** @private {!value_control.ValueControl} */ |
| 112 this.valueControl_ = new value_control.ValueControl(); |
| 113 this.valueControl_.load(this.deviceAddress_, this.serviceId_, this.info); |
| 114 this.valueControl_.setValue(this.info.last_known_value); |
| 115 |
106 // Create content for display in brief content container. | 116 // Create content for display in brief content container. |
107 var characteristicHeaderText = document.createElement('div'); | 117 var characteristicHeaderText = document.createElement('div'); |
108 characteristicHeaderText.textContent = 'Characteristic:'; | 118 characteristicHeaderText.textContent = 'Characteristic:'; |
109 | 119 |
110 var characteristicHeaderValue = document.createElement('div'); | 120 var characteristicHeaderValue = document.createElement('div'); |
111 characteristicHeaderValue.textContent = this.info.uuid.uuid; | 121 characteristicHeaderValue.textContent = this.info.uuid.uuid; |
112 | 122 |
113 var characteristicHeader = document.createElement('div'); | 123 var characteristicHeader = document.createElement('div'); |
114 characteristicHeader.appendChild(characteristicHeaderText); | 124 characteristicHeader.appendChild(characteristicHeaderText); |
115 characteristicHeader.appendChild(characteristicHeaderValue); | 125 characteristicHeader.appendChild(characteristicHeaderValue); |
116 this.briefContent_.appendChild(characteristicHeader); | 126 this.briefContent_.appendChild(characteristicHeader); |
117 | 127 |
118 // Create content for display in expanded content container. | 128 // Create content for display in expanded content container. |
119 var characteristicInfoHeader = document.createElement('h4'); | 129 var characteristicInfoHeader = document.createElement('h4'); |
120 characteristicInfoHeader.textContent = 'Characteristic Info'; | 130 characteristicInfoHeader.textContent = 'Characteristic Info'; |
121 | 131 |
122 var characteristicDiv = document.createElement('div'); | 132 var characteristicDiv = document.createElement('div'); |
123 characteristicDiv.classList.add('flex'); | 133 characteristicDiv.classList.add('flex'); |
124 characteristicDiv.appendChild(this.characteristicFieldSet_); | 134 characteristicDiv.appendChild(this.characteristicFieldSet_); |
125 | 135 |
126 var propertiesHeader = document.createElement('h4'); | 136 var propertiesHeader = document.createElement('h4'); |
127 propertiesHeader.textContent = 'Properties'; | 137 propertiesHeader.textContent = 'Properties'; |
128 | 138 |
129 var propertiesDiv = document.createElement('div'); | 139 var propertiesDiv = document.createElement('div'); |
130 propertiesDiv.classList.add('flex'); | 140 propertiesDiv.classList.add('flex'); |
131 propertiesDiv.appendChild(this.propertiesFieldSet_); | 141 propertiesDiv.appendChild(this.propertiesFieldSet_); |
132 | 142 |
133 var infoDiv = document.createElement('div'); | 143 var infoDiv = document.createElement('div'); |
134 infoDiv.classList.add('info-container'); | 144 infoDiv.classList.add('info-container'); |
| 145 |
| 146 var valueHeader = document.createElement('h4'); |
| 147 valueHeader.textContent = 'Value'; |
| 148 |
135 infoDiv.appendChild(characteristicInfoHeader); | 149 infoDiv.appendChild(characteristicInfoHeader); |
136 infoDiv.appendChild(characteristicDiv); | 150 infoDiv.appendChild(characteristicDiv); |
137 infoDiv.appendChild(propertiesHeader); | 151 infoDiv.appendChild(propertiesHeader); |
138 infoDiv.appendChild(propertiesDiv); | 152 infoDiv.appendChild(propertiesDiv); |
139 | 153 infoDiv.appendChild(valueHeader); |
| 154 infoDiv.appendChild(this.valueControl_); |
140 this.expandedContent_.appendChild(infoDiv); | 155 this.expandedContent_.appendChild(infoDiv); |
141 }, | 156 }, |
142 }; | 157 }; |
143 | 158 |
144 /** | 159 /** |
145 * A list that displays CharacteristicListItems. | 160 * A list that displays CharacteristicListItems. |
146 * @constructor | 161 * @constructor |
147 */ | 162 */ |
148 var CharacteristicList = cr.ui.define('list'); | 163 var CharacteristicList = cr.ui.define('list'); |
149 | 164 |
150 CharacteristicList.prototype = { | 165 CharacteristicList.prototype = { |
151 __proto__: ExpandableList.prototype, | 166 __proto__: ExpandableList.prototype, |
152 | 167 |
153 /** @override */ | 168 /** @override */ |
154 decorate: function() { | 169 decorate: function() { |
155 ExpandableList.prototype.decorate.call(this); | 170 ExpandableList.prototype.decorate.call(this); |
156 | 171 |
157 /** @private {boolean} */ | 172 /** @private {boolean} */ |
158 this.characteristicsRequested_ = false; | 173 this.characteristicsRequested_ = false; |
159 | 174 |
160 this.classList.add('characteristic-list'); | 175 this.classList.add('characteristic-list'); |
161 this.setEmptyMessage('No Characteristics Found'); | 176 this.setEmptyMessage('No Characteristics Found'); |
162 }, | 177 }, |
163 | 178 |
164 /** @override */ | 179 /** @override */ |
165 createItem: function(data) { | 180 createItem: function(data) { |
166 return new CharacteristicListItem(data); | 181 return new CharacteristicListItem( |
| 182 data, this.deviceAddress_, this.serviceId_); |
167 }, | 183 }, |
168 | 184 |
169 /** | 185 /** |
170 * Loads the characteristic list with an array of CharacteristicInfo from | 186 * Loads the characteristic list with an array of CharacteristicInfo from |
171 * the device with |deviceAddress| and service with |serviceId|. If no | 187 * the device with |deviceAddress| and service with |serviceId|. If no |
172 * active connection to the device exists, one is created. | 188 * active connection to the device exists, one is created. |
173 * @param {string} deviceAddress | 189 * @param {string} deviceAddress |
174 * @param {string} serviceId | 190 * @param {string} serviceId |
175 */ | 191 */ |
176 load: function(deviceAddress, serviceId) { | 192 load: function(deviceAddress, serviceId) { |
177 if (this.characteristicsRequested_ || !this.isLoading()) | 193 if (this.characteristicsRequested_ || !this.isLoading()) |
178 return; | 194 return; |
179 | 195 |
| 196 this.deviceAddress_ = deviceAddress; |
| 197 this.serviceId_ = serviceId; |
180 this.characteristicsRequested_ = true; | 198 this.characteristicsRequested_ = true; |
181 | 199 |
182 device_broker.connectToDevice(deviceAddress).then(function(device) { | 200 device_broker.connectToDevice(deviceAddress).then(function(device) { |
183 return device.getCharacteristics(serviceId); | 201 return device.getCharacteristics(serviceId); |
184 }.bind(this)).then(function(response) { | 202 }.bind(this)).then(function(response) { |
185 this.setData(new ArrayDataModel(response.characteristics)); | 203 this.setData(new ArrayDataModel(response.characteristics)); |
186 this.setLoading(false); | 204 this.setLoading(false); |
187 this.characteristicsRequested_ = false; | 205 this.characteristicsRequested_ = false; |
188 }.bind(this)).catch(function(error) { | 206 }.bind(this)).catch(function(error) { |
189 this.characteristicsRequested_ = false; | 207 this.characteristicsRequested_ = false; |
190 Snackbar.show( | 208 Snackbar.show( |
191 deviceAddress + ': ' + error.message, SnackbarType.ERROR, 'Retry', | 209 deviceAddress + ': ' + error.message, SnackbarType.ERROR, 'Retry', |
192 function() { | 210 function() { this.load(deviceAddress, serviceId); }.bind(this)); |
193 this.load(deviceAddress, serviceId); | |
194 }.bind(this)); | |
195 }.bind(this)); | 211 }.bind(this)); |
196 }, | 212 }, |
197 }; | 213 }; |
198 | 214 |
199 return { | 215 return { |
200 CharacteristicList: CharacteristicList, | 216 CharacteristicList: CharacteristicList, |
201 CharacteristicListItem: CharacteristicListItem, | 217 CharacteristicListItem: CharacteristicListItem, |
202 }; | 218 }; |
203 }); | 219 }); |
OLD | NEW |