diff --git a/src/Makefile b/src/Makefile index ce3a9ff54..dc5703700 100644 --- a/src/Makefile +++ b/src/Makefile @@ -100,8 +100,13 @@ VOICE = NO HAPTIC = NO # SmartieParts 2.2 Backlight support (inverted) +# Values = YES, NO SP22 = NO +# TelemetrEZ +# Values = YES, NO +TELEMETREZ = NO + # SPLASH on START # Values = YES, NO, FIXED SPLASH = YES @@ -281,7 +286,7 @@ SRC = STD_TTS_SRC = translations/tts_$(shell sh -c "echo $(TTS) | tr '[:upper:]' '[:lower:]'").cpp TTS_SRC = $(shell sh -c "if test -f $(STD_TTS_SRC); then echo $(STD_TTS_SRC); else echo translations/tts_en.cpp; fi") -CPPSRC = open9x.cpp $(PULSESSRC) stamp.cpp menus.cpp model_menus.cpp general_menus.cpp main_views.cpp statistics_views.cpp $(EEPROMSRC) lcd.cpp drivers.cpp translations.cpp $(TTS_SRC) +CPPSRC = open9x.cpp $(PULSESSRC) stamp.cpp menus.cpp model_menus.cpp general_menus.cpp main_views.cpp statistics_views.cpp $(EEPROMSRC) lcd.cpp keys.cpp translations.cpp $(TTS_SRC) ifeq ($(EXT), JETI) CPPSRC += jeti.cpp @@ -563,6 +568,10 @@ ifeq ($(PCB), STD128) ifeq ($(SP22), YES) CPPDEFS += -DSP22 endif + + ifeq ($(TELEMETREZ), YES) + CPPDEFS += -DTELEMETREZ + endif endif ifeq ($(PCB), STD) @@ -594,6 +603,10 @@ ifeq ($(PCB), STD) ifeq ($(SP22), YES) CPPDEFS += -DSP22 endif + + ifeq ($(TELEMETREZ), YES) + CPPDEFS += -DTELEMETREZ + endif endif ### Global Build-Option Directives ### diff --git a/src/beeper.cpp b/src/beeper.cpp index 0652fa358..15521344f 100644 --- a/src/beeper.cpp +++ b/src/beeper.cpp @@ -56,7 +56,7 @@ void beep(uint8_t val) haptic.event(val==0 ? AU_KEYPAD_UP : (val==4 ? AU_ERROR : AU_TIMER_10+beepAgain)); #endif - if(g_eeGeneral.flashBeep && val > 1 && g_LightOffCounter < FLASH_DURATION) g_LightOffCounter = FLASH_DURATION; + if (g_eeGeneral.flashBeep && val>1 && lightOffCounter0 || (g_eeGeneral.beeperMode==0 && val!=0) || (g_eeGeneral.beeperMode==-1 && val>=3)) { _beep(pgm_read_byte(beepTab+5*(2+g_eeGeneral.beeperLength)+val)); diff --git a/src/beeper.h b/src/beeper.h index b7acfc5f4..6c8ac0f8c 100644 --- a/src/beeper.h +++ b/src/beeper.h @@ -69,7 +69,7 @@ extern void beep(uint8_t val); #define AUDIO_TIMER_30() { beepAgain=2; beep(2); } #define AUDIO_TIMER_20() { beepAgain=1; beep(2); } #define AUDIO_TIMER_10() beep(2) -#define AUDIO_TIMER_LT3(x) beep(2) +#define AUDIO_TIMER_LT3(x) beep(2) #define AUDIO_MINUTE_BEEP() beep(2) #define AUDIO_INACTIVITY() beep(3) #define AUDIO_MIX_WARNING_1() beep(1) @@ -80,7 +80,7 @@ extern void beep(uint8_t val); #define AUDIO_VARIO_DOWN() _beep(1) #define AUDIO_TRIM(event, f) { if (!IS_KEY_FIRST(event)) warble = true; beep(1); } #define AUDIO_TRIM_MIDDLE(f) beep(2) -#define AUDIO_TRIM_END(f) beep(2) +#define AUDIO_TRIM_END(f) beep(2) #define AUDIO_PLAY(p) beep(3) #define IS_AUDIO_BUSY() (g_beepCnt || beepAgain || beepOn) diff --git a/src/board_gruvin9x.cpp b/src/board_gruvin9x.cpp index 3fb2512c6..122f139e3 100644 --- a/src/board_gruvin9x.cpp +++ b/src/board_gruvin9x.cpp @@ -157,9 +157,8 @@ ISR(USART1_RX_vect) } } } -#endif //EXTRA_ROTARY_ENCODERS - -#endif +#endif // EXTRA_ROTARY_ENCODERS +#endif // !SIMU uint8_t check_soft_power() { @@ -177,10 +176,7 @@ void soft_power_off() #endif } -#ifndef SIMU -FORCEINLINE -#endif -uint8_t keyDown() +FORCEINLINE uint8_t keyDown() { return (~PINL) & 0x3F; } @@ -239,10 +235,7 @@ bool keyState(EnumKeys enuk) return result; } -#ifndef SIMU -FORCEINLINE -#endif -void readKeysAndTrims() +FORCEINLINE void readKeysAndTrims() { /* Original keys were connected to PORTB as follows: @@ -296,3 +289,32 @@ void readKeysAndTrims() ++enuk; } } + +#if defined(ROTARY_ENCODERS) + +#if !defined(EXTRA_ROTARY_ENCODERS) +ISR(INT2_vect) +{ + uint8_t input = PIND & 0b00001100; + if (input == 0 || input == 0b00001100) incRotaryEncoder(0, -1); +} + +ISR(INT3_vect) +{ + uint8_t input = PIND & 0b00001100; + if (input == 0 || input == 0b00001100) incRotaryEncoder(0, +1); +} +#endif // !EXTRA_ROTARY_ENCODERS + +ISR(INT5_vect) +{ + uint8_t input = PINE & 0b01100000; + if (input == 0 || input == 0b01100000) incRotaryEncoder(1, +1); +} +ISR(INT6_vect) +{ + uint8_t input = PINE & 0b01100000; + if (input == 0 || input == 0b01100000) incRotaryEncoder(1, -1); +} + +#endif // ROTARY_ENCODERS diff --git a/src/frsky.cpp b/src/frsky.cpp index 6bdd3a272..2b1bac5bc 100644 --- a/src/frsky.cpp +++ b/src/frsky.cpp @@ -50,6 +50,10 @@ #define BYTESTUFF 0x7d #define STUFF_MASK 0x20 +#if defined(TELEMETREZ) +#define PRIVATE 0x1B +#endif + uint8_t frskyRxBuffer[FRSKY_RX_PACKET_SIZE]; // Receive buffer. 9 bytes (full packet), worst case 18 bytes with byte-stuffing (+1) uint8_t frskyTxBuffer[FRSKY_TX_PACKET_SIZE]; // Ditto for transmit buffer #if !defined(PCBSKY9X) @@ -392,11 +396,23 @@ void processFrskyPacket(uint8_t *packet) FrskyRxBufferReady = 0; } -// Receive buffer state machine state defs -#define frskyDataIdle 0 -#define frskyDataStart 1 -#define frskyDataInFrame 2 -#define frskyDataXOR 3 +// Receive buffer state machine state enum +enum FrSkyDataState { + STATE_DATA_IDLE, + STATE_DATA_START, + STATE_DATA_IN_FRAME, + STATE_DATA_XOR, +#if defined(TELEMETREZ) + STATE_DATA_PRIVATE_LEN, + STATE_DATA_PRIVATE_VALUE +#endif +}; + +#if defined(TELEMETREZ) +uint8_t privateDataLen; +uint8_t privateDataPos; +#endif + /* Receive serial (RS-232) characters, detecting and storing each Fr-Sky 0x7e-framed packet as it arrives. When a complete packet has been @@ -418,7 +434,7 @@ NOINLINE void processSerialData(uint8_t stat, uint8_t data) #endif { static uint8_t numPktBytes = 0; - static uint8_t dataState = frskyDataIdle; + static uint8_t dataState = STATE_DATA_IDLE; #if defined(BLUETOOTH) // TODO if (g_model.bt_telemetry) @@ -438,44 +454,70 @@ NOINLINE void processSerialData(uint8_t stat, uint8_t data) { switch (dataState) { - case frskyDataStart: + case STATE_DATA_START: if (data == START_STOP) break; // Remain in userDataStart if possible 0x7e,0x7e doublet found. if (numPktBytes < FRSKY_RX_PACKET_SIZE) frskyRxBuffer[numPktBytes++] = data; - dataState = frskyDataInFrame; + dataState = STATE_DATA_IN_FRAME; break; - case frskyDataInFrame: + case STATE_DATA_IN_FRAME: if (data == BYTESTUFF) { - dataState = frskyDataXOR; // XOR next byte + dataState = STATE_DATA_XOR; // XOR next byte break; } if (data == START_STOP) // end of frame detected { processFrskyPacket(frskyRxBuffer); // FrskyRxBufferReady = 1; - dataState = frskyDataIdle; + dataState = STATE_DATA_IDLE; break; } if (numPktBytes < FRSKY_RX_PACKET_SIZE) frskyRxBuffer[numPktBytes++] = data; break; - case frskyDataXOR: + case STATE_DATA_XOR: if (numPktBytes < FRSKY_RX_PACKET_SIZE) frskyRxBuffer[numPktBytes++] = data ^ STUFF_MASK; - dataState = frskyDataInFrame; + dataState = STATE_DATA_IN_FRAME; break; - case frskyDataIdle: - if (data == START_STOP) - { + case STATE_DATA_IDLE: + if (data == START_STOP) { numPktBytes = 0; - dataState = frskyDataStart; + dataState = STATE_DATA_START; + } +#if defined(TELEMETREZ) + if (data == PRIVATE) { + dataState = STATE_DATA_PRIVATE_LEN; + } +#endif + break; + +#if defined(TELEMETREZ) + case STATE_DATA_PRIVATE_LEN: + dataState = STATE_DATA_PRIVATE_VALUE; + privateDataLen = data; // Count of bytes to receive + privateDataPos = 0; + break; + + case STATE_DATA_PRIVATE_VALUE : + if (privateDataPos++ == 0) { + // process first private data byte + // PC6, PC7 + if ((data & 0x3F) == 0) // check byte is valid + { + DDRC |= 0xC0; // set as outputs + PORTC = ( PORTC & 0x3F ) | ( data & 0xC0 ); // update outputs + } + } + if (privateDataPos == privateDataLen) { + dataState = STATE_DATA_IDLE; } break; - +#endif } // switch } // if (FrskyRxBufferReady == 0) } diff --git a/src/general_menus.cpp b/src/general_menus.cpp index 3d7c2ab59..513dd7bbb 100644 --- a/src/general_menus.cpp +++ b/src/general_menus.cpp @@ -44,7 +44,9 @@ enum EnumTabDiag { e_Vers, e_Keys, e_Ana, +#if !defined(PCBX9D) // TODO IF_PCBSKY9X(e_Hardware) +#endif e_Calib }; @@ -66,7 +68,9 @@ const MenuFuncP_PROGMEM menuTabDiag[] PROGMEM = { menuGeneralVersion, menuGeneralDiagKeys, menuGeneralDiagAna, +#if !defined(PCBX9D) // TODO IF_PCBSKY9X(menuGeneralHardware) +#endif menuGeneralCalib }; @@ -140,7 +144,7 @@ void menuGeneralSetup(uint8_t event) } #endif - MENU(STR_MENURADIOSETUP, menuTabDiag, e_Setup, ITEM_SETUP_MAX+1, {0, IF_RTCLOCK(2) IF_RTCLOCK(2) (uint8_t)-1, 0, 0, IF_AUDIO(0) IF_VOICE(0) IF_HAPTIC((uint8_t)-1) IF_HAPTIC(0) IF_HAPTIC(0) IF_HAPTIC(0) IF_PCBSKY9X(0) 0, (uint8_t)-1, 0, IF_PCBSKY9X(0) IF_PCBSKY9X(0) 0, 0, 0, IF_ROTARY_ENCODERS(0) 0, 0, (uint8_t)-1, 0, 0, (uint8_t)-1, 0, 0, 0, IF_SPLASH(0) IF_FRSKY(0) IF_FRSKY(0) 0, (uint8_t)-1, 1}); + MENU(STR_MENURADIOSETUP, menuTabDiag, e_Setup, ITEM_SETUP_MAX+1, {0, IF_RTCLOCK(2) IF_RTCLOCK(2) (uint8_t)-1, 0, 0, IF_AUDIO(0) IF_VOICE(0) IF_HAPTIC((uint8_t)-1) IF_HAPTIC(0) IF_HAPTIC(0) IF_HAPTIC(0) IF_PCBSKY9X(0) 0, (uint8_t)-1, 0, IF_PCBSKY9X(0) IF_PCBSKY9X(0) 0, 0, 0, IF_ROTARY_ENCODERS(0) 0, 0, (uint8_t)-1, 0, 0, (uint8_t)-1, 0, 0, 0, IF_SPLASH(0) IF_FRSKY(0) IF_FRSKY(0) 0, (uint8_t)-1, IF_PCBX9D(0) 1/*to force edit mode*/}); uint8_t sub = m_posVert - 1; @@ -352,9 +356,9 @@ void menuGeneralSetup(uint8_t event) if(attr) g_eeGeneral.inactivityTimer = checkIncDec(event, g_eeGeneral.inactivityTimer, 0, 250, EE_GENERAL); //0..250minutes break; -#if defined(ROTARY_ENCODERS) +#if defined(ROTARY_ENCODERS) && NUM_ROTARY_ENCODERS > 0 case ITEM_SETUP_RE_NAVIGATION: - g_eeGeneral.reNavigation = selectMenuItem(RADIO_SETUP_2ND_COLUMN, y, STR_RENAVIG, STR_VRENAVIG, g_eeGeneral.reNavigation, 0, ROTARY_ENCODERS, attr, event); + g_eeGeneral.reNavigation = selectMenuItem(RADIO_SETUP_2ND_COLUMN, y, STR_RENAVIG, STR_VRENAVIG, g_eeGeneral.reNavigation, 0, NUM_ROTARY_ENCODERS, attr, event); if (attr && checkIncDec_Ret) { for (uint8_t i=0; i (max) ? ((min) + (val) - (max) - 1) : ((val) < (min) ? ((max) - (min) + (val) - 1) : (val))) +#define SCROLL(min, val, max) (int8_t(val) > int8_t(max) ? (int8_t(min) + int8_t(val) - int8_t(max) - 1) : (int8_t(val) < int8_t(min) ? (int8_t(max) - int8_t(min) + int8_t(val) + 1) : int8_t(val))) #else #define RE_NAV_ENTER (BTN_REa+g_eeGeneral.reNavigation-1) #define RE_NAV_ENABLE g_eeGeneral.reNavigation @@ -285,12 +285,20 @@ bool check(check_event_t event, uint8_t curr, const MenuFuncP *menuTab, uint8_t uint8_t maxcol = MAXCOL(l_posVert); #if defined(ROTARY_ENCODERS) + +#if defined(PCBX9D) + if (!(s_warning || s_menu_count || s_editMode<0)) + CHECK_ROTARY_ENCODER(event); +#else if (!(s_warning || s_menu_count)) CHECK_ROTARY_ENCODER(event); +#endif + if (l_posVert < 0 && (event==EVT_KEY_BREAK(RE_NAV_ENTER) || event==EVT_KEY_BREAK(KEY_MENU))) { popMenu(); return false; } + if (RE_NAV_ENABLE && event==EVT_KEY_BREAK(RE_NAV_ENTER)) { if (s_editMode > 0 && (maxcol & ZCHAR)) { if (l_posHorz < maxcol-ZCHAR) { @@ -346,7 +354,9 @@ bool check(check_event_t event, uint8_t curr, const MenuFuncP *menuTab, uint8_t int8_t cc = curr; if (scrollLR || (scrollRE && s_editMode < 0)) { - cc = SCROLL((int8_t)0, (int8_t)(curr - scrollLR + scrollRE), (int8_t)(menuTabSize-1)); + printf("tab size=%d cur=%d scrollLR=%d scrollRE=%d\n", menuTabSize, cc, scrollLR, scrollRE); fflush(stdout); + cc = SCROLL((int8_t)0, (int8_t)(cc - scrollLR + scrollRE), (int8_t)(menuTabSize-1)); + printf("cc=%d\n", cc); fflush(stdout); } switch(event) { @@ -396,12 +406,10 @@ bool check(check_event_t event, uint8_t curr, const MenuFuncP *menuTab, uint8_t if (scrollUD) { l_posVert = limit((int8_t)0, (int8_t)(l_posVert - scrollUD), (int8_t)maxrow); l_posHorz = min(l_posHorz, MAXCOL(l_posVert)); - BLINK_SYNC; } if (scrollLR && l_posVert>0) { l_posHorz = limit((int8_t)0, (int8_t)(l_posHorz - scrollLR), (int8_t)maxcol); - BLINK_SYNC; } #if defined(ROTARY_ENCODERS) @@ -509,7 +517,6 @@ bool check(check_event_t event, uint8_t curr, const MenuFuncP *menuTab, uint8_t AUDIO_MENUS(); l_posVert = 0; l_posHorz = 0; - BLINK_SYNC; } break; @@ -520,7 +527,6 @@ bool check(check_event_t event, uint8_t curr, const MenuFuncP *menuTab, uint8_t case EVT_KEY_FIRST(KEY_RIGHT)://inc if (!horTab || s_editMode>0) break; INC(l_posHorz, maxcol); - BLINK_SYNC; break; case EVT_KEY_REPT(KEY_LEFT): //dec if (l_posHorz==0) break; @@ -528,7 +534,6 @@ bool check(check_event_t event, uint8_t curr, const MenuFuncP *menuTab, uint8_t case EVT_KEY_FIRST(KEY_LEFT)://dec if (!horTab || s_editMode>0) break; DEC(l_posHorz, maxcol); - BLINK_SYNC; break; case EVT_KEY_REPT(KEY_DOWN): //inc if (l_posVert==maxrow) break; @@ -542,7 +547,6 @@ bool check(check_event_t event, uint8_t curr, const MenuFuncP *menuTab, uint8_t s_editMode = 0; #endif l_posHorz = min(l_posHorz, MAXCOL(l_posVert)); - BLINK_SYNC; break; case EVT_KEY_REPT(KEY_UP): //dec if (l_posVert==0) break; @@ -553,7 +557,6 @@ bool check(check_event_t event, uint8_t curr, const MenuFuncP *menuTab, uint8_t DEC(l_posVert, maxrow); } while(MAXCOL(l_posVert) == (uint8_t)-1); l_posHorz = min(l_posHorz, MAXCOL(l_posVert)); - BLINK_SYNC; break; #endif } diff --git a/src/model_menus.cpp b/src/model_menus.cpp index 02bc31f21..b351aac01 100644 --- a/src/model_menus.cpp +++ b/src/model_menus.cpp @@ -1005,7 +1005,7 @@ void menuModelPhaseOne(uint8_t event) } break; -#if defined(ROTARY_ENCODERS) +#if defined(ROTARY_ENCODERS) && NUM_ROTARY_ENCODERS > 0 case ITEM_MODEL_PHASE_ROTARY_ENCODERS: lcd_putsLeft(y, STR_ROTARY_ENCODER); for (uint8_t t=0; tdestCh+1,0); #if defined(ROTARY_ENCODERS) - if (m_posVert == MIX_FIELD_TRIM && md2->srcRaw > NUM_STICKS) - SUBMENU_NOTITLE(MIX_FIELD_COUNT, {IF_PCBSKY9X(ZCHAR|(sizeof(md2->name)-1)) 0, 0, 0, 0, IF_CURVES(1) 0, IF_FLIGHT_PHASES(MAX_PHASES-1) 0 /*, ...*/}) + if ((m_posVert == MIX_FIELD_TRIM && md2->srcRaw > NUM_STICKS) || (m_posVert == MIX_FIELD_CURVE && md2->curveMode == MODE_CURVE)) + SUBMENU_NOTITLE(MIX_FIELD_COUNT, {IF_PCBSKY9X(ZCHAR|(sizeof(md2->name)-1)) 0, 0, 0, 0, IF_CURVES(0) 0, IF_FLIGHT_PHASES(MAX_PHASES-1) 0 /*, ...*/}) else SUBMENU_NOTITLE(MIX_FIELD_COUNT, {IF_PCBSKY9X(ZCHAR|(sizeof(md2->name)-1)) 0, 0, 0, 1, IF_CURVES(1) 0, IF_FLIGHT_PHASES(MAX_PHASES-1) 0 /*, ...*/}); #else diff --git a/src/open9x.cpp b/src/open9x.cpp index 1c3b0904a..7fabc53e9 100644 --- a/src/open9x.cpp +++ b/src/open9x.cpp @@ -169,6 +169,63 @@ uint8_t zlen(const char *str, uint8_t size) } #endif +volatile tmr10ms_t g_tmr10ms; + +#if defined(PCBSKY9X) +volatile uint8_t rtc_count=0; +#endif + +void per10ms() +{ + g_tmr10ms++; + + if (lightOffCounter) lightOffCounter--; + if (s_noHi) s_noHi--; + if (trimsCheckTimer) trimsCheckTimer --; + if ((g_blinkTmr10ms & 0x1F) == 0) { + inacCounter++; + if ((((uint8_t)inacCounter)&0x0F)==0x01 && g_eeGeneral.inactivityTimer && g_vbat100mV>50 && inacCounter > ((uint16_t)g_eeGeneral.inactivityTimer*187)) + AUDIO_INACTIVITY(); + } + +#if defined (PCBSKY9X) + Tenms |= 1 ; // 10 mS has passed +#endif + +#if defined(RTCLOCK) + /* Update global Date/Time every 100 per10ms cycles */ + if (++g_ms100 == 100) { + g_rtcTime++; // inc global unix timestamp one second +#if defined (PCBSKY9X) + if (g_rtcTime < 60 || rtc_count<5) { + rtc_init(); + rtc_count++; + } + else { + read_coprocessor(true); + } +#endif + g_ms100 = 0; + } +#endif + + readKeysAndTrims(); + +#if defined(MAVLINK) && !defined(PCBSKY9X) + check_mavlink(); +#endif + +#if defined (FRSKY) && !defined(PCBSKY9X) && !(defined(PCBSTD) && (defined(AUDIO) || defined(VOICE))) + check_frsky(); +#endif + + // These moved here from perOut() to improve beep trigger reliability. + if(mixWarning & 1) if(((g_tmr10ms&0xFF)== 0)) AUDIO_MIX_WARNING_1(); + if(mixWarning & 2) if(((g_tmr10ms&0xFF)== 64) || ((g_tmr10ms&0xFF)== 72)) AUDIO_MIX_WARNING_2(); + if(mixWarning & 4) if(((g_tmr10ms&0xFF)==128) || ((g_tmr10ms&0xFF)==136) || ((g_tmr10ms&0xFF)==144)) AUDIO_MIX_WARNING_3(); + +} + PhaseData *phaseaddress(uint8_t idx) { return &g_model.phaseData[idx]; @@ -1034,22 +1091,7 @@ void putsTelemetryValue(uint8_t x, uint8_t y, int16_t val, uint8_t unit, uint8_t } #endif -void clearKeyEvents() -{ -#if defined(PCBSKY9X) - CoTickDelay(100); // 200ms -#endif - -#if defined(SIMU) - while (keyDown() && main_thread_running) sleep(1/*ms*/); -#else - while (keyDown()) wdt_reset(); // loop until all keys are up -#endif - memclear(keys, sizeof(keys)); - putEvent(0); -} - -#define INAC_DEVISOR 256 // Bypass splash screen with stick movement +#define INAC_DEVISOR 1024 // Bypass splash screen with stick movement uint16_t stickMoveValue() { uint16_t sum = 0; @@ -1063,7 +1105,7 @@ void checkBacklight() static uint8_t tmr10ms ; if (tmr10ms != g_blinkTmr10ms) { - tmr10ms = g_blinkTmr10ms ; + tmr10ms = g_blinkTmr10ms; uint16_t tsum = stickMoveValue(); if (tsum != inacSum) { inacSum = tsum; @@ -1071,16 +1113,8 @@ void checkBacklight() if (g_eeGeneral.backlightMode & e_backlight_mode_sticks) backlightOn(); } - else if (g_eeGeneral.inactivityTimer && (!g_vbat100mV || g_vbat100mV>50)) { - if (++inacPrescale > 15 ) { - inacCounter++; - inacPrescale = 0; - if (inacCounter > ((uint16_t)g_eeGeneral.inactivityTimer*25*15)) - if ((inacCounter&0x1F)==1) AUDIO_INACTIVITY(); - } - } - if (g_eeGeneral.backlightMode == e_backlight_mode_on || g_LightOffCounter || isFunctionActive(FUNC_BACKLIGHT)) + if (g_eeGeneral.backlightMode == e_backlight_mode_on || lightOffCounter || isFunctionActive(FUNC_BACKLIGHT)) BACKLIGHT_ON(); else BACKLIGHT_OFF(); @@ -1093,7 +1127,7 @@ void checkBacklight() void backlightOn() { - g_LightOffCounter = ((uint16_t)g_eeGeneral.lightAutoOff*250) << 1; + lightOffCounter = ((uint16_t)g_eeGeneral.lightAutoOff*250) << 1; } #if defined(SPLASH) @@ -1119,10 +1153,8 @@ void doSplash() lcdSetRefVolt(contrast); #endif -#if !defined(SIMU) for (uint8_t i=0; i<32; i++) getADC_filt(); // init ADC array -#endif uint16_t inacSum = stickMoveValue(); @@ -1130,11 +1162,11 @@ void doSplash() while (tgtime != get_tmr10ms()) { #if defined(SIMU) - if (!main_thread_running) return; - sleep(1/*ms*/); + SIMU_SLEEP(1); #elif defined(PCBSKY9X) CoTickDelay(1); #endif + getADC_filt(); uint16_t tsum = stickMoveValue(); @@ -1207,12 +1239,10 @@ void checkTHR() while (1) { -#ifdef SIMU - if (!main_thread_running) return; - sleep(1/*ms*/); -#else + SIMU_SLEEP(1); + getADC_single(); -#endif + int16_t v = thrAnaIn(thrchn); if (check_soft_power() > e_power_trainer || v<=lowLim || keyDown()) @@ -1265,10 +1295,7 @@ void checkSwitches() wdt_reset(); -#ifdef SIMU - if (!main_thread_running) return; - sleep(1/*ms*/); -#endif + SIMU_SLEEP(1); } } @@ -1278,11 +1305,7 @@ void alert(const pm_char * t, const pm_char *s MESSAGE_SOUND_ARG) while(1) { -#ifdef SIMU - if (!main_thread_running) return; - sleep(1/*ms*/); -#endif - + SIMU_SLEEP(1); if (check_soft_power() >= e_power_usb) return; // Usb on or power off @@ -1634,7 +1657,7 @@ void getADC_bandgap() #endif // SIMU uint8_t g_vbat100mV = 0; -uint16_t g_LightOffCounter; +uint16_t lightOffCounter; uint16_t s_timeCumTot; uint16_t s_timeCumThr; // THR in 1/16 sec @@ -2886,7 +2909,6 @@ void perMain() evt = checkTrim(evt); #endif - if (g_LightOffCounter) g_LightOffCounter--; if (evt && (g_eeGeneral.backlightMode & e_backlight_mode_keys)) backlightOn(); // on keypress turn the light on checkBacklight(); @@ -3245,33 +3267,6 @@ volatile rotenc_t g_rotenc[ROTARY_ENCODERS] = {0}; #ifndef SIMU -#if defined(PCBGRUVIN9X) && defined(ROTARY_ENCODERS) - -#if !defined(EXTRA_ROTARY_ENCODERS) -ISR(INT2_vect) -{ - uint8_t input = PIND & 0b00001100; - if (input == 0 || input == 0b00001100) incRotaryEncoder(0, -1); -} -ISR(INT3_vect) -{ - uint8_t input = PIND & 0b00001100; - if (input == 0 || input == 0b00001100) incRotaryEncoder(0, +1); -} -#endif //!EXTRA_ROTARY_ENCODERS - -ISR(INT5_vect) -{ - uint8_t input = PINE & 0b01100000; - if (input == 0 || input == 0b01100000) incRotaryEncoder(1, +1); -} -ISR(INT6_vect) -{ - uint8_t input = PINE & 0b01100000; - if (input == 0 || input == 0b01100000) incRotaryEncoder(1, -1); -} -#endif //PCBGRUVIN9X+ROTARY_ENCODERS - #if defined(PCBSKY9X) void stack_paint() { diff --git a/src/open9x.h b/src/open9x.h index da4d17be7..a2d21fc93 100644 --- a/src/open9x.h +++ b/src/open9x.h @@ -48,6 +48,12 @@ #define IF_PCBSKY9X(x) #endif +#if defined(PCBX9D) +#define IF_PCBX9D(x) x, +#else +#define IF_PCBX9D(x) +#endif + #if defined(RTCLOCK) #define IF_RTCLOCK(x) x, #else @@ -96,12 +102,6 @@ #define IF_SDCARD(x) #endif -#if defined(ROTARY_ENCODERS) -#define IF_ROTARY_ENCODERS(x) x, -#else -#define IF_ROTARY_ENCODERS(x) -#endif - #if defined(BLUETOOTH) #define IF_BLUETOOTH(x) x, #else @@ -190,6 +190,12 @@ extern void board_init(); #include "myeeprom.h" +#if defined(ROTARY_ENCODERS) && NUM_ROTARY_ENCODERS > 0 +#define IF_ROTARY_ENCODERS(x) x, +#else +#define IF_ROTARY_ENCODERS(x) +#endif + #define PPM_CENTER 1500 #if defined(PCBSKY9X) @@ -557,15 +563,18 @@ enum CswFunctions { #define CS_VDIFF 3 #define CS_STATE(x) ((x)= AU_WARNING1)) { - if (g_LightOffCounter < FLASH_DURATION) - g_LightOffCounter = FLASH_DURATION; + if (lightOffCounter < FLASH_DURATION) + lightOffCounter = FLASH_DURATION; } if (g_eeGeneral.beeperMode>0 || (g_eeGeneral.beeperMode==0 && e>=AU_TRIM_MOVE) || (g_eeGeneral.beeperMode>=-1 && e<=AU_ERROR)) { @@ -575,7 +575,6 @@ void audioEvent(uint8_t e, uint8_t f) // inactivity timer alert case AU_INACTIVITY: audioQueue.play(70, 20, 4, 2|PLAY_NOW); - audioQueue.pause(200); break; // low battery in tx case AU_TX_BATTERY_LOW: diff --git a/src/stock/audio.cpp b/src/stock/audio.cpp index 4e2aec268..ba7ad795d 100644 --- a/src/stock/audio.cpp +++ b/src/stock/audio.cpp @@ -134,7 +134,7 @@ void audioQueue::play(uint8_t tFreq, uint8_t tLen, uint8_t tPause, tFreq += g_eeGeneral.speakerPitch + BEEP_OFFSET; // add pitch compensator } tLen = getToneLength(tLen); - if (tFlags & PLAY_NOW || (!busy() && empty())) { + if ((tFlags & PLAY_NOW) || (!busy() && empty())) { toneFreq = tFreq; toneTimeLeft = tLen; tonePause = tPause; @@ -167,8 +167,8 @@ void audioQueue::event(uint8_t e, uint8_t f) #endif if (g_eeGeneral.flashBeep && (e <= AU_ERROR || e >= AU_WARNING1)) { - if (g_LightOffCounter < FLASH_DURATION) - g_LightOffCounter = FLASH_DURATION; + if (lightOffCounter < FLASH_DURATION) + lightOffCounter = FLASH_DURATION; } if (g_eeGeneral.beeperMode>0 || (g_eeGeneral.beeperMode==0 && e>=AU_TRIM_MOVE) || (g_eeGeneral.beeperMode>=-1 && e<=AU_ERROR)) { diff --git a/src/stock/audio.h b/src/stock/audio.h index 70e92bfce..3894acd83 100644 --- a/src/stock/audio.h +++ b/src/stock/audio.h @@ -37,7 +37,7 @@ #endif //audio -#define AUDIO_QUEUE_LENGTH (8) //8 seems to suit most alerts +#define AUDIO_QUEUE_LENGTH (8) // 8 seems to suit most alerts #define BEEP_DEFAULT_FREQ (70) #define BEEP_OFFSET (10) #define BEEP_KEY_UP_FREQ (BEEP_DEFAULT_FREQ+5) diff --git a/src/translations/en.h b/src/translations/en.h index d35133c76..5d2d70a63 100644 --- a/src/translations/en.h +++ b/src/translations/en.h @@ -210,8 +210,10 @@ #define LEN_VSRCRAW "\004" #if defined(PCBX9D) #define TR_POTS_VSRCRAW "S1\0 ""S2\0 ""S3\0 ""S4\0 " +#define TR_SW_VSRCRAW "SA\0 ""SB\0 ""SC\0 ""SD\0 ""SE\0 ""SF\0 ""SG\0 ""SH\0 " #else #define TR_POTS_VSRCRAW "P1\0 ""P2\0 ""P3\0 " +#define TR_SW_VSRCRAW "3POS" #endif #if defined(PCBX9D) #define TR_ROTARY_ENCODERS_VSRCRAW @@ -229,7 +231,7 @@ #else #define TR_CYC_VSRCRAW "[C1]""[C2]""[C3]" #endif -#define TR_VSRCRAW "Rud\0""Ele\0""Thr\0""Ail\0" TR_POTS_VSRCRAW TR_ROTARY_ENCODERS_VSRCRAW "TrmR" "TrmE" "TrmT" "TrmA" "MAX ""3POS" TR_CYC_VSRCRAW +#define TR_VSRCRAW "Rud\0""Ele\0""Thr\0""Ail\0" TR_POTS_VSRCRAW TR_ROTARY_ENCODERS_VSRCRAW "TrmR" "TrmE" "TrmT" "TrmA" "MAX " TR_SW_VSRCRAW TR_CYC_VSRCRAW #define LEN_VTMRMODES "\003" #define TR_VTMRMODES "OFF""ABS""THs""TH%""THt"