Subversion Repositories FlightCtrl

Compare Revisions

Ignore whitespace Rev 2416 → Rev 2417

/I2C_Telemetry/trunk/main.c
4,7 → 4,7
// + Software Nutzungsbedingungen (english version: see below)
// + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt -
// + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den
// + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool
// + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool
// + - nachfolgend Software genannt - nur für private Zwecke zu nutzen.
// + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig.
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
15,7 → 15,7
// + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren
// + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
// + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren
// + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand
// + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand
// + des Mitverschuldens offen.
// + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet.
// + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
29,7 → 29,7
// + Software LICENSING TERMS
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor -
// + The Licensor grants the customer a non-exclusive license to use the microcontroller firmware of the Flight-Ctrl, Navi-Ctrl, BL-Ctrl, and MK3Mag hardware
// + The Licensor grants the customer a non-exclusive license to use the microcontroller firmware of the Flight-Ctrl, Navi-Ctrl, BL-Ctrl, and MK3Mag hardware
// + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*.
// + The Software may only be used with the Licensor's products.
// + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this
50,6 → 50,8
// + #### END OF LICENSING TERMS ####
// + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de.
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
#include "stdio.h"
#include "main.h"
unsigned char DisableRcOffBeeping = 0;
unsigned char PlatinenVersion = 10;
121,21 → 123,21
unsigned int timer,i,timer2 = 0, timerPolling, timer1000ms;
unsigned char update_spi = 1, count5sec = 0;
DDRB = 0x00;
PORTB = 0x00;
PORTB = 0x00;
DDRD = 0x0A; // UART & J3 J4 J5
PORTD = 0x5F; // PPM-Input & UART
for(timer = 0; timer < 1000; timer++); // verzögern
 
 
if(PINB & 0x02)
if(PINB & 0x02)
{
if(PIND & 0x10) PlatinenVersion = 21; // No Bridge from J4 to GND
else { PlatinenVersion = 22; ACC_AltitudeControl = 1;};
}
else
else
{
PlatinenVersion = 25; ACC_AltitudeControl = 1;
}
}
 
 
DDRC = 0x81; // I2C, Speaker, TXD_PC_OFF
164,14 → 166,14
UBX_Init();
Capacity_Init();
LIBTEL_Init(LIB_TEL_COMPATIBLE);
 
GRN_ON;
sei();
ParamSet_Init();
 
 
 
 
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Check connected BL-Ctrls
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
184,9 → 186,9
 
printf("\n\rFound BL-Ctrl: ");
timer = SetDelay(4000);
 
timer1000ms = SetDelay(1000);
 
for(i=0; i < MAX_MOTORS; i++)
{
SendMotorData();
223,12 → 225,12
 
 
Fat16_Init();
// initialize the settings
// initialize the settings
Settings_Init();
// initialize logging (needs settings)
Logging_Init();
 
 
//if(EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)
{
printf("\n\rCalibrating pressure sensor..");
271,21 → 273,76
DebugOut.Status[0] = 0x01 | 0x02;
JetiBeep = 0;
if(EE_Parameter.ExtraConfig & CFG_NO_RCOFF_BEEPING) DisableRcOffBeeping = 1;
 
EEAR = EE_DUMMY; // Set the EEPROM Address pointer to an unused space
 
 
{
uint8_t i, buffer[512];
SD_Result_t res;
printf("\r\n Buffer: ");
for(i = 0; i<26 ; i++)
{
buffer[i] = 'a'+ i;
uart_putchar(buffer[i]);
}
res = SDC_PutSector(501, buffer);
printf("\r\n Put Sector = %d", res);
printf("\r\n Buffer: ");
for(i = 0; i<26 ; i++)
{
uart_putchar(buffer[i]);
}
 
res = SDC_GetSector (501, buffer);
printf("\r\n Get Sector = %d", res);
printf("\r\n Buffer: ");
for(i = 0; i<26 ; i++)
{
uart_putchar(buffer[i]);
}
 
}
/*
 
{
int8_t filename[] = "/toast/toasta/toast.txt";
File_t* f = 0;
 
 
printf("\r\nStart writing file");
f = fopen_("/toast/toasta/toast.txt", 'a');
if(f!= NULL)
{
printf("ok");
 
if(EOF == fputs_("\r\ntest edins sdv dsivbds iv dsivb disbv idsv bisd bv d suiv dsibsivbdis fbvisdöb visdbvisdb vidbfibds ibv", f))
printf("\r\nfputs error");
 
printf("\r\nClosing file:");
fclose_(f);
 
}
else
{
printf("failed");
}
}
*/
 
while(1)
{
if(SD_WatchDog)
 
if(SD_WatchDog)
{
SD_WatchDog = 30000;
//if(SDCardInfo.Valid == 1)
//if(SDCardInfo.Valid == 1)
Logging_Update(); // could be block some time for at max. 2 seconds, therefore move time critical part of the mainloop into the ISR of timer 1
// else if(FC_StatusFlags & FC_STATUS_START) SD_LoggingError = 100;
if(!SD_WatchDog) printf("\n\rSD-Watchdog - Logging aborted\n\r");
}
 
 
if(ReceiverUpdateModeActive) while (1) PORTC &= ~(1<<7); // Beeper off
//GRN_ON;
if(UpdateMotor && AdReady) // ReglerIntervall
292,12 → 349,12
{
//GRN_OFF;
cli();
UpdateMotor--;
UpdateMotor--;
sei();
MotorRegler();
 
FC_StatusFlags |= FC_STATUS_FLY;
 
SendMotorData();
ROT_OFF;
if(SenderOkay) { SenderOkay--; /*VersionInfo.HardwareError[1] &= ~FC_ERROR1_PPM;*/ }
315,8 → 372,8
count5sec = 0;
FreqGpsProcessedIn5Sec = CountGpsProcessedIn5Sec * 2;
FreqNewGpsDataIn5Sec = CountNewGpsDataIn5Sec * 2;
CountGpsProcessedIn5Sec = 0;
CountNewGpsDataIn5Sec = 0;
CountGpsProcessedIn5Sec = 0;
CountNewGpsDataIn5Sec = 0;
}
timer1000ms = SetDelay(1000);
}
345,8 → 402,8
LIBTEL_Polling();
 
if(!UpdateMotor)
{
if(NewSBusData) ProcessSBus();
{
if(NewSBusData) ProcessSBus();
else
{
if(CalculateServoSignals) CalculateServo();
360,7 → 417,7
CalcNickServoValue();
 
if(EE_Parameter.Receiver == RECEIVER_HOTT) HoTT_Menu();
else
else
if(EE_Parameter.Receiver == RECEIVER_JETI) BuildJeti_Vario();
 
if(MissingMotor)
370,10 → 427,10
}
else
{
if(!beeptime)
if(!beeptime)
{
if(I2CTimeout > 6) DebugOut.Status[1] &= ~0x02; // BL-Error-Status
}
}
}
if(DisableRcOffBeeping) if(SenderOkay > 150) { DisableRcOffBeeping = 0; beeptime = 5000;};
if(PcZugriff) PcZugriff--;
385,15 → 442,15
ExternStickGier = 0;
if(!SenderOkay)
{
if(BeepMuster == 0xffff && DisableRcOffBeeping != 2)
if(BeepMuster == 0xffff && DisableRcOffBeeping != 2)
{
beeptime = 15000;
BeepMuster = 0x0c00;
if(DisableRcOffBeeping) DisableRcOffBeeping = 2;
}
}
}
}
 
if(UBat < BattLowVoltageWarning)
{
FC_StatusFlags |= FC_STATUS_LOWBAT;
414,13 → 471,13
if(ShowSettingNameTime) ShowSettingNameTime--;
if(FC_StatusFlags & FC_STATUS_FLY) FlugSekunden++;
else timer2 = 1450; // 0,5 Minuten aufrunden
 
if(modell_fliegt < 1024)
{
if(StartLuftdruck < Luftdruck) StartLuftdruck += 5;
if(StartLuftdruck < Luftdruck) StartLuftdruck += 5;
else
if(StartLuftdruck > Luftdruck) StartLuftdruck -= 5;
}
if(StartLuftdruck > Luftdruck) StartLuftdruck -= 5;
}
}
// +++++++++++++++++++++++++++++++++
if(++timer2 == 2930) // eine Minute
437,16 → 494,16
}
LED_Update();
Capacity_Update();
}
}
} //else DebugOut.Analog[18]++;
if(update_spi) update_spi--;
} // 500Hz
/*if(update_spi == 0) // 41Hz
{
if(SPI_StartTransmitPacket()) update_spi = 12;
else
if(BytegapSPI == 0) SPI_TransmitByte();
}
{
if(SPI_StartTransmitPacket()) update_spi = 12;
else
if(BytegapSPI == 0) SPI_TransmitByte();
}
else if(BytegapSPI == 0) SPI_TransmitByte(); */
}
}