Rockbox.org home
Downloads
Release release
Dev builds dev builds
Extras extras
themes themes
Documentation
Manual manual
Wiki wiki
Device Status device status
Support
Forums forums
Mailing lists mailing lists
IRC IRC
Development
Bugs bugs
Patches patches
Dev Guide dev guide
translations translations
Search



Donate

Rockbox Technical Forums


Login with username, password and session length
Home Help Search Staff List Login Register
News:

Welcome to the Rockbox Technical Forums!

+  Rockbox Technical Forums
|-+  Support and General Use
| |-+  Plugins/Viewers
| | |-+  fopen file in .rockbox dir
« previous next »
  • Print
Pages: [1]

Author Topic: fopen file in .rockbox dir  (Read 654 times)

Offline rockbox_dev123

  • Member
  • *
  • Posts: 166
fopen file in .rockbox dir
« on: May 28, 2025, 03:26:44 PM »
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: [Select]
    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();
        }
    }

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: [Select]
open("/foo/bar.txt", "rt");It will work if you place this in the build directory where the simulator is:
Code: [Select]
├── simdisk
├── foo
│   └── bar.txt
└── rockboxui

I'll work out if I need to change the path once the plugin is finished and I'm ready to test on hardware.
« Last Edit: May 28, 2025, 03:38:28 PM by rockbox_dev123 »
Logged

Offline rockbox_dev123

  • Member
  • *
  • Posts: 166
Re: fopen file in .rockbox dir
« Reply #1 on: May 28, 2025, 06:53:21 PM »
I've finished writing my plugin and I'm ready to test it on my iPod. Unfortunately, I've found that when doing
Code: [Select]
rb->srand(*rb->current_tick);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
Logged

Offline Bilgus

  • Developer
  • Member
  • *
  • Posts: 1194
Re: fopen file in .rockbox dir
« Reply #2 on: May 29, 2025, 01:01:32 PM »
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: [Select]
static void wait(void)
{
#ifdef SIMULATOR
    rb->splashf(0, "Press any button.");
    while (rb->get_action(CONTEXT_STD, 1) == ACTION_NONE)
    {
        rb->yield();
    }
#endif
}
Logged

Offline rockbox_dev123

  • Member
  • *
  • Posts: 166
Re: fopen file in .rockbox dir
« Reply #3 on: June 02, 2025, 09:35:05 PM »
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>

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.
* dhammapada.c (7.92 kB - downloaded 83 times.)

* dump 250603-022456.png (1.05 kB, 320x240 - viewed 150 times.)

* dump 250603-022628.png (1.6 kB, 320x240 - viewed 146 times.)
* dhammapada-english-bps.txt (61.91 kB - downloaded 78 times.)
Logged

Offline rockbox_dev123

  • Member
  • *
  • Posts: 166
Re: fopen file in .rockbox dir
« Reply #4 on: June 18, 2025, 04:12:04 PM »
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!
* dhammapada.c (9.34 kB - downloaded 4 times.)
* dhammapada-english-bps.txt (64.4 kB - downloaded 2 times.)

* dump 250618-205655.png (1.3 kB, 320x240 - viewed 2 times.)

* dump 250618-204205.png (1.79 kB, 320x240 - viewed 3 times.)
« Last Edit: June 18, 2025, 04:22:08 PM by rockbox_dev123 »
Logged

  • Print
Pages: [1]
« previous next »
+  Rockbox Technical Forums
|-+  Support and General Use
| |-+  Plugins/Viewers
| | |-+  fopen file in .rockbox dir
 

  • SMF 2.0.19 | SMF © 2021, Simple Machines
  • Rockbox Privacy Policy
  • XHTML
  • RSS
  • WAP2

Page created in 0.048 seconds with 15 queries.