From 82a7a027880ecfc38d1fafd86e1793858ad57a09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?th=E1=BB=8Bnh?= Date: Wed, 4 Dec 2024 12:29:21 +0700 Subject: [PATCH 1/2] Clean up the firmware --- Friend/firmware/firmware_v1.0/src/button.c | 22 +-- Friend/firmware/firmware_v1.0/src/main.c | 2 +- Friend/firmware/firmware_v1.0/src/transport.c | 130 +++++++++--------- Friend/firmware/firmware_v1.0/src/usb.c | 7 - 4 files changed, 70 insertions(+), 91 deletions(-) diff --git a/Friend/firmware/firmware_v1.0/src/button.c b/Friend/firmware/firmware_v1.0/src/button.c index 0e0e5568c..fee8d20ff 100644 --- a/Friend/firmware/firmware_v1.0/src/button.c +++ b/Friend/firmware/firmware_v1.0/src/button.c @@ -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; @@ -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 diff --git a/Friend/firmware/firmware_v1.0/src/main.c b/Friend/firmware/firmware_v1.0/src/main.c index 3a7da0198..8876869c9 100644 --- a/Friend/firmware/firmware_v1.0/src/main.c +++ b/Friend/firmware/firmware_v1.0/src/main.c @@ -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) { diff --git a/Friend/firmware/firmware_v1.0/src/transport.c b/Friend/firmware/firmware_v1.0/src/transport.c index 8a828ee61..28acd3c8f 100644 --- a/Friend/firmware/firmware_v1.0/src/transport.c +++ b/Friend/firmware/firmware_v1.0/src/transport.c @@ -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 @@ -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; + heartbeat_count = 0; + printk("drawing\n"); + } } - if (conn) + else { - 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) - { - result = write_to_storage(); - } - if (result) - { - heartbeat_count++; - if (heartbeat_count == 255) - { - update_file_size(); - heartbeat_count = 0; - printk("drawing\n"); - } - } - else - { - - } - } - if (valid) - { - 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; diff --git a/Friend/firmware/firmware_v1.0/src/usb.c b/Friend/firmware/firmware_v1.0/src/usb.c index 11b6f9eea..270ddd701 100644 --- a/Friend/firmware/firmware_v1.0/src/usb.c +++ b/Friend/firmware/firmware_v1.0/src/usb.c @@ -5,13 +5,11 @@ #include #include #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) { @@ -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: From 6b7ba47ead547a03bdd1ec8e7ac1b6459d225a2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?th=E1=BB=8Bnh?= Date: Wed, 4 Dec 2024 15:42:07 +0700 Subject: [PATCH 2/2] Fix device name, bump version to 2.0.7 --- .../firmware_v1.0/prj_xiao_ble_sense_devkitv2-adafruit.conf | 2 +- Friend/firmware/firmware_v1.0/src/transport.c | 2 +- app/lib/pages/home/firmware_update.dart | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Friend/firmware/firmware_v1.0/prj_xiao_ble_sense_devkitv2-adafruit.conf b/Friend/firmware/firmware_v1.0/prj_xiao_ble_sense_devkitv2-adafruit.conf index a21751e23..936ec8e7d 100644 --- a/Friend/firmware/firmware_v1.0/prj_xiao_ble_sense_devkitv2-adafruit.conf +++ b/Friend/firmware/firmware_v1.0/prj_xiao_ble_sense_devkitv2-adafruit.conf @@ -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" # diff --git a/Friend/firmware/firmware_v1.0/src/transport.c b/Friend/firmware/firmware_v1.0/src/transport.c index 28acd3c8f..e2de8bd33 100644 --- a/Friend/firmware/firmware_v1.0/src/transport.c +++ b/Friend/firmware/firmware_v1.0/src/transport.c @@ -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); diff --git a/app/lib/pages/home/firmware_update.dart b/app/lib/pages/home/firmware_update.dart index 2fe5f5ab9..705138d34 100644 --- a/app/lib/pages/home/firmware_update.dart +++ b/app/lib/pages/home/firmware_update.dart @@ -101,8 +101,8 @@ class _FirmwareUpdateState extends State 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),