Book on the wrist

Posted on
  • Hi,

    I'm creating a kind of e-book reader for the Bangle. The app preloaded with a small part of Wuthering Heights is on my app loader (edit: not anymore). The app customizer is only a placeholder for now, just click upload to install the app.

    The code is here.

    I want the user to be able to get a .txt version of a book from https://www.gutenberg.org/ (e.g. the attached wuthering-heights.txt which is 700 kB) and upload it to the app cusomizer where some preprocessing will be made before the app and book is loaded to the Bangle.

    I'm not sure how to properly upload the book .txt-file and read it into a variable for manipulation. Is there a limit for how much memory a variable can occupy on the app customizer?

    I think I need to divide the book up in chunks that the app can manage without hitting ram limits. My first thought was to have a JSON-file for these chunks and read them into a variable when needed, but I suspect the size of the JSON-file would be a problem in and of itself? So what I really need to do would be dividing the book up in several files instead (book1, book2, etc.). Does that sound right?

    If anyone can help with some clarification on this it would be much appreciated! :)


    1 Attachment

  • I think the customizer will not be a problem, 700k in a variable in a browser should be normal stuff. Imagine images etc. beeing loaded into variables.
    In the gpstrek app, the route and its waypoint are loaded from one big file by storing offsets into that file in a variable. I read the file completely and build this index on the first load, but you could build your index in the customizer and upload it as json. Imageclock does something like that for the resources file containing all images for the watchface.
    You could just read a few k into memory at a time and store the indices for the previous and upcoming chunk somewhere to load them as soon as needed. The chunk size would need to be a tradeoff between index size and used RAM per chunk.
    I had really big files from the recorder, so I would expect the file system to handle those files just fine.

  • divide the book up in chunks that the app can manage without hitting ram limits

    If you upload it as a plain text file, you can use require("Storage").read(name, offset, length) to read in chunks. Memory should not be a problem, as it returns a memory-mapped String that points to the ROM anyway.

  • Great, thank you for your insight @halemmerich and @rigrig! Very helpful :) I might come back for more ;)

  • That sounds like a great idea! Yes, the app loader should handle large files (and their upload) just fine. To test I think you could also upload manually with the Web IDE.

    As @rigrig mentioned, require("Storage").read(name, offset, length) would then be the way to go to read just a part at a time.

  • Thanks @Gordon! I tested require("Storage").read(name, offset, length) with my code yesterday and it worked pretty good, but I didn't get it to behave exactly as I want yet. I think it's just a matter of me doing some more testing to get to know the function a little better 👍.

  • @Ganblejs Did you ever finish this?

  • Sorry to say I didn't! Feel free to use and build on the code.

    If I start working on it again I'll leave a note here first.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Book on the wrist

Posted by Avatar for Ganblejs @Ganblejs

Actions