4 #include "devGsensor.h"
15 static int system_quiet_state
= GSENSOR_SYSTEM_STATE_MOVING
;
16 static int system_quiet_pre_state
= GSENSOR_SYSTEM_STATE_MOVING
;
18 #define GSENSOR_DURATION 10
19 #define GSENSOR_SYSTEM_IDLE_INTERVAL 1000U
21 #define MULTIPLE_BUMP_INTERVAL 400U
22 #define BUMP_COMMAND_IDLE_TIME 10000U
24 static bool gSensorOk
= false;
26 static void initialize()
30 gSensorOk
= gsensor
.init();
36 if (OPT_HAS_GSENSOR
&& gSensorOk
)
38 return DURATION_IMMEDIATELY
;
40 return DURATION_NEVER
;
45 static unsigned long lastIdleCheckMs
= 0;
46 unsigned long now
= millis();
47 if (now
- lastIdleCheckMs
> GSENSOR_SYSTEM_IDLE_INTERVAL
)
51 system_quiet_state
= gsensor
.getSystemState();
52 //When system is idle, set power to minimum
53 if(config
.GetMotionMode() == 1)
55 if((system_quiet_state
== GSENSOR_SYSTEM_STATE_QUIET
) && (system_quiet_pre_state
== GSENSOR_SYSTEM_STATE_MOVING
) && !handset
->IsArmed())
57 POWERMGNT::setPower(MinPower
);
59 if((system_quiet_state
== GSENSOR_SYSTEM_STATE_MOVING
) && (system_quiet_pre_state
== GSENSOR_SYSTEM_STATE_QUIET
) && POWERMGNT::currPower() < (PowerLevels_e
)config
.GetPower())
61 POWERMGNT::setPower((PowerLevels_e
)config
.GetPower());
64 system_quiet_pre_state
= system_quiet_state
;
65 lastIdleCheckMs
= now
;
67 return GSENSOR_DURATION
;
70 device_t Gsensor_device
= {
71 .initialize
= initialize
,