<Gauge Name="FLight Data Recorder" Version="2.0">
<Size X="150" Y="75" />

	<!-- FILE PATH - WHATEVER FOLDER YOU WANT THE FILE WRITTEN INTO -->
	<Macro Name="Path">'C:\Users\Username\Desktop\Flight Data Recorder\'</Macro>

	<Update Frequency="18" Hidden="No">	
	<!-- INITIALIZE -->
		(L:InitSequence,bool) 0 ==
			if{
				3 (>L:SecondsToSkip, enum)	
				1 (>L:InitSequence,bool)
			}

		18 (L:SecondsToSkip, enum) * (>L:RecorderSkipCycles, enum)	<!-- Number of Update Cycles to skip between recording data -->
						
	<!-- WRITE FLIGHT PLAN WAYPOINT LAT, LON AND IDENT-->  
		(L:RecorderEnabled, bool)
			if{ 
				(L:WriteWaypoints, bool) 1 ==
					if{ 
						(C:fs9gps:FlightPlanTitle) (>C:LOGGER:string) 1 (>C:LOGGER:newline) 
						(C:fs9gps:FlightPlanWaypointsNumber) (>C:LOGGER:number) 
						'WAYPOINTS' (>C:LOGGER:string) 1 (>C:LOGGER:newline)
						'LAT' (>C:LOGGER:string) 
						'LON' (>C:LOGGER:string) 
						'DIST NM' (>C:LOGGER:string) 
						'DIST REM' (>C:LOGGER:string) 			
						'HDG MAG' (>C:LOGGER:string) 					
						'WPT IDENT' (>C:LOGGER:string) 
						'WPT TYPE'  (>C:LOGGER:string) 1 (>C:LOGGER:newline)	  			
						:101
							(L:WaypointsWritten,enum) (>C:fs9gps:FlightPlanWaypointIndex)
							(C:fs9gps:FlightPlanWaypointLatitude, degrees) (>C:LOGGER:number) 
							(C:fs9gps:FlightPlanWaypointLongitude, degrees) (>C:LOGGER:number) 				
							(C:fs9gps:FlightPlanWaypointDistance, nmiles) (>C:LOGGER:number)  
							(C:fs9gps:FlightPlanWaypointDistanceRemaining, nmiles) (>C:LOGGER:number)  
							(C:fs9gps:FlightPlanWaypointMagneticHeading, degrees) (>C:LOGGER:number) 
							(C:fs9gps:FlightPlanWaypointIdent) (>C:LOGGER:string)					
							'USER' 'NDB' 'VOR' 'INTERSECTION' 'AIRPORT' 'UNKN' 6 (C:fs9gps:FlightPlanWaypointType) case (>C:LOGGER:string)	1 (>C:LOGGER:newline) 			
							(L:WaypointsWritten,enum) 1 + (>L:WaypointsWritten,enum) 						
							(L:WaypointsWritten,enum) (C:fs9gps:FlightPlanWaypointsNumber) &lt; if{ g101 }
							9999 (>C:LOGGER:number) 1 (>C:LOGGER:newline) 
						'LAT' (>C:LOGGER:string) 
						'LON' (>C:LOGGER:string) 
						'ALT' (>C:LOGGER:string) 
						'VSI' (>C:LOGGER:string) 
						'ASPD' (>C:LOGGER:string) 
						'HDG MAG' (>C:LOGGER:string)
						'ABS TIME' (>C:LOGGER:string) 1 (>C:LOGGER:newline) 				
						0 (>L:WriteWaypoints, bool)
					}
		<!-- FLIGHT DATA RECORDER: LAT LON ALT VSI ASPD HDG ABS_TIME-->  
				(L:WriteWaypoints, bool) 0 == (L:SecondsSkipNumberEntryEnabled, bool) 0 == and 
					if{ 
						(L:NumberOfCyclesSkipped, enum) ++ (>L:NumberOfCyclesSkipped, enum)
						(L:NumberOfCyclesSkipped, enum) (L:RecorderSkipCycles, enum) >= 
							if{
								(A:PLANE LATITUDE, degrees) (>C:LOGGER:number)
								(A:PLANE LONGITUDE, degrees) (>C:LOGGER:number)
								(A:PLANE ALTITUDE, feet) (>C:LOGGER:number)
								(A:VERTICAL SPEED, feet per minute) (>C:LOGGER:number)
								(A:AIRSPEED INDICATED, knots) (>C:LOGGER:number)
								(A:PLANE HEADING DEGREES MAGNETIC, degrees) (>C:LOGGER:number)
								(P:ABSOLUTE TIME, seconds) (>C:LOGGER:number)
								(L:RecordsWritten, enum) 1 + (>L:RecordsWritten, enum)
								1 (>C:LOGGER:newline)
								0 (>L:NumberOfCyclesSkipped, enum)
							}
					}
			}
	</Update>

	<Element Name="B A C K G R O U N D   R E C T A N G L E">		
		<Position X="0" Y="0"/>
		<Rectangle Width="150" Height="75" Color="#100001" LineWidth="1" FillColor="gainsboro" Bright="Yes" />		
	</Element>
	<Element Name="FLIGHT DATA RECORDER">
		<Position X="5" Y="5"/>
			<FormattedText X="120" Y="12" Font="courier new" FontSize="10" LineSpacing="12" Color="#100001" BackgroundColor="gainsboro" Bright="Yes">
				<String>FLIGHT DATA RECORDER</String>
			</FormattedText>
	</Element>		
	<Element Name="RECORDER OFF">		
		<Position X="5" Y="50"/>
		<Rectangle Width="20" Height="20" FillColor="gray" Bright="Yes" />		
	</Element>
	<Element Name="RECORDER ON">	
		<Visible>(L:RecorderEnabled, bool) 1 ==</Visible>
		<Position X="5" Y="50"/>
		<Rectangle Width="20" Height="20" FillColor="lime" Bright="Yes" />		
	</Element>
	<Element Name="RECORDER INCREMENT">		
		<Position X="35" Y="50"/>
		<Rectangle Width="30" Height="20" FillColor="white" Bright="Yes" />		
	</Element>	
	<Element Name="RECORDER INCREMENT NUMBER ENTRY">	
		<Visible>(L:SecondsSkipNumberEntryEnabled, bool)</Visible>
		<Position X="35" Y="50"/>
		<Rectangle Width="30" Height="20" Color="red" LineWidth="2" Bright="Yes" />		
	</Element>		
	<Element Name="RECORDS">		
		<Position X="5" Y="25"/>
			<FormattedText X="100" Y="12" Font="courier new" FontSize="10" LineSpacing="12" Color="#100001" BackgroundColor="gainsboro" Bright="Yes">
				<String>RECORDS: %((L:RecordsWritten, enum))%!6d!</String>	
			</FormattedText>				
	</Element>	
	<Element Name="RECORD INCR">		
		<Position X="70" Y="48"/>
			<FormattedText X="60" Y="12" Font="courier new" FontSize="10" LineSpacing="12" Color="#100001" BackgroundColor="gainsboro" Bright="Yes">
				<String>RECORDER</String>	
			</FormattedText>				
	</Element>	
	<Element Name="SECONDS">		
		<Position X="70" Y="60"/>
			<FormattedText X="60" Y="12" Font="courier new" FontSize="10" LineSpacing="12" Color="#100001" BackgroundColor="gainsboro" Bright="Yes">
				<String>INCR (SEC)</String>	
			</FormattedText>				
	</Element>
	<Element Name="SECONDS TO SKIP">		
		<Position X="40" Y="54"/>
			<FormattedText X="20" Y="12" Font="courier new" FontSize="10" LineSpacing="12" Color="#100001" BackgroundColor="white" Bright="Yes">
				<String>%((L:SecondsToSkip, enum))%!-3d!</String>	
			</FormattedText>				
	</Element>	
		
	<Mouse>
	<!-- RECORDER ON-OFF BUTTON --> 
		<Area Left="5" Top="50" Width="20" Height="20">
		<Cursor Type="Hand" /> 
			<Visible>(L:SecondsSkipNumberEntryEnabled, bool) 0 ==</Visible>		
			<Click> 
				(L:RecorderEnabled, bool) ! (>L:RecorderEnabled, bool)			
				(L:RecorderEnabled, bool) 0 == 
					if{ 
						0 (>L:WriteWaypoints, bool)
						(L:RecordsWritten, enum) (>C:LOGGER:number)
						1 (>C:LOGGER:closeWrite) 
					}
				(L:RecorderEnabled, bool) 1 == 
					if{ 			
						@Path 
							'IFR' 'VFR' 'NONE' 3 (C:fs9gps:FlightPlanFlightPlanType) case ' '
							(C:fs9gps:FlightPlanDepartureAirportIdent) ' to ' 
							(C:fs9gps:FlightPlanDestinationAirportIdent) '_' 
							(C:fs9gps:FlightPlanWaypointsNumber) 'csv' scat scat scat scat scat scat scat scat (>C:LOGGER:openCsvWrite) <!-- Alternatively this can be a .txt file type. See LOGGER docs -->
						0 (>L:NumberOfCyclesSkipped, enum)
						1 (>L:WriteWaypoints, bool)
						0 (>L:WaypointsWritten,enum)
						0 (>L:RecordsWritten, enum)						
					}
			</Click>
		</Area>			
	<!-- RECORDER INCREMENT ENTRY --> 
		<Area Left="35" Top="50" Width="30" Height="20">
		<Cursor Type="Hand" /> 
			<Click> 		
				(L:SecondsSkipNumberEntryEnabled, bool) ! (>L:SecondsSkipNumberEntryEnabled, bool)
				(L:SecondsSkipNumberEntryEnabled, bool)
					if{
				       0 (>L:SecondsSkipNum1,enum)
				       0 (>L:SecondsSkipNum2,enum)
				       0 (>L:SecondsSkipNum3,enum)
						0  (>L:SecondsToSkip, enum)
					}
			</Click>
		</Area>			
	</Mouse>
	<Keys>
		<On Key="Ascii"> <!-- SECONDS SKIP KEYBOARD ENTRY -->
			<Visible>(L:SecondsSkipNumberEntryEnabled, bool) 1 ==</Visible>						
				(L:SecondsSkipNum2,enum) (>L:SecondsSkipNum3,enum)
				(L:SecondsSkipNum1,enum) (>L:SecondsSkipNum2,enum)
				(M:Key) (>L:SecondsSkipNum1,enum)
				(L:SecondsSkipNum3,enum) chr 100 *
				(L:SecondsSkipNum2,enum) chr 10 *
				(L:SecondsSkipNum1,enum) chr 1 * + +
				(>L:SecondsToSkip, enum)
		</On>			
	</Keys>	
</Gauge>

