/**
 * @file VariabelsConstants.h
 * @author Lukas Chytil (xchyti13@vutbr.cz)
 * @brief A file with constants and variables for modyfying the program
 * @date 2023-05-02
 *
 * @copyright Copyright (c) 2023
 *
 */
#ifndef VARIABELS_CONSTANTS
#define VARIABELS_CONSTANTS

// I2S amplifier connections
#define I2S_DOUT      22
#define I2S_BCLK      26
#define I2S_LRC       25


//input PWM pin from RC receiver
#define RC_PWM_PIN 34

//volume potenciometer input
#define VOLUME_PIN 35

//power potenciometer input
#define POWER_PIN 32



//------Time ON values---------------
#define NEUTRAL_TIME_ON_MICRO_SEC 1500	//set neutral time ON value depending on the transmitter setting, mostly 1500 microsec

//range for filtering out invalid values
#define MIN_TIME_ON_MICRO_SEC 900
#define MAX_TIME_ON_MICRO_SEC 2100
//-----------------------------------



//audio setup
#define TOLERANCY 22		//range for neutral engine track,(NEUTRAL -TOLERANCY, NEUTRAL + TOLERANCY)
#define STEP 26				//multiples of this variable determine the intervals in microseconds for engine audio tracks
#define REMOVE_EDGE 6		//specifies the distance between audio track intervals, this empty place remove thresholds between tracks
#define BRAKE_SENSITIVITY 10 //this white space eliminates unwanted track switching at the edges of the interval
#define BIG_ACC 10           //the difference of two consecutive signal values, crossing this threshold means a quick change of driving

//-------------------- Ultrasonic sensor configuration-----------------
//ultrasonic sensor pins
#define TRIGPIN 12
#define ECHOPIN 13
#define ULTRASONIC_ENABLE 0		//enable = 1 , disable = 0
#define SOUND_SPEED 0.034 		//define sound speed in cm/uS
//---------------------------------------------------------------------




//-----------------------------variables modified during the program runtime-------------------------------
//set speaker volume in the range <0.0, 4.0>, float value, recommended max 2.0
float volume = 0.1;

//in milliseconds, determines the power of the engine, determines the time for starting the engine performance.
// A higher value means a slower onset of performance.
int power = 10;

//saving the distance from the untrasonic sensor
float distance_cm = 0.0;

//timeON value received from the receiver for the current period
long time_on_value = 0;

//current engine timeON value
long  timeon_function_sound = 0;

//difference for acceleration evaluation
int difference = 0;

//the time when the last song started
unsigned long played_time = 0;

//turrent engine track number
int rpm_track = 0;

//array to store last previous TimeOn value
int prev_time_on_value[] = {
    NEUTRAL_TIME_ON_MICRO_SEC,
    NEUTRAL_TIME_ON_MICRO_SEC,
    NEUTRAL_TIME_ON_MICRO_SEC,
    NEUTRAL_TIME_ON_MICRO_SEC,
    NEUTRAL_TIME_ON_MICRO_SEC
};

//switching players
bool stop_main_player = false;
//-----------------------------------------------------------------------------------------------------




//global variables for ESP32 memory player
AudioGeneratorWAV *audio;
AudioFileSourcePROGMEM *file;
AudioOutputI2S *out;


//global variables for PROGMEM MIXER player. Mixes the sound of the engine and the reversing ultrasonic sensor
AudioGeneratorWAV *PROGMEMaudio_mixer[2];
AudioFileSourcePROGMEM *PROGMEMfile_mixer[2];
AudioOutputMixer *mixer;
AudioOutputMixerStub *stub[2];
AudioOutputI2S *PROGMEMout_mixer;

#endif //end VARIABELS_CONSTANTS