Logs : log all switches based on hardware config (#6611)
Make switch logging using hardware config
This commit is contained in:
@@ -791,7 +791,7 @@ void putsModelName(coord_t x, coord_t y, char *name, uint8_t id, LcdFlags att)
|
||||
void drawSwitch(coord_t x, coord_t y, swsrc_t idx, LcdFlags flags)
|
||||
{
|
||||
char s[8];
|
||||
getSwitchString(s, idx);
|
||||
getSwitchPositionName(s, idx);
|
||||
lcdDrawText(x, y, s, flags);
|
||||
}
|
||||
|
||||
|
||||
@@ -696,7 +696,7 @@ void putsModelName(coord_t x, coord_t y, char *name, uint8_t id, LcdFlags att)
|
||||
void drawSwitch(coord_t x, coord_t y, int32_t idx, LcdFlags flags)
|
||||
{
|
||||
char s[8];
|
||||
getSwitchString(s, idx);
|
||||
getSwitchPositionName(s, idx);
|
||||
lcdDrawText(x, y, s, flags);
|
||||
}
|
||||
|
||||
|
||||
@@ -290,7 +290,7 @@ void putsModelName(coord_t x, coord_t y, char * name, uint8_t id, LcdFlags att)
|
||||
void drawSwitch(coord_t x, coord_t y, swsrc_t idx, LcdFlags flags)
|
||||
{
|
||||
char s[8];
|
||||
getSwitchString(s, idx);
|
||||
getSwitchPositionName(s, idx);
|
||||
lcdDrawText(x, y, s, flags);
|
||||
}
|
||||
|
||||
|
||||
+29
-61
@@ -22,20 +22,21 @@
|
||||
#include "ff.h"
|
||||
|
||||
FIL g_oLogFile __DMA;
|
||||
const char * g_logError = NULL;
|
||||
const char * g_logError = nullptr;
|
||||
uint8_t logDelay;
|
||||
|
||||
void writeHeader();
|
||||
|
||||
#if defined(PCBTARANIS) || defined(PCBHORUS)
|
||||
#define GET_2POS_STATE(sw) (switchState(SW_ ## sw ## 0) ? -1 : 1)
|
||||
int getSwitchState(uint8_t swtch) {
|
||||
int value = getValue(MIXSRC_FIRST_SWITCH + swtch);
|
||||
return (value == 0) ? 0 : (value < 0) ? -1 : +1;
|
||||
}
|
||||
#else
|
||||
#define GET_2POS_STATE(sw) (switchState(SW_ ## sw) ? -1 : 1)
|
||||
#define GET_3POS_STATE(sw) (switchState(SW_ ## sw ## 0) ? -1 : (switchState(SW_ ## sw ## 2) ? 1 : 0))
|
||||
#endif
|
||||
|
||||
#define GET_3POS_STATE(sw) (switchState(SW_ ## sw ## 0) ? -1 : (switchState(SW_ ## sw ## 2) ? 1 : 0))
|
||||
|
||||
|
||||
void logsInit()
|
||||
{
|
||||
memset(&g_oLogFile, 0, sizeof(g_oLogFile));
|
||||
@@ -108,7 +109,7 @@ const char * logsOpen()
|
||||
writeHeader();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
tmr10ms_t lastLogTime = 0;
|
||||
@@ -166,18 +167,18 @@ void writeHeader()
|
||||
}
|
||||
f_putc(',', &g_oLogFile);
|
||||
}
|
||||
#if defined(PCBX7)
|
||||
#define STR_SWITCHES_LOG_HEADER "SA,SB,SC,SD,SF,SH"
|
||||
#elif defined(PCBXLITE)
|
||||
#define STR_SWITCHES_LOG_HEADER "SA,SB,SC,SD"
|
||||
#elif defined(PCBXLITES)
|
||||
#define STR_SWITCHES_LOG_HEADER "SA,SB,SC,SD,SE,SF"
|
||||
#elif defined(PCBX9LITE)
|
||||
#define STR_SWITCHES_LOG_HEADER "SA,SB,SC,SE,SF"
|
||||
#else
|
||||
#define STR_SWITCHES_LOG_HEADER "SA,SB,SC,SD,SE,SF,SG,SH"
|
||||
#endif
|
||||
f_puts(STR_SWITCHES_LOG_HEADER ",LSW,", &g_oLogFile);
|
||||
|
||||
for (uint8_t i=0; i<NUM_SWITCHES; i++) {
|
||||
if (SWITCH_EXISTS(i)) {
|
||||
char s[LEN_SWITCH_NAME + 2];
|
||||
char * temp;
|
||||
temp = getSwitchName(s, SWSRC_FIRST_SWITCH + i * 3);
|
||||
*temp++ = ',';
|
||||
*temp = '\0';
|
||||
f_puts(s, &g_oLogFile);
|
||||
}
|
||||
}
|
||||
f_puts("LSW,", &g_oLogFile);
|
||||
#else
|
||||
f_puts("Rud,Ele,Thr,Ail,P1,P2,P3,THR,RUD,ELE,3POS,AIL,GEA,TRN,", &g_oLogFile);
|
||||
#endif
|
||||
@@ -196,7 +197,7 @@ uint32_t getLogicalSwitchesStates(uint8_t first)
|
||||
|
||||
void logsWrite()
|
||||
{
|
||||
static const char * error_displayed = NULL;
|
||||
static const char * error_displayed = nullptr;
|
||||
|
||||
if (isFunctionActive(FUNCTION_LOGS) && logDelay > 0) {
|
||||
tmr10ms_t tmr10ms = get_tmr10ms();
|
||||
@@ -205,7 +206,7 @@ void logsWrite()
|
||||
|
||||
if (!g_oLogFile.obj.fs) {
|
||||
const char * result = logsOpen();
|
||||
if (result != NULL) {
|
||||
if (result) {
|
||||
if (result != error_displayed) {
|
||||
error_displayed = result;
|
||||
POPUP_WARNING(result);
|
||||
@@ -272,46 +273,13 @@ void logsWrite()
|
||||
f_printf(&g_oLogFile, "%d,", calibratedAnalogs[i]);
|
||||
}
|
||||
|
||||
// TODO: use hardware config to populate
|
||||
#if defined(PCBX9LITE)
|
||||
f_printf(&g_oLogFile, "%d,%d,%d,%d,0x%08X%08X,",
|
||||
GET_3POS_STATE(SA),
|
||||
GET_3POS_STATE(SB),
|
||||
GET_3POS_STATE(SC),
|
||||
GET_2POS_STATE(SD),
|
||||
GET_2POS_STATE(SE),
|
||||
getLogicalSwitchesStates(32),
|
||||
getLogicalSwitchesStates(0));
|
||||
#elif defined(PCBXLITE)
|
||||
f_printf(&g_oLogFile, "%d,%d,%d,%d,0x%08X%08X,",
|
||||
GET_3POS_STATE(SA),
|
||||
GET_3POS_STATE(SB),
|
||||
GET_3POS_STATE(SC),
|
||||
GET_3POS_STATE(SD),
|
||||
getLogicalSwitchesStates(32),
|
||||
getLogicalSwitchesStates(0));
|
||||
#elif defined(PCBX7)
|
||||
f_printf(&g_oLogFile, "%d,%d,%d,%d,%d,%d,0x%08X%08X,",
|
||||
GET_3POS_STATE(SA),
|
||||
GET_3POS_STATE(SB),
|
||||
GET_3POS_STATE(SC),
|
||||
GET_3POS_STATE(SD),
|
||||
GET_2POS_STATE(SF),
|
||||
GET_2POS_STATE(SH),
|
||||
getLogicalSwitchesStates(32),
|
||||
getLogicalSwitchesStates(0));
|
||||
#elif defined(PCBTARANIS) || defined(PCBHORUS)
|
||||
f_printf(&g_oLogFile, "%d,%d,%d,%d,%d,%d,%d,%d,0x%08X%08X,",
|
||||
GET_3POS_STATE(SA),
|
||||
GET_3POS_STATE(SB),
|
||||
GET_3POS_STATE(SC),
|
||||
GET_3POS_STATE(SD),
|
||||
GET_3POS_STATE(SE),
|
||||
GET_2POS_STATE(SF),
|
||||
GET_3POS_STATE(SG),
|
||||
GET_2POS_STATE(SH),
|
||||
getLogicalSwitchesStates(32),
|
||||
getLogicalSwitchesStates(0));
|
||||
#if defined(PCBTARANIS) || defined(PCBHORUS)
|
||||
for (uint8_t i=0; i<NUM_SWITCHES; i++) {
|
||||
if (SWITCH_EXISTS(i)) {
|
||||
f_printf(&g_oLogFile, "%d,", getSwitchState(i));
|
||||
}
|
||||
}
|
||||
f_printf(&g_oLogFile, "0x%08X%08X,", getLogicalSwitchesStates(32), getLogicalSwitchesStates(0));
|
||||
#else
|
||||
f_printf(&g_oLogFile, "%d,%d,%d,%d,%d,%d,%d,",
|
||||
GET_2POS_STATE(THR),
|
||||
@@ -334,7 +302,7 @@ void logsWrite()
|
||||
}
|
||||
}
|
||||
else {
|
||||
error_displayed = NULL;
|
||||
error_displayed = nullptr;
|
||||
if (g_oLogFile.obj.fs) {
|
||||
logsClose();
|
||||
}
|
||||
|
||||
+32
-23
@@ -241,7 +241,36 @@ char * getGVarString(char * dest, int idx)
|
||||
return dest;
|
||||
}
|
||||
|
||||
char * getSwitchString(char * dest, swsrc_t idx)
|
||||
#if !defined(PCBSKY9X)
|
||||
char * getSwitchName(char * dest, swsrc_t idx)
|
||||
{
|
||||
div_t swinfo = switchInfo(idx);
|
||||
if (ZEXIST(g_eeGeneral.switchNames[swinfo.quot])) {
|
||||
dest += zchar2str(dest, g_eeGeneral.switchNames[swinfo.quot], LEN_SWITCH_NAME);
|
||||
// TODO tous zchar2str
|
||||
}
|
||||
else {
|
||||
*dest++ = 'S';
|
||||
#if defined(PCBX7)
|
||||
if (swinfo.quot >= 5)
|
||||
*dest++ = 'H' + swinfo.quot - 5;
|
||||
else if (swinfo.quot == 4)
|
||||
#if defined(RADIO_T12)
|
||||
*dest++ = 'G';
|
||||
#else
|
||||
*dest++ = 'F';
|
||||
#endif
|
||||
else
|
||||
*dest++ = 'A'+swinfo.quot;
|
||||
#else
|
||||
*dest++ = 'A' + swinfo.quot;
|
||||
#endif
|
||||
}
|
||||
return dest;
|
||||
}
|
||||
#endif
|
||||
|
||||
char * getSwitchPositionName(char * dest, swsrc_t idx)
|
||||
{
|
||||
if (idx == SWSRC_NONE) {
|
||||
return getStringAtIndex(dest, STR_VSWITCHES, 0);
|
||||
@@ -267,27 +296,7 @@ char * getSwitchString(char * dest, swsrc_t idx)
|
||||
#define IDX_ON_IN_STR_VSWITCHES (IDX_TRIMS_IN_STR_VSWITCHES+SWSRC_LAST_TRIM-SWSRC_FIRST_TRIM+1)
|
||||
if (idx <= SWSRC_LAST_SWITCH) {
|
||||
div_t swinfo = switchInfo(idx);
|
||||
if (ZEXIST(g_eeGeneral.switchNames[swinfo.quot])) {
|
||||
s += zchar2str(s, g_eeGeneral.switchNames[swinfo.quot], LEN_SWITCH_NAME);
|
||||
// TODO tous zchar2str
|
||||
}
|
||||
else {
|
||||
*s++ = 'S';
|
||||
#if defined(PCBX7)
|
||||
if (swinfo.quot >= 5)
|
||||
*s++ = 'H' + swinfo.quot - 5;
|
||||
else if (swinfo.quot == 4)
|
||||
#if defined(RADIO_T12)
|
||||
*s++ = 'G';
|
||||
#else
|
||||
*s++ = 'F';
|
||||
#endif
|
||||
else
|
||||
*s++ = 'A'+swinfo.quot;
|
||||
#else
|
||||
*s++ = 'A' + swinfo.quot;
|
||||
#endif
|
||||
}
|
||||
s = getSwitchName(s, idx);
|
||||
*s++ = "\300-\301"[swinfo.rem];
|
||||
*s = '\0';
|
||||
}
|
||||
@@ -396,7 +405,7 @@ char * getSourceString(char * dest, mixsrc_t idx)
|
||||
}
|
||||
}
|
||||
else if (idx <= MIXSRC_LAST_LOGICAL_SWITCH) {
|
||||
getSwitchString(dest, SWSRC_SW1 + idx - MIXSRC_SW1);
|
||||
getSwitchPositionName(dest, SWSRC_SW1 + idx - MIXSRC_SW1);
|
||||
}
|
||||
else if (idx <= MIXSRC_LAST_TRAINER) {
|
||||
strAppendStringWithIndex(dest, STR_PPM_TRAINER, idx - MIXSRC_FIRST_TRAINER + 1);
|
||||
|
||||
@@ -35,7 +35,8 @@ char * strAppendStringWithIndex(char * dest, const char * s, int idx);
|
||||
char * getTimerString(char * dest, int32_t tme, uint8_t hours=0);
|
||||
char * getCurveString(char * dest, int idx);
|
||||
char * getGVarString(char * dest, int idx);
|
||||
char * getSwitchString(char * dest, swsrc_t idx);
|
||||
char * getSwitchPositionName(char * dest, swsrc_t idx);
|
||||
char * getSwitchName(char * dest, swsrc_t idx);
|
||||
char * getSourceString(char * dest, mixsrc_t idx);
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user