Skip to content

Commit

Permalink
Logarithmic scale used while mapping SNR.
Browse files Browse the repository at this point in the history
Fixed student mode crash.
  • Loading branch information
qba667 committed Jan 10, 2018
1 parent 0f68c00 commit b38dd05
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 8 deletions.
Binary file modified source/build/org.bin
Binary file not shown.
20 changes: 14 additions & 6 deletions source/source/alt.c
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,19 @@ void createPacketCh1114(){
*((int32_t*)(channel7Address + 4*i)) = value;
}
}

int mapSNR(){
int snr = getSensorValue(IBUS_MEAS_TYPE_SNR, 0,0);
if(snr == 0x8000) return -10000;
if(snr >= maxSNR) {
maxSNR = snr;
return 10000;
}
snr = maxSNR - snr;
if(snr > 20) return -10000;
snr = ((((10000 << 1) * (int32_t)snrMulti[snr])) >> 10) - 10000;
return snr;
}
int getAuxChannel(uint32_t request){
int sw1 = 0;
int sw2 = 0;
Expand Down Expand Up @@ -457,12 +470,7 @@ int getAuxChannel(uint32_t request){
}
}
else if(request == 10){ // SNR
sw1 = getSensorValue(IBUS_MEAS_TYPE_SNR, 0,0);
if(sw1 == 0x8000) sw1 = -10000;
if(sw1 >= 40) sw1 = 10000;
else if(sw1 <= 20) sw1 = -500* (20 - sw1);
else sw1 = 500 * (sw1 - 20);
return sw1;
return mapSNR();
}
else if(request == 8){ // B+C
sw1 = SW_C;
Expand Down
3 changes: 2 additions & 1 deletion source/source/alt.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ __attribute__((section (".mod_timerValue"))) uint32_t timerValue;
__attribute__((section (".mod_lastTimerUpdate"))) uint32_t lastTimerUpdate;
__attribute__((section (".mod_ticks100ms"))) uint8_t ticks100MS;
__attribute__((section (".mod_mavlinkGPSFrame"))) uint8_t mavlinkGPSFrame[22]; //22bytes
__attribute__((section (".mod_maxSNR"))) int32_t maxSNR;

#ifdef TGY_CAT01
__attribute__((section (".mod_altSensorMemory"))) uint32_t initPressure = 0;
Expand All @@ -126,7 +127,7 @@ __attribute__((section (".mod_altSensorMemory"))) int32_t initTemperature = 0;

__attribute__((section (".mod_varioMem"))) int32_t varioPrevValue = 0;
__attribute__((section (".mod_varioMem"))) int32_t varioPrevTime = 0;

__attribute__((section (".mod_mapSNR "))) int mapSNR();
__attribute__((section (".mod_beep_silent "))) void beepSilent();
__attribute__((section (".mod_configurePins"))) void configurePINS2();
__attribute__((section (".mod_getAuxChannel"))) int getAuxChannel(uint32_t request);
Expand Down
27 changes: 26 additions & 1 deletion source/source/mod.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,32 @@ __attribute__((section (".mod_radioModes"))) const uint8_t RADIO_MODES[] =
"SBUS/PWM\0"
"SBUS/PPM" // The last one without \0
;

//power gain << 10
//from 0 dB -20dB

const uint16_t __attribute__((section (".mod_SNR"))) snrMulti[] = {
1024,
813,
646,
513,
407,
323,
257,
204,
162,
128,
102,
81,
64,
51,
40,
32,
25,
20,
16,
12,
10,
} ;

const uint8_t __attribute__((section (".mod_voltSensors"))) voltageSensors[] = { IBUS_MEAS_TYPE_INTV, IBUS_MEAS_TYPE_EXTV} ;
const uint8_t __attribute__((section (".mod_armed"))) ARMED[] = "Armed";
Expand Down

0 comments on commit b38dd05

Please sign in to comment.