Subversion Repositories Projects

Rev

Rev 523 | Rev 734 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

/****************************************************************************
 *   Copyright (C) 2009 by Claas Anders "CaScAdE" Rathje                    *
 *   admiralcascade@gmail.com                                               *
 *   Project-URL: http://www.mylifesucks.de/oss/c-osd/                      *
 *                                                                          *
 *   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 <avr/pgmspace.h>
#include "mk-data-structs.h"

/* ##########################################################################
 * Debugging and general purpose definitions
 * ##########################################################################*/

#ifndef BUILDDATE
#define BUILDDATE "DEVEL-BUILD" // build date, this is testing...
#endif

#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 1 and flash firmware to write all chars
#endif

#ifndef NTSC                    // if NTSC is not thet via makefile
#define NTSC 0                  // set to 1 for NTSC mode + lifts the bottom line
#endif

#ifndef FCONLY
#define FCONLY 0                // set to 1 if you do NOT have a NaviCtrl and the OSD is
#endif                          // connected to the FC directly

#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 BIGVARIO 0                      // set to 1 to enable the big vario bar on right side
#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 (deprecated)
//#define UBAT_MAX 114          // maximal battery voltage for battery-sign (deprecated)
#define CELL_VOLT_MAX 37        // max voltage per battery cell (37 for LiPo)
#define CELL_VOLT_MIN 32        // min voltage per battery cell (maybe 32 for LiPo?)
#define CELL_NUM -1                     // -1 for auto, 3 for 3s1p and 4 for 4s1p
#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 that get saved
 * ##########################################################################*/

#define COSD_FLAG_HUD                     1
#define COSD_FLAG_ARTHORIZON      2
#define COSD_FLAG_BIGVARIO                4
#define COSD_FLAG_STATS                   8
#define COSD_FLAG_WARNINGS               16
#define COSD_FLAG_STROMVOLT              32

#define COSD_FLAG_NTSC                    1
#define COSD_FLAG_GPSHEIGHT               2
#define COSD_FLAG_FCMODE                  4

/* ##########################################################################
 * FLAGS only usable during runtime (not saved)
 * ##########################################################################*/

#define COSD_FLAG_STROMREC                1
#define COSD_ICONS_WRITTEN                2
#define COSD_WASFLYING                    4

/* ##########################################################################
 * 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))

/* ##########################################################################
 * extern spi controlled vars
 * ##########################################################################*/

extern volatile uint16_t icnt;
extern volatile unsigned char * iptr;
extern volatile uint8_t spi_cmd_buffer[];
extern volatile uint8_t spi_ready;
extern int16_t ampere, max_ampere, s_volt;
extern int32_t ampere_wasted;

/* ##########################################################################
 * struct for displaymodes
 * ##########################################################################*/

typedef struct {
   int (*dfun)(void);   // function pointer
   char *desc;                  // description text
} displaymode_t;

const displaymode_t ncdisplaymodes[2];
const displaymode_t fcdisplaymodes[2];

int (*osd_ncmode)(void);
int (*osd_fcmode)(void);

/* ##########################################################################
 * vars used by other parts as well
 * ##########################################################################*/

volatile uint16_t setsReceived;

volatile NaviData_t naviData;
volatile DebugOut_t debugData;

// cache old vars for blinking attribute, checkup is faster than full
// attribute write each time
volatile uint8_t last_UBat;
volatile uint8_t last_RC_Quality;

// 16bit should be enough, normal LiPos don't last that long
volatile uint16_t uptime;
volatile uint16_t timer;
volatile uint16_t flytime_fc;

// remember last time data was received
volatile uint8_t seconds_since_last_data;

// general PAL|NTSC distingiusch stuff
uint8_t top_line;
uint8_t bottom_line;

// battery voltages
uint8_t min_voltage;
uint8_t max_voltage;

// Flags
uint8_t COSD_FLAGS_MODES, COSD_FLAGS_CONFIG, COSD_FLAGS_RUNTIME, COSD_DISPLAYMODE;

// stats for after flight
int16_t max_Altimeter, altimeter_offset;
uint8_t min_UBat;

uint16_t max_GroundSpeed;
int16_t max_Distance;
uint16_t max_FlyingTime;

// flags from last round to check for changes
uint8_t old_MKFlags;

const char *directions[8];
const char *stats_item_pointers[8];