1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-23 08:15:17 +03:00

Badly displayed fields in Trainer Screen (thanks gbirkus!)

InstantTrim should work also in Telemetry View
Trims2Offsets function ok with Flight Phases
New Makefile option EEPROM_PROGRESS_BAR
Many flash savings ...
This commit is contained in:
bsongis 2012-03-28 17:01:58 +00:00
parent c63c467182
commit 9c16acb445
14 changed files with 215 additions and 207 deletions

View file

@ -95,6 +95,10 @@ SOMO = NO
# Values = en,
TRANSLATIONS = EN
# EEPROM_PROGRESS_BAR
# Values = YES, NO
EEPROM_PROGRESS_BAR = NO
# DEBUG mode
DEBUG = NO
@ -243,6 +247,10 @@ ifeq ($(DEBUG), YES)
CPPDEFS += -DDEBUG
endif
ifeq ($(EEPROM_PROGRESS_BAR), YES)
CPPDEFS += -DEEPROM_PROGRESS_BAR
endif
ifeq ($(PCB), ARM)
# V4 ARM, so ...
OPT = 2

View file

@ -144,7 +144,7 @@ void eeDeleteModel(uint8_t id)
{
eeCheck(true);
memset(ModelNames[id], ' ', sizeof(g_model.name));
memset(ModelNames[id], 0, sizeof(g_model.name));
Eeprom32_source_address = (uint8_t *)&g_model ; // Get data from here
Eeprom32_data_size = 0 ; // This much
@ -160,7 +160,10 @@ bool eeCopyModel(uint8_t dst, uint8_t src)
uint16_t size = File_system[src+1].size ;
read32_eeprom_data( (File_system[src+1].block_no << 12) + sizeof( struct t_eeprom_header), ( uint8_t *)&Eeprom_buffer.data.model_data, size, 0 ) ;
memcpy(ModelNames[dst], Eeprom_buffer.data.model_data.name, sizeof(g_model.name));
if (size > sizeof(g_model.name))
memcpy(ModelNames[dst], Eeprom_buffer.data.model_data.name, sizeof(g_model.name));
else
memset(ModelNames[dst], 0, sizeof(g_model.name));
Eeprom32_source_address = (uint8_t *)&Eeprom_buffer.data.model_data; // Get data from here
Eeprom32_data_size = sizeof(g_model) ; // This much
@ -173,18 +176,20 @@ bool eeCopyModel(uint8_t dst, uint8_t src)
void eeSwapModels(uint8_t id1, uint8_t id2)
{
// eeCheck(true) should have been called before entering here
// id2 must exist
uint16_t id1_size = File_system[id1+1].size;
uint32_t id1_block_no = File_system[id1+1].block_no;
eeCopyModel(id1, id2);
// block_no has been shifted now, but we have the size
// block_no(id1) has been shifted now, but we have the size
read32_eeprom_data( (id1_block_no << 12) + sizeof( struct t_eeprom_header), ( uint8_t *)&Eeprom_buffer.data.model_data, id1_size, 0 ) ;
// TODO flash saving with function above ...
memcpy(ModelNames[id2], Eeprom_buffer.data.model_data.name, sizeof(g_model.name));
if (id1_size > sizeof(g_model.name))
memcpy(ModelNames[id2], Eeprom_buffer.data.model_data.name, sizeof(g_model.name));
else
memset(ModelNames[id2], 0, sizeof(g_model.name));
Eeprom32_source_address = (uint8_t *)&Eeprom_buffer.data.model_data; // Get data from here
Eeprom32_data_size = sizeof(g_model) ; // This much
@ -509,7 +514,7 @@ void ee32LoadModelName(uint8_t id, char *buf, uint8_t len)
{
if (id < MAX_MODELS) {
id += 1;
memset(buf, ' ', len);
memset(buf, 0, len);
if (File_system[id].size > sizeof(g_model.name) ) {
read32_eeprom_data( ( File_system[id].block_no << 12) + 8, ( uint8_t *)buf, sizeof(g_model.name), 0 ) ;
}
@ -518,29 +523,15 @@ void ee32LoadModelName(uint8_t id, char *buf, uint8_t len)
void eeReadAll()
{
// txmit('a') ;
if (!ee32LoadGeneral() )
// !EeFsOpen() ||
// EeFsck() < 0 ||
// )
{
// txmit('b') ;
alert((char const *)"Bad EEprom Data", true);
g_eeGeneral.contrast = 25 ;
message(PSTR("EEPROM Formatting"));
// EeFsFormat();
//alert(PSTR("format ok"));
generalDefault();
// alert(PSTR("default ok"));
// uint16_t sz = theFile.writeRlc(FILE_GENERAL,FILE_TYP_GENERAL,(uint8_t*)&g_eeGeneral,sizeof(EEGeneral),200);
// if(sz!=sizeof(EEGeneral)) alert(PSTR("genwrite error"));
alert(STR_BADEEPROMDATA);
message(STR_MESSAGE, STR_EEPROMFORMATTING, NULL, NULL);
modelDefault(0);
//alert(PSTR("modef ok"));
// theFile.writeRlc(FILE_MODEL(0),FILE_TYP_MODEL,(uint8_t*)&g_model,sizeof(g_model),200);
//alert(PSTR("modwrite ok"));
STORE_GENERALVARS;
STORE_MODELVARS;
}
@ -722,14 +713,17 @@ void ee32_process()
eeAddress = File_system[Eeprom32_file_index].block_no ^ 1 ;
eeAddress <<= 12 ; // Block start address
Eeprom32_address = eeAddress ; // Where to put new data
#if 0
x = Eeprom32_data_size + sizeof( struct t_eeprom_header ) ; // Size needing to be checked
p = (uint8_t *) &Eeprom_buffer ;
read32_eeprom_data( eeAddress, p, x, 1 ) ;
#endif
Eeprom32_process_state = E32_READSENDING ;
}
if ( Eeprom32_process_state == E32_READSENDING )
{
#if 0
if ( Spi_complete )
{
uint32_t blank = 1 ;
@ -747,11 +741,12 @@ void ee32_process()
// If not blank, sort erasing here
if ( blank )
{
Eeprom32_state_after_erase = E32_IDLE ;
Eeprom32_state_after_erase = E32_IDLE ; // TODO really needed?
Eeprom32_process_state = E32_WRITESTART ;
}
else
{
#endif
eeAddress = Eeprom32_address ;
eeprom_write_enable() ;
p = Spi_tx_buf ;
@ -762,8 +757,8 @@ void ee32_process()
spi_PDC_action( p, 0, 0, 4, 0 ) ;
Eeprom32_process_state = E32_ERASESENDING ;
Eeprom32_state_after_erase = E32_WRITESTART ;
}
}
// }
// }
}
if ( Eeprom32_process_state == E32_WRITESTART )
@ -825,6 +820,7 @@ void ee32_process()
}
else
{
#if 0
// now erase the other block
File_system[Eeprom32_file_index].block_no ^= 1 ; // This is now the current block
eeAddress = Eeprom32_address ^ 0x00001000 ; // Address of block to erase
@ -837,6 +833,8 @@ void ee32_process()
spi_PDC_action( p, 0, 0, 4, 0 ) ;
Eeprom32_process_state = E32_ERASESENDING ;
Eeprom32_state_after_erase = E32_IDLE ;
#endif
Eeprom32_process_state = E32_IDLE ;
}
}
}

View file

@ -730,19 +730,17 @@ void eeReadAll()
EeFsck() < 0 ||
!eeLoadGeneral())
{
alert(STR_BADEEPROMDATA, true);
message(STR_EEPROMFORMATTING);
EeFsFormat();
//alert(PSTR("format ok"));
generalDefault();
//alert(PSTR("default ok"));
alert(STR_BADEEPROMDATA);
message(STR_MESSAGE, STR_EEPROMFORMATTING, NULL, NULL);
EeFsFormat();
theFile.writeRlc(FILE_GENERAL, FILE_TYP_GENERAL,(uint8_t*)&g_eeGeneral,sizeof(EEGeneral), true);
modelDefault(0);
//alert(PSTR("modef ok"));
theFile.writeRlc(FILE_MODEL(0), FILE_TYP_MODEL, (uint8_t*)&g_model, sizeof(g_model), true);
//alert(PSTR("modwrite ok"));
}
stickMode = g_eeGeneral.stickMode;

View file

@ -791,7 +791,6 @@ void putsTelemetryChannel(uint8_t x, uint8_t y, uint8_t channel, int16_t val, ui
channel -= MAX_TIMERS;
// A1 and A2
{
// TODO optimize this, avoid int32_t
int16_t converted_value = ((int32_t)val+g_model.frsky.channels[channel].offset) * (g_model.frsky.channels[channel].ratio << g_model.frsky.channels[channel].multiplier) * 2 / 51;
if (g_model.frsky.channels[channel].type >= UNIT_RAW) {
converted_value /= 10;

View file

@ -507,30 +507,29 @@ void menuProcTrainer(uint8_t event)
}
}
y += FH;
}
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);
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);
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;
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, 7*FH, (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, 7*FH, (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();
}
}
}

View file

@ -42,28 +42,28 @@ uint16_t anaIn(uint8_t chan)
TEST(trims, greaterTrimLink)
{
memset(&g_model, 0, sizeof(g_model));
setTrimValue(1, 0, TRIM_EXTENDED_MAX+3); // link to FP3 trim
setTrimValue(3, 0, 32);
EXPECT_EQ(getTrimValue(getTrimFlightPhase(0, 1), 0), 32);
setRawTrimValue(1, 0, TRIM_EXTENDED_MAX+3); // link to FP3 trim
setRawTrimValue(3, 0, 32);
EXPECT_EQ(getRawTrimValue(getTrimFlightPhase(0, 1), 0), 32);
}
TEST(trims, chainedTrims)
{
memset(&g_model, 0, sizeof(g_model));
setTrimValue(0, 0, 32);
setTrimValue(1, 0, TRIM_EXTENDED_MAX+1); // link to FP0 trim
setTrimValue(2, 0, TRIM_EXTENDED_MAX+2); // link to FP1 trim
EXPECT_EQ(getTrimValue(getTrimFlightPhase(0, 2), 0), 32);
setRawTrimValue(0, 0, 32);
setRawTrimValue(1, 0, TRIM_EXTENDED_MAX+1); // link to FP0 trim
setRawTrimValue(2, 0, TRIM_EXTENDED_MAX+2); // link to FP1 trim
EXPECT_EQ(getRawTrimValue(getTrimFlightPhase(0, 2), 0), 32);
}
TEST(trims, infiniteChainedTrims)
{
memset(&g_model, 0, sizeof(g_model));
setTrimValue(0, 0, 32);
setTrimValue(1, 0, TRIM_EXTENDED_MAX+3); // link to FP3 trim
setTrimValue(2, 0, TRIM_EXTENDED_MAX+2); // link to FP1 trim
setTrimValue(3, 0, TRIM_EXTENDED_MAX+3); // link to FP2 trim
EXPECT_EQ(getTrimValue(getTrimFlightPhase(0, 2), 0), 32);
setRawTrimValue(0, 0, 32);
setRawTrimValue(1, 0, TRIM_EXTENDED_MAX+3); // link to FP3 trim
setRawTrimValue(2, 0, TRIM_EXTENDED_MAX+2); // link to FP1 trim
setRawTrimValue(3, 0, TRIM_EXTENDED_MAX+3); // link to FP2 trim
EXPECT_EQ(getRawTrimValue(getTrimFlightPhase(0, 2), 0), 32);
}
TEST(outdezNAtt, test_unsigned) {

View file

@ -236,6 +236,7 @@ void lcd_outdezNAtt(uint8_t x, uint8_t y, int16_t val, uint8_t flags, uint8_t le
{
uint8_t fw = FWNUM;
int8_t mode = MODE(flags);
bool dblsize = flags & DBLSIZE;
bool neg = false;
if (flags & UNSIGN) { flags -= UNSIGN; }
@ -255,7 +256,7 @@ void lcd_outdezNAtt(uint8_t x, uint8_t y, int16_t val, uint8_t flags, uint8_t le
len = mode + 1;
}
if (flags & DBLSIZE) {
if (dblsize) {
fw += FWNUM;
}
else {
@ -268,7 +269,7 @@ void lcd_outdezNAtt(uint8_t x, uint8_t y, int16_t val, uint8_t flags, uint8_t le
if (flags & LEFT) {
x += len * fw;
if (neg)
x += (flags & DBLSIZE ? 7 : FWNUM);
x += (dblsize ? 7 : FWNUM);
}
lcd_lastPos = x;
@ -277,14 +278,14 @@ void lcd_outdezNAtt(uint8_t x, uint8_t y, int16_t val, uint8_t flags, uint8_t le
for (uint8_t i=1; i<=len; i++) {
char c = ((uint16_t)val % 10) + '0';
uint8_t f = flags;
if (flags & DBLSIZE) {
if (dblsize) {
if (c=='1' && i==len && xn>x+10) { x+=2; f|=CONDENSED; }
if (val >= 1000) { x+=FWNUM; f&=~DBLSIZE; }
}
lcd_putcAtt(x, y, c, f);
if (mode==i) {
flags &= ~PREC2; // TODO not needed but removes 64bytes, could be improved for sure, check asm
if (flags & DBLSIZE) {
if (dblsize) {
xn = x;
if(c=='2' || c=='3' || c=='1') ln++;
uint8_t tn = ((uint16_t)val/10) % 10;
@ -300,7 +301,7 @@ void lcd_outdezNAtt(uint8_t x, uint8_t y, int16_t val, uint8_t flags, uint8_t le
lcd_vline(x+1, y, 8);
}
}
if ((flags & DBLSIZE) && val >= 1000 && val < 10000) x-=2;
if (dblsize && val >= 1000 && val < 10000) x-=2;
val = ((uint16_t)val) / 10;
x-=fw;
}
@ -557,6 +558,20 @@ void putsTmrMode(uint8_t x, uint8_t y, int8_t mode, uint8_t att)
putsSwitches(x, y, mode-(TMR_VAROFS-1), att|SWONLY);
}
void putsTrimMode(uint8_t x, uint8_t y, uint8_t phase, uint8_t idx, uint8_t att)
{
int16_t v = getRawTrimValue(phase, idx);
if (v > TRIM_EXTENDED_MAX) {
uint8_t p = v - TRIM_EXTENDED_MAX - 1;
if (p >= phase) p++;
lcd_putcAtt(x, y, '0'+p, att);
}
else {
putsChnLetter(x, y, idx+1, att);
}
}
#ifdef PCBARM
#include "AT91SAM3S2.h"

View file

@ -105,6 +105,7 @@ extern void putsMixerSource(uint8_t x, uint8_t y, uint8_t idx, uint8_t att=0);
extern void putsFlightPhase(uint8_t x, uint8_t y, int8_t idx, uint8_t att=0);
extern void putsCurve(uint8_t x, uint8_t y, int8_t idx, uint8_t att=0);
extern void putsTmrMode(uint8_t x, uint8_t y, int8_t mode, uint8_t att);
extern void putsTrimMode(uint8_t x, uint8_t y, uint8_t phase, uint8_t idx, uint8_t att);
extern void putsChnRaw(uint8_t x,uint8_t y,uint8_t idx1,uint8_t att);
extern void putsChn(uint8_t x,uint8_t y,uint8_t idx1,uint8_t att);

View file

@ -74,8 +74,6 @@ void doMainScreenGrphics()
void menuMainView(uint8_t event)
{
static bool instantTrimSwLock;
uint8_t view = g_eeGeneral.view;
uint8_t view_base = view & 0x0f;
@ -163,7 +161,6 @@ void menuMainView(uint8_t event)
killEvents(KEY_EXIT);
killEvents(KEY_UP);
killEvents(KEY_DOWN);
instantTrimSwLock = true;
break;
#ifdef NAVIGATION_RE1
case EVT_KEY_LONG(BTN_RE1):
@ -180,10 +177,6 @@ void menuMainView(uint8_t event)
#endif
}
bool trimSw = isFunctionActive(FUNC_INSTANT_TRIM);
if (!instantTrimSwLock && trimSw) instantTrim();
instantTrimSwLock = trimSw;
{
uint8_t phase = getFlightPhase();
lcd_putsnAtt(6*FW+2, 2*FH, g_model.phaseData[phase].name, sizeof(g_model.phaseData[phase].name), ZCHAR);
@ -210,7 +203,7 @@ void menuMainView(uint8_t event)
xm = x[CONVERT_MODE(i+1)-1];
uint8_t att = ROUND;
int16_t val = getTrimValue(getTrimFlightPhase(i, phase), i);
int16_t val = getTrimValue(phase, i);
if (val < -125 || val > 125)
att = BLINK|INVERS|ROUND;

View file

@ -661,21 +661,14 @@ void menuProcPhaseOne(uint8_t event)
case 2:
lcd_putsLeft( y, STR_TRIMS);
for (uint8_t t=0; t<NUM_STICKS; t++) {
int16_t v = getTrimValue(s_currIdx, t);
if (v > TRIM_EXTENDED_MAX) {
uint8_t p = v - TRIM_EXTENDED_MAX - 1;
if (p >= s_currIdx) p++;
lcd_putcAtt((10+t)*FW, y, '0'+p, (attr && m_posHorz==t) ? ((s_editMode>0) ? BLINK|INVERS : INVERS) : 0);
}
else {
v = TRIM_EXTENDED_MAX;
putsChnLetter((10+t)*FW, y, t+1, (attr && m_posHorz==t) ? ((s_editMode>0) ? BLINK|INVERS : INVERS) : 0);
}
putsTrimMode((10+t)*FW, y, s_currIdx, t, (attr && m_posHorz==t) ? ((s_editMode>0) ? BLINK|INVERS : INVERS) : 0);
if (attr && m_posHorz==t && ((s_editMode>0) || p1valdiff)) {
int16_t v = getRawTrimValue(s_currIdx, t);
if (v < TRIM_EXTENDED_MAX) v = TRIM_EXTENDED_MAX;
v = checkIncDec(event, v, TRIM_EXTENDED_MAX, TRIM_EXTENDED_MAX+MAX_PHASES-1, EE_MODEL);
if (checkIncDec_Ret) {
if (v == TRIM_EXTENDED_MAX) v = 0;
setTrimValue(s_currIdx, t, v);
setRawTrimValue(s_currIdx, t, v);
}
}
}
@ -731,16 +724,7 @@ void menuProcPhasesAll(uint8_t event)
else {
putsSwitches(11*FW+FW/2, y, p->swtch, 0);
for (uint8_t t=0; t<NUM_STICKS; t++) {
// TODO duplicated code
int16_t v = getTrimValue(i, t);
if (v > TRIM_EXTENDED_MAX) {
uint8_t c = v - TRIM_EXTENDED_MAX - 1;
if (c >= i) c++;
lcd_putc((16+t)*FW-FW/2, y, '0'+c);
}
else {
putsChnLetter((16+t)*FW-FW/2, y, t+1, 0);
}
putsTrimMode((16+t)*FW-FW/2, y, i, t, 0);
}
}
if (p->fadeIn) lcd_putc(20*FW+2, y, 'I');
@ -1215,7 +1199,7 @@ void menuProcMixOne(uint8_t event)
case 0:
lcd_puts(2*FW, y, STR_SOURCE);
putsMixerSource(FW*10, y, md2->srcRaw, attr);
if(attr) CHECK_INCDEC_MODELVAR(event, md2->srcRaw, 1, NUM_XCHNMIX); // TODO use enum
if(attr) CHECK_INCDEC_MODELVAR(event, md2->srcRaw, 1, NUM_XCHNMIX);
break;
case 1:
lcd_puts(2*FW, y, STR_WEIGHT);

View file

@ -131,8 +131,9 @@ LimitData *limitaddress(uint8_t idx)
void generalDefault()
{
memset(&g_eeGeneral,0,sizeof(g_eeGeneral));
g_eeGeneral.myVers = EEPROM_VER;
memset(&g_eeGeneral, 0, sizeof(g_eeGeneral));
g_eeGeneral.lightSw = SWITCH_ON;
g_eeGeneral.myVers = EEPROM_VER;
g_eeGeneral.contrast = 25;
g_eeGeneral.vBatWarn = 90;
for (int i = 0; i < 7; ++i) {
@ -324,21 +325,24 @@ void applyExpos(int16_t *anas, uint8_t phase)
memcpy(anas2, anas, sizeof(anas2));
if (phase == 255)
phase = getFlightPhase();
phase = getFlightPhase();
phase++;
int8_t cur_chn = -1;
for (uint8_t i=0; i<MAX_EXPOS; i++) {
ExpoData &ed = g_model.expoData[i];
uint8_t ed_phase = ed.phase;
if (ed.mode==0) break; // end of list
if (ed.chn == cur_chn)
continue;
if (ed.phase != 0) {
if (ed_phase != 0) {
if (ed.negPhase) {
if (phase+1 == -ed.phase)
if (phase == ed_phase)
continue;
}
else {
if (phase+1 != ed.phase)
if (phase != ed_phase)
continue;
}
}
@ -348,7 +352,8 @@ void applyExpos(int16_t *anas, uint8_t phase)
cur_chn = ed.chn;
int16_t k = ed.expo;
v = expo(v, k);
if (ed.curve) v = applyCurve(v, ed.curve > 10 ? ed.curve + 4 : ed.curve);
uint8_t ed_curve = ed.curve;
if (ed_curve) v = applyCurve(v, ed_curve > 10 ? ed_curve + 4 : ed_curve);
v = ((int32_t)v * ed.weight) / 100;
anas[cur_chn] = v;
}
@ -368,18 +373,19 @@ int16_t applyLimits(uint8_t channel, int32_t value)
(value > 0) ? value * ((int32_t) lim_p - ofs) / 100000 :
-value * ((int32_t) lim_n - ofs) / 100000; //div by 100000 -> output = -1024..1024
// TODO work on an int16_t as soon as possible ...
value += calc1000toRESX(ofs);
lim_p = calc1000toRESX(lim_p);
lim_n = calc1000toRESX(lim_n);
if (value > lim_p) value = lim_p;
if (value < lim_n) value = lim_n;
if (g_model.limitData[channel].revert) value = -value; // finally do the reverse.
if (safetyCh[channel] != -128) // if safety channel available for channel check and replace val if needed
value = calc100toRESX(safetyCh[channel]);
ofs = value; // we convert value to a 16bit value and reuse ofs
if (g_model.limitData[channel].revert) ofs = -ofs; // finally do the reverse.
return value;
if (safetyCh[channel] != -128) // if safety channel available for channel check
ofs = calc100toRESX(safetyCh[channel]);
return ofs;
}
int16_t ex_chans[NUM_CHNOUT] = {0}; // Outputs (before LIMITS) of the last perMain
@ -514,6 +520,7 @@ bool __getSwitch(int8_t swtch)
// case CS_ANEG:
default:
result = (abs(x)<y);
break;
}
}
else {
@ -538,6 +545,7 @@ bool __getSwitch(int8_t swtch)
// case CS_ELESS:
default:
result = (x<=y);
break;
}
}
}
@ -563,7 +571,7 @@ uint8_t getFlightPhase()
return 0;
}
int16_t getTrimValue(uint8_t phase, uint8_t idx)
int16_t getRawTrimValue(uint8_t phase, uint8_t idx)
{
int16_t result;
if (s_trimPtr[idx]) {
@ -576,7 +584,12 @@ int16_t getTrimValue(uint8_t phase, uint8_t idx)
return result;
}
void setTrimValue(uint8_t phase, uint8_t idx, int16_t trim)
int16_t getTrimValue(uint8_t phase, uint8_t idx)
{
return getRawTrimValue(getTrimFlightPhase(phase, idx), idx);
}
void setRawTrimValue(uint8_t phase, uint8_t idx, int16_t trim)
{
if (s_trimPtr[idx]) {
*s_trimPtr[idx] = limit((int16_t)-125, trim, (int16_t)+125);
@ -589,11 +602,11 @@ void setTrimValue(uint8_t phase, uint8_t idx, int16_t trim)
STORE_MODELVARS;
}
uint8_t getTrimFlightPhase(uint8_t idx, uint8_t phase)
uint8_t getTrimFlightPhase(uint8_t phase, uint8_t idx)
{
for (uint8_t i=0; i<MAX_PHASES; i++) {
if (phase == 0) return 0;
int16_t trim = getTrimValue(phase, idx);
int16_t trim = getRawTrimValue(phase, idx);
if (trim <= TRIM_EXTENDED_MAX) return phase;
uint8_t result = trim-TRIM_EXTENDED_MAX-1;
if (result >= phase) result++;
@ -678,19 +691,6 @@ void checkLowEEPROM()
}
#endif
void alertMessages( const pm_char * s, const pm_char * t )
{
lcd_clear();
lcd_putsAtt(64-5*FW,0*FH,STR_ALERT,DBLSIZE);
lcd_putsLeft(4*FH,s);
lcd_putsLeft(5*FH,t);
lcd_putsLeft(6*FH, STR_PRESSANYKEYTOSKIP ) ;
refreshDisplay();
lcdSetRefVolt(g_eeGeneral.contrast);
clearKeyEvents();
}
void checkTHR()
{
if(g_eeGeneral.disableThrottleWarning) return;
@ -708,7 +708,7 @@ void checkTHR()
if(v<=lowLim) return;
// first - display warning
alertMessages( STR_THROTTLENOTIDLE, STR_RESETTHROTTLE ) ;
message(STR_ALERT, STR_THROTTLENOTIDLE, STR_RESETTHROTTLE, STR_PRESSANYKEYTOSKIP);
//loop until all switches are reset
while (1)
@ -742,7 +742,7 @@ void checkSwitches()
if(!g_eeGeneral.switchWarning) return; // if warning is on
// first - display warning
alertMessages( STR_SWITCHESNOTOFF, STR_PLEASERESETTHEM ) ;
message(STR_ALERT, STR_SWITCHESNOTOFF, STR_RESETTHROTTLE, STR_PLEASERESETTHEM);
bool state = (g_eeGeneral.switchWarning > 0);
@ -766,25 +766,10 @@ void checkSwitches()
}
}
void message(const pm_char * s)
void alert(const pm_char * s)
{
lcd_clear();
lcd_putsAtt(64-5*FW, 0*FH, STR_MESSAGE, DBLSIZE);
lcd_putsLeft(4*FW,s);
refreshDisplay();
lcdSetRefVolt(g_eeGeneral.contrast);
}
message(STR_ALERT, s, 0, STR_PRESSANYKEY);
void alert(const pm_char * s, bool defaults)
{
lcd_clear();
lcd_putsAtt(64-5*FW, 0*FH, STR_ALERT, DBLSIZE);
lcd_putsLeft(4*FH,s);
lcd_puts(64-LEN_PRESSANYKEY*FW/2, 7*FH, STR_PRESSANYKEY);
refreshDisplay();
lcdSetRefVolt(defaults ? 25 : g_eeGeneral.contrast);
AUDIO_ERROR();
clearKeyEvents();
while(1)
{
#ifdef SIMU
@ -793,15 +778,28 @@ void alert(const pm_char * s, bool defaults)
#endif
if(keyDown()) return; //wait for key release
if (getSwitch(g_eeGeneral.lightSw,0) || g_eeGeneral.lightAutoOff || defaults)
BACKLIGHT_ON;
else
BACKLIGHT_OFF;
checkBacklight();
wdt_reset();
}
}
void message(const pm_char *title, const pm_char *s, const pm_char *t, const char *last)
{
lcd_clear();
lcd_putsAtt(0, 0, title, DBLSIZE);
lcd_putsLeft(4*FH, s);
if (t)
lcd_putsLeft(5*FH, t);
if (last) {
lcd_putsLeft(7*FH, last);
AUDIO_ERROR();
clearKeyEvents();
}
refreshDisplay();
lcdSetRefVolt(g_eeGeneral.contrast);
}
int8_t *s_trimPtr[NUM_STICKS] = { NULL, NULL, NULL, NULL };
uint8_t checkTrim(uint8_t event)
@ -812,8 +810,8 @@ uint8_t checkTrim(uint8_t event)
if (k>=0 && k<8) { // && (event & _MSK_KEY_REPT))
//LH_DWN LH_UP LV_DWN LV_UP RV_DWN RV_UP RH_DWN RH_UP
uint8_t idx = CONVERT_MODE(1+k/2) - 1;
uint8_t phase = getTrimFlightPhase(idx, getFlightPhase());
int16_t before = getTrimValue(phase, idx);
uint8_t phase = getTrimFlightPhase(getFlightPhase(), idx);
int16_t before = getRawTrimValue(phase, idx);
int8_t v = (s==0) ? min(32, abs(before)/4+1) : 1 << (s-1); // 1=>1 2=>2 3=>4 4=>8
bool thro = (idx==THR_STICK && g_model.thrTrim);
if (thro) v = 4; // if throttle trim and trim trottle then step=4
@ -839,7 +837,7 @@ uint8_t checkTrim(uint8_t event)
after = TRIM_EXTENDED_MAX;
}
setTrimValue(phase, idx, after);
setRawTrimValue(phase, idx, after);
#if defined (AUDIO)
// toneFreq higher/lower according to trim position
@ -1142,7 +1140,7 @@ FORCEINLINE void evalTrims(uint8_t phase)
// do trim -> throttle trim if applicable
// TODO avoid int32_t vv
int32_t vv = 2*RESX;
int16_t trim = getTrimValue(getTrimFlightPhase(i, phase), i);
int16_t trim = getTrimValue(phase, i);
if (i==THR_STICK && g_model.thrTrim) {
if (g_eeGeneral.throttleReversed)
trim = -trim;
@ -1266,6 +1264,48 @@ void evalFunctions()
if (sd->func < FUNC_TRAINER && (g_menuStack[0] != menuProcFunctionSwitches || m_posVert != i+1 || m_posHorz > 1)) {
safetyCh[sd->func] = (int8_t)sd->param;
}
if (~active_functions & mask) {
if (sd->func == FUNC_INSTANT_TRIM) {
if (g_menuStack[0] == menuMainView
#if defined(FRSKY)
|| g_menuStack[0] == menuProcFrsky
#endif
)
instantTrim();
}
#if defined(SOMO)
if (sd->func == FUNC_PLAY_SOMO) {
somoPushPrompt(sd->param);
}
#endif
#if defined(DEBUG)
if (sd->func == FUNC_TEST) {
testFunc();
}
#endif
if (sd->func == FUNC_RESET) {
switch (sd->param) {
case 0:
case 1:
resetTimer(sd->param);
break;
case 2:
resetAll();
break;
#ifdef FRSKY
case 3:
resetTelemetry();
break;
#endif
}
}
}
if (sd->func == FUNC_PLAY_SOUND) {
#if defined(AUDIO)
audioDefevent(AU_FRSKY_FIRST+sd->param);
@ -1273,32 +1313,6 @@ void evalFunctions()
beep(3);
#endif
}
#if defined(SOMO)
if (sd->func == FUNC_PLAY_SOMO && (~active_functions & mask)) {
somoPushPrompt(sd->param);
}
#endif
if (sd->func == FUNC_RESET && (~active_functions & mask)) {
switch(sd->param) {
case 0:
case 1:
resetTimer(sd->param);
break;
case 2:
resetAll();
break;
#ifdef FRSKY
case 3:
resetTelemetry();
break;
#endif
}
}
#if defined(DEBUG)
if (sd->func == FUNC_TEST && (~active_functions & mask)) {
testFunc();
}
#endif
active_functions |= mask;
}
else {
@ -1519,15 +1533,14 @@ void perOut(uint8_t phase)
v = applyCurve(v, md->curve);
//========== TRIMS ===============
// TODO use k?
if (md->srcRaw>0 && md->srcRaw<=NUM_STICKS) {
if (k < NUM_STICKS) {
if (s_perout_mode < e_perout_mode_zeros && md->carryTrim == TRIM_ON) {
v += trims[md->srcRaw-1];
v += trims[k];
}
if (s_perout_mode == e_perout_mode_normal && md->carryTrim == TRIM_OFFSET) {
v = md->sOffset;
v = calc1000toRESX(v << 3);
s_trimPtr[md->srcRaw-1] = &md->sOffset; // use the value stored here for the trim
s_trimPtr[k] = &md->sOffset; // use the value stored here for the trim
}
}
@ -1835,6 +1848,8 @@ void perMain()
evalFunctions();
if (s_noHi) s_noHi--;
if (trimsCheckTimer) trimsCheckTimer --;
if (g_eeGeneral.inactivityTimer && g_vbat100mV>50) {
inacCounter++;
uint16_t tsum = 0;
@ -1847,9 +1862,6 @@ void perMain()
if((inacCounter&0x3F)==10) AUDIO_INACTIVITY();
}
if (trimsCheckTimer > 0)
trimsCheckTimer -= 1;
#if defined (LOGS)
writeLogs();
#endif
@ -2201,7 +2213,7 @@ void instantTrim()
for (uint8_t i=0; i<NUM_STICKS; i++) {
if (i!=THR_STICK) {
// don't instant trim the throttle stick
uint8_t trim_phase = getTrimFlightPhase(i, phase);
uint8_t trim_phase = getTrimFlightPhase(phase, i);
s_perout_mode = e_instant_trim;
evalSticks(phase);
s_perout_mode = e_perout_mode_normal;
@ -2212,7 +2224,7 @@ void instantTrim()
if (trim > TRIM_EXTENDED_MAX) {
trim = TRIM_EXTENDED_MAX;
}
setTrimValue(trim_phase, i, trim);
setRawTrimValue(trim_phase, i, trim);
}
}
@ -2236,12 +2248,10 @@ void moveTrimsToOffsets() // copy state of 3 primary to subtrim
s_perout_mode = e_perout_mode_normal;
for (uint8_t i=0; i<NUM_CHNOUT; i++) {
int16_t output = applyLimits(i, chans[i]);
int16_t output = applyLimits(i, chans[i]) - zeros[i];
int16_t v = g_model.limitData[i].offset;
// TODO flash saving?
v += g_model.limitData[i].revert ?
(zeros[i] - output) :
(output - zeros[i]);
if (g_model.limitData[i].revert) output = -output;
v += output;
// TODO * 125 / 128 ?
g_model.limitData[i].offset = limit((int16_t)-1000, (int16_t)v, (int16_t)1000); // make sure the offset doesn't go haywire
}
@ -2249,10 +2259,11 @@ void moveTrimsToOffsets() // copy state of 3 primary to subtrim
// reset all trims, except throttle (if throttle trim)
for (uint8_t i=0; i<NUM_STICKS; i++) {
if (i!=THR_STICK || !g_model.thrTrim) {
int16_t original_trim = getTrimValue(phase, i);
for (uint8_t phase=0; phase<MAX_PHASES; phase++) {
int16_t trim = getTrimValue(phase, i);
int16_t trim = getRawTrimValue(phase, i);
if (trim <= TRIM_EXTENDED_MAX)
setTrimValue(phase, i, 0);
setRawTrimValue(phase, i, trim - original_trim);
}
}
}

View file

@ -474,8 +474,9 @@ uint16_t evalChkSum();
/// Gibt Alarm Maske auf lcd aus.
/// Die Maske wird so lange angezeigt bis eine beliebige Taste gedrueckt wird.
void alert(const pm_char * s, bool defaults=false);
void message(const pm_char * s);
extern void alert(const pm_char * s);
extern void message(const pm_char *title, const pm_char *s, const pm_char *t, const char *last);
/// periodisches Hauptprogramm
void perMain();
/// Bearbeitet alle zeitkritischen Jobs.
@ -485,10 +486,11 @@ void per10ms();
int16_t getValue(uint8_t i);
bool getSwitch(int8_t swtch, bool nc);
uint8_t getFlightPhase();
uint8_t getTrimFlightPhase(uint8_t idx, uint8_t phase);
extern uint8_t getFlightPhase();
extern uint8_t getTrimFlightPhase(uint8_t phase, uint8_t idx);
extern int16_t getRawTrimValue(uint8_t phase, uint8_t idx);
extern int16_t getTrimValue(uint8_t phase, uint8_t idx);
extern void setTrimValue(uint8_t phase, uint8_t idx, int16_t trim);
extern void setRawTrimValue(uint8_t phase, uint8_t idx, int16_t trim);
extern uint16_t s_timeCumTot;
extern uint16_t s_timeCumThr; //gewichtete laufzeit in 1/16 sec

View file

@ -269,15 +269,15 @@
#define TR_MODEL "MODEL"
#define TR_FP "FP"
#define TR_EEPROMLOWMEM "EEPROM low mem"
#define TR_ALERT "ALERT"
#define TR_ALERT "\007ALERT"
#define TR_PRESSANYKEYTOSKIP "Press any key to skip"
#define TR_THROTTLENOTIDLE "Throttle not idle"
#define TR_RESETTHROTTLE "Reset throttle"
#define TR_ALARMSDISABLED "Alarms Disabled"
#define TR_SWITCHESNOTOFF "Switches not off"
#define TR_PLEASERESETTHEM "Please reset them"
#define TR_MESSAGE "MESSAGE"
#define TR_PRESSANYKEY "press any Key"
#define TR_MESSAGE "\004MESSAGE"
#define TR_PRESSANYKEY "\004Press any Key"
#define TR_BADEEPROMDATA "Bad EEprom Data"
#define TR_EEPROMFORMATTING "EEPROM Formatting"
#define TR_EEPROMOVERFLOW "EEPROM overflow"
@ -313,4 +313,4 @@
#define TR_MINRSSI "Min Rssi"
#define TR_LATITUDE "Latitude"
#define TR_LONGITUDE "Longitude"
#define TR_GPSCOORD "Gps Coords"
#define TR_GPSCOORD "Gps Coords"

View file

@ -270,7 +270,7 @@
#define TR_FP "PV"
#define TR_EEPROMLOWMEM "EEPROM low mem"
#define TR_ALERT "ALERTE"
#define TR_PRESSANYKEYTOSKIP "Appuyez sur touche"
#define TR_PRESSANYKEYTOSKIP "Touche pour ignorer"
#define TR_THROTTLENOTIDLE "Gaz pas a zero"
#define TR_RESETTHROTTLE "Reinitialisez le"
#define TR_ALARMSDISABLED "Alarmes Desactivees"