1/** 2 * Copyright 2020 The Pigweed Authors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 * use this file except in compliance with the License. You may obtain a copy of 6 * the License at 7 * 8 * https://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 * License for the specific language governing permissions and limitations under 14 * the License. 15 */ 16 17 18/** @see https://wicg.github.io/serial/#paritytype-enum */ 19type ParityType = 'none'|'even'|'odd'; 20 21/** @see https://wicg.github.io/serial/#serialoptions-dictionary */ 22interface SerialOptions { 23 baudrate: number; 24 databits?: number; 25 stopbits?: number; 26 parity?: ParityType; 27 buffersize?: number; 28 rtscts?: boolean; 29} 30 31/** @see https://wicg.github.io/serial/#serialport-interface */ 32declare class SerialPort { 33 readonly readable: ReadableStream<Uint8Array>; 34 readonly writable: WritableStream<Uint8Array>; 35 36 open(options?: SerialOptions): Promise<void>; 37 close(): void; 38} 39 40/** 41 * @see https://source.chromium.org/chromium/chromium/src/+/master:third_party/blink/renderer/modules/serial/serial_port_filter.idl 42 */ 43interface SerialPortFilter { 44 usbVendorId?: number; 45 usbProductId?: number; 46} 47 48/** 49 * @see https://source.chromium.org/chromium/chromium/src/+/master:third_party/blink/renderer/modules/serial/serial_port_request_options.idl 50 */ 51interface SerialPortRequestOptions { 52 filters?: SerialPortFilter[]; 53} 54 55/** 56 * @see https://source.chromium.org/chromium/chromium/src/+/master:third_party/blink/renderer/modules/serial/serial_connection_event_init.idl 57 */ 58interface SerialConnectionEventInit extends EventInit { 59 port: SerialPort; 60} 61 62/** 63 * @see https://source.chromium.org/chromium/chromium/src/+/master:third_party/blink/renderer/modules/serial/serial_connection_event.idl 64 */ 65declare class SerialConnectionEvent extends Event { 66 constructor(type: string, eventInitDict: SerialConnectionEventInit); 67 readonly port: SerialPort; 68} 69 70/** @see https://wicg.github.io/serial/#serial-interface */ 71declare class Serial extends EventTarget { 72 onconnect(): ((this: this, ev: SerialConnectionEvent) => any)|null; 73 ondisconnect(): ((this: this, ev: SerialConnectionEvent) => any)|null; 74 getPorts(): Promise<SerialPort[]>; 75 requestPort(options?: SerialPortRequestOptions): Promise<SerialPort>; 76 addEventListener( 77 type: 'connect'|'disconnect', 78 listener: (this: this, ev: SerialConnectionEvent) => any, 79 useCapture?: boolean): void; 80 addEventListener( 81 type: string, 82 listener: EventListenerOrEventListenerObject|null, 83 options?: boolean|AddEventListenerOptions): void; 84 removeEventListener( 85 type: 'connect'|'disconnect', 86 callback: (this: this, ev: SerialConnectionEvent) => any, 87 useCapture?: boolean): void; 88 removeEventListener( 89 type: string, 90 callback: EventListenerOrEventListenerObject|null, 91 options?: EventListenerOptions|boolean): void; 92} 93 94/** @see https://wicg.github.io/serial/#extensions-to-the-navigator-interface */ 95interface Navigator { 96 readonly serial: Serial; 97} 98 99/** 100 * @see https://wicg.github.io/serial/#extensions-to-workernavigator-interface 101 */ 102interface WorkerNavigator { 103 readonly serial: Serial; 104} 105