#include "triggers.h"
#include "FreeRTOS.h"
#include "task.h"
#include "settings_api.h"
#include <stdio.h>
#include <math.h>



// 
bool trig_low_value(float value, float lowlevel, float highlevel, float hyst, 
                    hyst_state_t *state) 
{
    (void)highlevel;
    
    if (*state == hyst_idle) {
        if (value <= lowlevel) {
            *state = hyst_down;
            return true;
        } else {
            return false;
        }
    } else if (*state == hyst_down) {
        if (value > (lowlevel + fabs(hyst))) {
            *state = hyst_idle;
            return false;
        } else {
            return true;
        }
    }

    return false;
}



bool trig_high_value(float value, float lowlevel, float highlevel, float hyst,
                     hyst_state_t *state) 
{
    (void)lowlevel;

    if (*state == hyst_idle) {
        if (value >= highlevel) {
            *state = hyst_up;
            return true;
        } else {
            return false;
        }
    } else if (*state == hyst_up) {
        if (value < (highlevel - fabs(hyst))) {
            *state = hyst_idle;
            return false;
        } else {
            return true;
        }
    }

    return false;
}