0,0 → 1,106 |
/**************************************************************************** |
* Copyright (C) 2011 by Claas Anders "CaScAdE" Rathje * |
* admiralcascade@gmail.com * |
* Project-URL: http://www.mylifesucks.de/oss/c-epilepsy/ * |
* * |
* 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 "nc_handler.h" |
|
volatile uint16_t nc_handler_time = 2; // request on first call |
uint8_t nc_handler_state = 0; |
|
|
NaviData_t naviData; // = malloc(sizeof(NaviData_t)); |
|
void inline nc_handler_timer_callback(void) { |
nc_handler_time++; |
} |
|
void show_heading_home(void) { |
uint16_t heading_home = (naviData.HomePositionDeviation.Bearing + 360) % 360; |
degree2epi(animation, heading_home); |
} |
|
uint8_t vario_state = 0; |
|
void show_vario(void) { |
uint8_t index = naviData.Variometer > 0 ? 0 : 1; |
if (naviData.Variometer == 0) index = 2; |
for (uint8_t i = 0; i <= 6; i++) { |
if (vario_state < 129) { |
animation[i] = COLORS[index][i]; |
} else { |
animation[i] = 0; |
} |
} |
vario_state += 64; |
} |
|
void spirit_level(void) { |
/* |
basic principle is: |
take degree nick as y coordinate of a point |
take degree roll as x coordinate of a point |
use atan2 to get the degree between the x-axis and that point |
substract 90 degree since the y-axis is heding front |
*/ |
int degree = atan2_fp(naviData.AngleNick, naviData.AngleRoll) / 10; |
degree = (degree + 360 - 90) % 360; |
//degree2epi(animation, degree); |
setLedsAround(animation, (degree * 10) / 75, 2, 1); |
} |
|
void nc_handler_change_state(void) { |
nc_handler_state = (nc_handler_state + 1) % 3; |
blinkNumer(animation, nc_handler_state + 1, 3); |
} |
|
void inline nc_handler(void) { |
if (nc_handler_time >= 2) { |
usart0_request_mk_data(NC_ADDRESS, 'o', 100); |
nc_handler_time = 0; |
LEDGREEN_TOGGLE |
} |
if (rxd_buffer_locked) { |
if (rxd_buffer[2] == 'O') { // NC OSD Data |
Decode64(); |
LEDRED_TOGGLE |
//naviData = *((NaviData_t*)pRxData); |
memcpy((unsigned char *) & naviData, (unsigned char *)pRxData, sizeof (NaviData_t)); |
rxd_buffer_locked = 0; |
} |
} |
|
switch (nc_handler_state) { |
case 0: |
show_heading_home(); |
break; |
case 1: |
show_vario(); |
break; |
case 2: |
spirit_level(); |
break; |
} |
if (set_pressed()) { |
nc_handler_change_state(); |
} |
} |
|
|
|