Subversion Repositories Projects

Rev

Rev 1199 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1199 - 1
/****************************************************************************
1437 - 2
 *   Copyright (C) 2011-2012 by Claas Anders "CaScAdE" Rathje               *
1199 - 3
 *   admiralcascade@gmail.com                                               *
4
 *   Project-URL: http://www.mylifesucks.de/oss/c-epilepsy/                 *
5
 *                                                                          *
6
 *   This program is free software; you can redistribute it and/or modify   *
7
 *   it under the terms of the GNU General Public License as published by   *
8
 *   the Free Software Foundation; either version 2 of the License.         *
9
 *                                                                          *
10
 *   This program is distributed in the hope that it will be useful,        *
11
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of         *
12
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
13
 *   GNU General Public License for more details.                           *
14
 *                                                                          *
15
 *   You should have received a copy of the GNU General Public License      *
16
 *   along with this program; if not, write to the                          *
17
 *   Free Software Foundation, Inc.,                                        *
18
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.              *
19
 ****************************************************************************/
20
 
21
 
22
#include "nc_handler.h"
23
 
24
volatile uint16_t nc_handler_time = 2; // request on first call
25
uint8_t nc_handler_state = 0;
26
 
27
 
28
NaviData_t naviData; // = malloc(sizeof(NaviData_t));
29
 
30
void inline nc_handler_timer_callback(void) {
31
    nc_handler_time++;
32
}
33
 
34
void show_heading_home(void) {
35
    uint16_t heading_home = (naviData.HomePositionDeviation.Bearing + 360) % 360;
36
    degree2epi(animation, heading_home);
37
}
38
 
39
uint8_t vario_state = 0;
40
 
41
void show_vario(void) {
42
    uint8_t index = naviData.Variometer > 0 ? 0 : 1;
43
    if (naviData.Variometer == 0) index = 2;
44
    for (uint8_t i = 0; i <= 6; i++) {
45
        if (vario_state < 129) {
46
            animation[i] = COLORS[index][i];
47
        } else {
48
            animation[i] = 0;
49
        }
50
    }
51
    vario_state += 64;
52
}
53
 
54
void spirit_level(void) {
55
    /*
56
        basic principle is:
57
        take degree nick as y coordinate of a point
58
        take degree roll as x coordinate of a point
59
        use atan2 to get the degree between the x-axis and that point
60
        substract 90 degree since the y-axis is heding front
61
     */
62
    int degree = atan2_fp(naviData.AngleNick, naviData.AngleRoll) / 10;
63
    degree = (degree + 360 - 90) % 360;
64
    //degree2epi(animation, degree);
65
    setLedsAround(animation, (degree * 10) / 75, 2, 1);
66
}
67
 
68
void nc_handler_change_state(void) {
69
    nc_handler_state = (nc_handler_state + 1) % 3;
70
    blinkNumer(animation, nc_handler_state + 1, 3);
71
}
72
 
73
void inline nc_handler(void) {
74
    if (nc_handler_time >= 2) {
75
        usart0_request_mk_data(NC_ADDRESS, 'o', 100);
76
        nc_handler_time = 0;
77
        LEDGREEN_TOGGLE
78
    }
79
    if (rxd_buffer_locked) {
80
        if (rxd_buffer[2] == 'O') { // NC OSD Data
81
            Decode64();
82
            LEDRED_TOGGLE
83
            //naviData = *((NaviData_t*)pRxData);
84
            memcpy((unsigned char *) & naviData, (unsigned char *)pRxData, sizeof (NaviData_t));
85
            rxd_buffer_locked = 0;
86
        }
87
    }
88
 
89
    switch (nc_handler_state) {
90
        case 0:
91
            show_heading_home();
92
            break;
93
        case 1:
94
            show_vario();
95
            break;
96
        case 2:
97
            spirit_level();
98
            break;
99
    }
100
    if (set_pressed()) {
101
        nc_handler_change_state();
102
    }
103
}
104
 
105
 
106