diff options
Diffstat (limited to 'src/system_fsm')
| -rw-r--r-- | src/system_fsm/booting.cpp | 3 | ||||
| -rw-r--r-- | src/system_fsm/include/service_locator.hpp | 10 | ||||
| -rw-r--r-- | src/system_fsm/include/system_events.hpp | 5 | ||||
| -rw-r--r-- | src/system_fsm/include/system_fsm.hpp | 2 | ||||
| -rw-r--r-- | src/system_fsm/system_fsm.cpp | 5 |
5 files changed, 25 insertions, 0 deletions
diff --git a/src/system_fsm/booting.cpp b/src/system_fsm/booting.cpp index 940e10db..affd3ebc 100644 --- a/src/system_fsm/booting.cpp +++ b/src/system_fsm/booting.cpp @@ -5,9 +5,11 @@ */ #include "collation.hpp" +#include "haptics.hpp" #include "system_fsm.hpp" #include <stdint.h> +#include <memory> #include "assert.h" #include "esp_err.h" @@ -75,6 +77,7 @@ auto Booting::entry() -> void { std::unique_ptr<drivers::NvsStorage>(drivers::NvsStorage::OpenSync())); sServices->touchwheel( std::unique_ptr<drivers::TouchWheel>{drivers::TouchWheel::Create()}); + sServices->haptics(std::make_unique<drivers::Haptics>()); auto adc = drivers::AdcBattery::Create(); sServices->battery(std::make_unique<battery::Battery>( diff --git a/src/system_fsm/include/service_locator.hpp b/src/system_fsm/include/service_locator.hpp index 327d0c50..4aa57df0 100644 --- a/src/system_fsm/include/service_locator.hpp +++ b/src/system_fsm/include/service_locator.hpp @@ -13,6 +13,7 @@ #include "collation.hpp" #include "database.hpp" #include "gpios.hpp" +#include "haptics.hpp" #include "nvs.hpp" #include "samd.hpp" #include "storage.hpp" @@ -79,6 +80,14 @@ class ServiceLocator { touchwheel_ = std::move(i); } + auto haptics() -> drivers::Haptics& { + return *haptics_; + } + + auto haptics(std::unique_ptr<drivers::Haptics> i) { + haptics_ = std::move(i); + } + auto database() -> std::weak_ptr<database::Database> { return database_; } auto database(std::unique_ptr<database::Database> i) { @@ -130,6 +139,7 @@ class ServiceLocator { std::unique_ptr<drivers::Samd> samd_; std::unique_ptr<drivers::NvsStorage> nvs_; std::unique_ptr<drivers::TouchWheel> touchwheel_; + std::unique_ptr<drivers::Haptics> haptics_; std::unique_ptr<drivers::Bluetooth> bluetooth_; std::unique_ptr<audio::TrackQueue> queue_; diff --git a/src/system_fsm/include/system_events.hpp b/src/system_fsm/include/system_events.hpp index 4db9beb0..2722fa80 100644 --- a/src/system_fsm/include/system_events.hpp +++ b/src/system_fsm/include/system_events.hpp @@ -10,6 +10,7 @@ #include "battery.hpp" #include "database.hpp" +#include "haptics.hpp" #include "service_locator.hpp" #include "tinyfsm.hpp" @@ -55,6 +56,10 @@ struct BatteryStateChanged : tinyfsm::Event { struct BluetoothDevicesChanged : tinyfsm::Event {}; +struct HapticTrigger : tinyfsm::Event { + drivers::Haptics::Effect effect; +}; + namespace internal { struct GpioInterrupt : tinyfsm::Event {}; diff --git a/src/system_fsm/include/system_fsm.hpp b/src/system_fsm/include/system_fsm.hpp index 28448e5a..c9803bef 100644 --- a/src/system_fsm/include/system_fsm.hpp +++ b/src/system_fsm/include/system_fsm.hpp @@ -50,6 +50,8 @@ class SystemState : public tinyfsm::Fsm<SystemState> { void react(const internal::GpioInterrupt&); void react(const internal::SamdInterrupt&); + void react(const HapticTrigger&); + virtual void react(const DisplayReady&) {} virtual void react(const BootComplete&) {} virtual void react(const StorageMounted&) {} diff --git a/src/system_fsm/system_fsm.cpp b/src/system_fsm/system_fsm.cpp index 1e92cd62..31aec789 100644 --- a/src/system_fsm/system_fsm.cpp +++ b/src/system_fsm/system_fsm.cpp @@ -29,6 +29,11 @@ void SystemState::react(const FatalError& err) { } } +void SystemState::react(const HapticTrigger& trigger) { + auto& haptics = sServices->haptics(); + haptics.PlayWaveformEffect(trigger.effect); +} + void SystemState::react(const internal::GpioInterrupt&) { auto& gpios = sServices->gpios(); bool prev_key_lock = gpios.Get(drivers::Gpios::Pin::kKeyLock); |
