feat(machine): add HAL IPC bridge for real hardware in Electron
HAL hardware drivers (serialport) run in the main process since they need Node.js. The renderer communicates via IPC for all hardware ops. - hal-service.ts: bridge between HAL drivers and Electron IPC - main.ts: HAL IPC handlers (init, dispense, validator stack/reject) - preload.ts: expose HAL API to renderer via contextBridge - atm.ts: IPC-based production init with validator event wiring - hal.ts: add 'hold' mode for escrow (async stack/reject decision) - electron.d.ts: HAL type declarations for window.electronAPI Bills go to escrow first; the renderer checks balance before accepting. Falls back to Lightning-only mock mode if HAL init fails. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
bb73e13e48
commit
2605c44ef8
7 changed files with 515 additions and 24 deletions
|
|
@ -49,6 +49,30 @@ contextBridge.exposeInMainWorld('electronAPI', {
|
|||
}) => ipcRenderer.invoke('state:record-transaction', tx),
|
||||
emptyCashbox: () => ipcRenderer.invoke('state:empty-cashbox'),
|
||||
|
||||
// HAL hardware (runs in main process, exposed via IPC)
|
||||
halInit: (config: any): Promise<{ success: boolean; error?: string }> =>
|
||||
ipcRenderer.invoke('hal:init', config),
|
||||
halDispense: (amounts: any): Promise<any> => ipcRenderer.invoke('hal:dispense', amounts),
|
||||
halEnableValidator: (): Promise<void> => ipcRenderer.invoke('hal:enable-validator'),
|
||||
halDisableValidator: (): Promise<void> => ipcRenderer.invoke('hal:disable-validator'),
|
||||
halStackBill: (): Promise<void> => ipcRenderer.invoke('hal:stack-bill'),
|
||||
halRejectBill: (): Promise<void> => ipcRenderer.invoke('hal:reject-bill'),
|
||||
halCleanup: (): Promise<void> => ipcRenderer.invoke('hal:cleanup'),
|
||||
|
||||
// HAL event listeners (main process → renderer)
|
||||
onHalBillRead: (callback: (denomination: number) => void) => {
|
||||
ipcRenderer.on('hal:bill-read', (_event, denomination) => callback(denomination))
|
||||
},
|
||||
onHalBillInserted: (callback: (denomination: number) => void) => {
|
||||
ipcRenderer.on('hal:bill-inserted', (_event, denomination) => callback(denomination))
|
||||
},
|
||||
onHalBillRejected: (callback: (reason: string) => void) => {
|
||||
ipcRenderer.on('hal:bill-rejected', (_event, reason) => callback(reason))
|
||||
},
|
||||
onHalError: (callback: (error: string) => void) => {
|
||||
ipcRenderer.on('hal:error', (_event, error) => callback(error))
|
||||
},
|
||||
|
||||
// Platform info
|
||||
platform: process.platform,
|
||||
})
|
||||
|
|
@ -75,6 +99,18 @@ declare global {
|
|||
bills: { denomination: number; count: number }[]
|
||||
}) => Promise<void>
|
||||
emptyCashbox: () => Promise<void>
|
||||
// HAL hardware IPC
|
||||
halInit: (config: any) => Promise<{ success: boolean; error?: string }>
|
||||
halDispense: (amounts: any) => Promise<any>
|
||||
halEnableValidator: () => Promise<void>
|
||||
halDisableValidator: () => Promise<void>
|
||||
halStackBill: () => Promise<void>
|
||||
halRejectBill: () => Promise<void>
|
||||
halCleanup: () => Promise<void>
|
||||
onHalBillRead: (callback: (denomination: number) => void) => void
|
||||
onHalBillInserted: (callback: (denomination: number) => void) => void
|
||||
onHalBillRejected: (callback: (reason: string) => void) => void
|
||||
onHalError: (callback: (error: string) => void) => void
|
||||
platform: NodeJS.Platform
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue