|
|
|
@ -3,7 +3,7 @@ import fetch from 'node-fetch' |
|
|
|
|
import fs from 'fs' |
|
|
|
|
import { Feedback } from './statuslogger.js' |
|
|
|
|
|
|
|
|
|
const CARDS_LOCATION = '/home/snufkin/Repos/apps/YACards/' |
|
|
|
|
const CARDS_LOCATION = '/home/dietpi/YACards/' |
|
|
|
|
const logger = Feedback() |
|
|
|
|
logger.initLCD() |
|
|
|
|
|
|
|
|
@ -25,27 +25,33 @@ nfc.on('error', err => { |
|
|
|
|
logger.error('[PCSC]:', err); |
|
|
|
|
}); |
|
|
|
|
nfc.on('reader', reader => { |
|
|
|
|
logger.info(reader) |
|
|
|
|
reader.on('card', card => { |
|
|
|
|
logger.info(`[PCSC] Card ${card.uid} scanned`) |
|
|
|
|
logger.lcd3('Card:' + card.uid.slice(0, 20 - 5)) |
|
|
|
|
if (status.card === null && !status.guestPlay) { |
|
|
|
|
status.card = card.uid |
|
|
|
|
status.confirmed = false |
|
|
|
|
status.countdown = 5 |
|
|
|
|
status.newCard = !fs.existsSync(CARDS_LOCATION + card.uid + '.track_0') |
|
|
|
|
logger.info(`[YACE] Telling YACE to insert ${card.uid}`) |
|
|
|
|
if (status.newCard) { |
|
|
|
|
logger.info(`[EABU] New card!`) |
|
|
|
|
logger.lcd2(' New card! ') |
|
|
|
|
status.newCardRegistration = true |
|
|
|
|
status.countdown = 600 // seconds
|
|
|
|
|
fetch('http://localhost:8082/api/v1/loadedCard?cardname=' + card.uid, { method: 'POST' }) |
|
|
|
|
if (status.readyCard) { |
|
|
|
|
status.card = card.uid |
|
|
|
|
status.confirmed = false |
|
|
|
|
status.countdown = 5 |
|
|
|
|
status.newCard = !fs.existsSync(CARDS_LOCATION + card.uid + '.track_0') |
|
|
|
|
logger.info(`[YACE] Telling YACE to insert ${card.uid}`) |
|
|
|
|
logger.info(`[EABU] New card!`) |
|
|
|
|
logger.lcd2(' New card! ') |
|
|
|
|
status.newCardRegistration = true |
|
|
|
|
status.countdown = 600 // seconds
|
|
|
|
|
fetch('http://127.0.0.1:8082/api/v1/loadedCard?cardname=' + card.uid, { method: 'POST' }) |
|
|
|
|
} else { |
|
|
|
|
logger.lcd2('Scan card only when ') |
|
|
|
|
logger.lcd3('game asks for it !! ') |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
logger.info(`[EABU] Existing card!`) |
|
|
|
|
logger.lcd2(' Welcome back! ') |
|
|
|
|
if (status.readyCard) { |
|
|
|
|
logger.info(`[EABU] Inserting...`) |
|
|
|
|
fetch('http://localhost:8082/api/v1/insertedCard?cardname=' + card.uid, { method: 'POST' }) |
|
|
|
|
fetch('http://127.0.0.1:8082/api/v1/insertedCard?cardname=' + card.uid, { method: 'POST' }) |
|
|
|
|
} else { |
|
|
|
|
logger.info(`[EABU] Not inserting as game isn't ready for it...`) |
|
|
|
|
logger.lcd2('Scan card only when ') |
|
|
|
@ -69,7 +75,7 @@ nfc.on('reader', reader => { |
|
|
|
|
|
|
|
|
|
const pollYACE = () => { |
|
|
|
|
if (status.card !== null) { |
|
|
|
|
fetch('http://localhost:8082/api/v1/hasCard') |
|
|
|
|
fetch('http://127.0.0.1:8082/api/v1/hasCard') |
|
|
|
|
.then(res => res.json()) |
|
|
|
|
.then(bool => { |
|
|
|
|
if (status.countdown > 0) { |
|
|
|
@ -86,7 +92,7 @@ const pollYACE = () => { |
|
|
|
|
logger.lcd1('FAILED??????????????') |
|
|
|
|
logger.error('[YACE] Could not confirm card presence with emulator!') |
|
|
|
|
logger.error('[YACE] Telling YACE to load dummy just in case') |
|
|
|
|
fetch('http://localhost:8082/api/v1/loadedCard?cardname=dummy', { method: 'POST' }) |
|
|
|
|
fetch('http://127.0.0.1:8082/api/v1/loadedCard?cardname=dummy', { method: 'POST' }) |
|
|
|
|
setTimeout(pollYACE, 1000) |
|
|
|
|
} else { |
|
|
|
|
// insertion confirmed! waiting for ejection
|
|
|
|
@ -100,7 +106,7 @@ const pollYACE = () => { |
|
|
|
|
status.newCard = false |
|
|
|
|
status.renewPossible = false |
|
|
|
|
logger.info('[YACE] Telling YACE to load dummy') |
|
|
|
|
fetch('http://localhost:8082/api/v1/loadedCard?cardname=dummy', { method: 'POST' }) |
|
|
|
|
fetch('http://127.0.0.1:8082/api/v1/loadedCard?cardname=dummy', { method: 'POST' }) |
|
|
|
|
} else { |
|
|
|
|
logger.lcd1(' Card renewed! ') |
|
|
|
|
status.newCard = false |
|
|
|
@ -114,7 +120,7 @@ const pollYACE = () => { |
|
|
|
|
setTimeout(pollYACE, 2000) |
|
|
|
|
}) |
|
|
|
|
} else { |
|
|
|
|
fetch('http://localhost:8082/api/v1/hasCard') |
|
|
|
|
fetch('http://127.0.0.1:8082/api/v1/hasCard') |
|
|
|
|
.then(res => res.json()) |
|
|
|
|
.then(bool => { |
|
|
|
|
if (status.guestPlay) { |
|
|
|
@ -131,27 +137,32 @@ const pollYACE = () => { |
|
|
|
|
setTimeout(pollYACE, 200) |
|
|
|
|
}) |
|
|
|
|
.catch(err => { |
|
|
|
|
logger.error('[EABU] Failure polling YACE') |
|
|
|
|
logger.error('[EABU] Failure polling YACE', err) |
|
|
|
|
setTimeout(pollYACE, 2000) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const pollYACE2 = () => { |
|
|
|
|
fetch('http://localhost:8082/api/v1/readyCard') |
|
|
|
|
fetch('http://127.0.0.1:8082/api/v1/readyCard') |
|
|
|
|
.then(res => res.json()) |
|
|
|
|
.then(bool => { |
|
|
|
|
status.readyCard = bool |
|
|
|
|
if (status.readyCard) { |
|
|
|
|
logger.lcd0('Wangan Maxi3DX+ ') |
|
|
|
|
logger.lcd1('!SCAN YOUR CARD NOW!') |
|
|
|
|
} else { |
|
|
|
|
logger.lcd0('Wangan Maxi3DX+ ') |
|
|
|
|
logger.lcd1('Waiting for game... ') |
|
|
|
|
} |
|
|
|
|
setTimeout(pollYACE2, 500) |
|
|
|
|
}) |
|
|
|
|
.catch(err => { |
|
|
|
|
logger.error('[EABU] Failure polling YACE (loop2)') |
|
|
|
|
setTimeout(pollYACE2, 2000)})} |
|
|
|
|
logger.error('[EABU] Failure polling YACE (loop2)', err) |
|
|
|
|
setTimeout(pollYACE2, 2000) |
|
|
|
|
logger.lcd0('/!\ Emulator offline') |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pollYACE() |
|
|
|
|
pollYACE2() |
|
|
|
|