Support and General Use > Plugins/Viewers

fopen file in .rockbox dir

(1/1)

rockbox_dev123:
Hi,

I'm playing around and compiling my first Rockbox plugin with the simulator but I'm having trouble opening files.

I'm doing this:

--- Code: ---    if (rb->file_exists(ROCKBOX_DIR"/foo/bar.txt"))
    {
        rb->splashf(2*HZ, "exists");
        dp = fopen(ROCKBOX_DIR"/foo/bar.txt", "rt");
        if (dp == NULL)
        {
            rb->splashf(2*HZ, "%d", errno);
            return PLUGIN_OK;
        }
        else
        {
            /* I never get here */
            do_something_with_bar();
        }
    }

--- End code ---

Which gives me a splash confirming that my file exists in the location I am trying to access it.

However, when I make the fopen call to the same path I get an errno value of 2 which I believe indicates ENOENT No such file or directory. Do I need to transform the path somehow?

EDIT:

I've managed to get it to work by placing my files in the same directory as the rockboxui binary.

e.g. if you are trying to access a file like this:

--- Code: ---open("/foo/bar.txt", "rt");
--- End code ---
It will work if you place this in the build directory where the simulator is:

--- Code: ---├── simdisk
├── foo
│   └── bar.txt
└── rockboxui

--- End code ---

I'll work out if I need to change the path once the plugin is finished and I'm ready to test on hardware.

rockbox_dev123:
I've finished writing my plugin and I'm ready to test it on my iPod. Unfortunately, I've found that when doing

--- Code: ---rb->srand(*rb->current_tick);
--- End code ---
to get a random value that if I call my plugin on startup, as the current tick is always the same the value is not random.

I've pored through the codebase and had a look at /firmware/libc/gmtime.c but I couldn't find a UNIX epoch time struct anywhere that I could use with srand like a traditional time() call.

Can anyone advise on how I can get a good seed for srand on the players boot?

Thanks in advance

Bilgus:
yeah our random is deterministic same srand same 'random' numbers
I assume this is in the sim? On an actual device I'd expect enough variability by the time you got into the plugin
to make this not occur maybe you can add in something that makes the wait a bit more variable prior to the srand call?

maybe something like waiting a bit:

--- Code: ---static void wait(void)
{
#ifdef SIMULATOR
    rb->splashf(0, "Press any button.");
    while (rb->get_action(CONTEXT_STD, 1) == ACTION_NONE)
    {
        rb->yield();
    }
#endif
}
--- End code ---

rockbox_dev123:
I managed to finish my plugin. It's a port of display-dhammapada with an updated translation courtesy of the BPS. It's not in a state to be upstreamed so I'm uploading it here instead for anyone interested.

The plugin selects a random set of verses and displays them verse by verse using simple_viewer.c. On an iPod Classic I can press skip backwards, menu or select to advance the verses until the end of the range.

I have the plugin set to run on startup now and it works well.


--- Quote ---display-dhammapada was originally written by Richard Cepas <rch@online.lt> and later updated by bodhi.zazen <bodhizazen at fedoraproject dot org> and paultag <paultag at ubuntu.com>
--- End quote ---

Place dhammapada-english-bps.txt into .rockbox/dhammapada/dhammapada-english-bps.txt then you can compile dhammapada.c like you would any other C plugin. Docs here.

rockbox_dev123:
Up to ~70 people downloaded the plugin so there must be some interest.

I spent time fixing bugs and polishing the plugin.

Some of the changes:

* The text file containing the verses has been modified to change the chapter numbering to Roman numerals. This prevents accidentally treating the chapter numbers as verses when reading the file.
* I added missing verses 246, 247 which were accidentally omitted. I've verified that all verses are now present in the file.
* There is now a header which displays "Dhammapada verses x - y" when displaying a range and "Dhammapada verse x" when displaying a single verse.
* The sizes of variables should be more accurate. I've verified that the longest verse range fits within the buffer.
* The marks struct has been rewritten to reflect the new structure of the text file for this plugin compared with the original display-dhammapada format.
* If the selected verse is supposed to be viewed with surrounding verses for context, they're no longer displayed as separate screens. They're now combined into a single string which is nicely scrollable by the simple_viewer plugin.
EDIT: To compile for hardware and not just the simulator, the call to strcmp has be changed to rb->strcmp. I forgot to do this before posting. I can't reupload an attachment without making a separate post. It's easy enough to make that change!

Navigation

[0] Message Index

Go to full version