Skip to content

Commit

Permalink
Fix bulk writing random serial to N2 Elite
Browse files Browse the repository at this point in the history
Closes #708
  • Loading branch information
AbandonedCart committed Aug 10, 2023
1 parent 3b6f0ff commit 22ae70e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
22 changes: 22 additions & 0 deletions app/src/main/java/com/hiddenramblings/tagmo/amiibo/AmiiboFile.kt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,28 @@ open class AmiiboFile : Parcelable {
return dataList
}

suspend fun withRandomSerials(count: Int) : ArrayList<AmiiboData> {
val dataList: ArrayList<AmiiboData> = arrayListOf()
this@AmiiboFile.data?.let { tagData ->
coroutineScope {
(0 until count).map {
async(Dispatchers.IO) {
try {
AmiiboData(tagData).apply {
uID = Foomiibo.generateRandomUID()
}.also {
dataList.add(it)
}
} catch (e: Exception) {
Debug.warn(e)
}
}
}.awaitAll()
}
}
return dataList
}

companion object {
@JvmField
val CREATOR: Parcelable.Creator<AmiiboFile?> = object : Parcelable.Creator<AmiiboFile?> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class PuckGattService : Service() {
slotsCount = data[2].toInt()
listener?.onPuckDeviceProfile(slotsCount)
} else {
puckArray.add(data.copyOfRange(2, data.size))
puckArray.add(data[1].toInt(), data.copyOfRange(2, data.size))
if (puckArray.size == slotsCount) {
listener?.onPuckListRetrieved(puckArray, activeSlot)
}
Expand Down Expand Up @@ -444,7 +444,9 @@ class PuckGattService : Service() {
}

val deviceDetails: Unit
get() { sendCommand(ByteArray(2).apply { this[0] = PUCK.INFO.bytes }, null) }
get() {
sendCommand(ByteArray(2).apply { this[0] = PUCK.INFO.bytes }, null)
}

val deviceAmiibo: Unit
get() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,15 @@ class EliteBankFragment : Fragment(), EliteBankAdapter.OnAmiiboClickListener {
override fun onAmiiboDataClicked(amiiboFile: AmiiboFile?, count: Int) {
CoroutineScope(Dispatchers.IO).launch {
amiiboFile?.let {
val amiiboData = it.withRandomSerials(keyManager, count)
val amiiboData = it.withRandomSerials(count)
withContext(Dispatchers.Main) {
writeAmiiboDataCollection(amiiboData)
if (amiiboData.isEmpty()) {
Toasty(requireActivity()).Short(
R.string.fail_randomize
)
} else {
writeAmiiboDataCollection(amiiboData)
}
}
}
}
Expand Down

0 comments on commit 22ae70e

Please sign in to comment.