Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions source/application/bluetooth.c
Original file line number Diff line number Diff line change
Expand Up @@ -446,12 +446,13 @@ void bluetooth_setup()
bond.keyset.keys_peer.p_id_key = &bond.peer_id_key;
bond.keyset.keys_peer.p_pk = &bond.peer_private_key;

// Set connection parameters
// Set connection parameters - maximum power optimization
// Ultra-low power: Wake only once per second or less
ble_gap_conn_params_t gap_conn_params = {0};
gap_conn_params.min_conn_interval = (15 * 1000) / 1250;
gap_conn_params.max_conn_interval = (15 * 1000) / 1250;
gap_conn_params.slave_latency = 0;
gap_conn_params.conn_sup_timeout = (2000 * 1000) / 10000;
gap_conn_params.min_conn_interval = (1000 * 1000) / 1250; // 1000ms = 1 second
gap_conn_params.max_conn_interval = (2000 * 1000) / 1250; // 2000ms = 2 seconds max
gap_conn_params.slave_latency = 4; // Skip 4 additional events
gap_conn_params.conn_sup_timeout = (8000 * 1000) / 10000; // 8s timeout
check_error(sd_ble_gap_ppcp_set(&gap_conn_params));

// Create the service UUIDs
Expand Down Expand Up @@ -554,7 +555,7 @@ void bluetooth_setup()
adv_params.properties.type = BLE_GAP_ADV_TYPE_CONNECTABLE_SCANNABLE_UNDIRECTED;
adv_params.primary_phy = BLE_GAP_PHY_1MBPS;
adv_params.secondary_phy = BLE_GAP_PHY_1MBPS;
adv_params.interval = (20 * 1000) / 625;
adv_params.interval = (2000 * 1000) / 625; // 2000ms = 2 seconds (maximum power saving)

// Configure the advertising set
check_error(sd_ble_gap_adv_set_configure(&ble_handles.advertising,
Expand Down
7 changes: 5 additions & 2 deletions source/application/lua_libraries/imu.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "lauxlib.h"
#include "lua.h"
#include "main.h"
#include "nrf_soc.h"
#include "nrfx_gpiote.h"
#include "nrfx_systick.h"
#include "pinout.h"
Expand Down Expand Up @@ -109,7 +110,7 @@ static imu_values_t get_imu_data(void)
check_error(i2c_write(MAGNETOMETER, 0x1B, 0x80, 0x80).fail);
check_error(i2c_write(MAGNETOMETER, 0x1D, 0x40, 0x40).fail);

// Wait until data is ready
// Wait until data is ready - power optimized
while (true)
{
if (not_real_hardware)
Expand All @@ -122,7 +123,9 @@ static imu_values_t get_imu_data(void)
break;
}

nrfx_systick_delay_ms(1);
// Power optimization: Use event-driven sleep instead of delay
// This allows CPU to sleep between magnetometer polls
check_error(sd_app_evt_wait());
}

// Read magnetometer (14 bit signed integers)
Expand Down
5 changes: 5 additions & 0 deletions source/application/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "nrf_clock.h"
#include "nrf_gpio.h"
#include "nrf_sdm.h"
#include "nrf_soc.h"
#include "nrf.h"
#include "nrfx_gpiote.h"
#include "nrfx_log.h"
Expand Down Expand Up @@ -476,5 +477,9 @@ int main(void)
reload_watchdog(NULL, NULL);

run_lua(bluetooth_is_paired());

// Power optimization: Put CPU to sleep until next event
// This prevents busy-wait loop that drains battery
check_error(sd_app_evt_wait());
}
}