Skip to content

Commit

Permalink
Verify battery plugged-in status before fully initializing app
Browse files Browse the repository at this point in the history
  • Loading branch information
hedgecrw committed Nov 10, 2023
1 parent 8e02635 commit 2222872
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion software/firmware/launchConfigs/TestFull.launch
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,6 @@
<listAttribute key="org.eclipse.debug.ui.favoriteGroups">
<listEntry value="org.eclipse.debug.ui.launchGroup.debug"/>
</listAttribute>
<stringAttribute key="org.eclipse.dsf.launch.MEMORY_BLOCKS" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#10;&lt;memoryBlockExpressionList context=&quot;Context string&quot;/&gt;&#10;"/>
<stringAttribute key="org.eclipse.dsf.launch.MEMORY_BLOCKS" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;memoryBlockExpressionList context=&quot;Context string&quot;/&gt;&#13;&#10;"/>
<stringAttribute key="process_factory_id" value="org.eclipse.cdt.dsf.gdb.GdbProcessFactory"/>
</launchConfiguration>
2 changes: 2 additions & 0 deletions software/firmware/src/peripherals/src/bluetooth.c
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,10 @@ void bluetooth_set_current_ranging_role(uint8_t ranging_role)
{
// Update the current device ranging role in the BLE advertisements
current_ranging_role[2] = ranging_role;
#ifndef _TEST_RANGING_TASK
AppAdvSetAdValue(APP_ADV_DATA_CONNECTABLE, DM_ADV_TYPE_MANUFACTURER, sizeof(current_ranging_role), (uint8_t*)current_ranging_role);
AppAdvStop();
#endif
}

void bluetooth_write_range_results(const uint8_t *results, uint16_t results_length)
Expand Down
4 changes: 3 additions & 1 deletion software/firmware/src/tasks/app_task_maintenance.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ void AppTaskMaintenance(void *uid)
app_task_handle = xTaskGetCurrentTaskHandle();
uint32_t notification_bits = 0;

// Register handler for battery status changes
// Register handler for battery status changes and verify correct mode of operation
battery_register_event_callback(battery_event_handler);
if (!battery_monitor_is_plugged_in())
storage_flush_and_shutdown();

// Wait until the BLE stack has been fully initialized
while (!bluetooth_is_initialized())
Expand Down
4 changes: 3 additions & 1 deletion software/firmware/src/tasks/app_task_ranging.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ void AppTaskRanging(void *uid)
battery_register_event_callback(battery_event_handler);
imu_register_motion_change_callback(motion_change_handler);
bluetooth_register_discovery_callback(ble_discovery_handler);
if (battery_monitor_is_plugged_in())
storage_flush_and_shutdown();

// Retrieve current experiment details from non-volatile storage
experiment_details_t current_experiment;
Expand All @@ -201,12 +203,12 @@ void AppTaskRanging(void *uid)
devices_found = false;
while (!bluetooth_is_initialized())
vTaskDelay(1);
bluetooth_set_current_ranging_role(ROLE_IDLE);

// Update the BLE address whitelist
bluetooth_clear_whitelist();
for (uint8_t i = 0; i < current_experiment.num_devices; ++i)
bluetooth_add_device_to_whitelist(current_experiment.uids[i]);
bluetooth_set_current_ranging_role(ROLE_IDLE);

// Loop forever, sleeping until an application notification is received
while (true)
Expand Down
2 changes: 1 addition & 1 deletion software/firmware/src/tasks/app_tasks.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

// Task Type Definitions -----------------------------------------------------------------------------------------------

typedef enum { ROLE_IDLE = 0, ROLE_MASTER, ROLE_PARTICIPANT, ROLE_ASLEEP } schedule_role_t;
typedef enum { ROLE_IDLE = 10, ROLE_MASTER, ROLE_PARTICIPANT, ROLE_ASLEEP } schedule_role_t;

typedef enum {
APP_NOTIFY_VERIFY_CONFIGURATION = 0b00000001,
Expand Down
6 changes: 3 additions & 3 deletions software/firmware/src/tasks/ranging_task.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Header Inclusions ---------------------------------------------------------------------------------------------------

#include "app_tasks.h"
#include "bluetooth.h"
#include "logging.h"
#include "rtc.h"
#include "scheduler.h"

Expand Down Expand Up @@ -41,9 +41,9 @@ void RangingTask(void *uid)
// Sleep until time to start ranging with the indicated role
if ((xTaskNotifyWait(pdFALSE, 0xffffffff, &desired_role_bits, portMAX_DELAY) == pdTRUE) && uid)
{
bluetooth_set_current_ranging_role(desired_role_bits);
print("TotTag Ranging: Starting ranging task as %s\n", (desired_role_bits == ROLE_MASTER) ? "MASTER" : "PARTICIPANT");
scheduler_run((schedule_role_t)desired_role_bits, rtc_get_timestamp());
bluetooth_set_current_ranging_role(ROLE_IDLE);
print("TotTag Ranging: Ranging task has stopped!\n");
}

// Notify the application that network connectivity has been lost
Expand Down

0 comments on commit 2222872

Please sign in to comment.