All files / sportident/src/SiDevice ISiDevice.ts

100% Statements 15/15
100% Branches 2/2
100% Functions 3/3
100% Lines 15/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57  5x     5x 5x 5x 5x 5x               5x   5x   46x 46x   46x     5x   16x 16x   16x                                                  
import type {ISiTargetMultiplexer} from '../SiStation/ISiTargetMultiplexer';
import * as utils from '../utils';
 
/* eslint-disable no-unused-vars,no-shadow */
export enum SiDeviceState {
    Closed = 0,
    Opening = 1,
    Opened = 2,
    Closing = 3,
}
/* eslint-enable no-unused-vars,no-shadow */
 
export interface ISiDeviceDriverData<T> {
    driver: T;
}
 
export class DeviceClosedError extends utils.SiError {}
 
export class SiDeviceStateChangeEvent extends utils.Event<'stateChange'> {
    constructor(
                public siDevice: ISiDevice<ISiDeviceDriverData<unknown>>,
                public state: SiDeviceState,
    ) {
        super();
    }
}
export class SiDeviceReceiveEvent extends utils.Event<'receive'> {
    constructor(
                public siDevice: ISiDevice<ISiDeviceDriverData<unknown>>,
                public uint8Data: number[],
    ) {
        super();
    }
}
 
export type SiDeviceEvents = {
    'stateChange': SiDeviceStateChangeEvent,
    'receive': SiDeviceReceiveEvent,
};
 
export interface ISiDevice<T extends ISiDeviceDriverData<unknown>>
        extends utils.IEventTarget<SiDeviceEvents>
{
    name: string;
    ident: string;
    state: SiDeviceState;
    setState: (newState: SiDeviceState) => void;
    data: T;
    siTargetMultiplexer?: ISiTargetMultiplexer;
    open: () => Promise<ISiDevice<T>>;
    close: () => Promise<ISiDevice<T>>;
    receiveLoop: () => void;
    shouldStopReceivingBecauseOfError: (error: unknown) => boolean;
    receive: () => Promise<number[]>;
    send: (buffer: number[]) => Promise<unknown>;
}