From d9cb411c120bab8287a57c326ed7f02399b26efa Mon Sep 17 00:00:00 2001 From: bsongis Date: Mon, 3 Sep 2012 18:13:55 +0000 Subject: [PATCH] Issue 34 fixed Issue 101 fixed --- src/board_ersky9x.cpp | 2 +- src/ersky9x/audio.cpp | 8 ++++ src/ersky9x/audio.h | 1 + src/open9x.cpp | 81 +++++++++++++++++++++++++++------------- src/open9x.h | 11 ++++++ src/statistics_views.cpp | 30 +++++++++++---- src/translations.cpp | 2 + src/translations.h | 2 + src/translations/cz.h | 10 ++++- src/translations/de.h | 10 ++++- src/translations/en.h | 8 +++- src/translations/fr.h | 10 ++++- src/translations/it.h | 10 ++++- src/translations/se.h | 10 ++++- 14 files changed, 150 insertions(+), 45 deletions(-) diff --git a/src/board_ersky9x.cpp b/src/board_ersky9x.cpp index a0f43bc54..e3faa29d3 100644 --- a/src/board_ersky9x.cpp +++ b/src/board_ersky9x.cpp @@ -1198,7 +1198,7 @@ uint16_t getCurrent() static uint8_t Current_count ; Current_sum += anaIn(NUMBER_ANALOG-1); - if ( ++Current_count > 49 ) { + if (++Current_count >= 50) { Current = Current_sum / 5 ; Current_sum = 0 ; Current_count = 0 ; diff --git a/src/ersky9x/audio.cpp b/src/ersky9x/audio.cpp index b58a4fe28..dcb4dc968 100644 --- a/src/ersky9x/audio.cpp +++ b/src/ersky9x/audio.cpp @@ -38,6 +38,7 @@ const char * audioFilenames[] = { "inactiv", "lowbatt", + "highmah", "hightemp", "thralert", "swalert", @@ -548,6 +549,13 @@ void audioEvent(uint8_t e, uint8_t f) audioQueue.play(80, 40, 6, 2, -1); } break; + case AU_TX_MAH_HIGH: + if (!audioQueue.busy()) { + // TODO Rob something better here? + audioQueue.play(60, 40, 6, 2, 1); + audioQueue.play(80, 40, 6, 2, -1); + } + break; case AU_TX_TEMP_HIGH: if (!audioQueue.busy()) { // TODO Rob something better here? diff --git a/src/ersky9x/audio.h b/src/ersky9x/audio.h index 0aa5a4c62..8c667f669 100644 --- a/src/ersky9x/audio.h +++ b/src/ersky9x/audio.h @@ -115,6 +115,7 @@ void audioEvent(uint8_t e, uint8_t f=BEEP_DEFAULT_FREQ); #define AUDIO_WARNING1() audioEvent(AU_WARNING1) #define AUDIO_WARNING2() audioEvent(AU_WARNING2) #define AUDIO_TX_BATTERY_LOW() audioEvent(AU_TX_BATTERY_LOW) +#define AUDIO_TX_MAH_HIGH() audioEvent(AU_TX_MAH_HIGH) #define AUDIO_TX_TEMP_HIGH() audioEvent(AU_TX_TEMP_HIGH) #define AUDIO_ERROR() audioEvent(AU_ERROR) #if defined(VOICE) diff --git a/src/open9x.cpp b/src/open9x.cpp index f87dab101..c760fc0f0 100644 --- a/src/open9x.cpp +++ b/src/open9x.cpp @@ -948,18 +948,35 @@ uint16_t stickMoveValue() void checkBacklight() { - if (g_eeGeneral.backlightMode == e_backlight_mode_on || g_LightOffCounter || isFunctionActive(FUNC_BACKLIGHT)) - BACKLIGHT_ON; - else - BACKLIGHT_OFF; - -#if defined(PCBSTD) && defined(VOICE) static uint8_t tmr10ms ; + if (tmr10ms != g_blinkTmr10ms) { tmr10ms = g_blinkTmr10ms ; + uint16_t tsum = stickMoveValue(); + if (tsum != inacSum) { + inacSum = tsum; + inacCounter = 0; + 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*100*60/16)) + if ((inacCounter&0x1F)==1) AUDIO_INACTIVITY(); + } + } + + if (g_eeGeneral.backlightMode == e_backlight_mode_on || g_LightOffCounter || isFunctionActive(FUNC_BACKLIGHT)) + BACKLIGHT_ON; + else + BACKLIGHT_OFF; + +#if defined(PCBSTD) && defined(VOICE) Voice.voice_process() ; - } #endif + } } void backlightOn() @@ -1263,6 +1280,10 @@ void checkTrims() #if defined(PCBARM) && defined(REVB) uint16_t Current_analogue; +uint16_t Current_max; +uint32_t Current_accumulator; +uint32_t Current_used; +uint16_t MAh_used; #define NUMBER_ANALOG 9 #else #define NUMBER_ANALOG 8 @@ -2258,6 +2279,8 @@ inline void doMixerCalculations(tmr10ms_t tmr10ms, uint8_t tick10ms) #if defined(PCBARM) && defined(REVB) && !defined(SIMU) Current_analogue = ( Current_analogue * 31 + s_anaFilt[8] ) >> 5 ; + if (Current_analogue > Current_max) + Current_max = Current_analogue ; #elif defined(PCBV4) && !defined(SIMU) // For PCB V4, use our own 1.2V, external reference (connected to ADC3) ADCSRB &= ~(1< NUM_POTS) { - val = g_chans512[g_model.thrTraceSrc-NUM_POTS-1]; + val = ex_chans[g_model.thrTraceSrc-NUM_POTS-1] / 2; } else { val = calibratedStick[g_model.thrTraceSrc+NUM_STICKS-1]; @@ -2548,10 +2571,20 @@ void perMain() #if defined(PCBARM) if (Tenms) { Tenms = 0 ; + if (Eeprom32_process_state != E32_IDLE) ee32_process(); else if (TIME_TO_WRITE) eeCheck(); + + Current_accumulator += Current_analogue ; + static uint32_t OneSecTimer; + if (++OneSecTimer >= 100) { + OneSecTimer -= 100 ; + Current_used += Current_accumulator / 100 ; // milliAmpSeconds (but scaled) + Current_accumulator = 0 ; + } + #if defined(SDCARD) && !defined(SIMU) sdPoll10mS(); #endif @@ -2567,22 +2600,6 @@ void perMain() if (!tick10ms) return; //make sure the rest happen only every 10ms. - uint16_t tsum = stickMoveValue(); - if (tsum != inacSum) { - inacSum = tsum; - inacCounter = 0; - if (g_eeGeneral.backlightMode & e_backlight_mode_sticks) - backlightOn(); - } - else if (g_eeGeneral.inactivityTimer && g_vbat100mV>50) { - if (++inacPrescale > 15 ) { - inacCounter++; - inacPrescale = 0; - if (inacCounter > ((uint16_t)g_eeGeneral.inactivityTimer*100*60/16)) - if ((inacCounter&0x1F)==1) AUDIO_INACTIVITY(); - } - } - #if defined(SDCARD) #if defined(PCBV4) static uint8_t mountTimer; @@ -2707,9 +2724,12 @@ void perMain() AUDIO_TX_BATTERY_LOW(); } #if defined(PCBARM) - if (temperature >= g_eeGeneral.temperatureWarn+80) { + else if (temperature >= g_eeGeneral.temperatureWarn+80) { AUDIO_TX_TEMP_HIGH(); } + else if (g_eeGeneral.mAhWarn && (MAh_used + Current_used * (488 + g_eeGeneral.currentCalib)/8192/36) / 500 >= g_eeGeneral.mAhWarn) { + AUDIO_TX_MAH_HIGH(); + } #endif } } @@ -3127,6 +3147,7 @@ inline void open9xInit(OPEN9X_INIT_ARGS) #if defined(PCBARM) setVolume(g_eeGeneral.speakerVolume); PWM->PWM_CH_NUM[0].PWM_CDTYUPD = g_eeGeneral.backlightBright; + MAh_used = g_eeGeneral.mAhUsed; #endif #if defined(PCBARM) && defined(BLUETOOTH) @@ -3648,7 +3669,15 @@ void menusTask(void * pdata) if (shutdown_state != e_power_usb) { displayPopup(STR_SHUTDOWN); - g_eeGeneral.unexpectedShutdown=0; + + MAh_used += Current_used/22/36; + if (g_eeGeneral.mAhUsed != MAh_used) { + g_eeGeneral.mAhUsed = MAh_used; + STORE_GENERALVARS; + } + + g_eeGeneral.unexpectedShutdown = 0; + eeDirty(EE_GENERAL); eeCheck(true); } diff --git a/src/open9x.h b/src/open9x.h index 69f2449d8..e7be26b1b 100644 --- a/src/open9x.h +++ b/src/open9x.h @@ -54,6 +54,14 @@ #include "board_ersky9x.h" #endif +#if defined(PCBARM) && defined(REVB) +extern uint16_t Current_analogue; +extern uint16_t Current_max; +extern uint32_t Current_accumulator; +extern uint32_t Current_used; +extern uint16_t MAh_used; +#endif + #if defined(SIMU) #include "simpgmspace.h" #elif defined(PCBARM) @@ -473,7 +481,9 @@ extern uint8_t heartbeat; #define MAX_ALERT_TIME 60 +extern uint8_t inacPrescale; extern uint16_t inacCounter; +extern uint16_t inacSum; #if defined(PXX) extern uint8_t pxxFlag; @@ -965,6 +975,7 @@ enum AUDIO_SOUNDS { AU_INACTIVITY, AU_TX_BATTERY_LOW, #if defined(PCBARM) + AU_TX_MAH_HIGH, AU_TX_TEMP_HIGH, #endif #if defined(VOICE) diff --git a/src/statistics_views.cpp b/src/statistics_views.cpp index 1f9ee2904..5d138b6da 100644 --- a/src/statistics_views.cpp +++ b/src/statistics_views.cpp @@ -79,12 +79,24 @@ void menuProcStatistic(uint8_t event) #endif } +#if defined(PCBARM) +#define MENU_DEBUG_COL_OFS (13*FW) +#else #define MENU_DEBUG_COL_OFS (14*FW) +#endif void menuProcDebug(uint8_t event) { TITLE(STR_MENUDEBUG); switch(event) { +#if defined(PCBARM) + case EVT_KEY_LONG(KEY_MENU): + MAh_used = 0; + Current_used = 0; + killEvents(event); + AUDIO_KEYPAD_UP(); + break; +#endif case EVT_KEY_FIRST(KEY_MENU): #if !defined(PCBARM) g_tmr1Latency_min = 0xff; @@ -111,23 +123,27 @@ void menuProcDebug(uint8_t event) lcd_outdez8(MENU_DEBUG_COL_OFS , 3*FH, (g_tmr1Latency_max - g_tmr1Latency_min) /2 ); #endif - lcd_putsLeft(4*FH, STR_TMAINMAXMS); #if defined(PCBARM) - lcd_outdezAtt(MENU_DEBUG_COL_OFS, 4*FH, (g_timeMainMax)/20, PREC2); + lcd_putsLeft(5*FH, STR_TMAINMAXMS); + lcd_outdezAtt(MENU_DEBUG_COL_OFS, 5*FH, (g_timeMainMax)/20, PREC2); #else + lcd_putsLeft(4*FH, STR_TMAINMAXMS); lcd_outdezAtt(MENU_DEBUG_COL_OFS, 4*FH, (g_timeMainMax*100)/16, PREC2); #endif #if defined(PCBARM) #if defined(REVB) - lcd_putsLeft(2*FH, STR_CURRENT); + lcd_putsLeft(2*FH, STR_CPU_CURRENT); putsTelemetryValue(MENU_DEBUG_COL_OFS, 2*FH, getCurrent(), UNIT_MILLIAMPS, 0); + uint32_t current_scale = 488 + g_eeGeneral.currentCalib; + putsTelemetryValue(20*FW+2, 2*FH, Current_max*10*current_scale/8192, UNIT_RAW, 0); + lcd_putsLeft(3*FH, STR_CPU_MAH); + putsTelemetryValue(MENU_DEBUG_COL_OFS, 3*FH, MAh_used + Current_used*current_scale/8192/36, UNIT_MAH, PREC1); #endif - lcd_putsLeft(3*FH, STR_CPU_TEMP); - putsTelemetryValue(MENU_DEBUG_COL_OFS, 3*FH, temperature, UNIT_DEGREES, 0); - putsTelemetryValue(20*FW+2, 3*FH, maxTemperature, UNIT_DEGREES, 0); - // TODO mAh, Battery from ersky9x? + lcd_putsLeft(4*FH, STR_CPU_TEMP); + putsTelemetryValue(MENU_DEBUG_COL_OFS, 4*FH, temperature, UNIT_DEGREES, 0); + putsTelemetryValue(20*FW+2, 4*FH, maxTemperature, UNIT_DEGREES, 0); #endif #if !defined(PCBARM) diff --git a/src/translations.cpp b/src/translations.cpp index 802e3a6cc..c1a488f1f 100644 --- a/src/translations.cpp +++ b/src/translations.cpp @@ -338,6 +338,8 @@ const pm_char STR_SPEAKER_VOLUME[] PROGMEM = TR_SPEAKER_VOLUME; const pm_char STR_OPTREX_DISPLAY[] PROGMEM = TR_OPTREX_DISPLAY; const pm_char STR_BRIGHTNESS[] PROGMEM = TR_BRIGHTNESS; const pm_char STR_CPU_TEMP[] PROGMEM = TR_CPU_TEMP; +const pm_char STR_CPU_CURRENT[] PROGMEM = TR_CPU_CURRENT; +const pm_char STR_CPU_MAH[] PROGMEM = TR_CPU_MAH; const pm_char STR_TEMPWARNING[] PROGMEM = TR_TEMPWARNING; const pm_char STR_CAPAWARNING[] PROGMEM = TR_CAPAWARNING; const pm_char STR_FUNC[] PROGMEM = TR_FUNC; diff --git a/src/translations.h b/src/translations.h index 6cfb3c50a..d2ad9efab 100644 --- a/src/translations.h +++ b/src/translations.h @@ -420,6 +420,8 @@ extern const pm_char STR_SPEAKER_VOLUME[]; extern const pm_char STR_OPTREX_DISPLAY[]; extern const pm_char STR_BRIGHTNESS[]; extern const pm_char STR_CPU_TEMP[]; +extern const pm_char STR_CPU_CURRENT[]; +extern const pm_char STR_CPU_MAH[]; extern const pm_char STR_CAPAWARNING[]; extern const pm_char STR_TEMPWARNING[]; extern const pm_char STR_FUNC[]; diff --git a/src/translations/cz.h b/src/translations/cz.h index 1417da021..0af981239 100644 --- a/src/translations/cz.h +++ b/src/translations/cz.h @@ -348,7 +348,11 @@ #define STR_US (STR_TMR1LATMAXUS+12) #define TR_TMR1LATMINUS "Tmr1Lat min\003us" #define TR_TMR1JITTERUS "Tmr1 Jitter\003us" -#define TR_TMAINMAXMS "Tmain max\005ms" +#if defined(PCBARM) +#define TR_TMAINMAXMS "Tmain max\004ms" +#else +#define TR_TMAINMAXMS "Tmain max\005ms" +#endif #define TR_T10MSUS "T10ms\007us" #define TR_FREESTACKMINB "Free Stack\004b" #define TR_MENUTORESET "[MENU] >> Reset" @@ -422,7 +426,9 @@ #define TR_SPEAKER_VOLUME "Hlasitost" #define TR_OPTREX_DISPLAY "Optrex Display" #define TR_BRIGHTNESS "Jas" -#define TR_CPU_TEMP "tepl. CPU\010>" +#define TR_CPU_TEMP "tepl. CPU\007>" +#define TR_CPU_CURRENT "Current\011>" +#define TR_CPU_MAH "Consumpt." #define TR_CAPAWARNING "Capacity Warning" #define TR_TEMPWARNING "Temp Warning" #define TR_FUNC "Fun." diff --git a/src/translations/de.h b/src/translations/de.h index 3caf0f453..1a9b258c4 100644 --- a/src/translations/de.h +++ b/src/translations/de.h @@ -348,7 +348,11 @@ #define STR_US (STR_TMR1LATMAXUS+12) #define TR_TMR1LATMINUS "Tmr1Lat min\003us" #define TR_TMR1JITTERUS "Tmr1 Jitter\003us" -#define TR_TMAINMAXMS "Tmain max\005ms" +#if defined(PCBARM) +#define TR_TMAINMAXMS "Tmain max\004ms" +#else +#define TR_TMAINMAXMS "Tmain max\005ms" +#endif #define TR_T10MSUS "T10ms\007us" #define TR_FREESTACKMINB "Free Stack\004b" #define TR_MENUTORESET "[MENU] f\205r Reset" @@ -422,7 +426,9 @@ #define TR_SPEAKER_VOLUME "Speaker Volume" #define TR_OPTREX_DISPLAY "Optrex Display" #define TR_BRIGHTNESS "Brightness" -#define TR_CPU_TEMP "CPU temp.\010>" +#define TR_CPU_TEMP "CPU temp.\007>" +#define TR_CPU_CURRENT "Current\011>" +#define TR_CPU_MAH "Consumpt." #define TR_CAPAWARNING "Capacity Warning" #define TR_TEMPWARNING "Temp Warning" #define TR_FUNC "Func" diff --git a/src/translations/en.h b/src/translations/en.h index 33c4df5a7..8a80f64ae 100644 --- a/src/translations/en.h +++ b/src/translations/en.h @@ -349,7 +349,11 @@ #define STR_US (STR_TMR1LATMAXUS+12) #define TR_TMR1LATMINUS "Tmr1Lat min\003us" #define TR_TMR1JITTERUS "Tmr1 Jitter\003us" +#if defined(PCBARM) +#define TR_TMAINMAXMS "Tmain max\004ms" +#else #define TR_TMAINMAXMS "Tmain max\005ms" +#endif #define TR_T10MSUS "T10ms\007us" #define TR_FREESTACKMINB "Free Stack\004b" #define TR_MENUTORESET "[MENU] to reset" @@ -423,7 +427,9 @@ #define TR_SPEAKER_VOLUME "Speaker Volume" #define TR_OPTREX_DISPLAY "Optrex Display" #define TR_BRIGHTNESS "Brightness" -#define TR_CPU_TEMP "CPU temp.\010>" +#define TR_CPU_TEMP "CPU Temp.\007>" +#define TR_CPU_CURRENT "Current\011>" +#define TR_CPU_MAH "Consumpt." #define TR_CAPAWARNING "Capacity Warning" #define TR_TEMPWARNING "Temp Warning" #define TR_FUNC "Func" diff --git a/src/translations/fr.h b/src/translations/fr.h index edf317269..86e1c65f4 100644 --- a/src/translations/fr.h +++ b/src/translations/fr.h @@ -346,7 +346,11 @@ #define STR_US (STR_TMR1LATMAXUS+12) #define TR_TMR1LATMINUS "Tmr1Lat min\003us" #define TR_TMR1JITTERUS "Tmr1 Jitter\003us" -#define TR_TMAINMAXMS "Tmain max\005ms" +#if defined(PCBARM) +#define TR_TMAINMAXMS "Tmain max\004ms" +#else +#define TR_TMAINMAXMS "Tmain max\005ms" +#endif #define TR_T10MSUS "T10ms\007us" #define TR_FREESTACKMINB "Free Stack\004b" #define TR_MENUTORESET "[MENU]pour reset" @@ -421,7 +425,9 @@ #define TR_SPEAKER_VOLUME "Volume haut-p." #define TR_OPTREX_DISPLAY "Afficheur Optrex" #define TR_BRIGHTNESS "Luminosit\200" -#define TR_CPU_TEMP "Temp. CPU\010>" +#define TR_CPU_TEMP "Temp. CPU\007>" +#define TR_CPU_CURRENT "Courant\011>" +#define TR_CPU_MAH "Consomm." #define TR_CAPAWARNING "Capacity Warning" #define TR_TEMPWARNING "Alarme temp" #define TR_FUNC "Fonc" diff --git a/src/translations/it.h b/src/translations/it.h index a945aa17a..5970431de 100644 --- a/src/translations/it.h +++ b/src/translations/it.h @@ -348,7 +348,11 @@ #define STR_US (STR_TMR1LATMAXUS+12) #define TR_TMR1LATMINUS "Tmr1Lat min\003us" #define TR_TMR1JITTERUS "Tmr1 Jitter\003us" -#define TR_TMAINMAXMS "Tmain max\005ms" +#if defined(PCBARM) +#define TR_TMAINMAXMS "Tmain max\004ms" +#else +#define TR_TMAINMAXMS "Tmain max\005ms" +#endif #define TR_T10MSUS "T10ms\007us" #define TR_FREESTACKMINB "Free Stack\004b" #define TR_MENUTORESET "[Men\200] x Azzerare" @@ -422,7 +426,9 @@ #define TR_SPEAKER_VOLUME "Volume Audio" #define TR_OPTREX_DISPLAY "Display Optrex" #define TR_BRIGHTNESS "Luminosita'" -#define TR_CPU_TEMP "Temp CPU \010>" +#define TR_CPU_TEMP "Temp CPU \007>" +#define TR_CPU_CURRENT "Current\011>" +#define TR_CPU_MAH "Consumpt." #define TR_CAPAWARNING "Capacity Warning" #define TR_TEMPWARNING "Temp Warning" #define TR_FUNC "Funz" diff --git a/src/translations/se.h b/src/translations/se.h index 6e22c2915..42e2cbc76 100644 --- a/src/translations/se.h +++ b/src/translations/se.h @@ -345,7 +345,11 @@ #define STR_US (STR_TMR1LATMAXUS+12) #define TR_TMR1LATMINUS "Tmr1Lat min\003us" #define TR_TMR1JITTERUS "Tmr1 Jitter\003us" -#define TR_TMAINMAXMS "Tmain max\005ms" +#if defined(PCBARM) +#define TR_TMAINMAXMS "Tmain max\004ms" +#else +#define TR_TMAINMAXMS "Tmain max\005ms" +#endif #define TR_T10MSUS "T10ms\007us" #define TR_FREESTACKMINB "Free Stack\004b" #define TR_MENUTORESET "[MENU] NOLLAR " @@ -420,7 +424,9 @@ #define TR_SPEAKER_VOLUME "Speaker Volume" #define TR_OPTREX_DISPLAY "Optrex Display" #define TR_BRIGHTNESS "Brightness" -#define TR_CPU_TEMP "CPU temp.\010>" +#define TR_CPU_TEMP "CPU temp.\007>" +#define TR_CPU_CURRENT "Current\011>" +#define TR_CPU_MAH "Consumpt." #define TR_CAPAWARNING "Capacity Warning" #define TR_TEMPWARNING "Temp Warning" #define TR_FUNC "Func"