rusefi-1/firmware/controllers/tachometer.cpp

43 lines
1.1 KiB
C++
Raw Normal View History

2015-08-18 12:03:44 -07:00
/*
* @file tachometer.cpp
2015-08-18 14:01:49 -07:00
* @brief This is about driving external analog tachometers
2015-08-18 12:03:44 -07:00
*
2016-05-24 19:02:13 -07:00
* todo: these is a bit of duplication with dizzySparkOutputPin
*
2015-08-18 12:03:44 -07:00
* @date Aug 18, 2015
2015-12-31 13:02:30 -08:00
* @author Andrey Belomutskiy, (c) 2012-2016
2015-08-18 12:03:44 -07:00
*/
#include "tachometer.h"
2015-08-18 14:01:49 -07:00
#include "trigger_central.h"
2015-08-18 12:03:44 -07:00
EXTERN_ENGINE;
2015-08-18 14:01:49 -07:00
static OutputPin tachOut;
2015-08-19 13:01:36 -07:00
static scheduling_s tachTurnSignalOff;
static void turnTachPinLow(void) {
2015-08-19 19:01:27 -07:00
tachOut.setValue(false);
2015-08-19 13:01:36 -07:00
}
2015-08-18 14:01:49 -07:00
static void tachSignalCallback(trigger_event_e ckpSignalType,
uint32_t index DECLARE_ENGINE_PARAMETER_S) {
2015-08-18 21:03:11 -07:00
if (index != engineConfiguration->tachPulseTriggerIndex) {
return;
}
tachOut.setValue(true);
2015-08-19 13:01:36 -07:00
scheduleTask("tach off", &tachTurnSignalOff, (int)MS2US(engineConfiguration->tachPulseDuractionMs), (schfunc_t) &turnTachPinLow, NULL);
2015-08-18 14:01:49 -07:00
}
2015-08-18 12:03:44 -07:00
void initTachometer(void) {
2015-08-18 21:03:11 -07:00
if (boardConfiguration->tachOutputPin == GPIO_UNASSIGNED) {
2015-08-18 12:03:44 -07:00
return;
2015-08-18 21:03:11 -07:00
}
2015-08-18 12:03:44 -07:00
2015-08-19 19:01:27 -07:00
outputPinRegisterExt2("analog tach output", &tachOut, boardConfiguration->tachOutputPin, &boardConfiguration->tachOutputPinMode);
2015-08-18 14:01:49 -07:00
addTriggerEventListener(tachSignalCallback, "tach", engine);
2015-08-18 12:03:44 -07:00
}