TODO build this with similar hash if logic: need to reconsider how to use this or whether to even have it. A "corresponding event" table might be good instead, kinda like the mapping above, but from real to real, only when the angles are exactly 360 out.

TODO Take the configuration from the decoder (as is) and mask it such that it does not affect the 6 other channels. Take the the number of output channels required from configuration and configure that many as outputs Configure the balance in whatever way is specified in the GPIO configuration - allow second input to be reused as GPI only.

TODO sync loss/gain semantics - how paranoid? under what circumstances? should we make it configurable whether a decoder that is in a situation where it would find sync if not synced, resets sync, or loses sync. Likewise, at initial sync gain time, should it go "prelim sync found" and only verify sync on the second lap around, or start firing events straight off the bat. Starting will suck if paranoid, but if there is noise at high load/rpm and events get mis-scheduled before sync is lost, that is serious. This is philosophical, and the reality is that you must assume that your signal is clean to some level and verified clean under lower risk conditions.

TODO Add verification reporting code here that disables the timer interrupts such that no events ever get scheduled, and then sits looping sending error packets out about what is wrong. set a whole bunch of flags and check them here sending a packet for each with a unique errorID for each and thus a unique easy to understand message for each on the PC side. BEFORE the priming code such that no fuel gets injected. Will need to modularise the comms stuff to process packets based on calls from this section too, avoid excess duplication if possible.

TODO two unsigned chars, and two unsigned shorts, which is the MAP ADC value, the MAP value is sampled on every event in a cycle, and if less than the previous stored value, which is reset at every zeroth event, with the old value and old event number stored globally.

TODO the same thing could be done, but with a median filter or similar, perhaps map sampling could be done dymanically like this, though it could yield unpredictable results, it could also yield the best running engines, just a thought...

TODO Schedule injection with real timing, requires some tweaks to work right.

TODO move this loop variable to fixedConfig and make a subset of the remainder of channels configured for fuel with a start time/tooth directly set for now, ie, make the 6 channels usable as fuel or ignition from reasonable configuration and write a guide on how to set it up for any engine.

TODO move sched code to a function or functions (inline?) that can be unit tested such that we KNOW it performs as anticipated rather than just trying it out on a 400hp turbo truck engine.

TODO keep an eye on overflow here when increasing resolution by scaling angles

TODO, do this ^ at init time from fixed config as an array of angles and a single engine offset combined into this runtime array.

TODO rather than look for the nearest tooth and then step through till you find the right one that can work, instead figure out the dwell in angle and subtract that too, and find the correct tooth first time, will save cpu cycles, and get same answer and be less complex...

TODO Schedule injection with real timing, requires some tweaks to work right.

TODO move this loop variable to fixedConfig and make a subset of the remainder of channels configured for fuel with a start time/tooth directly set for now, ie, make the 6 channels usable as fuel or ignition from reasonable configuration and write a guide on how to set it up for any engine.

TODO move sched code to a function or functions (inline?) that can be unit tested such that we KNOW it performs as anticipated rather than just trying it out on a 400hp turbo truck engine.

TODO keep an eye on overflow here when increasing resolution by scaling angles

TODO, do this ^ at init time from fixed config as an array of angles and a single engine offset combined into this runtime array.

TODO rather than look for the nearest tooth and then step through till you find the right one that can work, instead figure out the dwell in angle and subtract that too, and find the correct tooth first time, will save cpu cycles, and get same answer and be less complex...