2.4 continued (#8092)
Quite a bit of work on 2.4 Co-authored-by: 3djc <Th1sisfmyofmyo>
This commit is contained in:
co-authored by
3djc <Th1sisfmyofmyo>
parent
cd6aa7af00
commit
87cd9047b1
+24
-10
@@ -69,18 +69,15 @@ void saveTimers()
|
||||
|
||||
#define THR_TRG_TRESHOLD 13 // approximately 10% full throttle
|
||||
|
||||
#warning "Timer mode is switched into (mode + swtch), needs to be taken into account in UI"
|
||||
|
||||
void evalTimers(int16_t throttle, uint8_t tick10ms)
|
||||
{
|
||||
for (uint8_t i=0; i<TIMERS; i++) {
|
||||
tmrmode_t timerMode = g_model.timers[i].mode;
|
||||
int16_t timerSwtch = g_model.timers[i].swtch;
|
||||
if (timerMode && (!timerSwtch || getSwitch(timerSwtch))) {
|
||||
tmrstart_t timerStart = g_model.timers[i].start;
|
||||
TimerState * timerState = &timersStates[i];
|
||||
tmrstart_t timerStart = g_model.timers[i].start;
|
||||
TimerState * timerState = &timersStates[i];
|
||||
|
||||
if (timerState->state == TMR_OFF) {
|
||||
if (timerMode) {
|
||||
if ((timerState->state == TMR_OFF) && (timerMode != TMRMODE_THR_START)) {
|
||||
timerState->state = TMR_RUNNING;
|
||||
timerState->cnt = 0;
|
||||
timerState->sum = 0;
|
||||
@@ -105,13 +102,30 @@ void evalTimers(int16_t throttle, uint8_t tick10ms)
|
||||
else if (timerMode == TMRMODE_THR) {
|
||||
if (throttle) newTimerVal++;
|
||||
}
|
||||
else {
|
||||
if (timerState->cnt && (timerState->sum / timerState->cnt) >= 128) { // throttle was normalized to 0 to 128 value (throttle/64*2 (because - range is added as well)
|
||||
else if (timerMode == TMRMODE_THR_REL) {
|
||||
if ((timerState->sum/timerState->cnt) >= 128) { // throttle was normalized to 0 to 128 value (throttle/64*2 (because - range is added as well)
|
||||
newTimerVal++; // add second used of throttle
|
||||
timerState->sum -= 128 * timerState->cnt;
|
||||
timerState->sum -= 128*timerState->cnt;
|
||||
}
|
||||
timerState->cnt = 0;
|
||||
}
|
||||
else if (timerMode == TMRMODE_THR_START) {
|
||||
// we can't rely on (throttle || newTimerVal > 0) as a detection if timer should be running
|
||||
// because having persistent timer brakes this rule
|
||||
if ((throttle > THR_TRG_TRESHOLD) && timerState->state == TMR_OFF) {
|
||||
timerState->state = TMR_RUNNING; // start timer running
|
||||
timerState->cnt = 0;
|
||||
timerState->sum = 0;
|
||||
// TRACE("Timer[%d] THr triggered", i);
|
||||
}
|
||||
if (timerState->state != TMR_OFF) newTimerVal++;
|
||||
}
|
||||
else {
|
||||
if (timerMode > 0) timerMode -= (TMRMODE_COUNT-1);
|
||||
if (getSwitch(timerMode)) {
|
||||
newTimerVal++;
|
||||
}
|
||||
}
|
||||
|
||||
switch (timerState->state) {
|
||||
case TMR_RUNNING:
|
||||
|
||||
Reference in New Issue
Block a user