<script type="text/javascript">

	//-----------------------------------------------------------------------------------
	gauges_text_color 			= '#000000';
	gauges_inactive_ring_color	= '#BBBBBB';
	gauges_background_color 	= '#ffffff';
	
	gauges_radius				= '100%';
	gauges_cutout				= '55%';
	
	gauges_line_width			=   0 ;

	mini_maxi_font_size			=  16 ;
	mini_x_adjust				= -92 ;
	mini_y_adjust				=  86 ;
	maxi_x_adjust				=  92 ;
	maxi_y_adjust				=  86 ;

	title_font_size				=  18 ;
	title_x_adjust				=   0 ;
	title_y_adjust				= -67 ;
	
	unit_font_size				=  20 ;
	unit_x_adjust				=   5 ;
	unit_y_adjust				=  82 ;
	
	value_font_size				=  36 ;
	value_x_adjust				=   5 ;
	value_y_adjust				=  52 ;
	
	emoticon_x					=   0 ;
	emoticon_y					=   3 ;
	emoticon_width				=  68 ;
	emoticon_height				=  51 ;

	//-----------------------------------------------------------------------------------
	var image_T 	= new Image();
	image_T.src 	= "<?php echo($emoticon_T); ?>";
	var image_HR 	= new Image();
	image_HR.src 	= "<?php echo($emoticon_HR); ?>";
	var image_CO2 	= new Image();
	image_CO2.src	= "<?php echo($emoticon_CO2); ?>";
	var image_COV 	= new Image();
	image_COV.src	= "<?php echo($emoticon_COV); ?>";
	var image_HCHO 	= new Image();
	image_HCHO.src	= "<?php echo($emoticon_HCHO); ?>";
	var image_PM25 	= new Image();
	image_PM25.src	= "<?php echo($emoticon_PM25); ?>";
	var image_LUX 	= new Image();
	image_LUX.src	= "<?php echo($emoticon_LUX); ?>";
	var image_SPL 	= new Image();
	image_SPL.src 	= "<?php echo($emoticon_SPL); ?>";

function update_gauges_00(chart, data, text_valeur, color, FS_min, FS_max) {
	chart.data.datasets.pop();
	chart.data.datasets.push({
		data: data,
		backgroundColor: [color, gauges_inactive_ring_color],
		borderColor: '#000000',
		borderWidth: 0
	});

	chart.options.plugins.annotation.annotations.labelValue.content.pop();
	chart.options.plugins.annotation.annotations.labelValue.content.push(text_valeur);
	chart.options.plugins.annotation.annotations.labelMin.content.pop();
	chart.options.plugins.annotation.annotations.labelMin.content.push(FS_min);
	chart.options.plugins.annotation.annotations.labelMax.content.pop();
	chart.options.plugins.annotation.annotations.labelMax.content.push(FS_max);
}

function update_gauges(chart, data, text_valeur, color, FS_min, FS_max) {
	update_gauges_00(chart, data, text_valeur, color, FS_min, FS_max)
	chart.update();
}

function update_gauges_T(chart, data, text_valeur, color, FS_min, FS_max, emoticon) {
	update_gauges_00(chart, data, text_valeur, color, FS_min, FS_max)
	image_T.src = emoticon;
	chart.update();
}
function update_gauges_HR(chart, data, text_valeur, color, FS_min, FS_max, emoticon) {
	update_gauges_00(chart, data, text_valeur, color, FS_min, FS_max)
	image_HR.src = emoticon;
	chart.update();
}
function update_gauges_CO2(chart, data, text_valeur, color, FS_min, FS_max, emoticon) {
	update_gauges_00(chart, data, text_valeur, color, FS_min, FS_max)
	image_CO2.src = emoticon;
	chart.update();
}
function update_gauges_COV(chart, data, text_valeur, color, FS_min, FS_max, emoticon) {
	update_gauges_00(chart, data, text_valeur, color, FS_min, FS_max)
	image_COV.src = emoticon;
	chart.update();
}
function update_gauges_HCHO(chart, data, text_valeur, color, FS_min, FS_max, emoticon) {
	update_gauges_00(chart, data, text_valeur, color, FS_min, FS_max)
	image_HCHO.src = emoticon;
	chart.update();
}
function update_gauges_PM25(chart, data, text_valeur, color, FS_min, FS_max, emoticon) {
	update_gauges_00(chart, data, text_valeur, color, FS_min, FS_max)
	image_PM25.src = emoticon;
	chart.update();
}
function update_gauges_LUX(chart, data, text_valeur, color, FS_min, FS_max, emoticon) {
	update_gauges_00(chart, data, text_valeur, color, FS_min, FS_max)
	image_LUX.src = emoticon;
	chart.update();
}
function update_gauges_SPL(chart, data, text_valeur, color, FS_min, FS_max, emoticon) {
	update_gauges_00(chart, data, text_valeur, color, FS_min, FS_max)
	image_SPL.src = emoticon;
	chart.update();
}

var requestData = function() {
	
    $.ajax({
		
        url: './JSON_get_mesure.php',
		
        success: function(mesure) {
			
			//-------------------------------------------------------------------------------------
			var aqcm_CAPTEUR_CO2  = mesure[0];
			var aqcm_CAPTEUR_COV  = mesure[1];
			var aqcm_CAPTEUR_HCHO = mesure[2];
			var aqcm_CAPTEUR_PM25 = mesure[3];
			var aqcm_CAPTEUR_LUX  = mesure[4];
			var aqcm_CAPTEUR_SPL  = mesure[5];
			var aqcm_CAPTEUR_P    = mesure[6];

			//-------------------------------------------------------------------------------------
			var T_value			= eval(mesure[7]);
			var T_color			= mesure[8] ;
			var	T_mini_value	= eval(mesure[9]);
			var	T_maxi_value	= eval(mesure[10]);
			var T_emoticon   	= mesure[11] ;

			if ( (aqcm_CAPTEUR_CO2  == "SCD30")  || (aqcm_CAPTEUR_CO2 == "SCD41")  || (aqcm_CAPTEUR_CO2  == "CO2_BOTH" ) || 
				 (aqcm_CAPTEUR_P    == "BME680") || (aqcm_CAPTEUR_P   == "BMP390") || (aqcm_CAPTEUR_P    == "BMX_BOTH" ) ||  
				 (aqcm_CAPTEUR_COV  == "SGP40")  || (aqcm_CAPTEUR_COV == "SGP41")  || (aqcm_CAPTEUR_HCHO == "SFA30"    ) )      {
					 
				update_gauges_T(gauge_T, [T_value - T_mini_value, T_maxi_value - T_value], [T_value], T_color, T_mini_value, T_maxi_value, T_emoticon) ;
				
			}

			//-------------------------------------------------------------------------------------
			var HR_value		= eval(mesure[12]);
			var HR_color		= mesure[13] ;
			var	HR_mini_value	= 0;
			var	HR_maxi_value	= 100 ;
			var HR_emoticon   	= mesure[14] ;

			if ( (aqcm_CAPTEUR_CO2  == "SCD30") || (aqcm_CAPTEUR_CO2 == "SCD41")     || (aqcm_CAPTEUR_CO2 == "CO2_BOTH" ) || 
				 (aqcm_CAPTEUR_P == "BME680")   || (aqcm_CAPTEUR_P   == "BMX_BOTH" ) ||   
			     (aqcm_CAPTEUR_COV == "SGP40")  || (aqcm_CAPTEUR_COV == "SGP41")     || (aqcm_CAPTEUR_HCHO == "SFA30") )     {

				update_gauges_HR(gauge_HR, [HR_value - HR_mini_value, HR_maxi_value - HR_value], [HR_value], HR_color, HR_mini_value, HR_maxi_value, HR_emoticon) ;

			}
			
			//-------------------------------------------------------------------------------------
			var CO2_value			= eval(mesure[15]);
			var CO2_color			= mesure[16] ;
			var	CO2_mini_value		= 0;
			var	CO2_maxi_value		= eval(mesure[17]);
			var CO2_emoticon   		= mesure[18] ;
			
			if ( ( aqcm_CAPTEUR_CO2 == "SCD30" ) || ( aqcm_CAPTEUR_CO2 == "SCD41" ) || ( aqcm_CAPTEUR_CO2 == "CO2_BOTH" ) ) {

				update_gauges_CO2(gauge_CO2, [CO2_value - CO2_mini_value, CO2_maxi_value - CO2_value], [CO2_value], CO2_color, CO2_mini_value, CO2_maxi_value, CO2_emoticon) ;

			}

			//-------------------------------------------------------------------------------------
			var COV_value			= eval(mesure[19]);
			var COV_color			= mesure[20] ;
			var	COV_mini_value		= 0;
			var	COV_maxi_value		= 500;
			var COV_emoticon   		= mesure[21] ;

			if ( ( aqcm_CAPTEUR_COV == "SGP40" ) || ( aqcm_CAPTEUR_COV == "SGP41" ) ) {

				update_gauges_COV(gauge_COV, [COV_value - COV_mini_value, COV_maxi_value - COV_value], [COV_value], COV_color, COV_mini_value, COV_maxi_value, COV_emoticon) ;

			}

			//-------------------------------------------------------------------------------------
			var HCHO_value			= eval(mesure[22]);
			var HCHO_color			= mesure[23] ;
			var	HCHO_mini_value		= 0;
			var	HCHO_maxi_value		= eval(mesure[24]);
			var HCHO_emoticon   	= mesure[25] ;

			if ( aqcm_CAPTEUR_HCHO == "SFA30" ) {

				update_gauges_HCHO(gauge_HCHO, [HCHO_value - HCHO_mini_value, HCHO_maxi_value - HCHO_value], [HCHO_value], HCHO_color, HCHO_mini_value, HCHO_maxi_value, HCHO_emoticon) ;

			}

			//-------------------------------------------------------------------------------------
			var PM25_value			= eval(mesure[26]);
			var PM25_color			= mesure[27] ;
			var	PM25_mini_value		= 0;
			var	PM25_maxi_value		= eval(mesure[28]);
			var PM25_emoticon   	= mesure[29] ;

			if ( aqcm_CAPTEUR_PM25 == "SPS30" ) {

				update_gauges_PM25(gauge_PM25, [PM25_value - PM25_mini_value, PM25_maxi_value - PM25_value], [PM25_value], PM25_color, PM25_mini_value, PM25_maxi_value, PM25_emoticon) ;

			}

			//-------------------------------------------------------------------------------------
			var LUX_value			= eval(mesure[30]);
			var LUX_color			= mesure[31] ;
			var	LUX_mini_value		= 0;
			var	LUX_maxi_value		= eval(mesure[32]);
			var LUX_emoticon   		= mesure[33] ;
			
			if ( aqcm_CAPTEUR_LUX == "VEML7700" ) {

				update_gauges_LUX(gauge_LUX, [LUX_value - LUX_mini_value, LUX_maxi_value - LUX_value], [LUX_value], LUX_color, LUX_mini_value, LUX_maxi_value, LUX_emoticon) ;

			}
			
			//-------------------------------------------------------------------------------------
			var SPL_value		= eval(mesure[34]);
			var SPL_color   	= mesure[35] ;
			var	SPL_mini_value	= 0;
			var	SPL_maxi_value	= eval(mesure[36]);
			var SPL_emoticon   	= mesure[37] ;

			if ( aqcm_CAPTEUR_SPL == "I2S" ) {

				update_gauges_SPL(gauge_SPL, [SPL_value - SPL_mini_value, SPL_maxi_value - SPL_value], [SPL_value], SPL_color, SPL_mini_value, SPL_maxi_value, SPL_emoticon) ;

			}

			//-------------------------------------------------------------------------------------
			var P_value			= eval(mesure[38]);
			var P_color   		= mesure[39] ;
			var	P_mini_value	=  980;
			var	P_maxi_value	= 1050;
			var AQCM05_error_P	= eval(mesure[40]);

			if ( ( aqcm_CAPTEUR_P == "BME680") || ( aqcm_CAPTEUR_P == "BMP390") || ( aqcm_CAPTEUR_P == "BMX_BOTH") ) {

				if ( AQCM05_error_P != 0 ) {
					update_gauges(gauge_P, [P_value - P_mini_value, P_maxi_value - P_value], [P_value], P_color, P_mini_value, P_maxi_value) ;
				} 
				else {

				}

			}

			//-------------------------------------------------------------------------------------

        },
		
        cache: false
		
    });
	
}

setInterval(requestData, 1000);

</script>
