/***************************************************************************
 * Show Volume Test Plugin
 *
 * Copyright: Travis Sidelinger (2006May01)
 * License:
 *   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 program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *   
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the Free Software
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 * Descr:
 *   This is a simple plugin to get the right and left volume register
 *   values and display them.  This plugin will also wait for the off
 *   key press to exit.
 *
 * Version History:
 *   2006May01 : TLS : Created
 *   2006Jun30 : TLS : Did some code clean up, added more comments
 *
 ****************************************************************************/
 
/* Headers */
 
#include "plugin.h"
#include <stdlib.h>
#include <stdio.h>
 
/* Variables */
static struct plugin_api* rb;
static int fontwidth, fontheight;
 
/*************************************************************/
/* Functions */
 
void waitkey(void)
{
    int button = 0;
    int done   = 0;
 
    /* Wait for key press */
    while (!done)
    {
        button = rb->button_get(true);
        rb->reset_poweroff_timer();
 
        /* Which button was pressed */
        switch(button)
        {
            case BUTTON_OFF:
                done = true;
                break;
            default:
                if (rb->default_event_handler(button) == SYS_USB_CONNECTED) { return PLUGIN_USB_CONNECTED; }
                break;
            }
        }
    return;
    }
 
/*************************************************************/
/* Main */
enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
{
    /* Variables */
    (void)parameter;
    rb = api;
 
    int voll = 0;   /* volume left  */
    int volr = 0;   /* volume right */
    char buf[32];   /* display charactor buffer */
    int loop = 1;   /* 1=keep looping, 0=stop looping */
    int button = 0; /* store the button pressed */
 
    /* Main */
 
    /* Show splash screen */
    rb->splash(HZ*2, true, "Devry Project");
 
    while(loop)
    {
        /* Call rockbox api to get volume values */
        voll = rb->mas_codec_readreg(0xC);
        volr = rb->mas_codec_readreg(0xD);
 
        /* Determine font size */
        rb->lcd_getstringsize("X", &fontwidth, &fontheight);
 
        /* Display our stuff */
        rb->lcd_clear_display();
        rb->snprintf(buf, sizeof(buf), "Left Volume: %d", voll);
        rb->lcd_putsxy(0,0,buf);
        rb->snprintf(buf, sizeof(buf), "Right Volume: %d", volr);
        rb->lcd_putsxy(0,fontheight,buf);
        rb->lcd_update();
 
        /* Check for key press */
        button = rb->button_get(true);
        rb->reset_poweroff_timer();
 
        /* Which button was pressed */
        switch(button)
        {
            case BUTTON_DOWN: /* Stop the loop */
                loop = 0;
                break;
            default:
                if (rb->default_event_handler(button) == SYS_USB_CONNECTED) { return PLUGIN_USB_CONNECTED; }
                break;
            }
        }
 
        waitkey();
 
    /* End */
    return(PLUGIN_OK);
    }
 
/*************************************************************/
/var/www/sites/dokuwiki-2011-05-25a/data/pages/projects/devry/showvol.c.txt · Last modified: 2009/04/11 22:23 (external edit)
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki