Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1053 - 1
/*****************************************************************************
2
 *   Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net                  *
3
 *                                                                           *
4
 *   This program is free software; you can redistribute it and/or modify    *
5
 *   it under the terms of the GNU General Public License as published by    *
6
 *   the Free Software Foundation; either version 2 of the License.          *
7
 *                                                                           *
8
 *   This program is distributed in the hope that it will be useful,         *
9
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
10
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
11
 *   GNU General Public License for more details.                            *
12
 *                                                                           *
13
 *   You should have received a copy of the GNU General Public License       *
14
 *   along with this program; if not, write to the                           *
15
 *   Free Software Foundation, Inc.,                                         *
16
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.               *
17
 *                                                                           *
18
 *****************************************************************************/
19
 
20
#include <avr/io.h>
21
#include <avr/interrupt.h>
22
#include <avr/pgmspace.h>
23
#include <string.h>
24
 
25
#include "main.h"
26
#include "motortest.h"
27
#include "lcd.h"
28
#include "usart.h"
29
#include "timer.h"
30
 
31
 
32
uint8_t m;
33
uint8_t mmode;
34
uint8_t v;
35
 
36
 
37
volatile uint8_t i2c_state;
38
volatile uint8_t motor_addr = 0;
39
 
40
 
41
//*****************************************************************************
42
// 
43
void motor (uint8_t m,uint8_t v)
44
{
45
        memset (buffer, 0, 16);
46
 
47
        if(m == 0)
48
        {
49
                memset (buffer, v, 16);
50
        }
51
        else
52
        {
53
                buffer[m-1] = v;
54
        }
55
 
56
        SendOutData('t', ADDRESS_FC, 1, buffer, 16);
57
}
58
 
59
//*****************************************************************************
60
// 
61
void motor_test (void)
62
{
63
        //uint8_t m;
64
 
65
 
66
        lcd_cls ();
67
        mmode = 1;
68
        m = 0;
69
        v = 0;
70
 
71
        lcd_printp (PSTR("Motor Test"), 0);
72
        lcd_printpns_at (2, 2, PSTR("Motor: All"), 0);
73
        lcd_printpns_at (2, 3, PSTR("Value:   0"), 0);
74
        lcd_printpns_at (0, 7, PSTR(" \x18    \x19     Back   \x0c"), 0);
75
 
76
 
77
    lcd_printp_at (0, 2, PSTR("\x1D"), 0);
78
 
79
        if (hardware == NC && current_hardware == NC)
80
        {
81
                SwitchToFC();
82
        }
83
 
84
        do
85
        {
86
                if ((mmode == 0) && (get_key_press (1 << KEY_PLUS) || get_key_rpt (1 << KEY_PLUS)) && (v < 254))
87
                {
88
                        v++;
89
                        write_ndigit_number_u (9, 3, v, 3, 0);
90
                        lcd_frect ((8*1), (8*5), (v * (14*8)) / 255, 6, 1);
91
                }
92
                if ((mmode == 0) && (get_key_press (1 << KEY_MINUS) || get_key_rpt (1 << KEY_MINUS)) && (v > 0))
93
                {
94
                        lcd_frect ((8*1), (8*5), (v * (14*8)) / 255, 6, 0);
95
                        v--;
96
                        write_ndigit_number_u (9, 3, v, 3, 0);
97
                        lcd_frect ((8*1), (8*5), (v * (14*8)) / 255, 6, 1);
98
                }
99
                if ((mmode == 1) && (get_key_press (1 << KEY_PLUS) || get_key_rpt (1 << KEY_PLUS)) && (m < 16))
100
                {
101
                        m++;
102
                        write_ndigit_number_u (9, 2, m, 3, 0);
103
 
104
                }
105
                if ((mmode == 1) && (get_key_press (1 << KEY_MINUS) || get_key_rpt (1 << KEY_MINUS)) && (m > 0))
106
                {
107
                        m--;
108
                        if(m > 0) write_ndigit_number_u (9, 2, m, 3, 0);
109
                        if(m == 0) lcd_printpns_at (9, 2, PSTR("All"), 0);
110
                }
111
                if (get_key_press (1 << KEY_ENTER))
112
                {
113
                        if(mmode == 0)
114
                        {
115
                            lcd_printp_at (0, 2, PSTR("\x1D"), 0);
116
                                lcd_printp_at (0, 3, PSTR(" "), 0);
117
                                mmode = 1;
118
                        }
119
                        else
120
                        {
121
                                lcd_printp_at (0, 2, PSTR(" "), 0);
122
                            lcd_printp_at (0, 3, PSTR("\x1D"), 0);
123
                                mmode = 0;
124
                        };
125
                }
126
                motor (m,v);
127
        }
128
        while (!get_key_press (1 << KEY_ESC));
129
 
130
 
131
 
132
        // switch all engines off at exit !
133
        memset (buffer, 0, 16);
134
        SendOutData('t', ADDRESS_FC, 1, buffer, 16);
135
 
136
}