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