diff --git a/src/frsky.cpp b/src/frsky.cpp index b1398c380..b87b43bd3 100644 --- a/src/frsky.cpp +++ b/src/frsky.cpp @@ -139,10 +139,11 @@ inline void getGpsDistance() inline int8_t parseTelemHubIndex(uint8_t index) { - if (index > 0x3b) - index = 255; // invalid index - if (index > 0x39) + if (index > 0x39) { + if (index > 0x3b) + return -1; // invalid index index -= 17; + } return index*2; } diff --git a/src/jeti.cpp b/src/jeti.cpp index d496516b4..aa92ca1b1 100644 --- a/src/jeti.cpp +++ b/src/jeti.cpp @@ -37,7 +37,7 @@ uint16_t jeti_keys = JETI_KEY_NOCHANGE; uint8_t JetiBuffer[32]; // 32 characters uint8_t JetiBufferReady; - +#ifndef SIMU ISR (USART0_RX_vect) { uint8_t stat; @@ -76,8 +76,7 @@ ISR (USART0_RX_vect) } } - - +#endif void JETI_Init (void) { @@ -87,6 +86,8 @@ void JETI_Init (void) DDRE &= ~(1 << DDE0); // set RXD0 pin as input PORTE &= ~(1 << PORTE0); // disable pullup on RXD0 pin +#ifndef SIMU + #undef BAUD #define BAUD 9600 #include @@ -102,6 +103,7 @@ void JETI_Init (void) // flush receive buffer while ( UCSR0A & (1 << RXC0) ) UDR0; +#endif } diff --git a/src/logs.cpp b/src/logs.cpp index 34b56b09b..b494a7729 100644 --- a/src/logs.cpp +++ b/src/logs.cpp @@ -33,15 +33,13 @@ #include "open9x.h" #include "ff.h" -// "/G9XLOGS/M00_000.TXT\0" max required length = 21 -char g_logFilename[22]; - -// These global so we can close any open file from anywhere -FATFS FATFS_Obj; +char g_logFilename[21]; // "/O9XLOGS/M00_000.CSV\0" max required length = 21 +FATFS g_FATFS_Obj; FIL g_oLogFile; int8_t g_logState = 0; // 0=closed, >0=opened, <0=error +const pm_char * g_logError = NULL; -void startLogs() +void initLogs() { // Determine and set log file filename FRESULT result; @@ -50,22 +48,23 @@ void startLogs() if (g_oLogFile.fs) f_close(&g_oLogFile); g_logState = 0; - strcpy_P(g_logFilename, PSTR("/G9XLOGS/M00_000.TXT")); + strcpy_P(g_logFilename, PSTR(LOG_PATH "M00_000.CSV")); + // Set log file model number uint8_t num = g_eeGeneral.currModel + 1; - char *n = &g_logFilename[11]; + char *n = &g_logFilename[11]; // TODO constant *n = (char)((num % 10) + '0'); *(--n) = (char)((num / 10) + '0'); - result = f_mount(0, &FATFS_Obj); + result = f_mount(0, &g_FATFS_Obj); if (result!=FR_OK) { - strcpy_P(g_logFilename, PSTR("FILE SYSTEM ERROR")); g_logState = -result; + g_logError = PSTR("SDCARD F/S ERROR"); return; } - // Skip over any existing log files ... _000, _001, etc. (or find first gap in numbering) + // Loop, skipping over any existing log files ... _000, _001, etc. until we have a unique file name while (1) { result = f_open(&g_oLogFile, g_logFilename, FA_OPEN_EXISTING | FA_READ); @@ -97,10 +96,10 @@ void startLogs() } else if (result == FR_NO_PATH) { - if (f_mkdir("/G9XLOGS") != FR_OK) + if (f_mkdir(LOG_PATH) != FR_OK) { - strcpy_P(g_logFilename, PSTR("Check /G9XLOGS folder")); g_logState = -result; + g_logError = PSTR("Check " LOG_PATH " folder"); return; } } @@ -108,9 +107,9 @@ void startLogs() { g_logState = -result; if (result == FR_NOT_READY) - strcpy_P(g_logFilename, PSTR("DATA CARD NOT PRESENT")); + g_logError = PSTR("NO SDCARD"); else - strcpy_P(g_logFilename, PSTR("DATA CARD ERROR")); + g_logError = PSTR("SDCARD ERROR"); return; } } @@ -118,8 +117,7 @@ void startLogs() // g_logFilename should now be set appropriately. } -// TODO FORCEINLINE this function -void doLogs() +void writeLogs() { FRESULT result; @@ -127,25 +125,32 @@ void doLogs() { if (g_logState==0) { - result = f_mount(0, &FATFS_Obj); + result = f_mount(0, &g_FATFS_Obj); if (result != FR_OK) { g_logState = -result; // TODO beepAgain = result - 1; - AUDIO_KEYPAD_UP(); + AUDIO_WARNING1(); } else { - // create new log file using filename set up in startLogs() + // create new log file using filename set up in initLogs() result = f_open(&g_oLogFile, g_logFilename, FA_OPEN_ALWAYS | FA_WRITE); if (result != FR_OK) { g_logState = -result; - // TODO beepAgain = result - 1; + // TODO beepAgain = result - 1; // TODO FOR DEBUG -- count out error_number beeps AUDIO_KEYPAD_UP(); } else { + if (g_oLogFile.fsize == 0) { + // if data type == Hub TODO + f_puts("Buffer,RX,TX,A1,A2,Date,Time,Long,Lat,Course,Speed,Alt,BarAlt," + "Temp1,Temp2,RPM,Fuel,Volts,AccelX,AccelY,AccelZ,THR,RUD,ELE,IDL0,IDL1,IDL2,AIL,GEA,TRN\n", + &g_oLogFile); + } + f_lseek(&g_oLogFile, g_oLogFile.fsize); // append g_logState = 1; AUDIO_WARNING2(); @@ -155,7 +160,44 @@ void doLogs() if (g_logState>0) { - // TODO here we write logs +// For now, append 'anything' as a test + // if data type == Hub + f_printf(&g_oLogFile, "%d,", frskyStreaming); + f_printf(&g_oLogFile, "%d,", frskyRSSI[0].value); + f_printf(&g_oLogFile, "%d,", frskyRSSI[1].value); + f_printf(&g_oLogFile, "%d,", frskyTelemetry[0].value); + f_printf(&g_oLogFile, "%d,", frskyTelemetry[1].value); + f_printf(&g_oLogFile, "%4d-%02d-%02d,", frskyHubData.year+2000, frskyHubData.month, frskyHubData.day); + f_printf(&g_oLogFile, "%02d:%02d:%02d,", frskyHubData.hour, frskyHubData.min, frskyHubData.sec); + f_printf(&g_oLogFile, "%03d.%04d%c,", frskyHubData.gpsLongitude_bp, frskyHubData.gpsLongitude_ap, + frskyHubData.gpsLongitudeEW ? frskyHubData.gpsLongitudeEW : '-'); + f_printf(&g_oLogFile, "%03d.%04d%c,", frskyHubData.gpsLatitude_bp, frskyHubData.gpsLatitude_ap, + frskyHubData.gpsLatitudeNS ? frskyHubData.gpsLatitudeNS : '-'); + f_printf(&g_oLogFile, "%03d.%d,", frskyHubData.gpsCourse_bp, frskyHubData.gpsCourse_ap); + f_printf(&g_oLogFile, "%d.%d,", frskyHubData.gpsSpeed_bp, frskyHubData.gpsSpeed_ap); + f_printf(&g_oLogFile, "%03d.%d,", frskyHubData.gpsAltitude_bp, frskyHubData.gpsAltitude_ap); + f_printf(&g_oLogFile, "%d.%d,", frskyHubData.baroAltitude_bp + frskyHubData.baroAltitudeOffset, frskyHubData.baroAltitude_ap); + f_printf(&g_oLogFile, "%d,", frskyHubData.temperature1); + f_printf(&g_oLogFile, "%d,", frskyHubData.temperature2); + f_printf(&g_oLogFile, "%d,", frskyHubData.rpm); + f_printf(&g_oLogFile, "%d,", frskyHubData.fuelLevel); + f_printf(&g_oLogFile, "%d,", frskyHubData.volts); + f_printf(&g_oLogFile, "%d,", frskyHubData.accelX); + f_printf(&g_oLogFile, "%d,", frskyHubData.accelY); + f_printf(&g_oLogFile, "%d,", frskyHubData.accelZ); + f_printf(&g_oLogFile, "%d,", keyState(SW_ThrCt)); + f_printf(&g_oLogFile, "%d,", keyState(SW_RuddDR)); + f_printf(&g_oLogFile, "%d,", keyState(SW_ElevDR)); + f_printf(&g_oLogFile, "%d,", keyState(SW_ID0)); + f_printf(&g_oLogFile, "%d,", keyState(SW_ID1)); + f_printf(&g_oLogFile, "%d,", keyState(SW_ID2)); + f_printf(&g_oLogFile, "%d,", keyState(SW_AileDR)); + f_printf(&g_oLogFile, "%d,", keyState(SW_Gear)); + f_printf(&g_oLogFile, "%d\n", keyState(SW_Trainer)); + + // Don't close the log file here. We have 'soft off' available on the v4.1 board. Once + // that is implemented, it can take care of closing the file, should the radio be + // powered off before the FUNC SWITCH is turned off. } } else if (g_logState > 0) diff --git a/src/logs.h b/src/logs.h new file mode 100644 index 000000000..4d06adabf --- /dev/null +++ b/src/logs.h @@ -0,0 +1,47 @@ +/* + * Authors (alphabetical order) + * - Bertrand Songis + * - Bryan J. Rentoul (Gruvin) + * - Cameron Weeks + * - Erez Raviv + * - Jean-Pierre Parisy + * - Karl Szmutny + * - Michael Blandford + * - Michal Hlavinka + * - Philip Moss + * - Rob Thomson + * - Romolo Manfredini + * - Thomas Husterer + * + * open9x is based on code named + * gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/, + * er9x by Erez Raviv: http://code.google.com/p/er9x/, + * and the original (and ongoing) project by + * Thomas Husterer, th9x: http://code.google.com/p/th9x/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * 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. + * + */ + +#ifndef LOGS_H +#define LOGS_H + +#define LOG_PATH "/O9XLOGS" // no trailing slash = important + +extern char g_logFilename[21]; // "/O9XLOGS/M00_000.CSV\0" max required length = 21 +extern int8_t g_logState; // 0=closed, >0 = opened, <0 is error +extern FATFS g_FATFS_Obj; +extern FIL g_oLogFile; + +extern void initLogs(); +extern void writeLogs(); + +#endif + diff --git a/src/menus.h b/src/menus.h index 07481bf22..3e7de8cb0 100644 --- a/src/menus.h +++ b/src/menus.h @@ -36,8 +36,6 @@ #include #include "open9x.h" -#define IS_THROTTLE(x) (((2-(g_eeGeneral.stickMode&1)) == x) && (x<4)) - #define NO_HI_LEN 25 #define RESX 1024 @@ -110,6 +108,9 @@ int8_t checkIncDecGen(uint8_t event, int8_t i_val, int8_t i_min, int8_t i_max); #ifdef NAVIGATION_RE1 extern int8_t *s_inflight_value; extern const pm_char *s_inflight_label; +extern int16_t s_inflight_min; +extern int16_t s_inflight_max; +extern int16_t s_inflight_shift; #define INFLIGHT(val) (s_inflight_value==&val ? SURROUNDED : 0) void checkInFlightIncDecModel(uint8_t event, int8_t *value, int16_t i_min, int16_t i_max, int8_t i_shift, const pm_char *label); #define CHECK_INFLIGHT_INCDEC_MODELVAR(event, var, imin, imax, ishift, label) \ diff --git a/src/model_menus.cpp b/src/model_menus.cpp index 9ebfd677b..7025dd109 100644 --- a/src/model_menus.cpp +++ b/src/model_menus.cpp @@ -891,7 +891,7 @@ void menuProcCurveOne(uint8_t event) break; case EVT_KEY_REPT(KEY_RIGHT): case EVT_KEY_FIRST(KEY_RIGHT): - if (!autoThrStep && m_posHorz<((s_editMode>0) ? points-1 : ((g_menuStack[g_menuStackPtr-1] == menuProcExpoOne && IS_THROTTLE(expoaddress(s_currIdx)->chn)) ? 2 : 1))) m_posHorz++; + if (!autoThrStep && m_posHorz<((s_editMode>0) ? points-1 : ((g_menuStack[g_menuStackPtr-1] == menuProcExpoOne && expoaddress(s_currIdx)->chn == THR_STICK) ? 2 : 1))) m_posHorz++; break; } diff --git a/src/open9x.cpp b/src/open9x.cpp index 9ddfb2f35..6f3de2175 100644 --- a/src/open9x.cpp +++ b/src/open9x.cpp @@ -1178,8 +1178,8 @@ void perOut(int16_t *chanOut, uint8_t phase) if (s_noStickInputs) { for (uint8_t i=0; i> 8 ) ; // Checksum hi - putPcmByte( 0x7E ) ; // sync byte + putPcmHead( ) ; putPcmFlush() ; OCR1C += 40000 ; // 20mS on PORTB |= (1<