5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
24 uint8_t checkTrim(event_t event
);
29 doMixerCalculations();
31 #if defined(LCD_ST7920)
33 #define IS_LCD_REFRESH_ALLOWED() (0==lcdstate)
35 #define IS_LCD_REFRESH_ALLOWED() (1)
37 uint16_t t0
= getTmr16KHz();
38 int16_t delta
= (nextMixerEndTime
- lastMixerDuration
) - t0
;
39 if (delta
> 0 && delta
< MAX_MIXER_DELTA
) {
40 #if defined(PCBSTD) && defined(ROTARY_ENCODER_NAVIGATION)
44 // @@@ open.20.fsguruh
45 // SLEEP(); // wouldn't that make sense? should save a lot of battery power!!!
46 /* for future use; currently very very beta... */
47 #if defined(POWER_SAVE)
48 ADCSRA
&=0x7F; // disable ADC for power saving
49 ACSR
&=0xF7; // disable ACIE Interrupts
50 ACSR
|=0x80; // disable Analog Comparator
51 // maybe we disable here a lot more hardware components in future to save even more power
55 MCUCR
|=0x20; // enable Sleep (bit5)
56 // MCUCR|=0x28; // enable Sleep (bit5) enable ADC Noise Reduction (bit3)
57 // first tests showed: simple sleep would reduce cpu current from 40.5mA to 32.0mA
58 // noise reduction sleep would reduce it down to 28.5mA; However this would break pulses in theory
59 // however with standard module, it will need about 95mA. Therefore the drop to 88mA is not much noticable
61 asm volatile(" sleep \n\t"); // if _SLEEP() is not defined use this
63 delta
= (nextMixerEndTime
- lastMixerDuration
) - t0
;
64 } while ((delta
>0) && (delta
<MAX_MIXER_DELTA
));
66 // reenabling of the hardware components needed here
67 MCUCR
&=0x00; // disable sleep
68 ADCSRA
|=0x80; // enable ADC
73 nextMixerEndTime
= t0
+ MAX_MIXER_DELTA
;
74 // this is a very tricky implementation; lastMixerEndTime is just like a default value not to stop mixcalculations totally;
75 // the real value for lastMixerEndTime is calculated inside pulses_XXX.cpp which aligns the timestamp to the pulses generated
76 // nextMixerEndTime is actually defined inside pulses_XXX.h
78 doMixerCalculations();
80 t0
= getTmr16KHz() - t0
;
81 lastMixerDuration
= t0
;
82 if (t0
> maxMixerDuration
) maxMixerDuration
= t0
;
84 #if defined(MODULE_ALWAYS_SEND_PULSES)
85 if (startupWarningState
< STARTUP_WARNING_DONE
) {
86 // don't do menu's until throttle and switch warnings are handled
91 if (eepromIsTransferComplete()) {
92 if (theFile
.isWriting())
93 theFile
.nextWriteStep();
94 else if (TIME_TO_WRITE())
103 event_t evt
= getEvent();
104 evt
= checkTrim(evt
);
106 if (evt
&& (g_eeGeneral
.backlightMode
& e_backlight_mode_keys
)) backlightOn(); // on keypress turn the light on
107 doLoopCommonActions();
109 #if defined(TELEMETRY_FRSKY) || defined(TELEMETRY_MAVLINK)
113 #if defined(NAVIGATION_STICKS)
114 uint8_t sticks_evt
= getSticksNavigationEvent();
115 if (sticks_evt
) evt
= sticks_evt
;
119 const char * warn
= warningText
;
120 bool popupMenuActive
= (popupMenuNoItems
> 0);
122 if (IS_LCD_REFRESH_ALLOWED()) { // No need to redraw until lcdRefresh_ST7920(0) below completely refreshes the display.
125 menuVerticalPosition
= menuEvent
== EVT_ENTRY_UP
? menuVerticalPositions
[menuLevel
] : 0;
126 menuHorizontalPosition
= 0;
130 menuHandlers
[menuLevel
]((warn
|| popupMenuActive
) ? 0 : evt
);
132 if (warn
) DISPLAY_WARNING(evt
);
133 #if defined(NAVIGATION_MENUS)
134 if (popupMenuActive
) {
135 const char * result
= runPopupMenu(evt
);
137 popupMenuHandler(result
);
144 #if defined(LCD_KS108)
146 #elif defined(LCD_ST7920)
147 lcdstate
= lcdRefresh_ST7920(0);
152 #endif // defined(GUI)