Skip to content

Commit

Permalink
AP_ICEngine: Direction control for cranking.
Browse files Browse the repository at this point in the history
Added a parameter _DIR where 0 if forward and 1 or greater is reverse
direction for Engine Cranking. This is particular with Hirth Engine
where both options are available.
  • Loading branch information
loki077 committed Aug 12, 2024
1 parent a014bcb commit 261307f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
5 changes: 5 additions & 0 deletions libraries/AP_ICEngine/AP_ICEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ const AP_Param::GroupInfo AP_ICEngine::var_info[] = {

// 18 was IGNITION_RLY

#if AP_ICENGINE_TCA9554_STARTER_ENABLED
// @Group: _TCA9554
// @Path: AP_ICENGINE_TCA9554.cpp
AP_SUBGROUPINFO(tca9554_starter, "_TCA", 19, AP_ICEngine, AP_ICEngine_TCA9554),
#endif // AP_ICENGINE_TCA9554_STARTER_ENABLED

AP_GROUPEND
};
Expand Down
25 changes: 24 additions & 1 deletion libraries/AP_ICEngine/AP_ICEngine_TCA9554.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#if AP_ICENGINE_TCA9554_STARTER_ENABLED
#include "AP_ICEngine.h"
#include <AP_Param/AP_Param.h>

extern const AP_HAL::HAL& hal;

Expand All @@ -27,6 +28,24 @@ extern const AP_HAL::HAL& hal;
#define TCA9554_CONF 0x03 // Configuration Port register address [0 = Output]
#define TCA9554_PINS 0xC2 // Set all used ports to outputs = 1100 0010

const AP_Param::GroupInfo AP_ICEngine_TCA9554::var_info[] = {

// @Param: _DIR
// @DisplayName: Engine Cranking Direction for TCA9554
// @Description: This will define which direction the engine is cranking for the TCA9554 starter control
// @User: Standard
// @Values: 0:Forward,1:Reverse
AP_GROUPINFO("_DIR ", 1, AP_ICEngine_TCA9554, crank_direction, 0),

AP_GROUPEND
};

// constructor
AP_ICEngine_TCA9554::AP_ICEngine_TCA9554()
{
AP_Param::setup_object_defaults(this, var_info);
}

/*
initialise TCA9554
*/
Expand Down Expand Up @@ -91,7 +110,11 @@ void AP_ICEngine_TCA9554::set_starter(bool on)
return;
}
}
TCA9554_set(on? STARTER_ON : STARTER_OFF);
if (!crank_direction) {
TCA9554_set(on? STARTER_FORWARD : STARTER_OFF);
} else {
TCA9554_set(on? STARTER_REVERSE : STARTER_OFF);
}
}

#endif // AP_ICENGINE_TCA9554_STARTER_ENABLED
11 changes: 9 additions & 2 deletions libraries/AP_ICEngine/AP_ICEngine_TCA9554.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,19 @@

class AP_ICEngine_TCA9554 {
public:
AP_ICEngine_TCA9554();

static const struct AP_Param::GroupInfo var_info[];

void set_starter(bool on);

private:
AP_HAL::OwnPtr<AP_HAL::I2CDevice> dev_TCA9554;

enum TCA9554_state_t {
STARTER_OFF = 0x30, // output register - 0011 0000
STARTER_ON = 0x11, // output register - 0001 0001 - Forward direction
STARTER_OFF = 0x30, // output register - 0011 0000
STARTER_FORWARD = 0x11, // output register - 0001 0001 - Forward direction
STARTER_REVERSE = 0x01, // output register - 0000 0001 - Reverse direction
};
TCA9554_state_t last_state;

Expand All @@ -25,6 +30,8 @@ class AP_ICEngine_TCA9554 {
bool TCA9554_init();
void TCA9554_set(TCA9554_state_t value);
uint32_t last_reg_check_ms;
// crank engine direction
AP_Int8 crank_direction;
};

#endif // AP_ICENGINE_TCA9554_STARTER_ENABLED

0 comments on commit 261307f

Please sign in to comment.