28,7 → 28,9 |
#include <avr/io.h> |
#include <avr/interrupt.h> |
#include <util/delay.h> |
#include "max7456_software_spi.c" |
#include <avr/pgmspace.h> |
#include "main.h" |
#include "max7456_software_spi.h" |
#include "usart1.h" |
|
/* TODO: |
36,72 → 38,14 |
* - clean up code :) |
*/ |
|
/* ########################################################################## |
* Debugging and general purpose definitions |
* ##########################################################################*/ |
#define ALLCHARSDEBUG 0 // set to 1 and flash firmware to see all chars |
|
#ifndef WRITECHARS // if WRITECHARS not set via makefile |
#define WRITECHARS -1 // set to 2XX and flash firmware to write new char |
// enables the allchars as well to see results |
#endif |
|
#ifndef NTSC // if NTSC is not thet via makefile |
#define NTSC 0 // set to 1 for NTSC mode + lifts the bottom line |
#endif |
|
#define HUD 1 // set to 0 to disable HUD by default |
#define ARTHORIZON 0 // set to 1 to enable roll&nick artificial horizon by default |
#define STATS 1 // set to 1 to enable statistics during motor off by default |
#define WARNINGS 1 // set to 1 to display battery+rc warning even if HUD is disabled |
|
#define UBAT_WRN 94 // voltage for blinking warning, like FC settings |
#define RCLVL_WRN 100 // make the RC level blink if below this number |
|
// ### read datasheet before changing stuff below this line :) |
#define BLINK 0b01001111 // attribute byte for blinking chars |
|
/* ########################################################################## |
* FLAGS usable during runtime |
* ##########################################################################*/ |
#define COSD_FLAG_NTSC 1 |
#define COSD_FLAG_HUD 2 |
#define COSD_FLAG_ARTHORIZON 4 |
#define COSD_FLAG_STATS 8 |
#define COSD_FLAG_WARNINGS 16 |
#define COSD_ICONS_WRITTEN 32 |
|
/* ########################################################################## |
* LED controll |
* ##########################################################################*/ |
#define LED1_ON PORTC |= (1 << PC0); |
#define LED1_OFF PORTC &= ~(1 << PC0); |
#define LED2_ON PORTC |= (1 << PC1); |
#define LED2_OFF PORTC &= ~(1 << PC1); |
#define LED3_ON PORTC |= (1 << PC2); |
#define LED3_OFF PORTC &= ~(1 << PC2); |
#define LED4_ON PORTC |= (1 << PC3); |
#define LED4_OFF PORTC &= ~(1 << PC3); |
|
/* ########################################################################## |
* switch controll |
* ##########################################################################*/ |
#define S1_PRESSED !(PINC & (1<<PC5)) |
#define S2_PRESSED !(PINC & (1<<PC4)) |
|
#if !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
// data structs |
// data structs not needed for character flashin |
#include "mk-data-structs.h" |
|
/* ########################################################################## |
* global definitions and global vars |
* ##########################################################################*/ |
volatile uint8_t rxd_buffer_locked = 0; |
volatile uint8_t rxd_buffer[RXD_BUFFER_LEN]; |
volatile uint8_t txd_buffer[TXD_BUFFER_LEN]; |
volatile uint8_t ReceivedBytes = 0; |
volatile uint8_t *pRxData = 0; |
volatile uint8_t RxDataLen = 0; |
|
volatile uint16_t setsReceived = 0; |
|
volatile NaviData_t naviData; |
119,6 → 63,18 |
// remember last time data was received |
volatile uint8_t seconds_since_last_data = 0; |
|
// store stats description in progmem to save space |
char stats_item_0[] PROGMEM = "max Altitude:"; |
char stats_item_1[] PROGMEM = "max Speed :"; |
char stats_item_2[] PROGMEM = "max Distance:"; |
char stats_item_3[] PROGMEM = "min voltage :"; |
char stats_item_4[] PROGMEM = "max time :"; |
char* stats_item_pointers[] PROGMEM = {stats_item_0, stats_item_1, stats_item_2, stats_item_3, stats_item_4}; |
|
// store more fixed strings in progmen |
char ON[] PROGMEM = "ON "; |
char OFF[] PROGMEM = "OFF"; |
|
#endif // ends !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
|
// general PAL|NTSC distingiusch stuff |
153,7 → 109,7 |
/** |
* serial support |
*/ |
#include "usart1.c" |
//#include "usart1.c" |
|
|
/* ########################################################################## |
300,32 → 256,41 |
*/ |
void config_menu_drawings(uint8_t chosen) { |
// clear prevoius _cursor_ |
write_ascii_string(3, (chosen + 4) % 5, " "); |
write_ascii_string(3, (chosen + 6) % 7, " "); |
// draw current _cursor_ |
write_ascii_string(3, chosen + 6, ">"); |
if (COSD_FLAGS & COSD_FLAG_HUD) { |
write_ascii_string(23, 6, "ON "); |
write_ascii_string_pgm(23, 6, ON); |
} else { |
write_ascii_string(23, 6, "OFF"); |
write_ascii_string_pgm(23, 6, OFF); |
} |
if (COSD_FLAGS & COSD_FLAG_ARTHORIZON) { |
write_ascii_string(23, 7, "ON "); |
write_ascii_string_pgm(23, 7, ON); |
} else { |
write_ascii_string(23, 7, "OFF"); |
write_ascii_string_pgm(23, 7, OFF); |
} |
if (COSD_FLAGS & COSD_FLAG_STATS) { |
write_ascii_string(23, 8, "ON "); |
write_ascii_string_pgm(23, 8, ON); |
} else { |
write_ascii_string(23, 8, "OFF"); |
write_ascii_string_pgm(23, 8, OFF); |
} |
if (COSD_FLAGS & COSD_FLAG_WARNINGS) { |
write_ascii_string(23, 9, "ON "); |
write_ascii_string_pgm(23, 9, ON); |
} else { |
write_ascii_string(23, 9, "OFF"); |
write_ascii_string_pgm(23, 9, OFF); |
} |
} |
|
/** |
* some sort of clicking response in the menu |
*/ |
void config_menu_doclick(uint8_t chosen, char** menu) { |
write_ascii_string(4, chosen + 6, "DONE "); |
_delay_ms(1000); |
write_ascii_string(4, chosen + 6, menu[chosen]); |
} |
|
/** |
* a simple config menu tryout |
*/ |
void config_menu(void) { |
335,10 → 300,13 |
// clear screen |
clear(); |
|
char* menu[5] = {"Full HUD", |
char* menu[8] = {"Full HUD", |
"Art.Horizon in HUD", |
"Statistics", |
"Warnings", // TODO: do it! |
"Reset uptime", |
"Request OSD-data", |
"Disable Debug-data", |
"EXIT"}; |
|
uint8_t inmenu = 1; |
353,6 → 321,9 |
write_ascii_string(4, 8, menu[2]); |
write_ascii_string(4, 9, menu[3]); |
write_ascii_string(4, 10, menu[4]); |
write_ascii_string(4, 11, menu[5]); |
write_ascii_string(4, 12, menu[6]); |
write_ascii_string(4, 13, menu[7]); |
|
config_menu_drawings(chosen); |
|
359,7 → 330,7 |
while (inmenu) { |
if (s2_pressed()) { |
write_ascii_string(3, chosen+6, " "); |
chosen = (chosen + 1) % 5; |
chosen = (chosen + 1) % 8; |
write_ascii_string(3, chosen+6, ">"); |
_delay_ms(500); |
} else if (s1_pressed()) { |
380,7 → 351,22 |
COSD_FLAGS ^= COSD_FLAG_WARNINGS; |
config_menu_drawings(chosen); |
break; |
case 4: // exit |
case 4: // reset uptime |
uptime = 0; |
config_menu_doclick(chosen, menu); |
break; |
case 5: // re-request OSD data |
// request OSD Data from NC every 100ms |
usart1_request_mk_data(1, 'o', 100); |
config_menu_doclick(chosen, menu); |
break; |
case 6: // disable debug data |
// disable sending of debug data |
// may result in smoother ddata display |
usart1_request_mk_data(0, 'd', 0); |
config_menu_doclick(chosen, menu); |
break; |
case 7: // exit |
inmenu = 0; |
break; |
} |
530,16 → 516,14 |
//usart1_puts("hello world!\r\n"); |
|
|
// request data ever 100ms from FC |
//unsigned char ms = 10; |
//sendMKData('d', 0, &ms, 1); |
// request data ever 100ms from FC; |
//usart1_request_mk_data(0, 'd', 100); |
|
// request OSD Data from NC every 100ms |
unsigned char ms = 10; |
sendMKData('o', 1, &ms, 1); |
usart1_request_mk_data(1, 'o', 100); |
|
// and disable debug... |
//ms = 0; |
//sendMKData('d', 0, &ms, 1); |
//usart1_request_mk_data(0, 'd', 0); |
|
// disable TXD-pin |
usart1_DisableTXD(); |
648,19 → 632,19 |
} else { |
// stats |
if (COSD_FLAGS & COSD_FLAG_STATS) { |
write_ascii_string(2, 5, "max Altitude:"); |
write_ascii_string_pgm(2, 5, stats_item_pointers[0]); // max Altitude |
write_number_s(17, 5, max_Altimeter / 30); |
write_char_xy(22, 5, 204); // small meters m |
write_ascii_string(2, 6, "max Speed :"); |
write_ascii_string_pgm(2, 6, stats_item_pointers[1]); // max Speed |
write_3digit_number_u(19, 6, (uint16_t) (((uint32_t) max_GroundSpeed * 36) / 1000)); |
write_char_xy(22, 6, 203); // km/h |
write_ascii_string(2, 7, "max Distance:"); |
write_ascii_string_pgm(2, 7, stats_item_pointers[2]); // max Distance |
write_number_s(17, 7, max_Distance / 100); |
write_char_xy(22, 7, 204); // small meters m |
write_ascii_string(2, 8, "min voltage :"); |
write_ascii_string_pgm(2, 8, stats_item_pointers[3]); // min voltage |
write_number_u_10th(16, 8, min_UBat); |
write_ascii_string(22, 8, "V"); // voltage |
write_ascii_string(2, 9, "max time :"); |
write_ascii_string_pgm(2, 9, stats_item_pointers[4]); // max time |
write_time(16, 9, max_FlyingTime); |
write_char_xy(22, 9, 210); // fly clock |
} else if (COSD_FLAGS & COSD_FLAG_ARTHORIZON) { // if no stats there is space horizon |
711,31 → 695,12 |
} |
// handle keypress |
if (s1_pressed()) { |
//sendMKData('d', 1, (unsigned char*) 0, 1); |
// request OSD Data from NC every 100ms |
/*unsigned char ms = 10; |
sendMKData('o', 1, &ms, 1); |
_delay_ms(500);*/ |
config_menu(); |
} |
if (s2_pressed()) { |
uptime = 0; |
_delay_ms(100); |
} |
if (seconds_since_last_data > 2) { |
// re-request OSD Data from NC |
|
// re-enable TXD pin |
usart1_EnableTXD(); |
|
// every 100ms |
unsigned char ms = 10; |
sendMKData('o', 1, &ms, 1); |
|
// disable TXD pin again |
usart1_DisableTXD(); |
|
seconds_since_last_data = 0; |
// request OSD Data from NC every 100ms |
usart1_request_mk_data(1, 'o', 100); |
seconds_since_last_data = 0; |
} |
} |
#endif |