Speeduino
Loading...
Searching...
No Matches
decoder_t.h
Go to the documentation of this file.
1#pragma once
2
3#include <stdint.h>
4#include <Arduino.h>
5
7static constexpr uint8_t TRIGGER_EDGE_NONE = 99;
8// Just in case
9static_assert(TRIGGER_EDGE_NONE != LOW, "LOW edge value conflict");
10static_assert(TRIGGER_EDGE_NONE != HIGH, "HIGH edge value conflict");
11static_assert(TRIGGER_EDGE_NONE != RISING, "RISING edge value conflict");
12static_assert(TRIGGER_EDGE_NONE != FALLING, "FALLING edge value conflict");
13static_assert(TRIGGER_EDGE_NONE != CHANGE, "CHANGE edge value conflict");
14
17{
18 using callback_t = void(*)(void);
19
24
26 void attach(uint8_t pin) const
27 {
28 detach(pin);
29 if (isValid())
30 {
32 }
33 }
34
40
41 bool isValid(void) const
42 {
43 return edge!=TRIGGER_EDGE_NONE && callback!=nullptr;
44 }
45};
46
47
51enum class SyncStatus : uint8_t {
53 None,
57 Partial,
59 Full,
60};
61
68
69
83
uint32_t digitalPinToInterrupt(uint32_t Interrupt_pin)
Definition board_stm32_official.h:103
SyncStatus
The decoder trigger status.
Definition decoder_t.h:51
static constexpr uint8_t TRIGGER_EDGE_NONE
This constant represents no trigger edge.
Definition decoder_t.h:7
static TIntegral readSerialIntegralTimeout(void)
Reads an integral type, timing out if necessary.
Definition comms.cpp:175
Definition decoder_t.h:70
decoder_features_t(void)
‍Whether or not the decoder supports per-tooth ignition
Definition decoder_t.h:76
bool supportsPerToothIgnition
‍Whether or not the decoder supports fixed cranking timing
Definition decoder_t.h:74
bool supportsSequential
‍The use of the 2nd derivative calculation is limited to certain decoders.
Definition decoder_t.h:72
bool supports2ndDeriv
Definition decoder_t.h:71
bool hasFixedCrankingTiming
‍Whether or not the decoder supports sequential operation
Definition decoder_t.h:73
Current decoder status.
Definition decoder_t.h:63
SyncStatus syncStatus
‍Whether or not the triggerToothAngle variable is currently accurate. Some patterns have times when t...
Definition decoder_t.h:66
bool toothAngleIsCorrect
‍Is set true when the last trigger (Primary or secondary) was valid (ie passed filters)
Definition decoder_t.h:65
bool validTrigger
Definition decoder_t.h:64
This structure represents a decoder configuration.
Definition decoder_t.h:89
void(*)(void) setEndTeeth_t
The function to set the end teeth for ignition calculations.
Definition decoder_t.h:111
getCrankAngle_t getCrankAngle
The function to get the crank angle.
Definition decoder_t.h:106
reset_t reset
The function to reset the decoder. Called when the engine is stopped, or when the engine is started.
Definition decoder_t.h:118
bool(*)(uint32_t) engine_running_t
The function to test if the engine is running.
Definition decoder_t.h:131
uint16_t(*)(void) getRPM_t
The function to get the RPM.
Definition decoder_t.h:99
feature_fun_t getFeatures
The function to get the current decoder feature set.
Definition decoder_t.h:144
void(*)(void) reset_t
The function to reset the decoder. Called when the engine is stopped, or when the engine is started.
Definition decoder_t.h:117
interrupt_t tertiary
The tertiary interrupt configuration - for decoders that use a 3rd input. E.g. VVT.
Definition decoder_t.h:95
engine_running_t isEngineRunning
The function to test if the engine is running.
Definition decoder_t.h:132
setEndTeeth_t setEndTeeth
The function to set the end teeth for ignition calculations.
Definition decoder_t.h:112
decoder_status_t(*)(void) status_fun_t
The function to get the current decoder status.
Definition decoder_t.h:137
getRPM_t getRPM
The function to get the RPM.
Definition decoder_t.h:100
interrupt_t secondary
The secondary interrupt configuration - usually the cam trigger.
Definition decoder_t.h:93
interrupt_t primary
The primary interrupt configuration - usually the crank trigger.
Definition decoder_t.h:91
status_fun_t getStatus
The function to get the current decoder status.
Definition decoder_t.h:138
int16_t(*)(void) getCrankAngle_t
The function to get the crank angle.
Definition decoder_t.h:105
decoder_features_t(*)(void) feature_fun_t
The function to get the current decoder feature set.
Definition decoder_t.h:143
This structure represents a trigger interrupt.
Definition decoder_t.h:17
uint8_t edge
The edge type for the interrupt. E.g. RISING, FALLING, CHANGE.
Definition decoder_t.h:23
void(*)(void) callback_t
Definition decoder_t.h:18
callback_t callback
The callback function to be called on interrupt.
Definition decoder_t.h:21
bool isValid(void) const
Definition decoder_t.h:41
void attach(uint8_t pin) const
Attach the interrupt to a pin.
Definition decoder_t.h:26
void detach(uint8_t pin) const
Detach the interrupt from a pin.
Definition decoder_t.h:36