Reworked method to calc traveled distance
This commit is contained in:
parent
39fc8af955
commit
1ace7a8d6a
@ -25,9 +25,9 @@ typedef enum eEERequest
|
|||||||
typedef struct Globals_s
|
typedef struct Globals_s
|
||||||
{
|
{
|
||||||
tSystem_Status systemStatus = sysStat_Startup;
|
tSystem_Status systemStatus = sysStat_Startup;
|
||||||
uint8_t purgePulses= 0;
|
|
||||||
tSystem_Status resumeStatus = sysStat_Startup;
|
tSystem_Status resumeStatus = sysStat_Startup;
|
||||||
char systemStatustxt[16] = "";
|
char systemStatustxt[16] = "";
|
||||||
|
uint8_t purgePulses = 0;
|
||||||
eEERequest requestEEAction = EE_IDLE;
|
eEERequest requestEEAction = EE_IDLE;
|
||||||
} Globals_t;
|
} Globals_t;
|
||||||
|
|
||||||
|
@ -2,13 +2,11 @@
|
|||||||
|
|
||||||
uint32_t lubePulseTimestamp = 0;
|
uint32_t lubePulseTimestamp = 0;
|
||||||
|
|
||||||
void RunLubeApp(volatile uint32_t *wheelPulseCounter)
|
void RunLubeApp(uint32_t add_milimeters)
|
||||||
{
|
{
|
||||||
// Calculate traveled Distance in mm
|
// Add traveled Distance in mm
|
||||||
TravelDistance_highRes += (*wheelPulseCounter * (LubeConfig.DistancePerRevolution_mm / LubeConfig.PulsePerRevolution));
|
TravelDistance_highRes += add_milimeters;
|
||||||
*wheelPulseCounter = 0;
|
|
||||||
|
|
||||||
// check if we have to Lube!
|
|
||||||
switch (globals.systemStatus)
|
switch (globals.systemStatus)
|
||||||
{
|
{
|
||||||
case sysStat_Startup:
|
case sysStat_Startup:
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
#define LUBE_PULSE_PAUSE_MS 100
|
#define LUBE_PULSE_PAUSE_MS 100
|
||||||
#define STARTUP_DELAY 5000
|
#define STARTUP_DELAY 5000
|
||||||
|
|
||||||
void RunLubeApp(volatile uint32_t * wheelPulseCounter);
|
void RunLubeApp(uint32_t add_milimeters);
|
||||||
void LubePulse();
|
void LubePulse();
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -67,9 +67,7 @@ void Display_Process();
|
|||||||
void Button_Process();
|
void Button_Process();
|
||||||
void toggleWiFiAP(boolean shutdown = false);
|
void toggleWiFiAP(boolean shutdown = false);
|
||||||
void SystemShutdown();
|
void SystemShutdown();
|
||||||
#if PCB_REVISION >= 13
|
uint32_t Process_Impulse_WheelSpeed();
|
||||||
void Init_CAN();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef WIFI_CLIENT
|
#ifdef WIFI_CLIENT
|
||||||
void wifiMaintainConnectionTicker_callback();
|
void wifiMaintainConnectionTicker_callback();
|
||||||
@ -179,7 +177,18 @@ void setup()
|
|||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
RunLubeApp(&wheel_pulse);
|
uint32_t wheelDistance = 0;
|
||||||
|
|
||||||
|
switch (LubeConfig.SpeedSource)
|
||||||
|
{
|
||||||
|
case SOURCE_IMPULSE:
|
||||||
|
wheelDistance = Process_Impulse_WheelSpeed();
|
||||||
|
break;
|
||||||
|
case SOURCE_TIME:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
RunLubeApp(wheelDistance);
|
||||||
UpdateWebUITicker.update();
|
UpdateWebUITicker.update();
|
||||||
|
|
||||||
Display_Process();
|
Display_Process();
|
||||||
@ -652,24 +661,12 @@ void SystemShutdown()
|
|||||||
ESP.restart();
|
ESP.restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if PCB_REVISION >= 13
|
uint32_t Process_Impulse_WheelSpeed()
|
||||||
void Init_CAN()
|
|
||||||
{
|
{
|
||||||
// Initialize MCP2515 running at 16MHz with a baudrate of 500kb/s and the masks and filters disabled.
|
uint32_t add_milimeters;
|
||||||
if (CAN0.begin(MCP_ANY, CAN_500KBPS, MCP_16MHZ) == CAN_OK)
|
// Calculate traveled Distance in mm
|
||||||
Serial.println("MCP2515 Initialized Successfully!");
|
add_milimeters = (wheel_pulse * (LubeConfig.DistancePerRevolution_mm / LubeConfig.PulsePerRevolution));
|
||||||
else
|
wheel_pulse = 0;
|
||||||
Serial.println("Error Initializing MCP2515...");
|
|
||||||
|
|
||||||
CAN0.setMode(MCP_NORMAL); // Change to normal mode to allow messages to be transmitted
|
return add_milimeters;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Recieve_CAN()
|
|
||||||
{
|
|
||||||
long unsigned int rxId;
|
|
||||||
unsigned char len = 0;
|
|
||||||
unsigned char rxBuf[8];
|
|
||||||
|
|
||||||
CAN0.readMsgBuf(&rxId, &len, rxBuf); // Read data: len = data length, buf = data byte(s)
|
|
||||||
}
|
|
||||||
#endif
|
|
Loading…
x
Reference in New Issue
Block a user