master
Henry Jameson 2 years ago
parent daedc49e6b
commit 723837353b
  1. 35
      index.js
  2. 40
      statuslogger.js

@ -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) {
if (status.newCard) {
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}`)
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' })
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()

@ -14,40 +14,44 @@ export const Feedback = () => {
spinner: spinner[0]
}
return {
warn(string) {
console.warn(wrn('[!]') + ' ' + string)
warn(...string) {
console.warn(wrn('[!]') + ' ' + string.join(' '))
},
info(string) {
console.info(inf('[ ]') + ' ' + string)
info(...string) {
console.info(inf('[ ]') + ' ' + string.join(' '))
},
error(string) {
console.error(err('[!]') + ' ' + string)
error(...string) {
console.error(err('[!]') + ' ' + string.join(' '))
},
lcd0(string) {
lcd.printLineSync(0, string)
if (!status.hasLCD) return
status.lcd.printLineSync(0, string)
},
lcd1(string) {
lcd.printLineSync(1, string)
if (!status.hasLCD) return
status.lcd.printLineSync(1, string)
},
lcd2(string) {
lcd.printLineSync(2, string)
if (!status.hasLCD) return
status.lcd.printLineSync(2, string)
},
lcd3(string) {
lcd.printLineSync(3, string)
if (!status.hasLCD) return
status.lcd.printLineSync(3, string)
},
initLCD() {
this.info('Initializing LCD...')
let lcd = new LCD( 1, 0x27, 16, 2 );
return lcd
status.lcd = new LCD( 1, 0x27, 20, 4 );
return status.lcd
.begin()
.then(() => {
status.hasLCD = tru
status.hasLCD = true
this.info('LCD Initialized!')
lcd.clearSync()
lcd.printLineSync(0, 'Wangan Midnight ')
lcd.printLineSync(1, ' Maximum Tune 3DX+')
lcd.printLineSync(2, ' IC card support ')
lcd.printLineSync(3, ' by HJ (and GXTX)')
status.lcd.clearSync()
status.lcd.printLineSync(0, 'Wangan Midnight ')
status.lcd.printLineSync(1, ' Maximum Tune 3DX+')
status.lcd.printLineSync(2, ' IC card support ')
status.lcd.printLineSync(3, ' by HJ (and GXTX)')
})
.catch((e) => {
status.hasLCD = false

Loading…
Cancel
Save