custom-board-bundle-sample-.../firmware/development/analog_chart.cpp

80 lines
1.8 KiB
C++
Raw Normal View History

2014-08-29 07:52:33 -07:00
/**
2014-11-03 10:03:03 -08:00
* @file analog_chart.cpp
2014-08-29 07:52:33 -07:00
*
* @date Dec 20, 2013
2015-01-12 15:04:10 -08:00
* @author Andrey Belomutskiy, (c) 2012-2015
2014-08-29 07:52:33 -07:00
*/
#include "main.h"
#include "analog_chart.h"
2014-11-03 10:03:03 -08:00
#include "rpm_calculator.h"
2014-08-29 07:52:33 -07:00
#include "status_loop.h"
#include "engine_configuration.h"
#if EFI_ANALOG_CHART || defined(__DOXYGEN__)
static char LOGGING_BUFFER[5000];
2015-02-11 17:07:15 -08:00
static Logging logging("analog chart", LOGGING_BUFFER, sizeof(LOGGING_BUFFER));
2014-08-29 07:52:33 -07:00
static int pendingData = FALSE;
static int initialized = FALSE;
extern engine_configuration_s *engineConfiguration;
void acAddData(float angle, float value) {
2014-09-11 19:02:53 -07:00
if (!initialized) {
2014-08-29 07:52:33 -07:00
return; // this is possible because of initialization sequence
2014-09-11 19:02:53 -07:00
}
2014-08-29 07:52:33 -07:00
2015-02-08 16:04:13 -08:00
if (engineConfiguration->analogChartFrequency < 2) {
/**
* analog chart frequency cannot be 1 because of the way
* data flush is implemented, see below
*/
2014-08-29 07:52:33 -07:00
//todofirmwareError()
return;
}
if (getRevolutionCounter() % engineConfiguration->analogChartFrequency != 0) {
2015-02-08 16:04:13 -08:00
/**
* We are here if we do NOT need to add an event to the analog chart
*/
2014-08-29 07:52:33 -07:00
if (pendingData) {
2015-02-08 16:04:13 -08:00
/**
* We are here if that's the first time we do not need to add
* data after we have added some data - meaning it's time to flush
*/
2014-08-29 07:52:33 -07:00
// message terminator
appendPrintf(&logging, DELIMETER);
// output pending data
if (getFullLog()) {
scheduleLogging(&logging);
2014-09-11 19:02:53 -07:00
}
2015-01-19 07:03:57 -08:00
pendingData = false;
2014-08-29 07:52:33 -07:00
}
return;
}
if (!pendingData) {
2015-01-19 07:03:57 -08:00
pendingData = true;
2014-08-29 07:52:33 -07:00
resetLogging(&logging);
// message header
appendPrintf(&logging, "analog_chart%s", DELIMETER);
}
2014-09-11 19:02:53 -07:00
if (remainingSize(&logging) > 100) {
2014-08-29 07:52:33 -07:00
appendPrintf(&logging, "%f|%f|", angle, value);
2014-09-11 19:02:53 -07:00
}
2014-08-29 07:52:33 -07:00
}
2015-01-19 07:03:57 -08:00
static void setAnalogChartFrequency(int value) {
engineConfiguration->analogChartFrequency = value;
}
2014-08-29 07:52:33 -07:00
void initAnalogChart(void) {
2015-01-19 07:03:57 -08:00
addConsoleActionI("set_analog_chart_freq", setAnalogChartFrequency);
initialized = true;
2014-08-29 07:52:33 -07:00
}
#endif /* EFI_ANALOG_CHART */