summaryrefslogtreecommitdiff
path: root/src/system_fsm
diff options
context:
space:
mode:
Diffstat (limited to 'src/system_fsm')
-rw-r--r--src/system_fsm/booting.cpp19
-rw-r--r--src/system_fsm/include/system_events.hpp2
2 files changed, 18 insertions, 3 deletions
diff --git a/src/system_fsm/booting.cpp b/src/system_fsm/booting.cpp
index 006ed395..28cd8cf6 100644
--- a/src/system_fsm/booting.cpp
+++ b/src/system_fsm/booting.cpp
@@ -11,6 +11,7 @@
#include "audio_fsm.hpp"
#include "battery.hpp"
#include "bluetooth.hpp"
+#include "bluetooth_types.hpp"
#include "core/lv_obj.h"
#include "display_init.hpp"
#include "esp_err.h"
@@ -41,6 +42,12 @@ namespace states {
static const char kTag[] = "BOOT";
+static auto bt_event_cb(drivers::bluetooth::Event ev) -> void {
+ if (ev == drivers::bluetooth::Event::kKnownDevicesChanged) {
+ events::Ui().Dispatch(BluetoothDevicesChanged{});
+ }
+}
+
auto Booting::entry() -> void {
ESP_LOGI(kTag, "beginning tangara boot");
sServices.reset(new ServiceLocator());
@@ -71,9 +78,15 @@ auto Booting::entry() -> void {
sServices->track_queue(std::make_unique<audio::TrackQueue>());
sServices->tag_parser(std::make_unique<database::TagParserImpl>());
- // ESP_LOGI(kTag, "starting bluetooth");
- // sBluetooth.reset(new drivers::Bluetooth(sNvs.get()));
- // sBluetooth->Enable();
+ ESP_LOGI(kTag, "init bluetooth");
+ sServices->bluetooth(std::make_unique<drivers::Bluetooth>(sServices->nvs()));
+ sServices->bluetooth().SetEventHandler(bt_event_cb);
+
+ if (sServices->nvs().OutputMode().get() ==
+ drivers::NvsStorage::Output::kBluetooth) {
+ ESP_LOGI(kTag, "enabling bluetooth");
+ sServices->bluetooth().Enable();
+ }
BootComplete ev{.services = sServices};
events::Audio().Dispatch(ev);
diff --git a/src/system_fsm/include/system_events.hpp b/src/system_fsm/include/system_events.hpp
index e22fe2ae..9cd75d4d 100644
--- a/src/system_fsm/include/system_events.hpp
+++ b/src/system_fsm/include/system_events.hpp
@@ -56,6 +56,8 @@ struct HasPhonesChanged : tinyfsm::Event {
struct ChargingStatusChanged : tinyfsm::Event {};
struct BatteryStateChanged : tinyfsm::Event {};
+struct BluetoothDevicesChanged : tinyfsm::Event {};
+
namespace internal {
struct GpioInterrupt : tinyfsm::Event {};