Subversion Repositories idreammicro-avr

Rev

Rev 36 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

/**************************************************************************//**
 * \brief Deuligne library - Demonstration program
 * \author Copyright (C) 2011  Julien Le Sech - www.idreammicro.com
 * \version 1.0
 * \date 20121026
 *
 * This file is part of the iDreamMicro library.
 *
 * This library is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option) any
 * later version.
 *
 * This library 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 Lesser General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program. If not, see http://www.gnu.org/licenses/
 ******************************************************************************/


/**************************************************************************//**
 * \file deuligne__demo.c
 ******************************************************************************/


/******************************************************************************
 * Header file inclusions.
 ******************************************************************************/


#include <deuligne/deuligne.h>
#include <mcp23008/mcp23008.h>
#include <twi/twi.h>

#include <util/delay.h>

#include <stdio.h>

/******************************************************************************
 * Private constant definitions.
 ******************************************************************************/


static const char* strings[] =
{
    [DEULIGNE__KEY__RIGHT]  = "Right Key OK ",
    [DEULIGNE__KEY__UP]     = "Up Key OK    ",
    [DEULIGNE__KEY__DOWN]   = "Down Key OK  ",
    [DEULIGNE__KEY__LEFT]   = "Left Key OK  ",
    [DEULIGNE__KEY__SELECT] = "Select Key OK"
};

/******************************************************************************
 * Public function definitions.
 ******************************************************************************/


/**************************************************************************//**
 * \fn int main(void)
 *
 * \brief Main function.
 ******************************************************************************/

int
main
(
    void
){
    // Initialize TWI.
    twi__initialize(MCP23008__CLOCK_RATE);

    // Initialize Deuligne and configure display.
    deuligne__initialize();
    deuligne__set_display(true, false, false);

    // Switch on backlight.
    deuligne__switch_on_backlight();

    deuligne__set_cursor_position(DEULIGNE__DISPLAY_LINE_1, 5);
    deuligne__write_string("Setup");
    deuligne__set_cursor_position(DEULIGNE__DISPLAY_LINE_2, 7);
    deuligne__write_string("ok");
    _delay_ms(2000);

    deuligne__clear_display();
    deuligne__write_string("Move Joystick");

    // Infinite loop.
    for(;;)
    {
        // Get key.
        deuligne__key_t key = deuligne__get_key();
        if (key != DEULIGNE__KEY__NONE)
        {
            // Set cursor position.
            deuligne__set_cursor_position(DEULIGNE__DISPLAY_LINE_2, 0);

            // Write string.
            deuligne__write_string(strings[key]);
        }

        _delay_ms(250);
    }

    return 0;
}