fix(hal): re-initialize dispenser after errors
After a dispense error, the F56/Puloon drivers call close() which sets initialized=false. The next dispense would fail on a closed serial port. Now checks dispenser.initialized before each dispense and re-inits if needed, matching the lazy re-init pattern from brain.js (line 4072). Closes #29 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
0395aab3d1
commit
ab2ea0b811
2 changed files with 20 additions and 4 deletions
|
|
@ -93,10 +93,11 @@ export async function initializeHalServices(config: HalConfig): Promise<HalServi
|
|||
})
|
||||
|
||||
// Initialize dispenser
|
||||
await dispenser.init({
|
||||
const dispenserInitData = {
|
||||
fiatCode: valConfig.fiatCode,
|
||||
cassettes: dispConfig.cassettes,
|
||||
})
|
||||
}
|
||||
await dispenser.init(dispenserInitData)
|
||||
console.log('[HAL] Dispenser initialized')
|
||||
|
||||
// Start validator
|
||||
|
|
@ -121,6 +122,13 @@ export async function initializeHalServices(config: HalConfig): Promise<HalServi
|
|||
dispenseCash: async (amounts) => {
|
||||
console.log('[HAL] Dispensing:', amounts)
|
||||
|
||||
// Re-initialize dispenser if it was closed after a previous error
|
||||
if (!dispenser.initialized) {
|
||||
console.log('[HAL] Dispenser not initialized, re-initializing...')
|
||||
await dispenser.init(dispenserInitData)
|
||||
console.log('[HAL] Dispenser re-initialized')
|
||||
}
|
||||
|
||||
// Translate { denomination, count }[] to number[] by cassette position
|
||||
const notes: number[] = new Array(cassetteDenominations.length).fill(0)
|
||||
for (const { denomination, count } of amounts) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue