Subversion Repositories Projects

Compare Revisions

Ignore whitespace Rev 461 → Rev 465

/C-OSD/trunk/CHANGE.LOG
18,6 → 18,9
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
****************************************************************************/
 
20090516-2345
+some really testing stuff 'bout current measurement, more to come
 
20090513-2350
*cellnumber autoconfig modified, offset set to 1,5V
*copy paste nick/roll error fixed
/C-OSD/trunk/main.c
60,6 → 60,7
// 16bit should be enough, normal LiPos don't last that long
volatile uint16_t uptime = 0;
volatile uint16_t timer = 0;
volatile uint8_t short_timer = 0;
 
// remember last time data was received
volatile uint8_t seconds_since_last_data = 0;
90,7 → 91,7
uint8_t max_voltage = 0;
 
// Flags
uint8_t COSD_FLAGS = 0;
uint8_t COSD_FLAGS = 0, COSD_FLAGS2;
 
/* ##########################################################################
* debounce buttons
128,6 → 129,76
* timer stuff
* ##########################################################################*/
 
 
/* ##########################################################################
* STROM TEST
* ##########################################################################*/
#define INT0_HIGH PORTD |= (1 << PD2);
#define INT0_LOW PORTD &= ~(1 << PD2);
 
void SpiMasterInit(void)
{
volatile char IOReg;
// set PB4(/SS), PB5(MOSI), PB7(SCK) as output
DDRB = (1<<PB4)|(1<<PB5)|(1<<PB7);
PORTB |= (1 << PB4); // pullup SS
// enable SPI Interrupt and SPI in Master Mode with SCK = CK/128
SPCR = (1<<SPIE)|(1<<SPE)|(1<<MSTR)|(1<<SPR0)|(1<<SPR1);
IOReg = SPSR; // clear SPIF bit in SPSR
IOReg = SPDR;
//sei(); // we do it later
}
 
volatile size_t icnt = 0;
volatile unsigned char * iptr;
volatile unsigned char spi_cmd[5];
volatile uint8_t spi_ready = 1;
int16_t ampere = 0;
 
ISR(SPI_STC_vect)
{
/* Empfangenes Byte im Puffer ablegen. */
*iptr++ = SPDR;
/* Zähler dekrementieren. */
icnt--;
/* Falls Zähler noch nicht 0 ist... */
if (icnt) {
///_delay_ms(1);
/* ...nächstes Byte senden. */
//SPDR = *iptr;
spi_ready = 1;
}
else {
/* ...andernfalls Interrupt Modus deaktivieren. */
SPCR &= ~_BV(SPIE);
INT0_HIGH
//_delay_ms(1);
}
}
 
int TransferIsBusy(void)
{
return SPCR & _BV(SPIE);
}
 
void StartTransfer(unsigned char *data, size_t len)
{
INT0_LOW
/* Interrupt Datenpointer und Zähler setzen. */
iptr = data;
icnt = len;
/* SPI Interrupt aktivieren und Transfer anstossen. */
SPCR |= _BV(SPIE);
SPDR = *iptr;
}
 
 
/* ##########################################################################
* / STROM TEST END
* ##########################################################################*/
 
 
/**
* timer kicks in every 1000uS ^= 1ms
*/
138,9 → 209,12
timer = 999;
seconds_since_last_data++;
}
short_timer++;
if (spi_ready && icnt) {
SPDR = *iptr;
}
}
 
 
/* ##########################################################################
* A simple config menu for the flags
* ##########################################################################*/
333,12 → 407,13
COSD_FLAGS &= ~COSD_ICONS_WRITTEN;
}
 
#endif // ends !(ALLCHARSDEBUG|(WRITECHARS != -1))
#endif // ends !(ALLCHARSDEBUG|(WRITECHARS != -1))#endif // ends !(ALLCHARSDEBUG|(WRITECHARS != -1))
 
/* ##########################################################################
* MAIN
* ##########################################################################*/
int main(void) {
// set up FLAGS, compiler should flatten this one
COSD_FLAGS = (NTSC << 0);
COSD_FLAGS |= (HUD << 1);
426,8 → 501,12
OCR0 = 15; // preload
TIMSK |= (1 << TOIE0); // enable overflow timer0
 
DDRD |= (1 << PD2); // PD2 output (INT0)
SpiMasterInit();
 
// enable interrupts
sei();
#endif
 
//write_ascii_string(2, 7, " CaScAdE ");
470,7 → 549,27
//char arrowdir[8] = {218, 217, 224, 223, 222, 221, 220, 219};
#endif
 
 
 
while (1) {
if (!icnt && spi_ready) {
short_timer = 0;
ampere = spi_cmd[1] << 8;
ampere |= spi_cmd[2];
//write_ascii_char(7+4*30, spi_cmd[0]);
if (spi_cmd[0] == 'd') {
COSD_FLAGS2 |= COSD_FLAG_STROMREC;
//write_ascii_char(8+4*30, 'v'); // valid
} else {
COSD_FLAGS2 &= ~COSD_FLAG_STROMREC;
//write_ascii_char(8+4*30, 'i'); // invalid
}
spi_cmd[0] = 'A';
spi_cmd[1] = 'B';
spi_cmd[2] = 'C';
StartTransfer((unsigned char*)spi_cmd, 3);
}
if (rxd_buffer_locked) {
if (COSD_FLAGS & COSD_FLAG_HUD) {
#if FCONLY
/C-OSD/trunk/main.h
71,6 → 71,8
#define COSD_ICONS_WRITTEN 64
#define COSD_WASFLYING 128
 
#define COSD_FLAG_STROMREC 1
 
/* ##########################################################################
* LED controll
* ##########################################################################*/
/C-OSD/trunk/osd_ncmode_default.c
27,7 → 27,10
write_char_xy(20, top_line + 1, 0xB0); // left circle
write_char_xy(22, top_line + 1, 0xB2); // right circle
write_char_xy(27, top_line + 1, 0xCC); // small meters m home
write_char_xy(7, bottom_line, 0x9E); // small v
write_char_xy(7, bottom_line, 0x9E); // small V
if (COSD_FLAGS2 & COSD_FLAG_STROMREC) {
write_char_xy(7, bottom_line, 0x9F); // small A
}
write_char_xy(14, bottom_line, 0xD1); // on clock
write_char_xy(21, bottom_line, 0xD2); // fly clock
write_char_xy(26, bottom_line, 0xC8); // sat1
123,6 → 126,11
draw_big_variometer(27, 8, naviData.Variometer);
}
 
// pre-bottom line
if (COSD_FLAGS2 & COSD_FLAG_STROMREC) {
write_ndigit_number_s(3, bottom_line - 1, ampere, 1000, 0);
}
 
// bottom line
draw_battery(2, bottom_line, min_voltage, naviData.UBat, max_voltage);
write_ndigit_number_u_10th(3, bottom_line, naviData.UBat, 100, 0);