<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns="http://www.holeschak.de/BmwDeepObd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.holeschak.de/BmwDeepObd BmwDeepObd.xsd">
  <page name="HOME" display-mode="grid" fontsize="medium" gauges-portrait="3" gauges-landscape="5" logfile="DME_DDE.log">
    <strings lang="de">
      <string name="HOME">HOME</string>
	  <string name="!JOB#STATUS_MESSWERTBLOCK_LESEN#STAT_KUEHLMITTELTEMPERATUR_WERT"> Kühlmitteltemperatur [°C]</string>
      <string name="!JOB#STATUS_MESSWERTBLOCK_LESEN#STAT_LADELUFTTEMPERATUR_WERT"> Ladelufttemp. [°C]</string>
      <string name="!JOB#STATUS_MESSWERTBLOCK_LESEN#STAT_MOTORDREHZAHL_WERT"> Drehzahl [U/min]</string>
	  <string name="!JOB#LLA_ABGLEICH_LESEN_WERT"> Anhebung Leerlaufdrehzahl [u/min]</string>
      <string name="!JOB#STATUS_MESSWERTBLOCK_LESEN#STAT_MOTORMOMENT_AKTUELL_WERT"> Drehmoment [Nm]:</string>
	  
      <string name="!JOB#STATUS_MESSWERTBLOCK_LESEN#STAT_UBATT_WERT"> Batteriespannung [V]</string>
      <string name="!JOB#STATUS_MESSWERTBLOCK_LESEN#STAT_GENERATORLAST_WERT"> Generatorlast [%]</string>
      <string name="!JOB#STATUS_MESSWERTBLOCK_LESEN#STAT_ZUHEIZER_ANSTEUERUNG_WERT"> Zuheizer PWM [%]</string>
      <string name="!JOB#STATUS_MESSWERTBLOCK_LESEN#STAT_LADEDRUCK_WERT"> Ladedruck Ist [mbar]</string>
      <string name="!JOB#STATUS_MESSWERTBLOCK_LESEN#STAT_LADEDRUCK_SOLL_WERT"> Ladedruck Soll [mbar]</string>
      
      <string name="!JOB#STATUS_MESSWERTBLOCK_LESEN#STAT_LUFTMASSE_PRO_HUB_WERT"> Luftmasse [mg/Hub]</string>
      <string name="!JOB#STATUS_MESSWERTBLOCK_LESEN#STAT_UMGEBUNGSDRUCK_WERT"> Luftdruck [mbar]</string>
      <string name="!JOB#STATUS_MESSWERTBLOCK_LESEN#STAT_RAILDRUCK_WERT"> Raildruck Ist [bar]</string>
      <string name="!JOB#STATUS_MESSWERTBLOCK_LESEN#STAT_GESCHWINDIGKEIT_WERT"> Geschwindigkeit [km/h]</string>
      <string name="!JOB#STATUS_MESSWERTBLOCK_LESEN#STAT_FAHRZEUGBESCHLEUNIGUNG_WERT"> Beschleunigung [m/s²]</string>
	  
      <string name="!JOB#STATUS_MESSWERTBLOCK_LESEN#STAT_KUPPLUNGSSCHALTER_ROH_WERT">  Kupplungsschalter</string>
      <string name="!JOB#STATUS_MESSWERTBLOCK_LESEN#STAT_KLIMAKOMPRESSOR_STATUS_WERT">  Klimakompressor</string>
      <string name="!JOB#STATUS_MESSWERTBLOCK_LESEN#STAT_BEREITSCHAFT_KLIMA_WERT">  Klima Bereitschaft</string>
	  
      <string name="!JOB#STATUS_TOENS_IO#STAT_TOG_HIGH_WERT">  TÖNS Heizzeit [ms]</string>
      <string name="!JOB#STATUS_TOENS_IO#STAT_TOG_LOW_WERT">  TÖNS Kühlzeit [ms]</string>
    </strings>
    <strings>
      <string name="HOME">HOME</string>
      <string name="!JOB#STATUS_MESSWERTBLOCK_LESEN#STAT_KUEHLMITTELTEMPERATUR_WERT"> coolant [°C]</string>
      <string name="!JOB#STATUS_MESSWERTBLOCK_LESEN#STAT_LADELUFTTEMPERATUR_WERT"> charge air temperature [°C]</string>
      <string name="!JOB#STATUS_MESSWERTBLOCK_LESEN#STAT_MOTORDREHZAHL_WERT"> engine speed [U/min]</string>
	  <string name="!JOB#LLA_ABGLEICH_LESEN_WERT"> increase idle speed [rpm]</string>
      <string name="!JOB#STATUS_MESSWERTBLOCK_LESEN#STAT_MOTORMOMENT_AKTUELL_WERT"> torque [Nm]:</string>
      
      <string name="!JOB#STATUS_MESSWERTBLOCK_LESEN#STAT_UBATT_WERT"> voltage [V]</string>
	  <string name="!JOB#STATUS_MESSWERTBLOCK_LESEN#STAT_GENERATORLAST_WERT"> alternator load [%]</string>
	  <string name="!JOB#STATUS_MESSWERTBLOCK_LESEN#STAT_ZUHEIZER_ANSTEUERUNG_WERT"> aux heater PWM [%]</string>
      <string name="!JOB#STATUS_MESSWERTBLOCK_LESEN#STAT_LADEDRUCK_WERT"> act. boost pressure [mbar]</string>
      <string name="!JOB#STATUS_MESSWERTBLOCK_LESEN#STAT_LADEDRUCK_SOLL_WERT"> target boost pressure [mbar]</string>
	  	  
	  <string name="!JOB#STATUS_MESSWERTBLOCK_LESEN#STAT_LUFTMASSE_PRO_HUB_WERT"> air mass [mg/stroke]</string>
      <string name="!JOB#STATUS_MESSWERTBLOCK_LESEN#STAT_UMGEBUNGSDRUCK_WERT"> air pressure [mbar]</string>
      <string name="!JOB#STATUS_MESSWERTBLOCK_LESEN#STAT_RAILDRUCK_WERT"> act. rail pressure [bar]</string>
      <string name="!JOB#STATUS_MESSWERTBLOCK_LESEN#STAT_GESCHWINDIGKEIT_WERT"> speed [km/h]</string>
      <string name="!JOB#STATUS_MESSWERTBLOCK_LESEN#STAT_FAHRZEUGBESCHLEUNIGUNG_WERT"> acceleration [m/s²]</string>
      
	  <string name="!JOB#STATUS_TOENS_IO#STAT_TOG_HIGH_WERT">  TÖNS heating time [ms]</string>
      <string name="!JOB#STATUS_TOENS_IO#STAT_TOG_LOW_WERT">  TÖNS cooling time [ms]</string>
    </strings>
	
    <display name="!JOB#STATUS_MESSWERTBLOCK_LESEN#STAT_KUEHLMITTELTEMPERATUR_WERT" result="STAT_KUEHLMITTELTEMPERATUR_WERT" grid-type="simple-gauge-round" min-value="-20" max-value="120" log_tag="STAT_KUEHLMITTELTEMPERATUR_WERT" />
	<display name="!JOB#STATUS_MESSWERTBLOCK_LESEN#STAT_LADELUFTTEMPERATUR_WERT" result="STAT_LADELUFTTEMPERATUR_WERT" format=".1R" grid-type="simple-gauge-round" min-value="-20" max-value="80" log_tag="STAT_LADELUFTTEMPERATUR_WERT" />
    <display name="!JOB#STATUS_MESSWERTBLOCK_LESEN#STAT_MOTORDREHZAHL_WERT" result="STAT_MOTORDREHZAHL_WERT" grid-type="simple-gauge-round" min-value="0" max-value="5000" log_tag="STAT_MOTORDREHZAHL_WERT" />
	<display name="!JOB#LLA_ABGLEICH_LESEN_WERT" result="LLA_ABGLEICH_LESEN_WERT" format="L" display-order="0" grid-type="simple-gauge-round" min-value="0" max-value="250" log_tag="LLA" />
    <display name="!JOB#STATUS_MESSWERTBLOCK_LESEN#STAT_MOTORMOMENT_AKTUELL_WERT" result="STAT_MOTORMOMENT_AKTUELL_WERT" format="L" grid-type="simple-gauge-round" min-value="0" max-value="600" log_tag="STAT_MOTORMOMENT_AKTUELL_WERT" />
    
    <display name="!JOB#STATUS_MESSWERTBLOCK_LESEN#STAT_UBATT_WERT" result="STAT_UBATT_WERT" grid-type="simple-gauge-round" min-value="0" max-value="15" log_tag="STAT_UBATT_WERT" />
	<display name="!JOB#STATUS_MESSWERTBLOCK_LESEN#STAT_GENERATORLAST_WERT" result="STAT_GENERATORLAST_WERT" grid-type="simple-gauge-round" min-value="0" max-value="100" log_tag="STAT_GENERATORLAST_WERT" />
    <display name="!JOB#STATUS_MESSWERTBLOCK_LESEN#STAT_ZUHEIZER_ANSTEUERUNG_WERT" result="STAT_ZUHEIZER_ANSTEUERUNG_WERT" grid-type="simple-gauge-round" min-value="0" max-value="100" log_tag="STAT_ZUHEIZER_ANSTEUERUNG_WERT" />
    <display name="!JOB#STATUS_MESSWERTBLOCK_LESEN#STAT_LADEDRUCK_WERT" result="STAT_LADEDRUCK_WERT" format="4.1R" grid-type="simple-gauge-round" min-value="0" max-value="2500" log_tag="STAT_LADEDRUCK_WERT" />
    <display name="!JOB#STATUS_MESSWERTBLOCK_LESEN#STAT_LADEDRUCK_SOLL_WERT" result="STAT_LADEDRUCK_SOLL_WERT" format="4.1R" grid-type="simple-gauge-round" min-value="0" max-value="2500" log_tag="STAT_LADEDRUCK_SOLL_WERT" />
	
	<display name="!JOB#STATUS_MESSWERTBLOCK_LESEN#STAT_LUFTMASSE_PRO_HUB_WERT" result="STAT_LUFTMASSE_PRO_HUB_WERT" format="L" grid-type="simple-gauge-round" min-value="0" max-value="1500" log_tag="STAT_LUFTMASSE_PRO_HUB_WERT" />
    <display name="!JOB#STATUS_MESSWERTBLOCK_LESEN#STAT_UMGEBUNGSDRUCK_WERT" result="STAT_UMGEBUNGSDRUCK_WERT" format="4.1R" grid-type="simple-gauge-round" min-value="800" max-value="1300" log_tag="STAT_UMGEBUNGSDRUCK_WERT" />    
    <display name="!JOB#STATUS_MESSWERTBLOCK_LESEN#STAT_RAILDRUCK_WERT" result="STAT_RAILDRUCK_WERT" format="L" grid-type="simple-gauge-round" min-value="0" max-value="1400" log_tag="STAT_RAILDRUCK_WERT" />
    <display name="!JOB#STATUS_MESSWERTBLOCK_LESEN#STAT_GESCHWINDIGKEIT_WERT" result="STAT_GESCHWINDIGKEIT_WERT" format="L" grid-type="simple-gauge-round" min-value="0" max-value="250" log_tag="STAT_GESCHWINDIGKEIT_WERT" />
    <display name="!JOB#STATUS_MESSWERTBLOCK_LESEN#STAT_FAHRZEUGBESCHLEUNIGUNG_WERT" result="STAT_FAHRZEUGBESCHLEUNIGUNG_WERT" format="2.3R" grid-type="simple-gauge-round" min-value="-15" max-value="15" log_tag="STAT_FAHRZEUGBESCHLEUNIGUNG_WERT" />
	
    
	<display name="!JOB#STATUS_MESSWERTBLOCK_LESEN#STAT_KUPPLUNGSSCHALTER_ROH_WERT" result="STAT_KUPPLUNGSSCHALTER_ROH_WERT" format="L" grid-type="simple-gauge-round" min-value="0" max-value="1" log_tag="STAT_KUPPLUNGSSCHALTER_ROH_WERT" />
	<display name="!JOB#STATUS_MESSWERTBLOCK_LESEN#STAT_KLIMAKOMPRESSOR_STATUS_WERT" result="STAT_KLIMAKOMPRESSOR_STATUS_WERT" format="L" grid-type="simple-gauge-round" min-value="0" max-value="1" log_tag="STAT_KLIMAKOMPRESSOR_STATUS_WERT" />
	<display name="!JOB#STATUS_MESSWERTBLOCK_LESEN#STAT_BEREITSCHAFT_KLIMA_WERT" result="STAT_BEREITSCHAFT_KLIMA_WERT" format="L" grid-type="simple-gauge-round" min-value="0" max-value="1" log_tag="STAT_BEREITSCHAFT_KLIMA_WERT" />
	
    <display name="!JOB#STATUS_TOENS_IO#STAT_TOG_HIGH_WERT" result="STAT_TOG_HIGH_WERT" format="L" grid-type="simple-gauge-round" min-value="0" max-value="1000" log_tag="STAT_TOG_HIGH_WERT" />
    <display name="!JOB#STATUS_TOENS_IO#STAT_TOG_LOW_WERT" result="STAT_TOG_LOW_WERT" format="L" grid-type="simple-gauge-round" min-value="0" max-value="1000" log_tag="STAT_TOG_LOW_WERT" />
	
	<jobs sgbd="D50M57E1" />
    <code show_warnings="true">
    <![CDATA[
    class PageClass
    {	
		// PWM-Wert Ansteuerung Zuheizer, ab dem dieser als AN erkannt wird
		private double conf_ZuheizerAnAb = 25;
		
		// PWM-Wert Generatorlast, ab dem eine LL-Anhebung erfolgt
		private double conf_GeneratorlastHochAb = 60;
		private double conf_GeneratorlastSehrHochAb = 80;
		
		// Motortemperaturen
		private double conf_Temp_MotorSehrKaltBis = 25;
		private double conf_Temp_MotorKaltBis = 65;
		private double conf_Temp_MotorBetriebstempAb = 75;
		private double conf_Temp_MotorBetriebstempBis = 95;
		private double conf_Temp_MotorHeissAb = 100;
		
		// Ziel-Leerlaufanhebungswerte - es "gewinnt" immer der höchste Wert für die aktuellen Betriebsbedingungen
		private int conf_LLA_Basis = 0;                // wenn die Kupplung nicht betätigt und auch sonst keine höhere Anhebung aktiv ist
		private int conf_LLA_Kupplung = 150;
		private int conf_LLA_Zuheizer = 200;
		private int conf_LLA_MotorSehrKalt = 150;
		private int conf_LLA_MotorKalt = 100;
		private int conf_LLA_MotorVorBetriebstemp = 70;
		private int conf_LLA_MotorBetriebstemp = 50;
		private int conf_LLA_MotorHeiss = 200;
		private int conf_LLA_KlimaBereitschaft = 90;
		private int conf_LLA_Klimakompressor = 120;
		private int conf_LLA_GeneratorlastHoch = 90;
		private int conf_LLA_GeneratorlastSehrHoch = 120;
		
		// Konfiguration für Zähler (Anzahl Durchläufe bis eine Aktion eintritt)
		private int conf_countdown_ZuheizerAn_max = 5;
		private int conf_countdown_Kupplung_max = 5;
		private int conf_countdown_Generatorlast_max = 5;
		private int conf_countdown_LLA_aus = 15;
		private int conf_countdown_Job2_max = 10;
		
		// Statusvariablen
		private bool status_MotorHeiss = false;
		private bool status_Kupplung = false;
		private bool status_Zuheizer = false;
		//private bool status_Klima = false;
		private bool status_GeneratorlastHoch = false;
		private bool status_GeneratorlastSehrHoch = false;
		
		// Zähler
		private int countdown_ZuheizerAn = 0;
		private int countdown_Kupplung = 0;
		private int countdown_Generatorlast = 0;
		private int countdown_LLA_aus = 0;
		private int countdown_Job2 = 0;
		
		// Globale Variablen für Leerlaufanhebung
		private int LLA_momentan = 0;
		
						
		List<Dictionary<string, EdiabasNet.ResultData>> resultSets_Abgleich;
			
		public void ExecuteJob(EdiabasNet ediabas, ref MultiMap<string, EdiabasNet.ResultData> resultDict, bool firstCall)
        {
            List<Dictionary<string, EdiabasNet.ResultData>> resultSets;
            
            
			// Job 1 - ständig zu aktualisierende Werte
            ediabas.ArgString = "JA;ILMMG;IPLAD;IPUMG;IUBAT;IMOAK;INMOT;SPLAD;ITKUM;ITLAL;IPRDR;IAFZG;IVKMH;ITZUH;IGENL;RSKUP;IKLIS;IBKLI";
            ediabas.ArgBinaryStd = null;
            ediabas.ResultsRequests = string.Empty;
            ediabas.ExecuteJob("STATUS_MESSWERTBLOCK_LESEN");
            resultSets = ediabas.ResultSets;
            if (resultSets != null && resultSets.Count >= 2)
            {
                EdiabasThread.MergeResultDictionarys(ref resultDict, resultSets[1]);
            }
			
			
						
			// Job 2 - wird nur bei jedem X-ten Durchlauf ausgeführt (definiert von [conf_countdown_Job2_max])
			if(countdown_Job2 == 0) {
				ediabas.ArgString = "lla";
				ediabas.ArgBinaryStd = null;
				ediabas.ResultsRequests = string.Empty;
				ediabas.ExecuteJob("ABGLEICH_LESEN");
				resultSets_Abgleich = ediabas.ResultSets;
			}
			else if(countdown_Job2 >= conf_countdown_Job2_max) {
				countdown_Job2 = 0;
			}
			else {
				countdown_Job2++;
			}
			
			// da diese Werte nicht in jedem Durchlauf vom Steuergerät gelesen werden sind die Ergebnisdaten in einer 
			// globalen Variablen gespeichert und werden jedesmal übernommen, auch wenn nicht ganz aktuell
			if (resultSets_Abgleich != null && resultSets_Abgleich.Count >= 2)
			{
				EdiabasThread.MergeResultDictionarys(ref resultDict, resultSets_Abgleich[1], "LLA_");
			}
			
			
			
			// Werte für automatische Leerlaufanhebung holen
			
			EdiabasNet.ResultData resultData;
			
			// Kupplungsschalter 
			bool mom_Kupplung = false;
            if (resultSets[1].TryGetValue("STAT_KUPPLUNGSSCHALTER_ROH_WERT", out resultData))
                {
					if (resultData.OpData is Double) {
						if(((Double)resultData.OpData) > 0.0) mom_Kupplung = true;
					}
                }
				
			// Klimakompressor 
			bool mom_Klimakompressor = false;
            if (resultSets[1].TryGetValue("STAT_KLIMAKOMPRESSOR_STATUS_WERT", out resultData))
                {
					if (resultData.OpData is Double) {
						if(((Double)resultData.OpData) > 0.0) mom_Klimakompressor = true;
					}
                }
			
			// Klima-Bereitschaft 
			bool mom_KlimaBereitschaft = false;
            if (resultSets[1].TryGetValue("STAT_BEREITSCHAFT_KLIMA_WERT", out resultData))
                {
					if (resultData.OpData is Double) {
						if(((Double)resultData.OpData) > 0.0) mom_KlimaBereitschaft = true;
					}
                }

			
			// Zuheizer-Ansteuerung
			Double mom_Zuheizer_PWM = 0;
            if (resultSets[1].TryGetValue("STAT_ZUHEIZER_ANSTEUERUNG_WERT", out resultData))
                {
                    if (resultData.OpData is Double)
                    {
                        mom_Zuheizer_PWM = ((Double)resultData.OpData);
                    }
                }
				
			// Generatorlast
			Double mom_Generatorlast_PWM = 0;
            if (resultSets[1].TryGetValue("STAT_GENERATORLAST_WERT", out resultData))
                {
                    if (resultData.OpData is Double)
                    {
                        mom_Generatorlast_PWM = ((Double)resultData.OpData);
                    }
                }
			
			// Motortemperatur
			Double mom_MotorTemp = 0;
			if (resultSets[1].TryGetValue("STAT_KUEHLMITTELTEMPERATUR_WERT", out resultData))
                {
                    if (resultData.OpData is Double)
                    {
                        mom_MotorTemp = ((Double)resultData.OpData);
                    }
                }
			 
			// Abgleichwert Leerlaufanhebung
			if (resultSets_Abgleich[1].TryGetValue("LLA_ABGLEICH_LESEN_WERT", out resultData))
                {
                    if (resultData.OpData is Double)
                    {
                        LLA_momentan = (int)((Double)resultData.OpData);
                    }
			}
			
			
			// Automatische Leerlaufanhebung
			
			int LLA_neu = 0;
			
			// Kupplungsschalter
			// der countdown dient dazu dass die Leerlaufanhebung erst zurückgenommen wird, 
			// wenn die Kupplung schon eine Zeit lang nicht betätigt ist
			
			if (mom_Kupplung || status_Kupplung) {
				if(mom_Kupplung) countdown_Kupplung = conf_countdown_Kupplung_max;
				if(!status_Kupplung) status_Kupplung = true;
				if(conf_LLA_Kupplung > LLA_neu) LLA_neu = conf_LLA_Kupplung;
			}
			
			if (countdown_Kupplung > 0){
				countdown_Kupplung--;
			}
			else if (countdown_Kupplung == 0){
				status_Kupplung = false;
				if(conf_LLA_Basis > LLA_neu) LLA_neu = conf_LLA_Basis;
			}
			
			
			
			// Zuheizer
			// der countdown dient dazu dass die Leerlaufanhebung erst zurückgenommen wird, 
			// wenn der Zuheizer schon eine Zeit lang inaktiv ist (also z.B. nicht nur kurz wegen zu hoher Generatorlast abgeschaltet wurde)
			
			if (mom_Zuheizer_PWM > conf_ZuheizerAnAb || status_Zuheizer) {
				if(mom_Zuheizer_PWM > conf_ZuheizerAnAb) countdown_ZuheizerAn = conf_countdown_ZuheizerAn_max;
				if(!status_Zuheizer) status_Zuheizer = true;
				if(conf_LLA_Zuheizer > LLA_neu) LLA_neu = conf_LLA_Zuheizer;
			}
			
			if (countdown_ZuheizerAn > 0) {
				countdown_ZuheizerAn--;
			}
			else if (countdown_ZuheizerAn == 0) {
				status_Zuheizer = false;
				if(conf_LLA_Basis > LLA_neu) LLA_neu = conf_LLA_Basis;
			}
			
			
			
			// Generatorlast 
			
			if (mom_Generatorlast_PWM > conf_GeneratorlastSehrHochAb || status_GeneratorlastSehrHoch) {
				if(mom_Generatorlast_PWM > conf_GeneratorlastSehrHochAb) countdown_Generatorlast = conf_countdown_Generatorlast_max;
				if(!status_GeneratorlastSehrHoch) status_GeneratorlastSehrHoch = true;
				if(conf_LLA_GeneratorlastSehrHoch > LLA_neu) LLA_neu = conf_LLA_GeneratorlastSehrHoch;
			}
			else if (mom_Generatorlast_PWM > conf_GeneratorlastHochAb || status_GeneratorlastHoch) {
				if(mom_Generatorlast_PWM > conf_GeneratorlastHochAb) countdown_Generatorlast = conf_countdown_Generatorlast_max;
				if(!status_GeneratorlastHoch) status_GeneratorlastHoch = true;
				if(conf_LLA_GeneratorlastHoch > LLA_neu) LLA_neu = conf_LLA_GeneratorlastHoch;
			}
			
			if (countdown_Generatorlast > 0) {
				countdown_Generatorlast--;
			}
			else if (countdown_Generatorlast == 0) {
				status_GeneratorlastHoch = false;
				status_GeneratorlastSehrHoch = false;
				if(conf_LLA_Basis > LLA_neu) LLA_neu = conf_LLA_Basis;
			}
			
			
			
			// Klimakompressor und Klimabereitschaft
			if (mom_Klimakompressor) {
				if(conf_LLA_Klimakompressor > LLA_neu) LLA_neu = conf_LLA_Klimakompressor;
			}
			else if (mom_KlimaBereitschaft) {
				if(conf_LLA_KlimaBereitschaft > LLA_neu) LLA_neu = conf_LLA_KlimaBereitschaft;
			}
			
			
			
			// Drehzahlanhebung je nach Motortemperatur, 
			if(mom_MotorTemp < conf_Temp_MotorSehrKaltBis) {
				// Motor ist sehr kalt
				if(conf_LLA_MotorSehrKalt > LLA_neu) LLA_neu = conf_LLA_MotorSehrKalt;
			}
			else if(mom_MotorTemp < conf_Temp_MotorKaltBis) {
				// Motor ist kalt
				if(conf_LLA_MotorKalt > LLA_neu) LLA_neu = conf_LLA_MotorKalt;
			}
			else if(mom_MotorTemp >= conf_Temp_MotorKaltBis && mom_MotorTemp < conf_Temp_MotorBetriebstempAb) {
				// Motor ist nicht mehr kalt, aber noch nicht auf Betriebstemperatur
				if(conf_LLA_MotorVorBetriebstemp > LLA_neu) LLA_neu = conf_LLA_MotorVorBetriebstemp;
			}
			else if(mom_MotorTemp >= conf_Temp_MotorBetriebstempAb && mom_MotorTemp < conf_Temp_MotorHeissAb && !status_MotorHeiss) {
				// Motor ist auf Betriebstemperatur
				if(conf_LLA_MotorBetriebstemp > LLA_neu) LLA_neu = conf_LLA_MotorBetriebstemp;
			}
			else if(mom_MotorTemp >= conf_Temp_MotorBetriebstempAb && mom_MotorTemp < conf_Temp_MotorBetriebstempBis && status_MotorHeiss) {
				// Temperatur ist nachdem Status HEISS wieder weit genug gefallen -> Betriebstemperatur
				status_MotorHeiss = false;
				if(conf_LLA_MotorBetriebstemp > LLA_neu) LLA_neu = conf_LLA_MotorBetriebstemp;
			}
			else if(mom_MotorTemp >= conf_Temp_MotorHeissAb) {
				// Motor ist HEISS -> weitere LL Anhebung um die Kühlung zu verbessern aktivieren 
				// deaktivierung sobald die Temperatur wieder unter [conf_Temp_MotorBetriebstempBis] gefallen ist
				status_MotorHeiss = true;
				if(conf_LLA_MotorHeiss > LLA_neu) LLA_neu = conf_LLA_MotorHeiss;
			}
			
			
			// Motor auf Betriebstemperatur - reduziere LL auf minimum nach einiger Zeit
			if(LLA_neu == conf_LLA_MotorBetriebstemp) {
				if(countdown_LLA_aus == 0) {
					LLA_neu = conf_LLA_Basis;
				}
				else if(countdown_LLA_aus > 0) {
					countdown_LLA_aus--;
				}
			}
			else {
				countdown_LLA_aus = conf_countdown_LLA_aus;
			}
			
			
			
			// wenn der Ziel-LLA-Wert sich vom aktuell eingestellten unterscheidet -> Abgleich verstellen
			if (LLA_momentan != LLA_neu) {
				ediabas.ArgString = "lla;" + LLA_neu;
                ediabas.ArgBinaryStd = null;
                ediabas.ResultsRequests = "JOB_STATUS";
                ediabas.ExecuteJob("ABGLEICH_VERSTELLEN");
                
                //resultSets = ediabas.ResultSets;
                //if (resultSets != null && resultSets.Count >= 2)
                //{
                //  EdiabasThread.MergeResultDictionarys(ref resultDict, resultSets[1]);
                //}
                
                // Ablaufvariable wieder zurücksetzen, sonst würde diese funktion nun bei jedem folgenden durchlauf ausgeführt werden...
                LLA_momentan = LLA_neu;
				conf_countdown_Job2_max = 0;
			}
			
        }
		
		
        public string FormatResult(JobReader.PageInfo pageInfo, MultiMap<string, EdiabasNet.ResultData> resultDict, string resultName, ref Android.Graphics.Color? textColor)
        {
            string result = string.Empty;
            double value;
            bool found;
		
            switch (resultName)
            {
                case "STAT_MOTORDREHZAHL_WERT":
                    value = ActivityMain.GetResultDouble(resultDict, resultName, 0, out found);
                    
                    // result format: {0,[DIGITS TOTAL INCL COMMA],[0|0.0|0.00|0.000...]}
                    result = string.Format(ActivityMain.Culture, "{0,4:0}", value);
                    
					// Liste der möglichen Farbnamen: https://docs.microsoft.com/en-us/dotnet/api/android.graphics.color?view=xamarin-android-sdk-9
                    if (found && value <= 4000) textColor = Android.Graphics.Color.White;
                    else if (found && value <= 4250) textColor = Android.Graphics.Color.Yellow;
                    else if (found && value <= 4500) textColor = Android.Graphics.Color.Orange;
                    else if (found && value > 4500) textColor = Android.Graphics.Color.Red;
                    else textColor = Android.Graphics.Color.Gray;
                    
                    break;
                    
                case "STAT_UBATT_WERT":
                    value = ActivityMain.GetResultDouble(resultDict, resultName, 0, out found);
                    
                    // result format: {0,[DIGITS TOTAL INCL COMMA],[0|0.0|0.00|0.000...]}
                    result = string.Format(ActivityMain.Culture, "{0,4:0.0}", value);
                    
                    if (found && value < 10.5) textColor = Android.Graphics.Color.Red;
                    else if (found && value < 11.5) textColor = Android.Graphics.Color.Orange;
                    else if (found && value <= 12.5) textColor = Android.Graphics.Color.Yellow;
                    else if (found && value <= 13.2) textColor = Android.Graphics.Color.Gray;
                    else if (found && value <= 14.5) textColor = Android.Graphics.Color.White;
                    else if (found && value > 14.5) textColor = Android.Graphics.Color.Red;
                    else textColor = Android.Graphics.Color.Gray;
                    
                    break;
				
				case "STAT_GENERATORLAST_WERT":
                    value = ActivityMain.GetResultDouble(resultDict, resultName, 0, out found);
                    
                    // result format: {0,[DIGITS TOTAL INCL COMMA],[0|0.0|0.00|0.000...]}
                    result = string.Format(ActivityMain.Culture, "{0,3:0}", value);
                    
                    if (found && value <= 60) textColor = Android.Graphics.Color.White;
                    else if (found && value <= 70) textColor = Android.Graphics.Color.Yellow;
                    else if (found && value <= 80) textColor = Android.Graphics.Color.Orange;
                    else if (found && value > 80) textColor = Android.Graphics.Color.Red;
                    else textColor = Android.Graphics.Color.Gray;
                    
                    break;
					
				case "STAT_ZUHEIZER_ANSTEUERUNG_WERT":
                    value = ActivityMain.GetResultDouble(resultDict, resultName, 0, out found);
                    
                    // result format: {0,[DIGITS TOTAL INCL COMMA],[0|0.0|0.00|0.000...]}
                    result = string.Format(ActivityMain.Culture, "{0,3:0}", value);
                    
                    if (found && value <= 60) textColor = Android.Graphics.Color.White;
                    else if (found && value <= 70) textColor = Android.Graphics.Color.Yellow;
                    else if (found && value <= 80) textColor = Android.Graphics.Color.Orange;
                    else if (found && value > 80) textColor = Android.Graphics.Color.Red;
                    else textColor = Android.Graphics.Color.Gray;
                    
                    break;
					
		
                case "STAT_KUEHLMITTELTEMPERATUR_WERT":
                    value = ActivityMain.GetResultDouble(resultDict, resultName, 0, out found);
                    result = string.Format(ActivityMain.Culture, "{0,3:0}", value);
                    
                    if (found && value < 75) textColor = Android.Graphics.Color.Blue;
                    else if (found && value <= 105) textColor = Android.Graphics.Color.White;
                    else if (found && value <= 110) textColor = Android.Graphics.Color.Yellow;
                    else if (found && value <= 115) textColor = Android.Graphics.Color.Orange;
                    else if (found && value > 115) textColor = Android.Graphics.Color.Red;
                    else textColor = Android.Graphics.Color.Gray;
                    
                    break;
					
				case "STAT_LADELUFTTEMPERATUR_WERT":
                    value = ActivityMain.GetResultDouble(resultDict, resultName, 0, out found);
                    result = string.Format(ActivityMain.Culture, "{0,3:0}", value);
                    
                    if (found && value <= 55) textColor = Android.Graphics.Color.White;
                    else if (found && value <= 65) textColor = Android.Graphics.Color.Yellow;
                    else if (found && value <= 75) textColor = Android.Graphics.Color.Orange;
                    else if (found && value > 85) textColor = Android.Graphics.Color.Red;
                    else textColor = Android.Graphics.Color.Gray;
                    
                    break;
            }
            return result;
        }
    }
      ]]>
    </code>
	
  </page>
</fragment>