-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new input event APIs from SU 13 (needs testing)
Issue #86
- Loading branch information
Showing
12 changed files
with
280 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { open, Protocol } from '../../dist'; | ||
|
||
/** | ||
* Collects information about all available input events for the aircraft and prints them | ||
*/ | ||
open('My app', Protocol.KittyHawk) | ||
.then(({ recvOpen, handle }) => { | ||
console.log('Connected: ', recvOpen); | ||
|
||
let allInputEvents: { | ||
inputEventName: string; | ||
inputEventIdHash: string; | ||
params?: string; | ||
}[] = []; | ||
|
||
handle.on('inputEventsList', recvEnumerateInputEvents => { | ||
recvEnumerateInputEvents.inputEventDescriptors.forEach(e => { | ||
allInputEvents.push({ | ||
inputEventName: e.name, | ||
inputEventIdHash: e.inputEventIdHash.toString(), | ||
}); | ||
handle.enumerateInputEventParams(e.inputEventIdHash); | ||
}); | ||
}); | ||
|
||
handle.on('enumerateInputEventParams', recvEnumerateInputEventParams => { | ||
// Update the list with the received value | ||
allInputEvents = allInputEvents.map(inputEvent => { | ||
if ( | ||
inputEvent.inputEventIdHash === | ||
recvEnumerateInputEventParams.inputEventIdHash.toString() | ||
) { | ||
return { ...inputEvent, params: recvEnumerateInputEventParams.value }; | ||
} else { | ||
return inputEvent; | ||
} | ||
}); | ||
|
||
// Finally, when no input events are missing the params value, print the list | ||
if (allInputEvents.filter(ev => ev.params === undefined).length === 0) { | ||
console.log(allInputEvents); | ||
} | ||
}); | ||
|
||
handle.on('exception', ex => console.log('Exception', ex)); | ||
|
||
handle.enumerateInputEvents(0 /* request-id */); | ||
}) | ||
.catch(error => { | ||
console.log('Failed to connect', error); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { InputEventType } from '../enums/InputEventType'; | ||
import { RawBuffer } from '../RawBuffer'; | ||
|
||
export class InputEventDescriptor { | ||
name: string; | ||
|
||
inputEventIdHash: Long; | ||
|
||
type: InputEventType; | ||
|
||
constructor(data: RawBuffer) { | ||
this.name = data.readString64(); | ||
this.inputEventIdHash = data.readUint64(); | ||
this.type = data.readUint32() as InputEventType; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const enum InputEventType { | ||
DOUBLE, | ||
STRING, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { RawBuffer } from '../RawBuffer'; | ||
|
||
export class RecvEnumerateInputEventParams { | ||
inputEventIdHash: Long; | ||
|
||
value: string; | ||
|
||
constructor(data: RawBuffer) { | ||
this.inputEventIdHash = data.readUint64(); | ||
this.value = data.readStringV(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { RecvListTemplate } from './RecvListTemplate'; | ||
import { RawBuffer } from '../RawBuffer'; | ||
import { InputEventDescriptor } from '../datastructures/InputEventDescriptor'; | ||
|
||
export class RecvEnumerateInputEvents extends RecvListTemplate { | ||
inputEventDescriptors: InputEventDescriptor[] = []; | ||
|
||
constructor(data: RawBuffer) { | ||
super(data); | ||
|
||
this.inputEventDescriptors = []; | ||
for (let i = 0; i < this.arraySize; i++) { | ||
this.inputEventDescriptors.push(new InputEventDescriptor(data)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { RawBuffer } from '../RawBuffer'; | ||
import { DataRequestId } from '../Types'; | ||
import { InputEventType } from '../enums/InputEventType'; | ||
|
||
export class RecvGetInputEvent { | ||
requestID: DataRequestId; | ||
|
||
type: InputEventType; | ||
|
||
value: number | string; | ||
|
||
constructor(data: RawBuffer) { | ||
this.requestID = data.readInt32(); | ||
this.type = data.readUint32(); | ||
|
||
switch (this.type) { | ||
case InputEventType.STRING: | ||
this.value = data.readString256(); | ||
break; | ||
case InputEventType.DOUBLE: | ||
this.value = data.readFloat64(); | ||
break; | ||
default: | ||
throw Error(`Unknown input event type: ${this.type}`); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { RawBuffer } from '../RawBuffer'; | ||
import { InputEventType } from '../enums/InputEventType'; | ||
|
||
export class RecvSubscribeInputEvent { | ||
inputEventIdHash: Long; | ||
|
||
type: InputEventType; | ||
|
||
value: number | string; | ||
|
||
constructor(data: RawBuffer) { | ||
this.inputEventIdHash = data.readUint64(); | ||
this.type = data.readUint32(); | ||
|
||
switch (this.type) { | ||
case InputEventType.STRING: | ||
this.value = data.readString256(); | ||
break; | ||
case InputEventType.DOUBLE: | ||
this.value = data.readFloat64(); | ||
break; | ||
default: | ||
throw Error(`Unknown input event type: ${this.type}`); | ||
} | ||
} | ||
} |