import type { ESPLoader, FlashOptions } from "esptool-js"; export interface ESPFile { data: string; address: number; fileName?: string; } export interface FlashProgress { fileIndex: number; fileName: string; written: number; total: number; } export interface PartitionEntry { name: string; type: number; subType: number; offset: number; size: number; flags: number; endOffset: number; typeString: string; subTypeString: string; sizeFormatted: string; } export interface PartitionTable { entries: PartitionEntry[]; offset: number; isValid: boolean; totalSize: number; checksumValid: boolean; metadata: { detectedAt: number; readAt: Date; chipType?: string; flashSize?: number; }; } export interface PartitionDetectionResult { found: boolean; offset?: number; table?: PartitionTable; errors: string[]; warnings: string[]; } export interface ReadFlashOptions { offset: number; size: number; progressCallback?: (bytesRead: number, totalBytes: number) => void; } export interface FlashRegion { offset: number; size: number; data: Uint8Array; } export type FirmwareFileType = "bootloader" | "partition_table" | "app" | "ota_data" | "nvs" | "phy_init" | "unknown"; export interface FirmwareFileInfo { type: FirmwareFileType; isRequired: boolean; description: string; recommendedAddress?: number; validAddresses?: number[]; chipSpecific?: boolean; } export interface ChipFirmwareRequirements { chipName: string; bootloaderAddress: number; requiredFiles: { [key in FirmwareFileType]?: FirmwareFileInfo; }; commonAddresses: { [key in FirmwareFileType]?: number; }; } export interface FileValidationResult { isValid: boolean; warnings: string[]; errors: string[]; suggestions: string[]; detectedType?: FirmwareFileType; } export interface FirmwareValidationSummary { isComplete: boolean; missingRequired: FirmwareFileType[]; addressConflicts: Array<{ file1: string; file2: string; address: number; }>; warnings: string[]; suggestions: string[]; } export type { ESPLoader, FlashOptions }; export interface ESPLoaderState { transport: Transport | null; esploader: ESPLoader | null; chip: string | null; isConnected: boolean; isConsoleConnected: boolean; isLoading: boolean; isFlashing: boolean; isErasing: boolean; isReadingPartitions: boolean; error: Error | string | null; terminalOutput: string[]; flashProgress: FlashProgress | null; baudrate: number; consoleBaudrate: number; consoleDataBits: 7 | 8; consoleStopBits: 1 | 2; consoleParity: "none" | "even" | "odd"; debugLogging: boolean; partitionTable: PartitionTable | null; lastPartitionRead: Date | null; } export interface ESPLoaderActions { connect: (port?: SerialPort) => Promise; disconnect: () => Promise; program: (files: ESPFile[], options?: Partial>) => Promise; eraseFlash: () => Promise; startConsole: (port?: SerialPort) => Promise; stopConsole: () => Promise; resetDevice: () => Promise; getTrace: () => Promise; setBaudrate: (rate: number) => void; setConsoleBaudrate: (rate: number) => void; setConsoleDataBits: (bits: 7 | 8) => void; setConsoleStopBits: (bits: 1 | 2) => void; setConsoleParity: (parity: "none" | "even" | "odd") => void; setDebugLogging: (enabled: boolean) => void; clearTerminal: () => void; checkConnection: () => Promise; attemptConnectionRecovery: () => Promise; readPartitionTable: (forceRefresh?: boolean) => Promise; detectPartitionTable: () => Promise; readFlashRegion: (offset: number, size: number, progressCallback?: (bytesRead: number, totalBytes: number) => void) => Promise; parsePartitionTableBinary: (data: Uint8Array, offset: number) => PartitionTable; exportPartitionTableCsv: () => string; getPartitionByName: (name: string) => PartitionEntry | null; getPartitionsByType: (type: number | string) => PartitionEntry[]; } export type Transport = any; export type { WebSerialCompatibility } from "./utils/browserCompatibility"; declare global { interface SerialPort { readonly readable: ReadableStream | null; readonly writable: WritableStream | null; open(options: SerialOptions): Promise; close(): Promise; getInfo(): SerialPortInfo; getSignals(): Promise; setSignals(signals: SerialOutputSignals): Promise; addEventListener(type: "disconnect" | "connect", listener: (this: SerialPort, ev: Event) => any, options?: boolean | AddEventListenerOptions): void; removeEventListener(type: "disconnect" | "connect", listener: (this: SerialPort, ev: Event) => any, options?: boolean | EventListenerOptions): void; } interface SerialOptions { baudRate: number; dataBits?: 7 | 8; stopBits?: 1 | 2; parity?: "none" | "even" | "odd"; bufferSize?: number; flowControl?: "none" | "hardware"; } interface SerialPortInfo { usbVendorId?: number; usbProductId?: number; } interface SerialInputSignals { dataCarrierDetect: boolean; clearToSend: boolean; ringIndicator: boolean; dataSetReady: boolean; } interface SerialOutputSignals { dataTerminalReady?: boolean; requestToSend?: boolean; break?: boolean; } interface Serial { requestPort(options?: SerialPortRequestOptions): Promise; getPorts(): Promise; } interface SerialPortRequestOptions { filters?: SerialPortFilter[]; } interface SerialPortFilter { usbVendorId?: number; usbProductId?: number; } }