Subversion Repositories Projects

Rev

Rev 1307 | Blame | Last modification | View Log | RSS feed

/*****************************************************************************
 *   Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net                  *
 *                                                                           *
 *   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.          *
 *                                                                           *
 *   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.,                                         *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.               *
 *                                                                           *
 *****************************************************************************/


#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <string.h>

#include "main.h"
#include "motortest.h"
#include "lcd.h"
#include "usart.h"
#include "timer.h"


uint8_t m;
uint8_t mmode;
uint8_t v;


volatile uint8_t i2c_state;
volatile uint8_t motor_addr = 0;


//*****************************************************************************
//
void motor (uint8_t m,uint8_t v)
{
        memset (buffer, 0, 16);
       
        if(m == 0)
        {
                memset (buffer, v, 16);
        }
        else
        {
                buffer[m-1] = v;
        }

        SendOutData('t', ADDRESS_FC, 1, buffer, 16);
}

//*****************************************************************************
//
void motor_test (void)
{
        //uint8_t m;


        lcd_cls ();
        mmode = 1;
        m = 0;
        v = 0;

        lcd_printp (PSTR("Motor Test"), 0);
        lcd_printpns_at (2, 2, PSTR("Motor: All"), 0);
        lcd_printpns_at (2, 3, PSTR("Value:   0"), 0);
        lcd_printpns_at (0, 7, PSTR(" \x18    \x19     Back   \x0c"), 0);


    lcd_printp_at (0, 2, PSTR("\x1D"), 0);

        if (hardware == NC && current_hardware == NC)
        {
                SwitchToFC();
        }

        do
        {
                if ((mmode == 0) && (get_key_press (1 << KEY_PLUS) || get_key_rpt (1 << KEY_PLUS)) && (v < 254))
                {
                        v++;
                        write_ndigit_number_u (9, 3, v, 3, 0);
                        lcd_frect ((8*1), (8*5), (v * (14*8)) / 255, 6, 1);
                }
                if ((mmode == 0) && (get_key_press (1 << KEY_MINUS) || get_key_rpt (1 << KEY_MINUS)) && (v > 0))
                {
                        lcd_frect ((8*1), (8*5), (v * (14*8)) / 255, 6, 0);
                        v--;
                        write_ndigit_number_u (9, 3, v, 3, 0);
                        lcd_frect ((8*1), (8*5), (v * (14*8)) / 255, 6, 1);
                }
                if ((mmode == 1) && (get_key_press (1 << KEY_PLUS) || get_key_rpt (1 << KEY_PLUS)) && (m < 16))
                {
                        m++;
                        write_ndigit_number_u (9, 2, m, 3, 0);
                       
                }
                if ((mmode == 1) && (get_key_press (1 << KEY_MINUS) || get_key_rpt (1 << KEY_MINUS)) && (m > 0))
                {
                        m--;
                        if(m > 0) write_ndigit_number_u (9, 2, m, 3, 0);
                        if(m == 0) lcd_printpns_at (9, 2, PSTR("All"), 0);
                }
                if (get_key_press (1 << KEY_ENTER))
                {
                        if(mmode == 0)
                        {
                            lcd_printp_at (0, 2, PSTR("\x1D"), 0);
                                lcd_printp_at (0, 3, PSTR(" "), 0);
                                mmode = 1;
                        }
                        else
                        {
                                lcd_printp_at (0, 2, PSTR(" "), 0);
                            lcd_printp_at (0, 3, PSTR("\x1D"), 0);
                                mmode = 0;
                        };
                }
                motor (m,v);
        }
        while (!get_key_press (1 << KEY_ESC));



        // switch all engines off at exit !
        memset (buffer, 0, 16);
        SendOutData('t', ADDRESS_FC, 1, buffer, 16);

}