|
|
|
@ -6,7 +6,13 @@ const err = chalk.bold.redBright |
|
|
|
|
const inf = chalk.blueBright |
|
|
|
|
const wrn = chalk.yellowBright |
|
|
|
|
|
|
|
|
|
const SPINNER = ['/', '-', '\\', '|'] |
|
|
|
|
const SPIN_CHARS = [ |
|
|
|
|
[0x14,0x1c,0x15,0x1,0x6,0x0,0x00,0x0], |
|
|
|
|
[0x14,0x1c,0x15,0x1,0x6,0x0,0x10,0x0], |
|
|
|
|
[0x14,0x1c,0x15,0x1,0x6,0x0,0x14,0x0], |
|
|
|
|
[0x14,0x1c,0x15,0x1,0x6,0x0,0x15,0x0] |
|
|
|
|
] |
|
|
|
|
const SPINNER = SPIN_CHARS.map((c, i) => i) |
|
|
|
|
|
|
|
|
|
const STATUS_LINE = [ |
|
|
|
|
'Status: _______' |
|
|
|
@ -78,7 +84,7 @@ const THANKS_FOR_PLAYING = [ |
|
|
|
|
'time. t. hj', |
|
|
|
|
] |
|
|
|
|
|
|
|
|
|
export const Feedback = () => { |
|
|
|
|
export const Feedback = ({ bus, noLCD }) => { |
|
|
|
|
const status = { |
|
|
|
|
hasLCD: false, |
|
|
|
|
spinnerIndex: 0, |
|
|
|
@ -98,7 +104,7 @@ export const Feedback = () => { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const quipSelect = () => { |
|
|
|
|
if (status.messageCoundown !== 0) { |
|
|
|
|
if (status.messageCoundown > 0) { |
|
|
|
|
switch (status.messageType) { |
|
|
|
|
case 'cardPresent': |
|
|
|
|
if (status.mgmgtCard === 'guest') { |
|
|
|
@ -118,9 +124,15 @@ export const Feedback = () => { |
|
|
|
|
return RENEW_CARD |
|
|
|
|
case 'renew_ok': |
|
|
|
|
return RENEW_CARD_OK |
|
|
|
|
default: |
|
|
|
|
return [ |
|
|
|
|
'--------------------', |
|
|
|
|
'ERROR: INVALID MSG!!', |
|
|
|
|
'--------------------', |
|
|
|
|
] |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
if (!status.playing) { |
|
|
|
|
if (!status.mgmtCard) { |
|
|
|
|
return IDLE |
|
|
|
|
} else { |
|
|
|
|
if (status.mgmtCard === 'guest') { |
|
|
|
@ -133,10 +145,10 @@ export const Feedback = () => { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const statusLineGenerator = () => { |
|
|
|
|
let countdownI = countdown > 0 |
|
|
|
|
let countdownI = status.countdown > 0 |
|
|
|
|
? `${status.countdown}`.padStart(3, ' ') |
|
|
|
|
: ' ' |
|
|
|
|
let mgmtCardI = 0 |
|
|
|
|
let mgmtCardI = '-' |
|
|
|
|
if (status.mgmtCard === true) mgmtCardI = 'P' |
|
|
|
|
if (status.mgmtCard === 'guest') mgmtCardI = 'G' |
|
|
|
|
let emuCardI = status.emuCard ? 'C' : '_' |
|
|
|
@ -152,7 +164,7 @@ export const Feedback = () => { |
|
|
|
|
return STATUS_LINE[0].replace('_______', statusLineGenerator()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const bufferGen = () => [ ...lineGen, ...quipSelect ] |
|
|
|
|
const bufferGen = () => [ lineGen(), ...quipSelect() ] |
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
setMgmtCard(MgmtCard) { |
|
|
|
@ -176,21 +188,21 @@ export const Feedback = () => { |
|
|
|
|
}, |
|
|
|
|
warn(...string) { |
|
|
|
|
console.warn(wrn('[!]') + ' ' + string.join(' ')) |
|
|
|
|
this.advanceSpinner() |
|
|
|
|
}, |
|
|
|
|
info(...string) { |
|
|
|
|
console.info(inf('[ ]') + ' ' + string.join(' ')) |
|
|
|
|
this.advanceSpinner() |
|
|
|
|
}, |
|
|
|
|
error(...string) { |
|
|
|
|
console.error(err('[!]') + ' ' + string.join(' ')) |
|
|
|
|
this.advanceSpinner() |
|
|
|
|
}, |
|
|
|
|
initLCD() { |
|
|
|
|
this.info('Initializing LCD...') |
|
|
|
|
|
|
|
|
|
const loop = () => { |
|
|
|
|
const buffer = bufferGen() |
|
|
|
|
|
|
|
|
|
this.advanceSpinner() |
|
|
|
|
//lcd.clearSync()
|
|
|
|
|
buffer.forEach((line, i) => lcd.printLineSync(i, line.substring(0, 20))) |
|
|
|
|
if (status.messageCountdown > 0) { |
|
|
|
|
status.messageCountdown-- |
|
|
|
@ -202,7 +214,7 @@ export const Feedback = () => { |
|
|
|
|
setTimeout(loop, 500) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
lcd = new LCD( 1, 0x27, 20, 4 ); |
|
|
|
|
lcd = new LCD(Number(bus), 0x27, 20, 4); |
|
|
|
|
lcd |
|
|
|
|
.begin() |
|
|
|
|
.then(() => { |
|
|
|
@ -213,6 +225,9 @@ export const Feedback = () => { |
|
|
|
|
lcd.printLineSync(1, ' Maximum Tune 3DX+') |
|
|
|
|
lcd.printLineSync(2, ' IC card support ') |
|
|
|
|
lcd.printLineSync(3, ' by HJ (and GXTX)') |
|
|
|
|
SPIN_CHARS.forEach((c, i) => { |
|
|
|
|
lcd.createCharSync(i, c) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
setTimeout(loop, 3000) |
|
|
|
|
}) |
|
|
|
@ -223,7 +238,9 @@ export const Feedback = () => { |
|
|
|
|
}, |
|
|
|
|
advanceSpinner() { |
|
|
|
|
if (status.spinnerIndex >= SPINNER.length) status.spinnerIndex = 0 |
|
|
|
|
status.spinner = SPINNER[status.spinnerIndex++] |
|
|
|
|
console.log(lcd) |
|
|
|
|
status.spinner = LCD.getChar(status.spinnerIndex++) |
|
|
|
|
console.log(status.spinner) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|