Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for failed g-sensor #1698

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/lib/GSENSOR/devGsensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,19 @@ extern void deferExecution(uint32_t ms, std::function<void()> f);
#define MULTIPLE_BUMP_INTERVAL 400U
#define BUMP_COMMAND_IDLE_TIME 10000U

static bool gSensorOk = false;

static void initialize()
{
if (OPT_HAS_GSENSOR && GPIO_PIN_SCL != UNDEF_PIN && GPIO_PIN_SDA != UNDEF_PIN)
{
gsensor.init();
gSensorOk = gsensor.init();
}
}

static int start()
{
if (OPT_HAS_GSENSOR && GPIO_PIN_SCL != UNDEF_PIN && GPIO_PIN_SDA != UNDEF_PIN)
if (gSensorOk && OPT_HAS_GSENSOR && GPIO_PIN_SCL != UNDEF_PIN && GPIO_PIN_SDA != UNDEF_PIN)
{
return DURATION_IMMEDIATELY;
}
Expand Down
8 changes: 5 additions & 3 deletions src/lib/GSENSOR/gsensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,18 @@ ICACHE_RAM_ATTR void handleGsensorInterrupt()
interrupt = true;
}

void Gsensor::init()
bool Gsensor::init()
{
uint8_t id = -1;
int16_t id = -1;
if (OPT_HAS_GSENSOR_STK8xxx)
id = stk8xxx.STK8xxx_Initialization();
else
return;
return false;

if(id == -1)
{
ERRLN("Gsensor failed!");
return false;
}
else
{
Expand All @@ -71,6 +72,7 @@ void Gsensor::init()

system_state = GSENSOR_SYSTEM_STATE_MOVING;
is_flipped = false;
return true;
}

float get_data_average(float *data, int length)
Expand Down
2 changes: 1 addition & 1 deletion src/lib/GSENSOR/gsensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Gsensor
int system_state;
bool is_flipped;
public:
void init();
bool init();
void handle();
bool hasTriggered(unsigned long now);
void getGSensorData(float *X_DataOut, float *Y_DataOut, float *Z_DataOut);
Expand Down