Skip to content

Commit

Permalink
Clean up the firmware (#1469)
Browse files Browse the repository at this point in the history
  • Loading branch information
beastoin authored Dec 4, 2024
2 parents dee75f8 + 6b7ba47 commit 2f24fb9
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ CONFIG_BT_DIS_MODEL="Omi DevKit 2"
CONFIG_BT_DIS_MANUF="Based Hardware"
CONFIG_BT_DIS_FW_REV=y
CONFIG_BT_DIS_HW_REV=y
CONFIG_BT_DIS_FW_REV_STR="2.0.6"
CONFIG_BT_DIS_FW_REV_STR="2.0.7"
CONFIG_BT_DIS_HW_REV_STR="Seeed Xiao BLE Sense"

#
Expand Down
22 changes: 6 additions & 16 deletions Friend/firmware/firmware_v1.0/src/button.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
#include "transport.h"
#include "speaker.h"
#include "led.h"
#include "mic.h"
#include "sdcard.h"
LOG_MODULE_REGISTER(button, CONFIG_LOG_DEFAULT_LEVEL);

bool is_off = false;
extern bool from_wakeup;
static void button_ccc_config_changed_handler(const struct bt_gatt_attr *attr, uint16_t value);
static ssize_t button_data_read_characteristic(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset);
static struct gpio_callback button_cb_data;
Expand Down Expand Up @@ -227,21 +228,10 @@ void check_button_level(struct k_work *work_item)
btn_last_event = event;
notify_tap();

//Fire the long mode notify and enter a grace period
//turn off herre
if(!from_wakeup)
{
is_off = !is_off;
}
else
{
from_wakeup = false;
}
if (is_off)
{
bt_off();
turnoff_all();
}
// Enter the low power mode
is_off = true;
bt_off();
turnoff_all();
}

// Double tap
Expand Down
2 changes: 1 addition & 1 deletion Friend/firmware/firmware_v1.0/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,9 @@ int main(void)
set_led_blue(true);
k_msleep(1000);
set_led_blue(false);
printf("reset reas:%d\n",reset_reas);

}

printf("reset reas:%d\n",reset_reas);
while (1)
{
Expand Down
132 changes: 64 additions & 68 deletions Friend/firmware/firmware_v1.0/src/transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
#include "utils.h"
// #include "nfc.h"
#include "speaker.h"
#include "button.h"
#include "sdcard.h"
#include "storage.h"
#include "button.h"
#include "mic.h"
#include "lib/battery/battery.h"
// #include "friend.h"
LOG_MODULE_REGISTER(transport, CONFIG_LOG_DEFAULT_LEVEL);
Expand Down Expand Up @@ -626,7 +626,6 @@ bool write_to_storage(void) {//max possible packing
return true;
}

extern bool is_off;
static bool use_storage = true;
#define MAX_FILES 10
#define MAX_AUDIO_FILE_SIZE 300000
Expand All @@ -648,84 +647,81 @@ void pusher(void)
//
// Load current connection
//
if(!is_off)
struct bt_conn *conn = current_connection;
//updating the most recent file size is expensive!
static bool file_size_updated = true;
static bool connection_was_true = false;
if (conn && !connection_was_true)
{
struct bt_conn *conn = current_connection;
//updating the most recent file size is expensive!
static bool file_size_updated = true;
static bool connection_was_true = false;
if (conn && !connection_was_true)
{
k_msleep(100);
file_size_updated = false;
connection_was_true = true;
}
else if (!conn)
k_msleep(100);
file_size_updated = false;
connection_was_true = true;
}
else if (!conn)
{
connection_was_true = false;
}
if (!file_size_updated)
{
printk("updating file size\n");
update_file_size();

file_size_updated = true;
}
if (conn)
{
conn = bt_conn_ref(conn);
}
bool valid = true;
if (current_mtu < MINIMAL_PACKET_SIZE)
{
valid = false;
}
else if (!conn)
{
valid = false;
}
else
{
valid = bt_gatt_is_subscribed(conn, &audio_service.attrs[1], BT_GATT_CCC_NOTIFY); // Check if subscribed
}

if (!valid && !storage_is_on)
{
bool result = false;
if (file_num_array[1] < MAX_STORAGE_BYTES)
{
connection_was_true = false;
result = write_to_storage();
}
if (!file_size_updated)
if (result)
{
printk("updating file size\n");
heartbeat_count++;
if (heartbeat_count == 255)
{
update_file_size();

file_size_updated = true;
}
if (conn)
{
conn = bt_conn_ref(conn);
}
bool valid = true;
if (current_mtu < MINIMAL_PACKET_SIZE)
{
valid = false;
}
else if (!conn)
{
valid = false;
}
else
{
valid = bt_gatt_is_subscribed(conn, &audio_service.attrs[1], BT_GATT_CCC_NOTIFY); // Check if subscribed
heartbeat_count = 0;
printk("drawing\n");
}
}

if (!valid && !storage_is_on)
{
bool result = false;
if (file_num_array[1] < MAX_STORAGE_BYTES)
{
result = write_to_storage();
}
if (result)
{
heartbeat_count++;
if (heartbeat_count == 255)
{
update_file_size();
heartbeat_count = 0;
printk("drawing\n");
}
}
else
{

}
}
if (valid)
else
{
bool sent = push_to_gatt(conn);
if (!sent)
{
// k_sleep(K_MSEC(50));
}

}
if (conn)
}
if (valid)
{
bool sent = push_to_gatt(conn);
if (!sent)
{
bt_conn_unref(conn);
// k_sleep(K_MSEC(50));
}
}
if (conn)
{
bt_conn_unref(conn);
}

k_yield();
k_yield();
}
}
extern struct bt_gatt_service storage_service;
Expand Down
7 changes: 0 additions & 7 deletions Friend/firmware/firmware_v1.0/src/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
#include <zephyr/logging/log.h>
#include <zephyr/usb/usb_device.h>
#include "usb.h"
#include "button.h"
#include "speaker.h"
#include "transport.h"
LOG_MODULE_REGISTER(usb, CONFIG_LOG_DEFAULT_LEVEL);
//add all device drivers here?
bool usb_charge = false;
extern bool is_off;
usb_dc_status_callback udc_status_cb(enum usb_dc_status_code status,
const uint8_t *param)
{
Expand All @@ -21,11 +19,6 @@ usb_dc_status_callback udc_status_cb(enum usb_dc_status_code status,
usb_charge = true;
break;
case USB_DC_DISCONNECTED:
if (is_off)
{
bt_off();
turnoff_all();
}
usb_charge = false;
break;
default:
Expand Down
4 changes: 2 additions & 2 deletions app/lib/pages/home/firmware_update.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ class _FirmwareUpdateState extends State<FirmwareUpdate> with FirmwareMixin {
children: [
const Text('Firmware Updated Successfully'),
const SizedBox(height: 10),
const Text(
'Please restart the Friend device to complete the update',
Text(
'Please restart your ${widget.device?.name ?? "Omi device"} to complete the update',
textAlign: TextAlign.center,
),
const SizedBox(height: 20),
Expand Down

0 comments on commit 2f24fb9

Please sign in to comment.