#!/usr/bin/perl -w

# check 
# http://www.vems-group.org/index.php?page=GenBoard%2FManual%2FConfig%2FInjectorOpening
# this is somewhere between 1 and 2:
my $rampup_func_power = 1.5;
# after integrating:
my $integrated_func_power = $rampup_func_power + 1;
# inverse function (sqrt()):
my $exponent = 1 / $integrated_func_power;

my $xmax = 63;
my $ymax = 255.49;

print ' /* Automatically generated by ' . $0
	. " */\n#include <inttypes.h>\n#include <avr/pgmspace.h>\n"
	. "\nuint8_t PROGMEM INJOPENTABLE[] = \{\n";

my $scale =  $ymax / (1 - $exponent);
my $x;
for($x = 0; $x <= $xmax; $x++){
	my $xs = $x / $xmax;	# scaled to 0..1
	
	my $req_fuel_part_of_pw_that_is_already_added = $xs / $integrated_func_power;
	print '' . ($x>0 ? ",\n" : "\n")
		.int( 0.5 + $scale * ( $xs ** $exponent - $req_fuel_part_of_pw_that_is_already_added));

# the 
}

print "\n\};\n\n";

