Skip to content

Commit

Permalink
Detecting jostle and still running low power
Browse files Browse the repository at this point in the history
  • Loading branch information
ps2 committed May 24, 2017
1 parent 194fd36 commit d7f7a23
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/jostle_detect.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void jostle_detect_init() {
err_code = nrf_drv_gpiote_init();
APP_ERROR_CHECK(err_code);

nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_TOGGLE(true);
nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_TOGGLE(false);
in_config.pull = NRF_GPIO_PIN_PULLUP;

err_code = nrf_drv_gpiote_in_init(INT1_GPIO_PIN, &in_config, motion_handler);
Expand All @@ -77,13 +77,14 @@ void jostle_detect_init() {

// enable 4G range
write_register(MMA8451_REG_XYZ_DATA_CFG, MMA8451_RANGE_4_G);
// High res
write_register(MMA8451_REG_CTRL_REG2, 0x02);

// Low power mode
write_register(MMA8451_REG_CTRL_REG2, 0b00000011);

// Setup motion detection
write_register(MMA8451_REG_FF_MT_CFG, 0b11111000); // Enable motion, and x,y,z
write_register(MMA8451_REG_FF_MT_THS, 17); // Threshold: 17 * 0.063g = 1.071g
write_register(MMA8451_REG_FF_MT_COUNT, 15); // debounce counter: 15 * 1.25ms = 18.75ms
write_register(MMA8451_REG_FF_MT_COUNT, 1); // debounce counter: 20ms @ 50hz

// Setup interrupts
write_register(MMA8451_REG_CTRL_REG4, INT_EN_FF_MT | INT_EN_PULSE); // Enable Freefall/Motion int, and pulse
Expand All @@ -93,11 +94,11 @@ void jostle_detect_init() {
//write_register(MMA8451_REG_PL_CFG, 0x40);

// ASLP_RATE = 50hz
// ODR = 800hz (1.25ms period)
// ODR = 50hz
// LNOISE = 1
// F_READ = normal
// ACTIVE = active
write_register(MMA8451_REG_CTRL_REG1, 0b00000101);
write_register(MMA8451_REG_CTRL_REG1, 0b00100101);
}

bool jostle_detect_get_flag() {
Expand Down

0 comments on commit d7f7a23

Please sign in to comment.