-
-
Notifications
You must be signed in to change notification settings - Fork 858
/
VtxDeviceStatusFactory.js
40 lines (31 loc) · 1.04 KB
/
VtxDeviceStatusFactory.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const vtxDeviceStatusFactory = {
_vtxDeviceStatusClasses: [],
// call this to register a new vtx type like SmartAudio, Tramp or Rtc6705
registerVtxDeviceStatusClass: function(vtxDeviceStatusClass)
{
this._vtxDeviceStatusClasses.push(vtxDeviceStatusClass);
},
createVtxDeviceStatus: function(byteArray)
{
const dataView = new DataView(byteArray.buffer);
const vtxTypeIndex = dataView.readU8();
const vtxDeviceStatusClass = this._getDeviceStatusClass(vtxTypeIndex);
return new vtxDeviceStatusClass(dataView);
},
_readVtxType: function(dataView)
{
return dataView.readU8();
},
_getDeviceStatusClass: function(vtxTypeIndex)
{
let result = this._vtxDeviceStatusClasses.find(
(vtxClass) => {
return vtxClass.staticDeviceStatusType === vtxTypeIndex;
});
if (typeof result === 'undefined') {
result = VtxDeviceStatus;
}
return result;
},
};
export default vtxDeviceStatusFactory;