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
Search



Donate

Rockbox Technical Forums


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

Thank You for your continued support and contributions!

+  Rockbox Technical Forums
|-+  Rockbox Development
| |-+  Starting Development and Compiling
| | |-+  Error making a menu?
« previous next »
  • Print
Pages: [1] 2

Author Topic: Error making a menu?  (Read 3621 times)

Offline motionman95

  • Member
  • *
  • Posts: 108
  • aka coderkid
    • coderkid
Error making a menu?
« on: March 02, 2009, 11:38:14 PM »
I'm a rockbox noob, and, thanks to the helpful people on this forum, I've got my development platform all set up (thanks!). I'm playing with making a plugin, and so far all want to do is make a menu, but it's not working:

Code: [Select]
/***************************************************************************
 *             __________               __   ___.
 *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
 *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
 *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
 *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
 *                     \/            \/     \/    \/            \/
 * $Id: helloworld.c 17847 2008-06-28 18:10:04Z bagder $
 *
 * Copyright (C) 2002 Björn Stenberg
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 * KIND, either express or implied.
 *
 ****************************************************************************/
#include "plugin.h"
#include "menu.h"

/* welcome to the example rockbox plugin */

/* This macros must always be included. Should be placed at the top by
   convention, although the actual position doesn't matter */
PLUGIN_HEADER

/* here is a global api struct pointer. while not strictly necessary,
   it's nice not to have to pass the api pointer in all function calls
   in the plugin */
static const struct plugin_api* rb;

/* this is the plugin entry point */
enum plugin_status plugin_start(const struct plugin_api* api, const void* parameter)
{
    /* if you don't use the parameter, you can do like
       this to avoid the compiler warning about it */
    (void)parameter;

    /* if you are using a global api pointer, don't forget to copy it!
       otherwise you will get lovely "I04: IllInstr" errors... :-) */
    rb = api;

    /* now go ahead and have fun! */
    MAKE_MENU(menu, "RockLock", NULL, "Input Password", "Set Password")
switch (rb->do_menu(&menu, NULL))
{
    case 0: /* "Input Password" */
        rb->splash(HZ*2, "Hello world!");
    break;
    case 1: /* "Set Password" */
        rb->splash(HZ*2, "Hello world!");
    break;
    default: rb->splash(HZ*2, "Hello world!");
}

    return 0;
}

But the compiler reports errors, and they make no sense to me:

Quote
CC apps/plugins/helloworld.c
/home/user/rockbox/apps/plugins/helloworld.c: In function 'plugin_start':
/home/user/rockbox/apps/plugins/helloworld.c:47: warning: initialization from incompatible pointer type
/home/user/rockbox/apps/plugins/helloworld.c:47: warning: initialization makes integer from pointer without a cast
/home/user/rockbox/apps/plugins/helloworld.c:48: error: too few arguments to function 'rb->do_menu'
make: *** [/home/user/rockbox/build_c200/apps/plugins/helloworld.o] Error 1

Help me please!
Logged
My MP3 Player: Sansa C250 (2GB)
OS: Win XP SP3

Offline nls

  • Developer
  • Member
  • *
  • Posts: 460
Re: Error making a menu?
« Reply #1 on: March 03, 2009, 02:44:06 AM »
When starting out with plugins like this it is a good idea to look at what other plugins do.
First you are using an old version of helloworld.c plugins should no longer be passed the api poiter as a parameter.

"error: too few arguments to function 'rb->do_menu'" This error is pretty clear, you are not passing enough arguments to do_menu, it wants 4 arguments and you pass it 2.
You can find prototypes for all functions in the api in plugin.h, for do_menu it looks like this:
    int (*do_menu)(const struct menu_item_ex *menu, int *start_selected,
                   struct viewport parent[NB_SCREENS], bool hide_bars);

Hope this helps you a bit, google knows a lot of useful c resources so a bit of reading might be a good idea ;)
Logged

Offline motionman95

  • Member
  • *
  • Posts: 108
  • aka coderkid
    • coderkid
Re: Error making a menu?
« Reply #2 on: March 03, 2009, 07:43:10 AM »
Quote
First you are using an old version of helloworld.c plugins should no longer be passed the api poiter as a parameter.

I don't understand?
Logged
My MP3 Player: Sansa C250 (2GB)
OS: Win XP SP3

Offline nls

  • Developer
  • Member
  • *
  • Posts: 460
Re: Error making a menu?
« Reply #3 on: March 03, 2009, 09:27:22 AM »
The code you posted is from a modified helloworld.c but not from the most recent version. If you are using a recent version of the rockbox source, your "plugin_start" function should only take one argument, and that is "const void* parameter".
Logged

Offline motionman95

  • Member
  • *
  • Posts: 108
  • aka coderkid
    • coderkid
Re: Error making a menu?
« Reply #4 on: March 03, 2009, 11:57:05 PM »
Where should I look to find out how to detect when the left, right, up, or down keys are pressed?
Logged
My MP3 Player: Sansa C250 (2GB)
OS: Win XP SP3

Offline AlexP

  • Global Moderator
  • Member
  • *
  • Posts: 3688
  • ex-BigBambi
Re: Error making a menu?
« Reply #5 on: March 04, 2009, 03:22:36 AM »
Any other plugin?
Logged
H140, F60, S120, e260, c240, Clip, Fuze v2, Connect, MP170, Meizu M3, Nano 1G, Android

Offline motionman95

  • Member
  • *
  • Posts: 108
  • aka coderkid
    • coderkid
Re: Error making a menu?
« Reply #6 on: March 05, 2009, 11:27:18 AM »
Thanks! This is what I have so far, but the compiler says there's something wrong with my Unlock function declaration.

Code: [Select]
/***************************************************************************
 *             __________               __   ___.
 *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
 *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
 *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
 *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
 *                     \/            \/     \/    \/            \/
 * $Id: helloworld.c 19776 2009-01-16 10:34:40Z unhelpful $
 *
 * Copyright (C) 2002 Björn Stenberg
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 * KIND, either express or implied.
 *
 ****************************************************************************/
#include "plugin.h"


/* welcome to the example rockbox plugin */

/* This macros must always be included. Should be placed at the top by
   convention, although the actual position doesn't matter */
PLUGIN_HEADER

#if (CONFIG_KEYPAD == SANSA_C200_PAD)
#   define KEY_LEFT       BUTTON_LEFT
#   define KEY_RIGHT      BUTTON_RIGHT
#endif

/* this is the plugin entry point */
enum plugin_status plugin_start(const void* parameter)
{
    /* if you don't use the parameter, you can do like
       this to avoid the compiler warning about it */
    (void)parameter;

    /* now go ahead and have fun! */
    MENUITEM_STRINGLIST(menu, "RockLock Menu", NULL, "Unlock", "Reset Password")

    switch (rb->do_menu(&menu, NULL, NULL, false))
        {
            case 0:
    Unlock()
return PLUGIN_OK;
            break;

case 1:
    return PLUGIN_OK;
            break;
}

return PLUGIN_OK;
}

static void Unlock(void) {
        (void)parameter;
    switch((rb->button_get(true)){
            case KEY_RIGHT:
        return PLUGIN_OK;
break

case KEY_LEFT:
        return PLUGIN_OK;
break
}
    return PLUGIN_OK;
}
Logged
My MP3 Player: Sansa C250 (2GB)
OS: Win XP SP3

Offline nls

  • Developer
  • Member
  • *
  • Posts: 460
Re: Error making a menu?
« Reply #7 on: March 05, 2009, 01:06:54 PM »
Quote from: motionman95 on March 05, 2009, 11:27:18 AM
Thanks! This is what I have so far, but the compiler says there's something wrong with my Unlock function declaration.

Code: [Select]
/***************************************************************************

static void Unlock(void) {
        (void)parameter;
    switch((rb->button_get(true)){

The function does not take any parameter nor do you have a var called "parameter" so the compiler will not know what to do with this, what is it you are trying to do?

Maybe it would be a good idea to read up on C?
Logged

Offline cool_walking_

  • Rockbox Expert
  • Member
  • *
  • Posts: 695
Re: Error making a menu?
« Reply #8 on: March 05, 2009, 06:05:48 PM »
Also, Unlock() is called before it's defined, so you should put a function prototype above plugin_start().
Logged

Offline motionman95

  • Member
  • *
  • Posts: 108
  • aka coderkid
    • coderkid
Re: Error making a menu?
« Reply #9 on: March 06, 2009, 02:44:16 PM »
Thanks for all the awesome help! I've read up on C, and I've gotten much better! I have a really nice script going! The only help I need is a list of keys (for the c200). All I have currently is this, and I need to get the rest of the keys:

Quote
#if (CONFIG_KEYPAD == SANSA_C200_PAD)
#   define KEY_LEFT       BUTTON_LEFT
#   define KEY_RIGHT      BUTTON_RIGHT
#   define KEY_SELECT     BUTTON_SELECT
#   define KEY_UP         BUTTON_UP
#   define KEY_DOWN       BUTTON_DOWN
#endif
Logged
My MP3 Player: Sansa C250 (2GB)
OS: Win XP SP3

Offline saratoga

  • Developer
  • Member
  • *
  • Posts: 8974
Re: Error making a menu?
« Reply #10 on: March 06, 2009, 05:56:15 PM »
See firmware\target\arm\sandisk\sansa-c200\button-c200.c
Logged

Offline motionman95

  • Member
  • *
  • Posts: 108
  • aka coderkid
    • coderkid
Re: Error making a menu?
« Reply #11 on: March 07, 2009, 10:30:24 AM »
Thanks!!! I cannot express how thankful I am for all the help and gratitude. I only have one last question: How do I add a string and an integer together? The following isn't working:

Quote
int how_old = 20;
char name = "John Jameson";
char final_string = "";

final_string = name + " is " + how_old;
Logged
My MP3 Player: Sansa C250 (2GB)
OS: Win XP SP3

Offline saratoga

  • Developer
  • Member
  • *
  • Posts: 8974
Re: Error making a menu?
« Reply #12 on: March 07, 2009, 12:10:21 PM »
The + operator in c literally just does addition.  You can't use it for concatenation or formatting like in other languages.  Instead, you'll need sprintf:

http://www.cplusplus.com/reference/clibrary/cstdio/sprintf.html

You may also be interested in the functions in string.h.
Logged

Offline motionman95

  • Member
  • *
  • Posts: 108
  • aka coderkid
    • coderkid
Re: Error making a menu?
« Reply #13 on: March 07, 2009, 02:06:35 PM »
Once again, I cannot express my thankfulness. I'm trying to use the virtual keyboard, and nls post (on a different thread) was very helpful. The only problem is, I can't get it to work.

What nls posted:

Quote
You just need to call rb->kbd_input() where the first argument is a char* to a buffer and the second is the length of the buffer.

see apps/recorder/keyboard.c and apps/keyboard.h

What I tried:

Quote
text = rb->kbd_input(char, buffer_length);

Where can I get the values that char and buffer_length are supposed to have?
Logged
My MP3 Player: Sansa C250 (2GB)
OS: Win XP SP3

Offline nls

  • Developer
  • Member
  • *
  • Posts: 460
Re: Error making a menu?
« Reply #14 on: March 08, 2009, 05:20:16 AM »
This is something that is done in several places in rockbox code, so you can find out how these things work by looking around.

This is how you would usually do it:
Code: [Select]
char buf[100];
rb->kbd_input(buf, sizeof (buf));

the text entered in the keyboard will end up in buf, 100 is the length of that buffer, and sizeof is just used to avoid
issues if that number is changed in the future but could be replaced by 100 if you like.

the return code for the function is either -1 (user aborted) or 0 (success).
Logged

  • Print
Pages: [1] 2
« previous next »
+  Rockbox Technical Forums
|-+  Rockbox Development
| |-+  Starting Development and Compiling
| | |-+  Error making a menu?
 

  • SMF 2.0.17 | SMF © 2019, Simple Machines
  • Rockbox Privacy Policy
  • XHTML
  • RSS
  • WAP2

Page created in 0.104 seconds with 15 queries.