From 4cc49d0d3057e4daf9022452541fb42e2890aeb4 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Sat, 25 Jun 2016 18:15:53 +0200 Subject: [PATCH] [Horus] Mouse analogs now OK --- .../THEMES/Default/stick_background.png} | Bin .../horus/THEMES/Default/stick_pointer.png} | Bin radio/src/datastructs.h | 4 +- radio/src/gui/horus/radio_calibration.cpp | 32 +++++-- radio/src/gui/horus/view_statistics.cpp | 5 +- radio/src/gui/horus/widgets.cpp | 9 -- radio/src/gui/horus/widgets.h | 1 - radio/src/mixer.cpp | 85 +++++++++--------- radio/src/opentx.cpp | 4 +- radio/src/opentx.h | 8 +- 10 files changed, 80 insertions(+), 68 deletions(-) rename radio/{src/bitmaps/horus/calibration/alpha_stick_background.png => sdcard/horus/THEMES/Default/stick_background.png} (100%) rename radio/{src/bitmaps/horus/calibration/alpha_stick_pointer.png => sdcard/horus/THEMES/Default/stick_pointer.png} (100%) diff --git a/radio/src/bitmaps/horus/calibration/alpha_stick_background.png b/radio/sdcard/horus/THEMES/Default/stick_background.png similarity index 100% rename from radio/src/bitmaps/horus/calibration/alpha_stick_background.png rename to radio/sdcard/horus/THEMES/Default/stick_background.png diff --git a/radio/src/bitmaps/horus/calibration/alpha_stick_pointer.png b/radio/sdcard/horus/THEMES/Default/stick_pointer.png similarity index 100% rename from radio/src/bitmaps/horus/calibration/alpha_stick_pointer.png rename to radio/sdcard/horus/THEMES/Default/stick_pointer.png diff --git a/radio/src/datastructs.h b/radio/src/datastructs.h index 07779da3f..20ec3b0c7 100644 --- a/radio/src/datastructs.h +++ b/radio/src/datastructs.h @@ -983,7 +983,7 @@ PACK(struct TrainerData { PACK(struct RadioData { NOBACKUP(uint8_t version); NOBACKUP(uint16_t variant); - CalibData calib[NUM_STICKS+NUM_POTS]; + CalibData calib[NUM_STICKS+NUM_POTS+NUM_MOUSE_ANALOGS]; NOBACKUP(uint16_t chkSum); N_HORUS_FIELD(int8_t currModel); N_HORUS_FIELD(uint8_t contrast); @@ -1103,7 +1103,7 @@ static inline void check_struct() CHKSIZE(FrSkyTelemetryData, 7); CHKSIZE(ModelHeader, 27); CHKSIZE(CurveData, 4); - CHKSIZE(RadioData, 835); + CHKSIZE(RadioData, 847); CHKSIZE(ModelData, 9380); #elif defined(PCBSKY9X) diff --git a/radio/src/gui/horus/radio_calibration.cpp b/radio/src/gui/horus/radio_calibration.cpp index 83d05fc2b..92aa779c4 100644 --- a/radio/src/gui/horus/radio_calibration.cpp +++ b/radio/src/gui/horus/radio_calibration.cpp @@ -22,10 +22,8 @@ #define XPOT_DELTA 10 #define XPOT_DELAY 10 /* cycles */ -#define POT_BAR_INTERVAL 20 -#define POT_BAR_BOTTOM 200 #define STICKS_WIDTH 90 -#define STICKS_Y 110 +#define STICKS_Y 60 #define STICK_LEFT_X 25 #define STICK_RIGHT_X (LCD_W-STICK_LEFT_X-STICKS_WIDTH) @@ -37,6 +35,17 @@ enum CalibrationState { CALIB_FINISHED }; +#define STICK_PANEL_WIDTH 68 + +void drawStick(coord_t x, coord_t y, int16_t xval, int16_t yval) +{ + static const BitmapBuffer * stick_background = BitmapBuffer::load(getThemePath("stick_background.png")); + static const BitmapBuffer * stick_pointer = BitmapBuffer::load(getThemePath("stick_pointer.png")); + + lcd->drawBitmap(x, y, stick_background); + lcd->drawBitmap(x + 2 + STICK_PANEL_WIDTH/2 + STICK_PANEL_WIDTH/2 * xval/RESX, y + 2 + STICK_PANEL_WIDTH/2 - STICK_PANEL_WIDTH/2 * yval/RESX, stick_pointer); +} + void drawSticks() { int16_t calibStickVert = calibratedStick[CONVERT_MODE(1)]; @@ -63,12 +72,17 @@ void drawPots() OPTION_SLIDER_SQUARE_BUTTON); } +void drawMouse() +{ + drawStick(STICK_LEFT_X, STICKS_Y+100, calibratedStick[11], calibratedStick[12]); +} + bool menuCommonCalib(evt_t event) { drawMenuTemplate(NULL, ICON_RADIO_CALIBRATION, NULL, OPTION_MENU_NO_FOOTER); - for (uint8_t i=0; i= POT1 && i <= POT_LAST) { @@ -141,10 +155,10 @@ bool menuCommonCalib(evt_t event) // SET MIDPOINT lcdDrawText(50, 3, STR_MENUCALIBRATION, MENU_TITLE_COLOR); lcdDrawText(50, 3+FH, STR_SETMIDPOINT, MENU_TITLE_COLOR); - for (int i=0; i 50) { g_eeGeneral.calib[i].mid = reusableBuffer.calib.midVals[i]; int16_t v = reusableBuffer.calib.midVals[i] - reusableBuffer.calib.loVals[i]; @@ -205,8 +219,10 @@ bool menuCommonCalib(evt_t event) if (horus) { lcd->drawBitmap((LCD_W-horus->getWidth())/2, LCD_H-20-horus->getHeight(), horus); } + drawSticks(); drawPots(); + drawMouse(); return true; } diff --git a/radio/src/gui/horus/view_statistics.cpp b/radio/src/gui/horus/view_statistics.cpp index 352bb2901..4297f511e 100644 --- a/radio/src/gui/horus/view_statistics.cpp +++ b/radio/src/gui/horus/view_statistics.cpp @@ -160,7 +160,10 @@ bool menuStatsAnalogs(evt_t event) lcdDrawNumber(x+140, y, avgJitter[i].get()); lcdDrawNumber(x+180, y, (int16_t)calibratedStick[CONVERT_MODE(i)]*250/256, PREC1); #else - lcdDrawNumber(x+100, y, (int16_t)calibratedStick[CONVERT_MODE(i)]*25/256); + if (i < NUM_STICKS+NUM_POTS) + lcdDrawNumber(x+100, y, (int16_t)calibratedStick[CONVERT_MODE(i)]*25/256); + else if (i >= MOUSE1) + lcdDrawNumber(x+100, y, (int16_t)calibratedStick[NUM_STICKS+NUM_POTS+i-MOUSE1]*25/256); #endif } diff --git a/radio/src/gui/horus/widgets.cpp b/radio/src/gui/horus/widgets.cpp index b2f952afb..90fef1749 100644 --- a/radio/src/gui/horus/widgets.cpp +++ b/radio/src/gui/horus/widgets.cpp @@ -34,15 +34,6 @@ void drawColumnHeader(const char * const * headers, const char * const * descrip } } -#include "alpha_stick_background.lbm" -#include "alpha_stick_pointer.lbm" -#define STICK_PANEL_WIDTH 68 -void drawStick(coord_t x, coord_t y, int16_t xval, int16_t yval) -{ - lcd->drawBitmap(x, y, &ALPHA_STICK_BACKGROUND); - lcd->drawBitmap(x + 2 + STICK_PANEL_WIDTH/2 + STICK_PANEL_WIDTH/2 * xval/RESX, y + 2 + STICK_PANEL_WIDTH/2 - STICK_PANEL_WIDTH/2 * yval/RESX, &ALPHA_STICK_POINTER); -} - #include "alpha_button_on.lbm" #include "alpha_button_off.lbm" diff --git a/radio/src/gui/horus/widgets.h b/radio/src/gui/horus/widgets.h index e6a2eac8c..86fe123d4 100644 --- a/radio/src/gui/horus/widgets.h +++ b/radio/src/gui/horus/widgets.h @@ -42,7 +42,6 @@ void drawStatusText(const char * text); void drawColumnHeader(const char * const * headers, const char * const * descriptions, uint8_t index); void drawTopbarDatetime(); -void drawStick(coord_t x, coord_t y, int16_t xval, int16_t yval); #define BUTTON_ON 0x10 #define BUTTON_OFF 0x20 diff --git a/radio/src/mixer.cpp b/radio/src/mixer.cpp index 356dd1fa1..326af5552 100644 --- a/radio/src/mixer.cpp +++ b/radio/src/mixer.cpp @@ -41,7 +41,7 @@ uint8_t mixWarning; uint8_t startupWarningState; #endif -int16_t calibratedStick[NUM_STICKS+NUM_POTS]; +int16_t calibratedStick[NUM_STICKS+NUM_POTS+NUM_MOUSE_ANALOGS]; int16_t channelOutputs[NUM_CHNOUT] = {0}; int16_t ex_chans[NUM_CHNOUT] = {0}; // Outputs (before LIMITS) of the last perMain; @@ -424,27 +424,19 @@ void evalInputs(uint8_t mode) } #endif - for (uint8_t i=0; i [-1024..1024] uint8_t ch = (i < NUM_STICKS ? CONVERT_MODE(i) : i); - -#if defined(ROTARY_ENCODERS) - int16_t v = ((i < NUM_STICKS+NUM_POTS+NUM_MOUSE_ANALOGS) ? anaIn(i) : getRotaryEncoder(i-(NUM_STICKS+NUM_POTS))); -#else int16_t v = anaIn(i); -#endif #if !defined(SIMU) - if (i < NUM_STICKS+NUM_POTS) { - if (IS_POT_MULTIPOS(i)) { - v -= RESX; - } - else { - CalibData * calib = &g_eeGeneral.calib[i]; - v -= calib->mid; - v = v * (int32_t)RESX / (max((int16_t)100, (v>0 ? calib->spanPos : calib->spanNeg))); - } + if (IS_POT_MULTIPOS(i)) { + v -= RESX; + } + else { + CalibData * calib = &g_eeGeneral.calib[i]; + v -= calib->mid; + v = v * (int32_t) RESX / (max((int16_t) 100, (v > 0 ? calib->spanPos : calib->spanNeg))); } #endif @@ -463,35 +455,26 @@ void evalInputs(uint8_t mode) BeepANACenter mask = (BeepANACenter)1 << ch; - if (i < NUM_STICKS+NUM_POTS) { + calibratedStick[ch] = v; // for show in expo - calibratedStick[ch] = v; // for show in expo - - // filtering for center beep - uint8_t tmp = (uint16_t)abs(v) / 16; + // filtering for center beep + uint8_t tmp = (uint16_t)abs(v) / 16; #if defined(CPUARM) - if (mode == e_perout_mode_normal) { - if (tmp==0 || (tmp==1 && (bpanaCenter & mask))) { - anaCenter |= mask; - if ((g_model.beepANACenter & mask) && !(bpanaCenter & mask) && !calibrationState) { - if (!IS_POT(i) || IS_POT_AVAILABLE(i)) { - AUDIO_POT_MIDDLE(i); - } + if (mode == e_perout_mode_normal) { + if (tmp==0 || (tmp==1 && (bpanaCenter & mask))) { + anaCenter |= mask; + if ((g_model.beepANACenter & mask) && !(bpanaCenter & mask) && !calibrationState) { + if (!IS_POT(i) || IS_POT_AVAILABLE(i)) { + AUDIO_POT_MIDDLE(i); } } } + } #else - if (tmp <= 1) anaCenter |= (tmp==0 ? mask : (bpanaCenter & mask)); -#endif - } -#if defined(ROTARY_ENCODERS) - else if (i >= NUM_STICKS+NUM_POTS+NUM_MOUSE_ANALOGS) { - // rotary encoders - if (v == 0) anaCenter |= mask; - } + if (tmp <= 1) anaCenter |= (tmp==0 ? mask : (bpanaCenter & mask)); #endif - if (ch < NUM_STICKS) { //only do this for sticks + if (ch < NUM_STICKS) { // only do this for sticks #if defined(VIRTUALINPUTS) if (mode & e_perout_mode_nosticks) { v = 0; @@ -519,21 +502,41 @@ void evalInputs(uint8_t mode) } } - #if defined(VIRTUALINPUTS) calibratedStick[ch] = v; #else - #if defined(HELI) +#if defined(HELI) if (d && (ch==ELE_STICK || ch==AIL_STICK)) { v = (int32_t(v) * calc100toRESX(g_model.swashR.value)) / int32_t(d); } - #endif +#endif rawAnas[ch] = v; anas[ch] = v; // set values for mixer #endif } } +#if defined(ROTARY_ENCODERS) + for (uint8_t i=0; i 0 + for (uint8_t i=0; imid; + v = v * (int32_t) RESX / (max((int16_t) 100, (v > 0 ? calib->spanPos : calib->spanNeg))); + if (v < -RESX) v = -RESX; + if (v > RESX) v = RESX; + calibratedStick[ch] = v; + } +#endif + /* EXPOs */ applyExpos(anas, mode); diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index bc064b17e..1501f9568 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -521,7 +521,7 @@ int8_t getMovedSource(GET_MOVED_SOURCE_PARAMS) } #endif - static int16_t sourcesStates[NUM_STICKS+NUM_POTS]; + static int16_t sourcesStates[NUM_STICKS+NUM_POTS+NUM_MOUSE_ANALOGS]; if (result == 0) { for (uint8_t i=0; i 512) { @@ -677,7 +677,7 @@ void incRotaryEncoder(uint8_t idx, int8_t inc) { g_rotenc[idx] += inc; int16_t *value = &(flightModeAddress(getRotaryEncoderFlightPhase(idx))->rotaryEncoders[idx]); - *value = limit((int16_t)-1024, (int16_t)(*value + (inc * 8)), (int16_t)+1024); + *value = limit((int16_t)-RESX, (int16_t)(*value + (inc * 8)), (int16_t)+RESX); storageDirty(EE_MODEL); } #endif diff --git a/radio/src/opentx.h b/radio/src/opentx.h index b09598d79..07e784e03 100644 --- a/radio/src/opentx.h +++ b/radio/src/opentx.h @@ -1159,7 +1159,7 @@ int16_t applyLimits(uint8_t channel, int32_t value); void evalInputs(uint8_t mode); uint16_t anaIn(uint8_t chan); -extern int16_t calibratedStick[NUM_STICKS+NUM_POTS]; +extern int16_t calibratedStick[NUM_STICKS+NUM_POTS+NUM_MOUSE_ANALOGS]; #define FLASH_DURATION 20 /*200ms*/ @@ -1495,9 +1495,9 @@ union ReusableBuffer // 103 bytes struct { - int16_t midVals[NUM_STICKS+NUM_POTS]; - int16_t loVals[NUM_STICKS+NUM_POTS]; - int16_t hiVals[NUM_STICKS+NUM_POTS]; + int16_t midVals[NUM_STICKS+NUM_POTS+NUM_MOUSE_ANALOGS]; + int16_t loVals[NUM_STICKS+NUM_POTS+NUM_MOUSE_ANALOGS]; + int16_t hiVals[NUM_STICKS+NUM_POTS+NUM_MOUSE_ANALOGS]; uint8_t state; #if defined(PCBTARANIS) || defined(PCBFLAMENCO) || defined(PCBHORUS) struct {