mirror of
https://github.com/opentx/opentx.git
synced 2025-07-21 15:25:17 +03:00
Flash saving: around 100bytes (saved in TRAINER menu). UNSTABLE_BANDGAP option removed (always used). Keys react a little better in simu.
This commit is contained in:
parent
a8167c5e0c
commit
a5fef987df
5 changed files with 64 additions and 122 deletions
10
src/Makefile
10
src/Makefile
|
@ -71,10 +71,6 @@ HAPTIC = NO
|
|||
# SPLASH on START
|
||||
SPLASH = YES
|
||||
|
||||
# BATT voltage algorithm.
|
||||
# Values = BANDGAP, UNSTABLE_BANDGAP (default for stock board)
|
||||
BATT = UNSTABLE_BANDGAP
|
||||
|
||||
# Decimals display in the main view (PPM calibration,
|
||||
# Values = YES, NO
|
||||
DECIMALS = YES
|
||||
|
@ -311,14 +307,8 @@ else
|
|||
else
|
||||
CPPSRC += beeper.cpp
|
||||
endif
|
||||
|
||||
# If BandGap is not rock solid
|
||||
ifeq ($(BATT), UNSTABLE_BANDGAP)
|
||||
CPPDEFS += -DBATT_UNSTABLE_BANDGAP
|
||||
endif
|
||||
endif
|
||||
|
||||
|
||||
### Global Build-Option Directives ###
|
||||
|
||||
ifeq ($(DECIMALS), YES)
|
||||
|
|
|
@ -421,71 +421,75 @@ void menuProcTrainer(uint8_t event)
|
|||
{
|
||||
MENU(STR_MENUTRAINER, menuTabDiag, e_Trainer, 7, {0, 2, 2, 2, 2, 0/*, 0*/});
|
||||
|
||||
int8_t sub = m_posVert;
|
||||
uint8_t subSub = m_posHorz;
|
||||
uint8_t y;
|
||||
bool edit;
|
||||
uint8_t blink ;
|
||||
|
||||
if (SLAVE_MODE) { // i am the slave
|
||||
lcd_puts(7*FW, 3*FH, STR_SLAVE);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
lcd_puts(3*FW, 1*FH, STR_MODESRC);
|
||||
|
||||
lcd_puts(3*FW, 1*FH, STR_MODESRC);
|
||||
y = 2*FH;
|
||||
blink = (s_editMode>0) ? BLINK : INVERS ;
|
||||
|
||||
sub--;
|
||||
y = 2*FH;
|
||||
blink = (s_editMode>0) ? BLINK : INVERS ;
|
||||
for (uint8_t i=1; i<=NUM_STICKS; i++) {
|
||||
uint8_t chan = channel_order(i);
|
||||
|
||||
for (uint8_t i=0; i<NUM_STICKS; i++) {
|
||||
uint8_t chan = channel_order(i+1);
|
||||
volatile TrainerMix *td = &g_eeGeneral.trainer.mix[chan-1];
|
||||
|
||||
volatile TrainerMix *td = &g_eeGeneral.trainer.mix[chan-1];
|
||||
putsChnRaw(0, y, chan, 0);
|
||||
|
||||
putsChnRaw(0, y, chan, 0);
|
||||
for (uint8_t j=0; j<3; j++) {
|
||||
edit = (m_posVert==i && m_posHorz==j);
|
||||
bool incdec = (edit && s_editMode>0);
|
||||
|
||||
edit = (sub==i && subSub==0);
|
||||
lcd_putsnAtt(4*FW, y, STR_TRNMODE+LEN_TRNMODE*td->mode, LEN_TRNMODE, edit ? blink : 0);
|
||||
if (edit && s_editMode>0)
|
||||
CHECK_INCDEC_GENVAR(event, td->mode, 0, 2);
|
||||
switch(j) {
|
||||
case 0:
|
||||
lcd_putsnAtt(4*FW, y, STR_TRNMODE+LEN_TRNMODE*td->mode, LEN_TRNMODE, edit ? blink : 0);
|
||||
if (incdec)
|
||||
CHECK_INCDEC_GENVAR(event, td->mode, 0, 2);
|
||||
break;
|
||||
|
||||
edit = (sub==i && subSub==1);
|
||||
lcd_outdezAtt(11*FW, y, td->studWeight, edit ? blink : 0);
|
||||
if (edit && s_editMode>0)
|
||||
CHECK_INCDEC_GENVAR(event, td->studWeight, -100, 100);
|
||||
case 1:
|
||||
lcd_outdezAtt(11*FW, y, td->studWeight, edit ? blink : 0);
|
||||
if (incdec)
|
||||
CHECK_INCDEC_GENVAR(event, td->studWeight, -100, 100);
|
||||
break;
|
||||
|
||||
edit = (sub==i && subSub==2);
|
||||
lcd_putsnAtt(12*FW, y, STR_TRNCHN+LEN_TRNCHN*td->srcChn, LEN_TRNCHN, edit ? blink : 0);
|
||||
if (edit && s_editMode>0)
|
||||
CHECK_INCDEC_GENVAR(event, td->srcChn, 0, 3);
|
||||
case 2:
|
||||
lcd_putsnAtt(12*FW, y, STR_TRNCHN+LEN_TRNCHN*td->srcChn, LEN_TRNCHN, edit ? blink : 0);
|
||||
if (incdec)
|
||||
CHECK_INCDEC_GENVAR(event, td->srcChn, 0, 3);
|
||||
break;
|
||||
}
|
||||
}
|
||||
y += FH;
|
||||
}
|
||||
|
||||
edit = (sub==i && subSub==3);
|
||||
edit = (m_posVert==5);
|
||||
lcd_puts(0*FW, 6*FH, STR_MULTIPLIER);
|
||||
lcd_outdezAtt(13*FW, 6*FH, g_eeGeneral.PPM_Multiplier+10, (edit ? INVERS : 0)|PREC1);
|
||||
if (edit) CHECK_INCDEC_GENVAR(event, g_eeGeneral.PPM_Multiplier, -10, 40);
|
||||
|
||||
y += FH;
|
||||
}
|
||||
|
||||
lcd_puts(0*FW, y, STR_MULTIPLIER);
|
||||
lcd_outdezAtt(13*FW, y, g_eeGeneral.PPM_Multiplier+10, (sub==4 ? INVERS : 0)|PREC1);
|
||||
if(sub==4) CHECK_INCDEC_GENVAR(event, g_eeGeneral.PPM_Multiplier, -10, 40);
|
||||
y += FH;
|
||||
|
||||
edit = (sub==5);
|
||||
lcd_putsAtt(0*FW, y, STR_CAL, edit ? INVERS : 0);
|
||||
for (uint8_t i=0; i<4; i++) {
|
||||
uint8_t x = (i*8+16)*FW/2;
|
||||
edit = (m_posVert==6);
|
||||
lcd_putsAtt(0*FW, 7*FH, STR_CAL, edit ? INVERS : 0);
|
||||
for (uint8_t i=0; i<4; i++) {
|
||||
uint8_t x = (i*8+16)*FW/2;
|
||||
#if defined (DECIMALS_DISPLAYED)
|
||||
lcd_outdezAtt(x , y, (g_ppmIns[i]-g_eeGeneral.trainer.calib[i])*2, PREC1);
|
||||
lcd_outdezAtt(x, 7*FH, (g_ppmIns[i]-g_eeGeneral.trainer.calib[i])*2, PREC1);
|
||||
#else
|
||||
lcd_outdezAtt(x , y, (g_ppmIns[i]-g_eeGeneral.trainer.calib[i])/5, 0);
|
||||
lcd_outdezAtt(x, 7*FH, (g_ppmIns[i]-g_eeGeneral.trainer.calib[i])/5, 0);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
if (edit) {
|
||||
if (event==EVT_KEY_FIRST(KEY_MENU)){
|
||||
memcpy(g_eeGeneral.trainer.calib, g_ppmIns, sizeof(g_eeGeneral.trainer.calib));
|
||||
eeDirty(EE_GENERAL);
|
||||
AUDIO_KEYPAD_UP();
|
||||
if (edit) {
|
||||
if (event==EVT_KEY_FIRST(KEY_MENU)){
|
||||
memcpy(g_eeGeneral.trainer.calib, g_ppmIns, sizeof(g_eeGeneral.trainer.calib));
|
||||
eeDirty(EE_GENERAL);
|
||||
AUDIO_KEYPAD_UP();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -494,11 +498,11 @@ void menuProcDiagVers(uint8_t event)
|
|||
{
|
||||
SIMPLE_MENU(STR_MENUVERSION, menuTabDiag, e_Vers, 1);
|
||||
|
||||
lcd_putsLeft( 2*FH,stamp1 );
|
||||
lcd_putsLeft( 3*FH,stamp2 );
|
||||
lcd_putsLeft( 4*FH,stamp3 );
|
||||
lcd_putsLeft( 5*FH,stamp4 );
|
||||
lcd_putsLeft( 7*FH,STR_EEPROMV);
|
||||
lcd_putsLeft(2*FH, stamp1);
|
||||
lcd_putsLeft(3*FH, stamp2);
|
||||
lcd_putsLeft(4*FH, stamp3);
|
||||
lcd_putsLeft(5*FH, stamp4);
|
||||
lcd_putsLeft(7*FH, STR_EEPROMV);
|
||||
lcd_outdezAtt(8*FW, 7*FH, g_eeGeneral.myVers, LEFT);
|
||||
}
|
||||
|
||||
|
@ -506,8 +510,7 @@ void menuProcDiagKeys(uint8_t event)
|
|||
{
|
||||
SIMPLE_MENU(STR_MENUDIAG, menuTabDiag, e_Keys, 1);
|
||||
|
||||
for(uint8_t i=0; i<9; i++)
|
||||
{
|
||||
for(uint8_t i=0; i<9; i++) {
|
||||
uint8_t y=i*FH; //+FH;
|
||||
if(i>(SW_ID0-SW_BASE_DIAG)) y-=FH; //overwrite ID0
|
||||
bool t=keyState((EnumKeys)(SW_BASE_DIAG+i));
|
||||
|
@ -515,8 +518,7 @@ void menuProcDiagKeys(uint8_t event)
|
|||
lcd_putcAtt(11*FW+2, y, t+'0', t ? INVERS : 0);
|
||||
}
|
||||
|
||||
for(uint8_t i=0; i<6; i++)
|
||||
{
|
||||
for(uint8_t i=0; i<6; i++) {
|
||||
uint8_t y=(5-i)*FH+2*FH;
|
||||
bool t=keyState((EnumKeys)(KEY_MENU+i));
|
||||
lcd_putsn(0, y, STR_VKEYS+LEN_VKEYS*i, LEN_VKEYS);
|
||||
|
@ -532,14 +534,13 @@ void menuProcDiagKeys(uint8_t event)
|
|||
#endif
|
||||
|
||||
lcd_puts(14*FW, 3*FH, STR_VTRIM);
|
||||
for(uint8_t i=0; i<4; i++)
|
||||
{
|
||||
for(uint8_t i=0; i<4; i++) {
|
||||
uint8_t y=i*FH+FH*4;
|
||||
lcd_img(14*FW, y, sticks,i,0);
|
||||
bool tm=keyState((EnumKeys)(TRM_BASE+2*i));
|
||||
bool tp=keyState((EnumKeys)(TRM_BASE+2*i+1));
|
||||
lcd_putcAtt(18*FW, y, tm+'0',tm ? INVERS : 0);
|
||||
lcd_putcAtt(20*FW, y, tp+'0',tp ? INVERS : 0);
|
||||
lcd_putcAtt(18*FW, y, tm+'0', tm ? INVERS : 0);
|
||||
lcd_putcAtt(20*FW, y, tp+'0', tp ? INVERS : 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -547,27 +548,21 @@ void menuProcDiagAna(uint8_t event)
|
|||
{
|
||||
SIMPLE_MENU(STR_MENUANA, menuTabDiag, e_Ana, 2);
|
||||
|
||||
int8_t sub = m_posVert ;
|
||||
|
||||
for(uint8_t i=0; i<8; i++)
|
||||
{
|
||||
for (uint8_t i=0; i<8; i++) {
|
||||
uint8_t y=i*FH;
|
||||
putsStrIdx(4*FW, y, PSTR("A"), i+1);
|
||||
lcd_outhex4( 8*FW, y, anaIn(i));
|
||||
if(i<7)
|
||||
if (i<7)
|
||||
lcd_outdez8(17*FW, y, (int32_t)calibratedStick[i]*100/1024);
|
||||
else
|
||||
putsVolts(17*FW, y, g_vbat100mV, (sub==1 ? INVERS : 0));
|
||||
putsVolts(17*FW, y, g_vbat100mV, (m_posVert==1 ? INVERS : 0));
|
||||
}
|
||||
// lcd_outdezAtt( 21*FW, 3*FH, g_eeGeneral.vBatCalib, 0) ;
|
||||
// lcd_outdezAtt( 21*FW, 4*FH, abRunningAvg, 0) ;
|
||||
// Display raw BandGap result (debug)
|
||||
lcd_puts( 19*FW, 5*FH, STR_BG) ;
|
||||
lcd_outdezAtt(21*FW, 6*FH, BandGap, 0);
|
||||
lcd_outdezAtt(21*FW, 7*FH, anaIn(7)*35/512, PREC1);
|
||||
|
||||
if(sub==1) CHECK_INCDEC_GENVAR(event, g_eeGeneral.vBatCalib, -127, 127);
|
||||
|
||||
if (m_posVert==1) CHECK_INCDEC_GENVAR(event, g_eeGeneral.vBatCalib, -127, 127);
|
||||
}
|
||||
|
||||
void menuProcDiagCalib(uint8_t event)
|
||||
|
|
|
@ -885,13 +885,7 @@ void getADC_bandgap()
|
|||
|
||||
#endif // SIMU
|
||||
|
||||
|
||||
#ifndef BATT_UNSTABLE_BANDGAP
|
||||
uint16_t abRunningAvg = 0;
|
||||
uint8_t g_vbat100mV;
|
||||
#else
|
||||
uint16_t g_vbat100mV = 0;
|
||||
#endif
|
||||
|
||||
volatile uint8_t tick10ms = 0;
|
||||
uint16_t g_LightOffCounter;
|
||||
|
@ -1735,49 +1729,17 @@ void perMain()
|
|||
|
||||
case 2:
|
||||
{
|
||||
/*
|
||||
Gruvin:
|
||||
Interesting fault with new unit. Sample is reading 0x06D0 (around 12.3V) but
|
||||
we're only seeing around 0.2V displayed! (Calibrate = 0)
|
||||
|
||||
Long story short, the higher voltage of the new 8-pack of AA alkaline cells I put in the stock
|
||||
'9X, plus just a tiny bit of calibration applied, were causing an overflow in the 16-bit math,
|
||||
causing a wrap-around to a very small voltage.
|
||||
|
||||
See the wiki (VoltageAveraging) if you're interested in my long-winded analysis.
|
||||
*/
|
||||
|
||||
#ifndef BATT_UNSTABLE_BANDGAP
|
||||
// initialize to first sample if on first averaging cycle
|
||||
if (abRunningAvg == 0) abRunningAvg = anaIn(7);
|
||||
|
||||
// G: Running average (virtual 7 stored plus current sample) for batt volts to stablise display
|
||||
// Average the raw samples so the calibrartion screen updates instantly
|
||||
int32_t ab = ((abRunningAvg * 7) + anaIn(7)) / 8;
|
||||
abRunningAvg = (uint16_t)ab;
|
||||
|
||||
// Calculation By Mike Blandford
|
||||
// Resistor divide on battery voltage is 5K1 and 2K7 giving a fraction of 2.7/7.8
|
||||
// If battery voltage = 10V then A2D voltage = 3.462V
|
||||
// 11 bit A2D count is 1417 (3.462/5*2048).
|
||||
// 1417*18/256 = 99 (actually 99.6) to represent 9.9 volts.
|
||||
// Erring on the side of low is probably best.
|
||||
|
||||
g_vbat100mV = (ab*16 + (ab*g_eeGeneral.vBatCalib)/8)/BandGap;
|
||||
#else
|
||||
int32_t instant_vbat = anaIn(7);
|
||||
instant_vbat = (instant_vbat*16 + instant_vbat*g_eeGeneral.vBatCalib/8) / BandGap;
|
||||
if (g_vbat100mV == 0 || g_menuStack[0] != menuMainView) g_vbat100mV = instant_vbat;
|
||||
g_vbat100mV = (instant_vbat + g_vbat100mV*7) / 8;
|
||||
#endif
|
||||
|
||||
static uint8_t s_batCheck;
|
||||
s_batCheck+=32;
|
||||
if(s_batCheck==0 && g_vbat100mV<g_eeGeneral.vBatWarn && g_vbat100mV>50) {
|
||||
if (s_batCheck==0 && g_vbat100mV<g_eeGeneral.vBatWarn && g_vbat100mV>50) {
|
||||
AUDIO_ERROR();
|
||||
if (g_eeGeneral.flashBeep) g_LightOffCounter = FLASH_DURATION;
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -619,12 +619,7 @@ extern const char stamp2[];
|
|||
extern const char stamp3[];
|
||||
extern const char stamp4[];
|
||||
|
||||
#ifndef BATT_UNSTABLE_BANDGAP
|
||||
extern uint16_t abRunningAvg;
|
||||
extern uint8_t g_vbat100mV;
|
||||
#else
|
||||
extern uint16_t g_vbat100mV;
|
||||
#endif
|
||||
extern volatile uint16_t g_tmr10ms;
|
||||
extern volatile uint8_t g_blinkTmr10ms;
|
||||
extern uint8_t g_beepCnt;
|
||||
|
|
|
@ -242,7 +242,7 @@ long Open9xSim::onTimeout(FXObject*,FXSelector,void*)
|
|||
|
||||
per10ms();
|
||||
refreshDiplay();
|
||||
getApp()->addTimeout(this,2,10);
|
||||
getApp()->addTimeout(this,2,5);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue