DanTheMan827 / ntag215-puck.js

https://dantheman827.github.io/ntag215-puck.js/
MIT License
22 stars 14 forks source link

Pixljs Support? #25

Open christopher-roelofs opened 2 years ago

christopher-roelofs commented 2 years ago

Can pixljs support be added? It looks like the firmware patch could support several eapruino boards with the same hardware but I think pixljs has the most potential with the lcd.

DanTheMan827 commented 2 years ago

The script may already work for the pixl.js provided that the appropriate custom firmware is built for it, but I don't have a pixl that I could actually test with, so I can't verify.

Here's the custom firmware built for pixl.js if you want to try

espruino_2v15.1_pixljs.zip

The firmware patch itself should work on Puck (Including Lite), Pixl, and Bangle (1 and 2), but the script has no special accommodations for hardware with screens

christopher-roelofs commented 2 years ago

Thanks. My pixljs hasn't arrived yet but I took some time today and built the firmware with your patch. I'm planning on starting with your script and build up from there. In a reddit post, you mentioned issues with the newest firmware. We're you able to resolve those?

DanTheMan827 commented 2 years ago

Since posting that, I've moved everything important into native code in the custom firmware, you have the NTAG215 javascript object that handles all the setup and NFC communication.

christopher-roelofs commented 2 years ago

I was able to load up the custom firmware and test the script with only a few modifications and it's working as expected. I noticed you had custom firmware for the banglejs watches but since they are using different chips, I don't think they will support the add ntag lib you created. With that said, I think we can close this.

Is there any way to get the amiibo id or name from the tag? I see you have get tag info but I'm not sure how to get the values in text.

DanTheMan827 commented 2 years ago

getTagInfo returns the minimal information needed to identify an amiibo and to decrypt the nickname given.

The function slices data off the full tag, so to reconstruct it you would reconstruct as follows:

After that, everything is in the same place as an encrypted tag, except for the game data.

christopher-roelofs commented 2 years ago

You are right, the banglejs2 has the same chip as the puck and pixl. It is the original bangle that has a nRF52832. I Actually own a banglejs2 so I should try the custom firmware and see if it works.

The biggest changes so far I made to the script is identifying the pixl vs the puck from the BOARD and then using BTN1 instead of BTN. I could test it again but I don't think BTN was working. Beyond that, I'm hoping to print the current tag information to the LCD.

Trying to wrap my head around how to convert the bytes to get the head and tail values mentioned here:

To determine amiibo model type, use data from page #21 and #22. Page #21 (bytes[84..<88]) is the "head" and page #22 (bytes[88..<92]) is the "tail" - you can use these values at amiiboapi.com.

DanTheMan827 commented 2 years ago

https://stackoverflow.com/questions/34309988/byte-array-to-hex-string-conversion-in-javascript

DanTheMan827 commented 2 years ago

Reopened because I want to implement at least basic support for the pixl.js (and the other capable espruino hardware)

I don't have any devices with a screen, but I figure I could at minimum make use of the menu module shared across the different devices

christopher-roelofs commented 2 years ago

Instead of trying to keep one script for all the devices, I stripped out the puck specific functionality I didn't care about to reduce the bloat. Not sure if you want to re-use anything.

https://github.com/christopher-roelofs/ntag215-puck.js/blob/master/pixl.js

Also, based on the comments from the Espruino creator, both bangle and bangle2 don't have the same nfc functionality so I think the only official boards applicable for this are puck, pixl and the MDBT42Q Breakout

DanTheMan827 commented 2 years ago

That's unfortunate that the bangle devices don't have the NFC capability.

As far as a single script for multiple boards, I use terser to minify the code and that removes dead code paths as part of the minification and optimization.

So, if you set a constant to a value and then check that value, it will evaluate the if and remove that code branch entirely if the check fails.

Think if it like how you might use preprocessor conditions in a language like C or C++ to only build certain code paths.