[TCU] Button Shifting (#1750)

* add buttonshift files

* buttonshift includes, targets, and init
This commit is contained in:
David Holdeman 2020-09-02 19:17:58 -05:00 committed by GitHub
parent 6a9317661e
commit b8838de309
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 111 additions and 1 deletions

View File

@ -16,6 +16,7 @@
#include "accel_enrichment.h"
#include "trigger_central.h"
#include "local_version_holder.h"
#include "buttonshift.h"
#include "tcu.h"
#if EFI_SIGNAL_EXECUTOR_ONE_TIMER

View File

@ -0,0 +1,82 @@
/**
* @file buttonshift.cpp
* @brief Polls pins for gear changes
*
* @date Aug 31, 2020
* @author David Holdeman, (c) 2020
*/
#include "buttonshift.h"
#include "engine.h"
EXTERN_ENGINE;
ButtonShiftController buttonShiftController;
void ButtonShiftController::init (DECLARE_ENGINE_PARAMETER_SIGNATURE) {
// 500 millisecond is maybe a little long?
debounceUp.init(500, CONFIG(tcuUpshiftButtonPin), CONFIG(tcuUpshiftButtonPinMode));
debounceDown.init(500, CONFIG(tcuDownshiftButtonPin), CONFIG(tcuDownshiftButtonPinMode));
}
void ButtonShiftController::update() {
bool upPinState = false;
bool downPinState = false;
// Read pins
upPinState = debounceUp.readPinEvent();
downPinState = debounceDown.readPinEvent();
gear_e gear = getDesiredGear();
// Select new gear based on current desired gear.
if (upPinState) {
switch (gear) {
case REVERSE:
setDesiredGear(NEUTRAL);
break;
case NEUTRAL:
setDesiredGear(GEAR_1);
break;
case GEAR_1:
setDesiredGear(GEAR_2);
break;
case GEAR_2:
setDesiredGear(GEAR_3);
break;
case GEAR_3:
setDesiredGear(GEAR_4);
break;
default:
break;
}
} else if (downPinState) {
switch (gear) {
case NEUTRAL:
setDesiredGear(REVERSE);
break;
case GEAR_1:
setDesiredGear(NEUTRAL);
break;
case GEAR_2:
setDesiredGear(GEAR_1);
break;
case GEAR_3:
setDesiredGear(GEAR_2);
break;
case GEAR_4:
setDesiredGear(GEAR_3);
break;
default:
break;
}
}
// We are responsible for telling the transmission controller
// what gear we want.
transmissionController.update(getDesiredGear());
// Post state to TS
postState();
}
void initButtonShift(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
buttonShiftController.init(PASS_ENGINE_PARAMETER_SIGNATURE);
engine->gearController = &buttonShiftController;
INJECT_ENGINE_REFERENCE(&buttonShiftController);
}

View File

@ -0,0 +1,24 @@
/**
* @file buttonshift.cpp
* @brief Polls pins for gear changes
*
* @date Aug 31, 2020
* @author David Holdeman, (c) 2020
*/
#pragma once
#include "tcu.h"
#include "globalaccess.h"
#include "debounce.h"
class ButtonShiftController: public GearControllerBase {
public:
DECLARE_ENGINE_PTR;
void update();
void init(DECLARE_ENGINE_PARAMETER_SIGNATURE);
private:
ButtonDebounce debounceUp;
ButtonDebounce debounceDown;
};
void initButtonShift(DECLARE_ENGINE_PARAMETER_SIGNATURE);

View File

@ -48,9 +48,9 @@ CONTROLLERS_SRC_CPP = \
$(CONTROLLERS_DIR)/persistent_store.cpp \
$(CONTROLLERS_DIR)/serial/serial_rx.cpp \
$(CONTROLLERS_DIR)/serial/serial_sensor.cpp \
$(CONTROLLERS_DIR)/buttonshift.cpp \
$(CONTROLLERS_DIR)/tcu.cpp \
CONTROLLERS_INC=\
$(CONTROLLERS_DIR) \
$(CONTROLLERS_DIR)/system \

View File

@ -57,6 +57,7 @@
#include "tachometer.h"
#include "gppwm.h"
#include "date_stamp.h"
#include "buttonshift.h"
#if EFI_SENSOR_CHART
#include "sensor_chart.h"
@ -588,6 +589,8 @@ void commonInitEngineController(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_S
startIdleThread(sharedLogger PASS_ENGINE_PARAMETER_SUFFIX);
#endif /* EFI_IDLE_CONTROL */
initButtonShift(PASS_ENGINE_PARAMETER_SIGNATURE);
#if EFI_ELECTRONIC_THROTTLE_BODY
initElectronicThrottle(PASS_ENGINE_PARAMETER_SIGNATURE);
#endif /* EFI_ELECTRONIC_THROTTLE_BODY */